quark.c 11 KB

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