quark.c 11 KB

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