cpu.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * Copyright (C) 2014-2015 Stefan Roese <sr@denx.de>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <netdev.h>
  8. #include <asm/io.h>
  9. #include <asm/pl310.h>
  10. #include <asm/arch/cpu.h>
  11. #include <asm/arch/soc.h>
  12. #define DDR_BASE_CS_OFF(n) (0x0000 + ((n) << 3))
  13. #define DDR_SIZE_CS_OFF(n) (0x0004 + ((n) << 3))
  14. static struct mbus_win windows[] = {
  15. /* PCIE MEM address space */
  16. { DEFADR_PCI_MEM, 256 << 20, CPU_TARGET_PCIE13, CPU_ATTR_PCIE_MEM },
  17. /* PCIE IO address space */
  18. { DEFADR_PCI_IO, 64 << 10, CPU_TARGET_PCIE13, CPU_ATTR_PCIE_IO },
  19. /* SPI */
  20. { DEFADR_SPIF, 8 << 20, CPU_TARGET_DEVICEBUS_BOOTROM_SPI,
  21. CPU_ATTR_SPIFLASH },
  22. /* NOR */
  23. { DEFADR_BOOTROM, 8 << 20, CPU_TARGET_DEVICEBUS_BOOTROM_SPI,
  24. CPU_ATTR_BOOTROM },
  25. };
  26. void reset_cpu(unsigned long ignored)
  27. {
  28. struct mvebu_system_registers *reg =
  29. (struct mvebu_system_registers *)MVEBU_SYSTEM_REG_BASE;
  30. writel(readl(&reg->rstoutn_mask) | 1, &reg->rstoutn_mask);
  31. writel(readl(&reg->sys_soft_rst) | 1, &reg->sys_soft_rst);
  32. while (1)
  33. ;
  34. }
  35. int mvebu_soc_family(void)
  36. {
  37. u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
  38. if (devid == SOC_MV78460_ID)
  39. return MVEBU_SOC_AXP;
  40. if (devid == SOC_88F6810_ID || devid == SOC_88F6820_ID ||
  41. devid == SOC_88F6828_ID)
  42. return MVEBU_SOC_A38X;
  43. return MVEBU_SOC_UNKNOWN;
  44. }
  45. #if defined(CONFIG_DISPLAY_CPUINFO)
  46. int print_cpuinfo(void)
  47. {
  48. u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
  49. u8 revid = readl(MVEBU_REG_PCIE_REVID) & 0xff;
  50. puts("SoC: ");
  51. switch (devid) {
  52. case SOC_MV78460_ID:
  53. puts("MV78460-");
  54. break;
  55. case SOC_88F6810_ID:
  56. puts("MV88F6810-");
  57. break;
  58. case SOC_88F6820_ID:
  59. puts("MV88F6820-");
  60. break;
  61. case SOC_88F6828_ID:
  62. puts("MV88F6828-");
  63. break;
  64. default:
  65. puts("Unknown-");
  66. break;
  67. }
  68. if (mvebu_soc_family() == MVEBU_SOC_AXP) {
  69. switch (revid) {
  70. case 1:
  71. puts("A0\n");
  72. break;
  73. case 2:
  74. puts("B0\n");
  75. break;
  76. default:
  77. printf("?? (%x)\n", revid);
  78. break;
  79. }
  80. }
  81. if (mvebu_soc_family() == MVEBU_SOC_A38X) {
  82. switch (revid) {
  83. case MV_88F68XX_Z1_ID:
  84. puts("Z1\n");
  85. break;
  86. case MV_88F68XX_A0_ID:
  87. puts("A0\n");
  88. break;
  89. default:
  90. printf("?? (%x)\n", revid);
  91. break;
  92. }
  93. }
  94. return 0;
  95. }
  96. #endif /* CONFIG_DISPLAY_CPUINFO */
  97. /*
  98. * This function initialize Controller DRAM Fastpath windows.
  99. * It takes the CS size information from the 0x1500 scratch registers
  100. * and sets the correct windows sizes and base addresses accordingly.
  101. *
  102. * These values are set in the scratch registers by the Marvell
  103. * DDR3 training code, which is executed by the BootROM before the
  104. * main payload (U-Boot) is executed. This training code is currently
  105. * only available in the Marvell U-Boot version. It needs to be
  106. * ported to mainline U-Boot SPL at some point.
  107. */
  108. static void update_sdram_window_sizes(void)
  109. {
  110. u64 base = 0;
  111. u32 size, temp;
  112. int i;
  113. for (i = 0; i < SDRAM_MAX_CS; i++) {
  114. size = readl((MVEBU_SDRAM_SCRATCH + (i * 8))) & SDRAM_ADDR_MASK;
  115. if (size != 0) {
  116. size |= ~(SDRAM_ADDR_MASK);
  117. /* Set Base Address */
  118. temp = (base & 0xFF000000ll) | ((base >> 32) & 0xF);
  119. writel(temp, MVEBU_SDRAM_BASE + DDR_BASE_CS_OFF(i));
  120. /*
  121. * Check if out of max window size and resize
  122. * the window
  123. */
  124. temp = (readl(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i)) &
  125. ~(SDRAM_ADDR_MASK)) | 1;
  126. temp |= (size & SDRAM_ADDR_MASK);
  127. writel(temp, MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i));
  128. base += ((u64)size + 1);
  129. } else {
  130. /*
  131. * Disable window if not used, otherwise this
  132. * leads to overlapping enabled windows with
  133. * pretty strange results
  134. */
  135. clrbits_le32(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i), 1);
  136. }
  137. }
  138. }
  139. #ifdef CONFIG_ARCH_CPU_INIT
  140. static void set_cbar(u32 addr)
  141. {
  142. asm("mcr p15, 4, %0, c15, c0" : : "r" (addr));
  143. }
  144. int arch_cpu_init(void)
  145. {
  146. /* Linux expects the internal registers to be at 0xf1000000 */
  147. writel(SOC_REGS_PHY_BASE, INTREG_BASE_ADDR_REG);
  148. set_cbar(SOC_REGS_PHY_BASE + 0xC000);
  149. /*
  150. * We need to call mvebu_mbus_probe() before calling
  151. * update_sdram_window_sizes() as it disables all previously
  152. * configured mbus windows and then configures them as
  153. * required for U-Boot. Calling update_sdram_window_sizes()
  154. * without this configuration will not work, as the internal
  155. * registers can't be accessed reliably because of potenial
  156. * double mapping.
  157. * After updating the SDRAM access windows we need to call
  158. * mvebu_mbus_probe() again, as this now correctly configures
  159. * the SDRAM areas that are later used by the MVEBU drivers
  160. * (e.g. USB, NETA).
  161. */
  162. /*
  163. * First disable all windows
  164. */
  165. mvebu_mbus_probe(NULL, 0);
  166. if (mvebu_soc_family() == MVEBU_SOC_AXP) {
  167. /*
  168. * Now the SDRAM access windows can be reconfigured using
  169. * the information in the SDRAM scratch pad registers
  170. */
  171. update_sdram_window_sizes();
  172. }
  173. /*
  174. * Finally the mbus windows can be configured with the
  175. * updated SDRAM sizes
  176. */
  177. mvebu_mbus_probe(windows, ARRAY_SIZE(windows));
  178. return 0;
  179. }
  180. #endif /* CONFIG_ARCH_CPU_INIT */
  181. /*
  182. * SOC specific misc init
  183. */
  184. #if defined(CONFIG_ARCH_MISC_INIT)
  185. int arch_misc_init(void)
  186. {
  187. /* Nothing yet, perhaps we need something here later */
  188. return 0;
  189. }
  190. #endif /* CONFIG_ARCH_MISC_INIT */
  191. #ifdef CONFIG_MVNETA
  192. int cpu_eth_init(bd_t *bis)
  193. {
  194. u32 enet_base[] = { MVEBU_EGIGA0_BASE, MVEBU_EGIGA1_BASE,
  195. MVEBU_EGIGA2_BASE, MVEBU_EGIGA3_BASE };
  196. u8 phy_addr[] = CONFIG_PHY_ADDR;
  197. int i;
  198. /*
  199. * Only Armada XP supports all 4 ethernet interfaces. A38x has
  200. * slightly different base addresses for its 2-3 interfaces.
  201. */
  202. if (mvebu_soc_family() != MVEBU_SOC_AXP) {
  203. enet_base[1] = MVEBU_EGIGA2_BASE;
  204. enet_base[2] = MVEBU_EGIGA3_BASE;
  205. }
  206. for (i = 0; i < ARRAY_SIZE(phy_addr); i++)
  207. mvneta_initialize(bis, enet_base[i], i, phy_addr[i]);
  208. return 0;
  209. }
  210. #endif
  211. #ifndef CONFIG_SYS_DCACHE_OFF
  212. void enable_caches(void)
  213. {
  214. struct pl310_regs *const pl310 =
  215. (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
  216. /* First disable L2 cache - may still be enable from BootROM */
  217. if (mvebu_soc_family() == MVEBU_SOC_A38X)
  218. clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
  219. /* Avoid problem with e.g. neta ethernet driver */
  220. invalidate_dcache_all();
  221. /* Enable D-cache. I-cache is already enabled in start.S */
  222. dcache_enable();
  223. }
  224. #endif