cpu.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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 <ahci.h>
  9. #include <linux/mbus.h>
  10. #include <asm/io.h>
  11. #include <asm/pl310.h>
  12. #include <asm/arch/cpu.h>
  13. #include <asm/arch/soc.h>
  14. #include <sdhci.h>
  15. #define DDR_BASE_CS_OFF(n) (0x0000 + ((n) << 3))
  16. #define DDR_SIZE_CS_OFF(n) (0x0004 + ((n) << 3))
  17. static struct mbus_win windows[] = {
  18. /* SPI */
  19. { MBUS_SPI_BASE, MBUS_SPI_SIZE,
  20. CPU_TARGET_DEVICEBUS_BOOTROM_SPI, CPU_ATTR_SPIFLASH },
  21. /* NOR */
  22. { MBUS_BOOTROM_BASE, MBUS_BOOTROM_SIZE,
  23. CPU_TARGET_DEVICEBUS_BOOTROM_SPI, CPU_ATTR_BOOTROM },
  24. };
  25. void reset_cpu(unsigned long ignored)
  26. {
  27. struct mvebu_system_registers *reg =
  28. (struct mvebu_system_registers *)MVEBU_SYSTEM_REG_BASE;
  29. writel(readl(&reg->rstoutn_mask) | 1, &reg->rstoutn_mask);
  30. writel(readl(&reg->sys_soft_rst) | 1, &reg->sys_soft_rst);
  31. while (1)
  32. ;
  33. }
  34. int mvebu_soc_family(void)
  35. {
  36. u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
  37. if (devid == SOC_MV78460_ID)
  38. return MVEBU_SOC_AXP;
  39. if (devid == SOC_88F6810_ID || devid == SOC_88F6820_ID ||
  40. devid == SOC_88F6828_ID)
  41. return MVEBU_SOC_A38X;
  42. return MVEBU_SOC_UNKNOWN;
  43. }
  44. #if defined(CONFIG_DISPLAY_CPUINFO)
  45. int print_cpuinfo(void)
  46. {
  47. u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
  48. u8 revid = readl(MVEBU_REG_PCIE_REVID) & 0xff;
  49. puts("SoC: ");
  50. switch (devid) {
  51. case SOC_MV78460_ID:
  52. puts("MV78460-");
  53. break;
  54. case SOC_88F6810_ID:
  55. puts("MV88F6810-");
  56. break;
  57. case SOC_88F6820_ID:
  58. puts("MV88F6820-");
  59. break;
  60. case SOC_88F6828_ID:
  61. puts("MV88F6828-");
  62. break;
  63. default:
  64. puts("Unknown-");
  65. break;
  66. }
  67. if (mvebu_soc_family() == MVEBU_SOC_AXP) {
  68. switch (revid) {
  69. case 1:
  70. puts("A0\n");
  71. break;
  72. case 2:
  73. puts("B0\n");
  74. break;
  75. default:
  76. printf("?? (%x)\n", revid);
  77. break;
  78. }
  79. }
  80. if (mvebu_soc_family() == MVEBU_SOC_A38X) {
  81. switch (revid) {
  82. case MV_88F68XX_Z1_ID:
  83. puts("Z1\n");
  84. break;
  85. case MV_88F68XX_A0_ID:
  86. puts("A0\n");
  87. break;
  88. default:
  89. printf("?? (%x)\n", revid);
  90. break;
  91. }
  92. }
  93. return 0;
  94. }
  95. #endif /* CONFIG_DISPLAY_CPUINFO */
  96. /*
  97. * This function initialize Controller DRAM Fastpath windows.
  98. * It takes the CS size information from the 0x1500 scratch registers
  99. * and sets the correct windows sizes and base addresses accordingly.
  100. *
  101. * These values are set in the scratch registers by the Marvell
  102. * DDR3 training code, which is executed by the BootROM before the
  103. * main payload (U-Boot) is executed. This training code is currently
  104. * only available in the Marvell U-Boot version. It needs to be
  105. * ported to mainline U-Boot SPL at some point.
  106. */
  107. static void update_sdram_window_sizes(void)
  108. {
  109. u64 base = 0;
  110. u32 size, temp;
  111. int i;
  112. for (i = 0; i < SDRAM_MAX_CS; i++) {
  113. size = readl((MVEBU_SDRAM_SCRATCH + (i * 8))) & SDRAM_ADDR_MASK;
  114. if (size != 0) {
  115. size |= ~(SDRAM_ADDR_MASK);
  116. /* Set Base Address */
  117. temp = (base & 0xFF000000ll) | ((base >> 32) & 0xF);
  118. writel(temp, MVEBU_SDRAM_BASE + DDR_BASE_CS_OFF(i));
  119. /*
  120. * Check if out of max window size and resize
  121. * the window
  122. */
  123. temp = (readl(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i)) &
  124. ~(SDRAM_ADDR_MASK)) | 1;
  125. temp |= (size & SDRAM_ADDR_MASK);
  126. writel(temp, MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i));
  127. base += ((u64)size + 1);
  128. } else {
  129. /*
  130. * Disable window if not used, otherwise this
  131. * leads to overlapping enabled windows with
  132. * pretty strange results
  133. */
  134. clrbits_le32(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i), 1);
  135. }
  136. }
  137. }
  138. void mmu_disable(void)
  139. {
  140. asm volatile(
  141. "mrc p15, 0, r0, c1, c0, 0\n"
  142. "bic r0, #1\n"
  143. "mcr p15, 0, r0, c1, c0, 0\n");
  144. }
  145. #ifdef CONFIG_ARCH_CPU_INIT
  146. static void set_cbar(u32 addr)
  147. {
  148. asm("mcr p15, 4, %0, c15, c0" : : "r" (addr));
  149. }
  150. #define MV_USB_PHY_BASE (MVEBU_AXP_USB_BASE + 0x800)
  151. #define MV_USB_PHY_PLL_REG(reg) (MV_USB_PHY_BASE | (((reg) & 0xF) << 2))
  152. #define MV_USB_X3_BASE(addr) (MVEBU_AXP_USB_BASE | BIT(11) | \
  153. (((addr) & 0xF) << 6))
  154. #define MV_USB_X3_PHY_CHANNEL(dev, reg) (MV_USB_X3_BASE((dev) + 1) | \
  155. (((reg) & 0xF) << 2))
  156. static void setup_usb_phys(void)
  157. {
  158. int dev;
  159. /*
  160. * USB PLL init
  161. */
  162. /* Setup PLL frequency */
  163. /* USB REF frequency = 25 MHz */
  164. clrsetbits_le32(MV_USB_PHY_PLL_REG(1), 0x3ff, 0x605);
  165. /* Power up PLL and PHY channel */
  166. clrsetbits_le32(MV_USB_PHY_PLL_REG(2), 0, BIT(9));
  167. /* Assert VCOCAL_START */
  168. clrsetbits_le32(MV_USB_PHY_PLL_REG(1), 0, BIT(21));
  169. mdelay(1);
  170. /*
  171. * USB PHY init (change from defaults) specific for 40nm (78X30 78X60)
  172. */
  173. for (dev = 0; dev < 3; dev++) {
  174. clrsetbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 3), 0, BIT(15));
  175. /* Assert REG_RCAL_START in channel REG 1 */
  176. clrsetbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), 0, BIT(12));
  177. udelay(40);
  178. clrsetbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12), 0);
  179. }
  180. }
  181. int arch_cpu_init(void)
  182. {
  183. #ifndef CONFIG_SPL_BUILD
  184. if (mvebu_soc_family() == MVEBU_SOC_A38X) {
  185. struct pl310_regs *const pl310 =
  186. (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
  187. /*
  188. * Only with disabled MMU its possible to switch the base
  189. * register address on Armada 38x. Without this the SDRAM
  190. * located at >= 0x4000.0000 is also not accessible, as its
  191. * still locked to cache.
  192. *
  193. * So to fully release / unlock this area from cache, we need
  194. * to first flush all caches, then disable the MMU and
  195. * disable the L2 cache.
  196. */
  197. icache_disable();
  198. dcache_disable();
  199. mmu_disable();
  200. clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
  201. }
  202. #endif
  203. /* Linux expects the internal registers to be at 0xf1000000 */
  204. writel(SOC_REGS_PHY_BASE, INTREG_BASE_ADDR_REG);
  205. set_cbar(SOC_REGS_PHY_BASE + 0xC000);
  206. /*
  207. * We need to call mvebu_mbus_probe() before calling
  208. * update_sdram_window_sizes() as it disables all previously
  209. * configured mbus windows and then configures them as
  210. * required for U-Boot. Calling update_sdram_window_sizes()
  211. * without this configuration will not work, as the internal
  212. * registers can't be accessed reliably because of potenial
  213. * double mapping.
  214. * After updating the SDRAM access windows we need to call
  215. * mvebu_mbus_probe() again, as this now correctly configures
  216. * the SDRAM areas that are later used by the MVEBU drivers
  217. * (e.g. USB, NETA).
  218. */
  219. /*
  220. * First disable all windows
  221. */
  222. mvebu_mbus_probe(NULL, 0);
  223. if (mvebu_soc_family() == MVEBU_SOC_AXP) {
  224. /*
  225. * Now the SDRAM access windows can be reconfigured using
  226. * the information in the SDRAM scratch pad registers
  227. */
  228. update_sdram_window_sizes();
  229. }
  230. /*
  231. * Finally the mbus windows can be configured with the
  232. * updated SDRAM sizes
  233. */
  234. mvebu_mbus_probe(windows, ARRAY_SIZE(windows));
  235. if (mvebu_soc_family() == MVEBU_SOC_AXP) {
  236. /* Enable GBE0, GBE1, LCD and NFC PUP */
  237. clrsetbits_le32(ARMADA_XP_PUP_ENABLE, 0,
  238. GE0_PUP_EN | GE1_PUP_EN | LCD_PUP_EN |
  239. NAND_PUP_EN | SPI_PUP_EN);
  240. /* Configure USB PLL and PHYs on AXP */
  241. setup_usb_phys();
  242. }
  243. /* Enable NAND and NAND arbiter */
  244. clrsetbits_le32(MVEBU_SOC_DEV_MUX_REG, 0, NAND_EN | NAND_ARBITER_EN);
  245. /* Disable MBUS error propagation */
  246. clrsetbits_le32(SOC_COHERENCY_FABRIC_CTRL_REG, MBUS_ERR_PROP_EN, 0);
  247. return 0;
  248. }
  249. #endif /* CONFIG_ARCH_CPU_INIT */
  250. u32 mvebu_get_nand_clock(void)
  251. {
  252. return CONFIG_SYS_MVEBU_PLL_CLOCK /
  253. ((readl(MVEBU_CORE_DIV_CLK_CTRL(1)) &
  254. NAND_ECC_DIVCKL_RATIO_MASK) >> NAND_ECC_DIVCKL_RATIO_OFFS);
  255. }
  256. /*
  257. * SOC specific misc init
  258. */
  259. #if defined(CONFIG_ARCH_MISC_INIT)
  260. int arch_misc_init(void)
  261. {
  262. /* Nothing yet, perhaps we need something here later */
  263. return 0;
  264. }
  265. #endif /* CONFIG_ARCH_MISC_INIT */
  266. #ifdef CONFIG_MVNETA
  267. int cpu_eth_init(bd_t *bis)
  268. {
  269. u32 enet_base[] = { MVEBU_EGIGA0_BASE, MVEBU_EGIGA1_BASE,
  270. MVEBU_EGIGA2_BASE, MVEBU_EGIGA3_BASE };
  271. u8 phy_addr[] = CONFIG_PHY_ADDR;
  272. int i;
  273. /*
  274. * Only Armada XP supports all 4 ethernet interfaces. A38x has
  275. * slightly different base addresses for its 2-3 interfaces.
  276. */
  277. if (mvebu_soc_family() != MVEBU_SOC_AXP) {
  278. enet_base[1] = MVEBU_EGIGA2_BASE;
  279. enet_base[2] = MVEBU_EGIGA3_BASE;
  280. }
  281. for (i = 0; i < ARRAY_SIZE(phy_addr); i++)
  282. mvneta_initialize(bis, enet_base[i], i, phy_addr[i]);
  283. return 0;
  284. }
  285. #endif
  286. #ifdef CONFIG_MV_SDHCI
  287. int board_mmc_init(bd_t *bis)
  288. {
  289. mv_sdh_init(MVEBU_SDIO_BASE, 0, 0,
  290. SDHCI_QUIRK_32BIT_DMA_ADDR | SDHCI_QUIRK_WAIT_SEND_CMD);
  291. return 0;
  292. }
  293. #endif
  294. #ifdef CONFIG_SCSI_AHCI_PLAT
  295. #define AHCI_VENDOR_SPECIFIC_0_ADDR 0xa0
  296. #define AHCI_VENDOR_SPECIFIC_0_DATA 0xa4
  297. #define AHCI_WINDOW_CTRL(win) (0x60 + ((win) << 4))
  298. #define AHCI_WINDOW_BASE(win) (0x64 + ((win) << 4))
  299. #define AHCI_WINDOW_SIZE(win) (0x68 + ((win) << 4))
  300. static void ahci_mvebu_mbus_config(void __iomem *base)
  301. {
  302. const struct mbus_dram_target_info *dram;
  303. int i;
  304. dram = mvebu_mbus_dram_info();
  305. for (i = 0; i < 4; i++) {
  306. writel(0, base + AHCI_WINDOW_CTRL(i));
  307. writel(0, base + AHCI_WINDOW_BASE(i));
  308. writel(0, base + AHCI_WINDOW_SIZE(i));
  309. }
  310. for (i = 0; i < dram->num_cs; i++) {
  311. const struct mbus_dram_window *cs = dram->cs + i;
  312. writel((cs->mbus_attr << 8) |
  313. (dram->mbus_dram_target_id << 4) | 1,
  314. base + AHCI_WINDOW_CTRL(i));
  315. writel(cs->base >> 16, base + AHCI_WINDOW_BASE(i));
  316. writel(((cs->size - 1) & 0xffff0000),
  317. base + AHCI_WINDOW_SIZE(i));
  318. }
  319. }
  320. static void ahci_mvebu_regret_option(void __iomem *base)
  321. {
  322. /*
  323. * Enable the regret bit to allow the SATA unit to regret a
  324. * request that didn't receive an acknowlegde and avoid a
  325. * deadlock
  326. */
  327. writel(0x4, base + AHCI_VENDOR_SPECIFIC_0_ADDR);
  328. writel(0x80, base + AHCI_VENDOR_SPECIFIC_0_DATA);
  329. }
  330. void scsi_init(void)
  331. {
  332. printf("MVEBU SATA INIT\n");
  333. ahci_mvebu_mbus_config((void __iomem *)MVEBU_SATA0_BASE);
  334. ahci_mvebu_regret_option((void __iomem *)MVEBU_SATA0_BASE);
  335. ahci_init((void __iomem *)MVEBU_SATA0_BASE);
  336. }
  337. #endif
  338. #ifndef CONFIG_SYS_DCACHE_OFF
  339. void enable_caches(void)
  340. {
  341. struct pl310_regs *const pl310 =
  342. (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
  343. /* First disable L2 cache - may still be enable from BootROM */
  344. if (mvebu_soc_family() == MVEBU_SOC_A38X)
  345. clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
  346. /* Avoid problem with e.g. neta ethernet driver */
  347. invalidate_dcache_all();
  348. /* Enable D-cache. I-cache is already enabled in start.S */
  349. dcache_enable();
  350. }
  351. #endif