quark.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. /*
  2. * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <mmc.h>
  8. #include <asm/io.h>
  9. #include <asm/irq.h>
  10. #include <asm/mrccache.h>
  11. #include <asm/mtrr.h>
  12. #include <asm/pci.h>
  13. #include <asm/post.h>
  14. #include <asm/processor.h>
  15. #include <asm/arch/device.h>
  16. #include <asm/arch/msg_port.h>
  17. #include <asm/arch/quark.h>
  18. static struct pci_device_id mmc_supported[] = {
  19. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QRK_SDIO },
  20. {},
  21. };
  22. /*
  23. * TODO:
  24. *
  25. * This whole routine should be removed until we fully convert the ICH SPI
  26. * driver to DM and make use of DT to pass the bios control register offset
  27. */
  28. static void unprotect_spi_flash(void)
  29. {
  30. u32 bc;
  31. qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, 0xd8, &bc);
  32. bc |= 0x1; /* unprotect the flash */
  33. qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, 0xd8, bc);
  34. }
  35. static void quark_setup_mtrr(void)
  36. {
  37. u32 base, mask;
  38. int i;
  39. disable_caches();
  40. /* mark the VGA RAM area as uncacheable */
  41. msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_16K_A0000,
  42. MTRR_FIX_TYPE(MTRR_TYPE_UNCACHEABLE));
  43. msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_16K_B0000,
  44. MTRR_FIX_TYPE(MTRR_TYPE_UNCACHEABLE));
  45. /* mark other fixed range areas as cacheable */
  46. msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_64K_00000,
  47. MTRR_FIX_TYPE(MTRR_TYPE_WRBACK));
  48. msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_64K_40000,
  49. MTRR_FIX_TYPE(MTRR_TYPE_WRBACK));
  50. msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_16K_80000,
  51. MTRR_FIX_TYPE(MTRR_TYPE_WRBACK));
  52. msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_16K_90000,
  53. MTRR_FIX_TYPE(MTRR_TYPE_WRBACK));
  54. for (i = MTRR_FIX_4K_C0000; i <= MTRR_FIX_4K_FC000; i++)
  55. msg_port_write(MSG_PORT_HOST_BRIDGE, i,
  56. MTRR_FIX_TYPE(MTRR_TYPE_WRBACK));
  57. /* variable range MTRR#0: ROM area */
  58. mask = ~(CONFIG_SYS_MONITOR_LEN - 1);
  59. base = CONFIG_SYS_TEXT_BASE & mask;
  60. msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_VAR_PHYBASE(MTRR_VAR_ROM),
  61. base | MTRR_TYPE_WRBACK);
  62. msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_VAR_PHYMASK(MTRR_VAR_ROM),
  63. mask | MTRR_PHYS_MASK_VALID);
  64. /* variable range MTRR#1: eSRAM area */
  65. mask = ~(ESRAM_SIZE - 1);
  66. base = CONFIG_ESRAM_BASE & mask;
  67. msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_VAR_PHYBASE(MTRR_VAR_ESRAM),
  68. base | MTRR_TYPE_WRBACK);
  69. msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_VAR_PHYMASK(MTRR_VAR_ESRAM),
  70. mask | MTRR_PHYS_MASK_VALID);
  71. /* enable both variable and fixed range MTRRs */
  72. msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_DEF_TYPE,
  73. MTRR_DEF_TYPE_EN | MTRR_DEF_TYPE_FIX_EN);
  74. enable_caches();
  75. }
  76. static void quark_setup_bars(void)
  77. {
  78. /* GPIO - D31:F0:R44h */
  79. qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_GBA,
  80. CONFIG_GPIO_BASE | IO_BAR_EN);
  81. /* ACPI PM1 Block - D31:F0:R48h */
  82. qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_PM1BLK,
  83. CONFIG_ACPI_PM1_BASE | IO_BAR_EN);
  84. /* GPE0 - D31:F0:R4Ch */
  85. qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_GPE0BLK,
  86. CONFIG_ACPI_GPE0_BASE | IO_BAR_EN);
  87. /* WDT - D31:F0:R84h */
  88. qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_WDTBA,
  89. CONFIG_WDT_BASE | IO_BAR_EN);
  90. /* RCBA - D31:F0:RF0h */
  91. qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA,
  92. CONFIG_RCBA_BASE | MEM_BAR_EN);
  93. /* ACPI P Block - Msg Port 04:R70h */
  94. msg_port_write(MSG_PORT_RMU, PBLK_BA,
  95. CONFIG_ACPI_PBLK_BASE | IO_BAR_EN);
  96. /* SPI DMA - Msg Port 04:R7Ah */
  97. msg_port_write(MSG_PORT_RMU, SPI_DMA_BA,
  98. CONFIG_SPI_DMA_BASE | IO_BAR_EN);
  99. /* PCIe ECAM */
  100. msg_port_write(MSG_PORT_MEM_ARBITER, AEC_CTRL,
  101. CONFIG_PCIE_ECAM_BASE | MEM_BAR_EN);
  102. msg_port_write(MSG_PORT_HOST_BRIDGE, HEC_REG,
  103. CONFIG_PCIE_ECAM_BASE | MEM_BAR_EN);
  104. }
  105. static void quark_pcie_early_init(void)
  106. {
  107. /*
  108. * Step1: Assert PCIe signal PERST#
  109. *
  110. * The CPU interface to the PERST# signal is platform dependent.
  111. * Call the board-specific codes to perform this task.
  112. */
  113. board_assert_perst();
  114. /* Step2: PHY common lane reset */
  115. msg_port_alt_setbits(MSG_PORT_SOC_UNIT, PCIE_CFG, PCIE_PHY_LANE_RST);
  116. /* wait 1 ms for PHY common lane reset */
  117. mdelay(1);
  118. /* Step3: PHY sideband interface reset and controller main reset */
  119. msg_port_alt_setbits(MSG_PORT_SOC_UNIT, PCIE_CFG,
  120. PCIE_PHY_SB_RST | PCIE_CTLR_MAIN_RST);
  121. /* wait 80ms for PLL to lock */
  122. mdelay(80);
  123. /* Step4: Controller sideband interface reset */
  124. msg_port_alt_setbits(MSG_PORT_SOC_UNIT, PCIE_CFG, PCIE_CTLR_SB_RST);
  125. /* wait 20ms for controller sideband interface reset */
  126. mdelay(20);
  127. /* Step5: De-assert PERST# */
  128. board_deassert_perst();
  129. /* Step6: Controller primary interface reset */
  130. msg_port_alt_setbits(MSG_PORT_SOC_UNIT, PCIE_CFG, PCIE_CTLR_PRI_RST);
  131. /* Mixer Load Lane 0 */
  132. msg_port_io_clrbits(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L0,
  133. (1 << 6) | (1 << 7));
  134. /* Mixer Load Lane 1 */
  135. msg_port_io_clrbits(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L1,
  136. (1 << 6) | (1 << 7));
  137. }
  138. static void quark_usb_early_init(void)
  139. {
  140. /* The sequence below comes from Quark firmware writer guide */
  141. msg_port_alt_clrsetbits(MSG_PORT_USB_AFE, USB2_GLOBAL_PORT,
  142. 1 << 1, (1 << 6) | (1 << 7));
  143. msg_port_alt_clrsetbits(MSG_PORT_USB_AFE, USB2_COMPBG,
  144. (1 << 8) | (1 << 9), (1 << 7) | (1 << 10));
  145. msg_port_alt_setbits(MSG_PORT_USB_AFE, USB2_PLL2, 1 << 29);
  146. msg_port_alt_setbits(MSG_PORT_USB_AFE, USB2_PLL1, 1 << 1);
  147. msg_port_alt_clrsetbits(MSG_PORT_USB_AFE, USB2_PLL1,
  148. (1 << 3) | (1 << 4) | (1 << 5), 1 << 6);
  149. msg_port_alt_clrbits(MSG_PORT_USB_AFE, USB2_PLL2, 1 << 29);
  150. msg_port_alt_setbits(MSG_PORT_USB_AFE, USB2_PLL2, 1 << 24);
  151. }
  152. static void quark_thermal_early_init(void)
  153. {
  154. /* The sequence below comes from Quark firmware writer guide */
  155. /* thermal sensor mode config */
  156. msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG1,
  157. (1 << 3) | (1 << 4) | (1 << 5), 1 << 5);
  158. msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG1,
  159. (1 << 8) | (1 << 9) | (1 << 10) | (1 << 11) |
  160. (1 << 12), 1 << 9);
  161. msg_port_alt_setbits(MSG_PORT_SOC_UNIT, TS_CFG1, 1 << 14);
  162. msg_port_alt_clrbits(MSG_PORT_SOC_UNIT, TS_CFG1, 1 << 17);
  163. msg_port_alt_clrbits(MSG_PORT_SOC_UNIT, TS_CFG1, 1 << 18);
  164. msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG2, 0xffff, 0x011f);
  165. msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG3, 0xff, 0x17);
  166. msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG3,
  167. (1 << 8) | (1 << 9), 1 << 8);
  168. msg_port_alt_clrbits(MSG_PORT_SOC_UNIT, TS_CFG3, 0xff000000);
  169. msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG4,
  170. 0x7ff800, 0xc8 << 11);
  171. /* thermal monitor catastrophic trip set point (105 celsius) */
  172. msg_port_clrsetbits(MSG_PORT_RMU, TS_TRIP, 0xff, 155);
  173. /* thermal monitor catastrophic trip clear point (0 celsius) */
  174. msg_port_clrsetbits(MSG_PORT_RMU, TS_TRIP, 0xff0000, 50 << 16);
  175. /* take thermal sensor out of reset */
  176. msg_port_alt_clrbits(MSG_PORT_SOC_UNIT, TS_CFG4, 1 << 0);
  177. /* enable thermal monitor */
  178. msg_port_setbits(MSG_PORT_RMU, TS_MODE, 1 << 15);
  179. /* lock all thermal configuration */
  180. msg_port_setbits(MSG_PORT_RMU, RMU_CTRL, (1 << 5) | (1 << 6));
  181. }
  182. static void quark_enable_legacy_seg(void)
  183. {
  184. msg_port_setbits(MSG_PORT_HOST_BRIDGE, HMISC2,
  185. HMISC2_SEGE | HMISC2_SEGF | HMISC2_SEGAB);
  186. }
  187. int arch_cpu_init(void)
  188. {
  189. int ret;
  190. post_code(POST_CPU_INIT);
  191. ret = x86_cpu_init_f();
  192. if (ret)
  193. return ret;
  194. /*
  195. * Quark SoC does not support MSR MTRRs. Fixed and variable range MTRRs
  196. * are accessed indirectly via the message port and not the traditional
  197. * MSR mechanism. Only UC, WT and WB cache types are supported.
  198. */
  199. quark_setup_mtrr();
  200. /*
  201. * Quark SoC has some non-standard BARs (excluding PCI standard BARs)
  202. * which need be initialized with suggested values
  203. */
  204. quark_setup_bars();
  205. /* Initialize USB2 PHY */
  206. quark_usb_early_init();
  207. /* Initialize thermal sensor */
  208. quark_thermal_early_init();
  209. /* Turn on legacy segments (A/B/E/F) decode to system RAM */
  210. quark_enable_legacy_seg();
  211. unprotect_spi_flash();
  212. return 0;
  213. }
  214. int arch_cpu_init_dm(void)
  215. {
  216. /*
  217. * Initialize PCIe controller
  218. *
  219. * Quark SoC holds the PCIe controller in reset following a power on.
  220. * U-Boot needs to release the PCIe controller from reset. The PCIe
  221. * controller (D23:F0/F1) will not be visible in PCI configuration
  222. * space and any access to its PCI configuration registers will cause
  223. * system hang while it is held in reset.
  224. */
  225. quark_pcie_early_init();
  226. return 0;
  227. }
  228. int print_cpuinfo(void)
  229. {
  230. post_code(POST_CPU_INFO);
  231. return default_print_cpuinfo();
  232. }
  233. void reset_cpu(ulong addr)
  234. {
  235. /* cold reset */
  236. x86_full_reset();
  237. }
  238. static void quark_pcie_init(void)
  239. {
  240. u32 val;
  241. /* PCIe upstream non-posted & posted request size */
  242. qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_CCFG,
  243. CCFG_UPRS | CCFG_UNRS);
  244. qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_CCFG,
  245. CCFG_UPRS | CCFG_UNRS);
  246. /* PCIe packet fast transmit mode (IPF) */
  247. qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_MPC2, MPC2_IPF);
  248. qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_MPC2, MPC2_IPF);
  249. /* PCIe message bus idle counter (SBIC) */
  250. qrk_pci_read_config_dword(QUARK_PCIE0, PCIE_RP_MBC, &val);
  251. val |= MBC_SBIC;
  252. qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_MBC, val);
  253. qrk_pci_read_config_dword(QUARK_PCIE1, PCIE_RP_MBC, &val);
  254. val |= MBC_SBIC;
  255. qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_MBC, val);
  256. }
  257. static void quark_usb_init(void)
  258. {
  259. u32 bar;
  260. /* Change USB EHCI packet buffer OUT/IN threshold */
  261. qrk_pci_read_config_dword(QUARK_USB_EHCI, PCI_BASE_ADDRESS_0, &bar);
  262. writel((0x7f << 16) | 0x7f, bar + EHCI_INSNREG01);
  263. /* Disable USB device interrupts */
  264. qrk_pci_read_config_dword(QUARK_USB_DEVICE, PCI_BASE_ADDRESS_0, &bar);
  265. writel(0x7f, bar + USBD_INT_MASK);
  266. writel((0xf << 16) | 0xf, bar + USBD_EP_INT_MASK);
  267. writel((0xf << 16) | 0xf, bar + USBD_EP_INT_STS);
  268. }
  269. int arch_early_init_r(void)
  270. {
  271. quark_pcie_init();
  272. quark_usb_init();
  273. return 0;
  274. }
  275. int cpu_mmc_init(bd_t *bis)
  276. {
  277. return pci_mmc_init("Quark SDHCI", mmc_supported);
  278. }
  279. void cpu_irq_init(void)
  280. {
  281. struct quark_rcba *rcba;
  282. u32 base;
  283. qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, &base);
  284. base &= ~MEM_BAR_EN;
  285. rcba = (struct quark_rcba *)base;
  286. /*
  287. * Route Quark PCI device interrupt pin to PIRQ
  288. *
  289. * Route device#23's INTA/B/C/D to PIRQA/B/C/D
  290. * Route device#20,21's INTA/B/C/D to PIRQE/F/G/H
  291. */
  292. writew(PIRQC, &rcba->rmu_ir);
  293. writew(PIRQA | (PIRQB << 4) | (PIRQC << 8) | (PIRQD << 12),
  294. &rcba->d23_ir);
  295. writew(PIRQD, &rcba->core_ir);
  296. writew(PIRQE | (PIRQF << 4) | (PIRQG << 8) | (PIRQH << 12),
  297. &rcba->d20d21_ir);
  298. }
  299. int arch_misc_init(void)
  300. {
  301. #ifdef CONFIG_ENABLE_MRC_CACHE
  302. /*
  303. * We intend not to check any return value here, as even MRC cache
  304. * is not saved successfully, it is not a severe error that will
  305. * prevent system from continuing to boot.
  306. */
  307. mrccache_save();
  308. #endif
  309. return 0;
  310. }
  311. void board_final_cleanup(void)
  312. {
  313. struct quark_rcba *rcba;
  314. u32 base, val;
  315. qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, &base);
  316. base &= ~MEM_BAR_EN;
  317. rcba = (struct quark_rcba *)base;
  318. /* Initialize 'Component ID' to zero */
  319. val = readl(&rcba->esd);
  320. val &= ~0xff0000;
  321. writel(val, &rcba->esd);
  322. /* Lock HMBOUND for security */
  323. msg_port_setbits(MSG_PORT_HOST_BRIDGE, HM_BOUND, HM_BOUND_LOCK);
  324. return;
  325. }
  326. int reserve_arch(void)
  327. {
  328. #ifdef CONFIG_ENABLE_MRC_CACHE
  329. return mrccache_reserve();
  330. #else
  331. return 0;
  332. #endif
  333. }