cpu.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. /*
  2. * Copyright (C) 2014-2016 Stefan Roese <sr@denx.de>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <ahci.h>
  8. #include <linux/mbus.h>
  9. #include <asm/io.h>
  10. #include <asm/pl310.h>
  11. #include <asm/arch/cpu.h>
  12. #include <asm/arch/soc.h>
  13. #include <sdhci.h>
  14. #define DDR_BASE_CS_OFF(n) (0x0000 + ((n) << 3))
  15. #define DDR_SIZE_CS_OFF(n) (0x0004 + ((n) << 3))
  16. static struct mbus_win windows[] = {
  17. /* SPI */
  18. { MBUS_SPI_BASE, MBUS_SPI_SIZE,
  19. CPU_TARGET_DEVICEBUS_BOOTROM_SPI, CPU_ATTR_SPIFLASH },
  20. /* NOR */
  21. { MBUS_BOOTROM_BASE, MBUS_BOOTROM_SIZE,
  22. CPU_TARGET_DEVICEBUS_BOOTROM_SPI, CPU_ATTR_BOOTROM },
  23. };
  24. void lowlevel_init(void)
  25. {
  26. /*
  27. * Dummy implementation, we only need LOWLEVEL_INIT
  28. * on Armada to configure CP15 in start.S / cpu_init_cp15()
  29. */
  30. }
  31. void reset_cpu(unsigned long ignored)
  32. {
  33. struct mvebu_system_registers *reg =
  34. (struct mvebu_system_registers *)MVEBU_SYSTEM_REG_BASE;
  35. writel(readl(&reg->rstoutn_mask) | 1, &reg->rstoutn_mask);
  36. writel(readl(&reg->sys_soft_rst) | 1, &reg->sys_soft_rst);
  37. while (1)
  38. ;
  39. }
  40. int mvebu_soc_family(void)
  41. {
  42. u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
  43. if ((devid == SOC_MV78260_ID) || (devid == SOC_MV78460_ID))
  44. return MVEBU_SOC_AXP;
  45. if (devid == SOC_88F6810_ID || devid == SOC_88F6820_ID ||
  46. devid == SOC_88F6828_ID)
  47. return MVEBU_SOC_A38X;
  48. return MVEBU_SOC_UNKNOWN;
  49. }
  50. #if defined(CONFIG_DISPLAY_CPUINFO)
  51. #if defined(CONFIG_ARMADA_38X)
  52. /* SAR frequency values for Armada 38x */
  53. struct sar_freq_modes sar_freq_tab[] = {
  54. { 0x0, 0x0, 666, 333, 333 },
  55. { 0x2, 0x0, 800, 400, 400 },
  56. { 0x4, 0x0, 1066, 533, 533 },
  57. { 0x6, 0x0, 1200, 600, 600 },
  58. { 0x8, 0x0, 1332, 666, 666 },
  59. { 0xc, 0x0, 1600, 800, 800 },
  60. { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
  61. };
  62. #else
  63. /* SAR frequency values for Armada XP */
  64. struct sar_freq_modes sar_freq_tab[] = {
  65. { 0xa, 0x5, 800, 400, 400 },
  66. { 0x1, 0x5, 1066, 533, 533 },
  67. { 0x2, 0x5, 1200, 600, 600 },
  68. { 0x2, 0x9, 1200, 600, 400 },
  69. { 0x3, 0x5, 1333, 667, 667 },
  70. { 0x4, 0x5, 1500, 750, 750 },
  71. { 0x4, 0x9, 1500, 750, 500 },
  72. { 0xb, 0x9, 1600, 800, 533 },
  73. { 0xb, 0xa, 1600, 800, 640 },
  74. { 0xb, 0x5, 1600, 800, 800 },
  75. { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
  76. };
  77. #endif
  78. void get_sar_freq(struct sar_freq_modes *sar_freq)
  79. {
  80. u32 val;
  81. u32 freq;
  82. int i;
  83. val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */
  84. freq = (val & SAR_CPU_FREQ_MASK) >> SAR_CPU_FREQ_OFFS;
  85. #if !defined(CONFIG_ARMADA_38X)
  86. /*
  87. * Shift CPU0 clock frequency select bit from SAR2 register
  88. * into correct position
  89. */
  90. freq |= ((readl(CONFIG_SAR2_REG) & SAR2_CPU_FREQ_MASK)
  91. >> SAR2_CPU_FREQ_OFFS) << 3;
  92. #endif
  93. for (i = 0; sar_freq_tab[i].val != 0xff; i++) {
  94. if (sar_freq_tab[i].val == freq) {
  95. #if defined(CONFIG_ARMADA_38X)
  96. *sar_freq = sar_freq_tab[i];
  97. return;
  98. #else
  99. int k;
  100. u8 ffc;
  101. ffc = (val & SAR_FFC_FREQ_MASK) >>
  102. SAR_FFC_FREQ_OFFS;
  103. for (k = i; sar_freq_tab[k].ffc != 0xff; k++) {
  104. if (sar_freq_tab[k].ffc == ffc) {
  105. *sar_freq = sar_freq_tab[k];
  106. return;
  107. }
  108. }
  109. i = k;
  110. #endif
  111. }
  112. }
  113. /* SAR value not found, return 0 for frequencies */
  114. *sar_freq = sar_freq_tab[i - 1];
  115. }
  116. int print_cpuinfo(void)
  117. {
  118. u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
  119. u8 revid = readl(MVEBU_REG_PCIE_REVID) & 0xff;
  120. struct sar_freq_modes sar_freq;
  121. puts("SoC: ");
  122. switch (devid) {
  123. case SOC_MV78260_ID:
  124. puts("MV78260-");
  125. break;
  126. case SOC_MV78460_ID:
  127. puts("MV78460-");
  128. break;
  129. case SOC_88F6810_ID:
  130. puts("MV88F6810-");
  131. break;
  132. case SOC_88F6820_ID:
  133. puts("MV88F6820-");
  134. break;
  135. case SOC_88F6828_ID:
  136. puts("MV88F6828-");
  137. break;
  138. default:
  139. puts("Unknown-");
  140. break;
  141. }
  142. if (mvebu_soc_family() == MVEBU_SOC_AXP) {
  143. switch (revid) {
  144. case 1:
  145. puts("A0");
  146. break;
  147. case 2:
  148. puts("B0");
  149. break;
  150. default:
  151. printf("?? (%x)", revid);
  152. break;
  153. }
  154. }
  155. if (mvebu_soc_family() == MVEBU_SOC_A38X) {
  156. switch (revid) {
  157. case MV_88F68XX_Z1_ID:
  158. puts("Z1");
  159. break;
  160. case MV_88F68XX_A0_ID:
  161. puts("A0");
  162. break;
  163. default:
  164. printf("?? (%x)", revid);
  165. break;
  166. }
  167. }
  168. get_sar_freq(&sar_freq);
  169. printf(" at %d MHz\n", sar_freq.p_clk);
  170. return 0;
  171. }
  172. #endif /* CONFIG_DISPLAY_CPUINFO */
  173. /*
  174. * This function initialize Controller DRAM Fastpath windows.
  175. * It takes the CS size information from the 0x1500 scratch registers
  176. * and sets the correct windows sizes and base addresses accordingly.
  177. *
  178. * These values are set in the scratch registers by the Marvell
  179. * DDR3 training code, which is executed by the BootROM before the
  180. * main payload (U-Boot) is executed. This training code is currently
  181. * only available in the Marvell U-Boot version. It needs to be
  182. * ported to mainline U-Boot SPL at some point.
  183. */
  184. static void update_sdram_window_sizes(void)
  185. {
  186. u64 base = 0;
  187. u32 size, temp;
  188. int i;
  189. for (i = 0; i < SDRAM_MAX_CS; i++) {
  190. size = readl((MVEBU_SDRAM_SCRATCH + (i * 8))) & SDRAM_ADDR_MASK;
  191. if (size != 0) {
  192. size |= ~(SDRAM_ADDR_MASK);
  193. /* Set Base Address */
  194. temp = (base & 0xFF000000ll) | ((base >> 32) & 0xF);
  195. writel(temp, MVEBU_SDRAM_BASE + DDR_BASE_CS_OFF(i));
  196. /*
  197. * Check if out of max window size and resize
  198. * the window
  199. */
  200. temp = (readl(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i)) &
  201. ~(SDRAM_ADDR_MASK)) | 1;
  202. temp |= (size & SDRAM_ADDR_MASK);
  203. writel(temp, MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i));
  204. base += ((u64)size + 1);
  205. } else {
  206. /*
  207. * Disable window if not used, otherwise this
  208. * leads to overlapping enabled windows with
  209. * pretty strange results
  210. */
  211. clrbits_le32(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i), 1);
  212. }
  213. }
  214. }
  215. void mmu_disable(void)
  216. {
  217. asm volatile(
  218. "mrc p15, 0, r0, c1, c0, 0\n"
  219. "bic r0, #1\n"
  220. "mcr p15, 0, r0, c1, c0, 0\n");
  221. }
  222. #ifdef CONFIG_ARCH_CPU_INIT
  223. static void set_cbar(u32 addr)
  224. {
  225. asm("mcr p15, 4, %0, c15, c0" : : "r" (addr));
  226. }
  227. #define MV_USB_PHY_BASE (MVEBU_AXP_USB_BASE + 0x800)
  228. #define MV_USB_PHY_PLL_REG(reg) (MV_USB_PHY_BASE | (((reg) & 0xF) << 2))
  229. #define MV_USB_X3_BASE(addr) (MVEBU_AXP_USB_BASE | BIT(11) | \
  230. (((addr) & 0xF) << 6))
  231. #define MV_USB_X3_PHY_CHANNEL(dev, reg) (MV_USB_X3_BASE((dev) + 1) | \
  232. (((reg) & 0xF) << 2))
  233. static void setup_usb_phys(void)
  234. {
  235. int dev;
  236. /*
  237. * USB PLL init
  238. */
  239. /* Setup PLL frequency */
  240. /* USB REF frequency = 25 MHz */
  241. clrsetbits_le32(MV_USB_PHY_PLL_REG(1), 0x3ff, 0x605);
  242. /* Power up PLL and PHY channel */
  243. setbits_le32(MV_USB_PHY_PLL_REG(2), BIT(9));
  244. /* Assert VCOCAL_START */
  245. setbits_le32(MV_USB_PHY_PLL_REG(1), BIT(21));
  246. mdelay(1);
  247. /*
  248. * USB PHY init (change from defaults) specific for 40nm (78X30 78X60)
  249. */
  250. for (dev = 0; dev < 3; dev++) {
  251. setbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 3), BIT(15));
  252. /* Assert REG_RCAL_START in channel REG 1 */
  253. setbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12));
  254. udelay(40);
  255. clrbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12));
  256. }
  257. }
  258. /*
  259. * This function is not called from the SPL U-Boot version
  260. */
  261. int arch_cpu_init(void)
  262. {
  263. struct pl310_regs *const pl310 =
  264. (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
  265. /*
  266. * Only with disabled MMU its possible to switch the base
  267. * register address on Armada 38x. Without this the SDRAM
  268. * located at >= 0x4000.0000 is also not accessible, as its
  269. * still locked to cache.
  270. */
  271. mmu_disable();
  272. /* Linux expects the internal registers to be at 0xf1000000 */
  273. writel(SOC_REGS_PHY_BASE, INTREG_BASE_ADDR_REG);
  274. set_cbar(SOC_REGS_PHY_BASE + 0xC000);
  275. /*
  276. * From this stage on, the SoC detection is working. As we have
  277. * configured the internal register base to the value used
  278. * in the macros / defines in the U-Boot header (soc.h).
  279. */
  280. if (mvebu_soc_family() == MVEBU_SOC_A38X) {
  281. /*
  282. * To fully release / unlock this area from cache, we need
  283. * to flush all caches and disable the L2 cache.
  284. */
  285. icache_disable();
  286. dcache_disable();
  287. clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
  288. }
  289. /*
  290. * We need to call mvebu_mbus_probe() before calling
  291. * update_sdram_window_sizes() as it disables all previously
  292. * configured mbus windows and then configures them as
  293. * required for U-Boot. Calling update_sdram_window_sizes()
  294. * without this configuration will not work, as the internal
  295. * registers can't be accessed reliably because of potenial
  296. * double mapping.
  297. * After updating the SDRAM access windows we need to call
  298. * mvebu_mbus_probe() again, as this now correctly configures
  299. * the SDRAM areas that are later used by the MVEBU drivers
  300. * (e.g. USB, NETA).
  301. */
  302. /*
  303. * First disable all windows
  304. */
  305. mvebu_mbus_probe(NULL, 0);
  306. if (mvebu_soc_family() == MVEBU_SOC_AXP) {
  307. /*
  308. * Now the SDRAM access windows can be reconfigured using
  309. * the information in the SDRAM scratch pad registers
  310. */
  311. update_sdram_window_sizes();
  312. }
  313. /*
  314. * Finally the mbus windows can be configured with the
  315. * updated SDRAM sizes
  316. */
  317. mvebu_mbus_probe(windows, ARRAY_SIZE(windows));
  318. if (mvebu_soc_family() == MVEBU_SOC_AXP) {
  319. /* Enable GBE0, GBE1, LCD and NFC PUP */
  320. clrsetbits_le32(ARMADA_XP_PUP_ENABLE, 0,
  321. GE0_PUP_EN | GE1_PUP_EN | LCD_PUP_EN |
  322. NAND_PUP_EN | SPI_PUP_EN);
  323. /* Configure USB PLL and PHYs on AXP */
  324. setup_usb_phys();
  325. }
  326. /* Enable NAND and NAND arbiter */
  327. clrsetbits_le32(MVEBU_SOC_DEV_MUX_REG, 0, NAND_EN | NAND_ARBITER_EN);
  328. /* Disable MBUS error propagation */
  329. clrsetbits_le32(SOC_COHERENCY_FABRIC_CTRL_REG, MBUS_ERR_PROP_EN, 0);
  330. return 0;
  331. }
  332. #endif /* CONFIG_ARCH_CPU_INIT */
  333. u32 mvebu_get_nand_clock(void)
  334. {
  335. return CONFIG_SYS_MVEBU_PLL_CLOCK /
  336. ((readl(MVEBU_CORE_DIV_CLK_CTRL(1)) &
  337. NAND_ECC_DIVCKL_RATIO_MASK) >> NAND_ECC_DIVCKL_RATIO_OFFS);
  338. }
  339. /*
  340. * SOC specific misc init
  341. */
  342. #if defined(CONFIG_ARCH_MISC_INIT)
  343. int arch_misc_init(void)
  344. {
  345. /* Nothing yet, perhaps we need something here later */
  346. return 0;
  347. }
  348. #endif /* CONFIG_ARCH_MISC_INIT */
  349. #ifdef CONFIG_MV_SDHCI
  350. int board_mmc_init(bd_t *bis)
  351. {
  352. mv_sdh_init(MVEBU_SDIO_BASE, 0, 0,
  353. SDHCI_QUIRK_32BIT_DMA_ADDR | SDHCI_QUIRK_WAIT_SEND_CMD);
  354. return 0;
  355. }
  356. #endif
  357. #ifdef CONFIG_SCSI_AHCI_PLAT
  358. #define AHCI_VENDOR_SPECIFIC_0_ADDR 0xa0
  359. #define AHCI_VENDOR_SPECIFIC_0_DATA 0xa4
  360. #define AHCI_WINDOW_CTRL(win) (0x60 + ((win) << 4))
  361. #define AHCI_WINDOW_BASE(win) (0x64 + ((win) << 4))
  362. #define AHCI_WINDOW_SIZE(win) (0x68 + ((win) << 4))
  363. static void ahci_mvebu_mbus_config(void __iomem *base)
  364. {
  365. const struct mbus_dram_target_info *dram;
  366. int i;
  367. dram = mvebu_mbus_dram_info();
  368. for (i = 0; i < 4; i++) {
  369. writel(0, base + AHCI_WINDOW_CTRL(i));
  370. writel(0, base + AHCI_WINDOW_BASE(i));
  371. writel(0, base + AHCI_WINDOW_SIZE(i));
  372. }
  373. for (i = 0; i < dram->num_cs; i++) {
  374. const struct mbus_dram_window *cs = dram->cs + i;
  375. writel((cs->mbus_attr << 8) |
  376. (dram->mbus_dram_target_id << 4) | 1,
  377. base + AHCI_WINDOW_CTRL(i));
  378. writel(cs->base >> 16, base + AHCI_WINDOW_BASE(i));
  379. writel(((cs->size - 1) & 0xffff0000),
  380. base + AHCI_WINDOW_SIZE(i));
  381. }
  382. }
  383. static void ahci_mvebu_regret_option(void __iomem *base)
  384. {
  385. /*
  386. * Enable the regret bit to allow the SATA unit to regret a
  387. * request that didn't receive an acknowlegde and avoid a
  388. * deadlock
  389. */
  390. writel(0x4, base + AHCI_VENDOR_SPECIFIC_0_ADDR);
  391. writel(0x80, base + AHCI_VENDOR_SPECIFIC_0_DATA);
  392. }
  393. void scsi_init(void)
  394. {
  395. printf("MVEBU SATA INIT\n");
  396. ahci_mvebu_mbus_config((void __iomem *)MVEBU_SATA0_BASE);
  397. ahci_mvebu_regret_option((void __iomem *)MVEBU_SATA0_BASE);
  398. ahci_init((void __iomem *)MVEBU_SATA0_BASE);
  399. }
  400. #endif
  401. void enable_caches(void)
  402. {
  403. /* Avoid problem with e.g. neta ethernet driver */
  404. invalidate_dcache_all();
  405. /* Enable D-cache. I-cache is already enabled in start.S */
  406. dcache_enable();
  407. }
  408. void v7_outer_cache_enable(void)
  409. {
  410. if (mvebu_soc_family() == MVEBU_SOC_AXP) {
  411. struct pl310_regs *const pl310 =
  412. (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
  413. u32 u;
  414. /* The L2 cache is already disabled at this point */
  415. /*
  416. * For Aurora cache in no outer mode, enable via the CP15
  417. * coprocessor broadcasting of cache commands to L2.
  418. */
  419. asm volatile("mrc p15, 1, %0, c15, c2, 0" : "=r" (u));
  420. u |= BIT(8); /* Set the FW bit */
  421. asm volatile("mcr p15, 1, %0, c15, c2, 0" : : "r" (u));
  422. isb();
  423. /* Enable the L2 cache */
  424. setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
  425. }
  426. }
  427. void v7_outer_cache_disable(void)
  428. {
  429. struct pl310_regs *const pl310 =
  430. (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
  431. clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
  432. }