board-v7.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Device Tree support for Armada 370 and XP platforms.
  4. *
  5. * Copyright (C) 2012 Marvell
  6. *
  7. * Lior Amsalem <[email protected]>
  8. * Gregory CLEMENT <[email protected]>
  9. * Thomas Petazzoni <[email protected]>
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/of_address.h>
  14. #include <linux/of_fdt.h>
  15. #include <linux/io.h>
  16. #include <linux/clocksource.h>
  17. #include <linux/dma-mapping.h>
  18. #include <linux/memblock.h>
  19. #include <linux/mbus.h>
  20. #include <linux/slab.h>
  21. #include <linux/irqchip.h>
  22. #include <asm/hardware/cache-l2x0.h>
  23. #include <asm/mach/arch.h>
  24. #include <asm/mach/map.h>
  25. #include <asm/mach/time.h>
  26. #include <asm/smp_scu.h>
  27. #include "armada-370-xp.h"
  28. #include "common.h"
  29. #include "coherency.h"
  30. #include "mvebu-soc-id.h"
  31. static void __iomem *scu_base;
  32. /*
  33. * Enables the SCU when available. Obviously, this is only useful on
  34. * Cortex-A based SOCs, not on PJ4B based ones.
  35. */
  36. static void __init mvebu_scu_enable(void)
  37. {
  38. struct device_node *np =
  39. of_find_compatible_node(NULL, NULL, "arm,cortex-a9-scu");
  40. if (np) {
  41. scu_base = of_iomap(np, 0);
  42. scu_enable(scu_base);
  43. of_node_put(np);
  44. }
  45. }
  46. void __iomem *mvebu_get_scu_base(void)
  47. {
  48. return scu_base;
  49. }
  50. /*
  51. * When returning from suspend, the platform goes through the
  52. * bootloader, which executes its DDR3 training code. This code has
  53. * the unfortunate idea of using the first 10 KB of each DRAM bank to
  54. * exercise the RAM and calculate the optimal timings. Therefore, this
  55. * area of RAM is overwritten, and shouldn't be used by the kernel if
  56. * suspend/resume is supported.
  57. */
  58. #ifdef CONFIG_SUSPEND
  59. #define MVEBU_DDR_TRAINING_AREA_SZ (10 * SZ_1K)
  60. static int __init mvebu_scan_mem(unsigned long node, const char *uname,
  61. int depth, void *data)
  62. {
  63. const char *type = of_get_flat_dt_prop(node, "device_type", NULL);
  64. const __be32 *reg, *endp;
  65. int l;
  66. if (type == NULL || strcmp(type, "memory"))
  67. return 0;
  68. reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l);
  69. if (reg == NULL)
  70. reg = of_get_flat_dt_prop(node, "reg", &l);
  71. if (reg == NULL)
  72. return 0;
  73. endp = reg + (l / sizeof(__be32));
  74. while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) {
  75. u64 base, size;
  76. base = dt_mem_next_cell(dt_root_addr_cells, &reg);
  77. size = dt_mem_next_cell(dt_root_size_cells, &reg);
  78. memblock_reserve(base, MVEBU_DDR_TRAINING_AREA_SZ);
  79. }
  80. return 0;
  81. }
  82. static void __init mvebu_memblock_reserve(void)
  83. {
  84. of_scan_flat_dt(mvebu_scan_mem, NULL);
  85. }
  86. #else
  87. static void __init mvebu_memblock_reserve(void) {}
  88. #endif
  89. static void __init mvebu_init_irq(void)
  90. {
  91. irqchip_init();
  92. mvebu_scu_enable();
  93. coherency_init();
  94. BUG_ON(mvebu_mbus_dt_init(coherency_available()));
  95. }
  96. static void __init i2c_quirk(void)
  97. {
  98. struct device_node *np;
  99. u32 dev, rev;
  100. /*
  101. * Only revisons more recent than A0 support the offload
  102. * mechanism. We can exit only if we are sure that we can
  103. * get the SoC revision and it is more recent than A0.
  104. */
  105. if (mvebu_get_soc_id(&dev, &rev) == 0 && rev > MV78XX0_A0_REV)
  106. return;
  107. for_each_compatible_node(np, NULL, "marvell,mv78230-i2c") {
  108. struct property *new_compat;
  109. new_compat = kzalloc(sizeof(*new_compat), GFP_KERNEL);
  110. new_compat->name = kstrdup("compatible", GFP_KERNEL);
  111. new_compat->length = sizeof("marvell,mv78230-a0-i2c");
  112. new_compat->value = kstrdup("marvell,mv78230-a0-i2c",
  113. GFP_KERNEL);
  114. of_update_property(np, new_compat);
  115. }
  116. }
  117. static void __init mvebu_dt_init(void)
  118. {
  119. if (of_machine_is_compatible("marvell,armadaxp"))
  120. i2c_quirk();
  121. }
  122. static void __init armada_370_xp_dt_fixup(void)
  123. {
  124. #ifdef CONFIG_SMP
  125. smp_set_ops(smp_ops(armada_xp_smp_ops));
  126. #endif
  127. }
  128. static const char * const armada_370_xp_dt_compat[] __initconst = {
  129. "marvell,armada-370-xp",
  130. NULL,
  131. };
  132. DT_MACHINE_START(ARMADA_370_XP_DT, "Marvell Armada 370/XP (Device Tree)")
  133. .l2c_aux_val = 0,
  134. .l2c_aux_mask = ~0,
  135. .init_machine = mvebu_dt_init,
  136. .init_irq = mvebu_init_irq,
  137. .restart = mvebu_restart,
  138. .reserve = mvebu_memblock_reserve,
  139. .dt_compat = armada_370_xp_dt_compat,
  140. .dt_fixup = armada_370_xp_dt_fixup,
  141. MACHINE_END
  142. static const char * const armada_375_dt_compat[] __initconst = {
  143. "marvell,armada375",
  144. NULL,
  145. };
  146. DT_MACHINE_START(ARMADA_375_DT, "Marvell Armada 375 (Device Tree)")
  147. .l2c_aux_val = 0,
  148. .l2c_aux_mask = ~0,
  149. .init_irq = mvebu_init_irq,
  150. .init_machine = mvebu_dt_init,
  151. .restart = mvebu_restart,
  152. .dt_compat = armada_375_dt_compat,
  153. MACHINE_END
  154. static const char * const armada_38x_dt_compat[] __initconst = {
  155. "marvell,armada380",
  156. "marvell,armada385",
  157. NULL,
  158. };
  159. DT_MACHINE_START(ARMADA_38X_DT, "Marvell Armada 380/385 (Device Tree)")
  160. .l2c_aux_val = 0,
  161. .l2c_aux_mask = ~0,
  162. .init_irq = mvebu_init_irq,
  163. .restart = mvebu_restart,
  164. .dt_compat = armada_38x_dt_compat,
  165. MACHINE_END
  166. static const char * const armada_39x_dt_compat[] __initconst = {
  167. "marvell,armada390",
  168. "marvell,armada398",
  169. NULL,
  170. };
  171. DT_MACHINE_START(ARMADA_39X_DT, "Marvell Armada 39x (Device Tree)")
  172. .l2c_aux_val = 0,
  173. .l2c_aux_mask = ~0,
  174. .init_irq = mvebu_init_irq,
  175. .restart = mvebu_restart,
  176. .dt_compat = armada_39x_dt_compat,
  177. MACHINE_END