cpu.c 9.8 KB

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