cpu.c 14 KB

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