highbank.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright 2010-2011 Calxeda, Inc.
  4. */
  5. #include <linux/clk.h>
  6. #include <linux/clkdev.h>
  7. #include <linux/clocksource.h>
  8. #include <linux/dma-map-ops.h>
  9. #include <linux/input.h>
  10. #include <linux/io.h>
  11. #include <linux/irqchip.h>
  12. #include <linux/pl320-ipc.h>
  13. #include <linux/of.h>
  14. #include <linux/of_irq.h>
  15. #include <linux/of_address.h>
  16. #include <linux/reboot.h>
  17. #include <linux/amba/bus.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/psci.h>
  20. #include <asm/hardware/cache-l2x0.h>
  21. #include <asm/mach/arch.h>
  22. #include <asm/mach/map.h>
  23. #include "core.h"
  24. #include "sysregs.h"
  25. void __iomem *sregs_base;
  26. void __iomem *scu_base_addr;
  27. static void __init highbank_scu_map_io(void)
  28. {
  29. unsigned long base;
  30. /* Get SCU base */
  31. asm("mrc p15, 4, %0, c15, c0, 0" : "=r" (base));
  32. scu_base_addr = ioremap(base, SZ_4K);
  33. }
  34. static void highbank_l2c310_write_sec(unsigned long val, unsigned reg)
  35. {
  36. if (reg == L2X0_CTRL)
  37. highbank_smc1(0x102, val);
  38. else
  39. WARN_ONCE(1, "Highbank L2C310: ignoring write to reg 0x%x\n",
  40. reg);
  41. }
  42. static void __init highbank_init_irq(void)
  43. {
  44. irqchip_init();
  45. if (of_find_compatible_node(NULL, NULL, "arm,cortex-a9"))
  46. highbank_scu_map_io();
  47. }
  48. static void highbank_power_off(void)
  49. {
  50. highbank_set_pwr_shutdown();
  51. while (1)
  52. cpu_do_idle();
  53. }
  54. static int highbank_platform_notifier(struct notifier_block *nb,
  55. unsigned long event, void *__dev)
  56. {
  57. struct resource *res;
  58. int reg = -1;
  59. u32 val;
  60. struct device *dev = __dev;
  61. if (event != BUS_NOTIFY_ADD_DEVICE)
  62. return NOTIFY_DONE;
  63. if (of_device_is_compatible(dev->of_node, "calxeda,hb-ahci"))
  64. reg = 0xc;
  65. else if (of_device_is_compatible(dev->of_node, "calxeda,hb-sdhci"))
  66. reg = 0x18;
  67. else if (of_device_is_compatible(dev->of_node, "arm,pl330"))
  68. reg = 0x20;
  69. else if (of_device_is_compatible(dev->of_node, "calxeda,hb-xgmac")) {
  70. res = platform_get_resource(to_platform_device(dev),
  71. IORESOURCE_MEM, 0);
  72. if (res) {
  73. if (res->start == 0xfff50000)
  74. reg = 0;
  75. else if (res->start == 0xfff51000)
  76. reg = 4;
  77. }
  78. }
  79. if (reg < 0)
  80. return NOTIFY_DONE;
  81. if (of_property_read_bool(dev->of_node, "dma-coherent")) {
  82. val = readl(sregs_base + reg);
  83. writel(val | 0xff01, sregs_base + reg);
  84. dev->dma_coherent = true;
  85. }
  86. return NOTIFY_OK;
  87. }
  88. static struct notifier_block highbank_amba_nb = {
  89. .notifier_call = highbank_platform_notifier,
  90. };
  91. static struct notifier_block highbank_platform_nb = {
  92. .notifier_call = highbank_platform_notifier,
  93. };
  94. static struct platform_device highbank_cpuidle_device = {
  95. .name = "cpuidle-calxeda",
  96. };
  97. static int hb_keys_notifier(struct notifier_block *nb, unsigned long event, void *data)
  98. {
  99. u32 key = *(u32 *)data;
  100. if (event != 0x1000)
  101. return 0;
  102. if (key == KEY_POWER)
  103. orderly_poweroff(false);
  104. else if (key == 0xffff)
  105. ctrl_alt_del();
  106. return 0;
  107. }
  108. static struct notifier_block hb_keys_nb = {
  109. .notifier_call = hb_keys_notifier,
  110. };
  111. static void __init highbank_init(void)
  112. {
  113. struct device_node *np;
  114. /* Map system registers */
  115. np = of_find_compatible_node(NULL, NULL, "calxeda,hb-sregs");
  116. sregs_base = of_iomap(np, 0);
  117. WARN_ON(!sregs_base);
  118. pm_power_off = highbank_power_off;
  119. highbank_pm_init();
  120. bus_register_notifier(&platform_bus_type, &highbank_platform_nb);
  121. bus_register_notifier(&amba_bustype, &highbank_amba_nb);
  122. pl320_ipc_register_notifier(&hb_keys_nb);
  123. if (psci_ops.cpu_suspend)
  124. platform_device_register(&highbank_cpuidle_device);
  125. }
  126. static const char *const highbank_match[] __initconst = {
  127. "calxeda,highbank",
  128. "calxeda,ecx-2000",
  129. NULL,
  130. };
  131. DT_MACHINE_START(HIGHBANK, "Highbank")
  132. #if defined(CONFIG_ZONE_DMA) && defined(CONFIG_ARM_LPAE)
  133. .dma_zone_size = (4ULL * SZ_1G),
  134. #endif
  135. .l2c_aux_val = 0,
  136. .l2c_aux_mask = ~0,
  137. .l2c_write_sec = highbank_l2c310_write_sec,
  138. .init_irq = highbank_init_irq,
  139. .init_machine = highbank_init,
  140. .dt_compat = highbank_match,
  141. .restart = highbank_restart,
  142. MACHINE_END