highbank.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * Copyright 2010-2011 Calxeda, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <linux/clk.h>
  17. #include <linux/clkdev.h>
  18. #include <linux/clocksource.h>
  19. #include <linux/dma-mapping.h>
  20. #include <linux/input.h>
  21. #include <linux/io.h>
  22. #include <linux/irqchip.h>
  23. #include <linux/pl320-ipc.h>
  24. #include <linux/of.h>
  25. #include <linux/of_irq.h>
  26. #include <linux/of_address.h>
  27. #include <linux/reboot.h>
  28. #include <linux/amba/bus.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/psci.h>
  31. #include <asm/hardware/cache-l2x0.h>
  32. #include <asm/mach/arch.h>
  33. #include <asm/mach/map.h>
  34. #include "core.h"
  35. #include "sysregs.h"
  36. void __iomem *sregs_base;
  37. void __iomem *scu_base_addr;
  38. static void __init highbank_scu_map_io(void)
  39. {
  40. unsigned long base;
  41. /* Get SCU base */
  42. asm("mrc p15, 4, %0, c15, c0, 0" : "=r" (base));
  43. scu_base_addr = ioremap(base, SZ_4K);
  44. }
  45. static void highbank_l2c310_write_sec(unsigned long val, unsigned reg)
  46. {
  47. if (reg == L2X0_CTRL)
  48. highbank_smc1(0x102, val);
  49. else
  50. WARN_ONCE(1, "Highbank L2C310: ignoring write to reg 0x%x\n",
  51. reg);
  52. }
  53. static void __init highbank_init_irq(void)
  54. {
  55. irqchip_init();
  56. if (of_find_compatible_node(NULL, NULL, "arm,cortex-a9"))
  57. highbank_scu_map_io();
  58. }
  59. static void highbank_power_off(void)
  60. {
  61. highbank_set_pwr_shutdown();
  62. while (1)
  63. cpu_do_idle();
  64. }
  65. static int highbank_platform_notifier(struct notifier_block *nb,
  66. unsigned long event, void *__dev)
  67. {
  68. struct resource *res;
  69. int reg = -1;
  70. u32 val;
  71. struct device *dev = __dev;
  72. if (event != BUS_NOTIFY_ADD_DEVICE)
  73. return NOTIFY_DONE;
  74. if (of_device_is_compatible(dev->of_node, "calxeda,hb-ahci"))
  75. reg = 0xc;
  76. else if (of_device_is_compatible(dev->of_node, "calxeda,hb-sdhci"))
  77. reg = 0x18;
  78. else if (of_device_is_compatible(dev->of_node, "arm,pl330"))
  79. reg = 0x20;
  80. else if (of_device_is_compatible(dev->of_node, "calxeda,hb-xgmac")) {
  81. res = platform_get_resource(to_platform_device(dev),
  82. IORESOURCE_MEM, 0);
  83. if (res) {
  84. if (res->start == 0xfff50000)
  85. reg = 0;
  86. else if (res->start == 0xfff51000)
  87. reg = 4;
  88. }
  89. }
  90. if (reg < 0)
  91. return NOTIFY_DONE;
  92. if (of_property_read_bool(dev->of_node, "dma-coherent")) {
  93. val = readl(sregs_base + reg);
  94. writel(val | 0xff01, sregs_base + reg);
  95. set_dma_ops(dev, &arm_coherent_dma_ops);
  96. }
  97. return NOTIFY_OK;
  98. }
  99. static struct notifier_block highbank_amba_nb = {
  100. .notifier_call = highbank_platform_notifier,
  101. };
  102. static struct notifier_block highbank_platform_nb = {
  103. .notifier_call = highbank_platform_notifier,
  104. };
  105. static struct platform_device highbank_cpuidle_device = {
  106. .name = "cpuidle-calxeda",
  107. };
  108. static int hb_keys_notifier(struct notifier_block *nb, unsigned long event, void *data)
  109. {
  110. u32 key = *(u32 *)data;
  111. if (event != 0x1000)
  112. return 0;
  113. if (key == KEY_POWER)
  114. orderly_poweroff(false);
  115. else if (key == 0xffff)
  116. ctrl_alt_del();
  117. return 0;
  118. }
  119. static struct notifier_block hb_keys_nb = {
  120. .notifier_call = hb_keys_notifier,
  121. };
  122. static void __init highbank_init(void)
  123. {
  124. struct device_node *np;
  125. /* Map system registers */
  126. np = of_find_compatible_node(NULL, NULL, "calxeda,hb-sregs");
  127. sregs_base = of_iomap(np, 0);
  128. WARN_ON(!sregs_base);
  129. pm_power_off = highbank_power_off;
  130. highbank_pm_init();
  131. bus_register_notifier(&platform_bus_type, &highbank_platform_nb);
  132. bus_register_notifier(&amba_bustype, &highbank_amba_nb);
  133. pl320_ipc_register_notifier(&hb_keys_nb);
  134. if (psci_ops.cpu_suspend)
  135. platform_device_register(&highbank_cpuidle_device);
  136. }
  137. static const char *const highbank_match[] __initconst = {
  138. "calxeda,highbank",
  139. "calxeda,ecx-2000",
  140. NULL,
  141. };
  142. DT_MACHINE_START(HIGHBANK, "Highbank")
  143. #if defined(CONFIG_ZONE_DMA) && defined(CONFIG_ARM_LPAE)
  144. .dma_zone_size = (4ULL * SZ_1G),
  145. #endif
  146. .l2c_aux_val = 0,
  147. .l2c_aux_mask = ~0,
  148. .l2c_write_sec = highbank_l2c310_write_sec,
  149. .init_irq = highbank_init_irq,
  150. .init_machine = highbank_init,
  151. .dt_compat = highbank_match,
  152. .restart = highbank_restart,
  153. MACHINE_END