quark.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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/mtrr.h>
  11. #include <asm/pci.h>
  12. #include <asm/post.h>
  13. #include <asm/processor.h>
  14. #include <asm/arch/device.h>
  15. #include <asm/arch/msg_port.h>
  16. #include <asm/arch/quark.h>
  17. static struct pci_device_id mmc_supported[] = {
  18. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QRK_SDIO },
  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. #ifdef CONFIG_SYS_X86_TSC_TIMER
  190. timer_set_base(rdtsc());
  191. #endif
  192. ret = x86_cpu_init_f();
  193. if (ret)
  194. return ret;
  195. /*
  196. * Quark SoC does not support MSR MTRRs. Fixed and variable range MTRRs
  197. * are accessed indirectly via the message port and not the traditional
  198. * MSR mechanism. Only UC, WT and WB cache types are supported.
  199. */
  200. quark_setup_mtrr();
  201. /*
  202. * Quark SoC has some non-standard BARs (excluding PCI standard BARs)
  203. * which need be initialized with suggested values
  204. */
  205. quark_setup_bars();
  206. /*
  207. * Initialize PCIe controller
  208. *
  209. * Quark SoC holds the PCIe controller in reset following a power on.
  210. * U-Boot needs to release the PCIe controller from reset. The PCIe
  211. * controller (D23:F0/F1) will not be visible in PCI configuration
  212. * space and any access to its PCI configuration registers will cause
  213. * system hang while it is held in reset.
  214. */
  215. quark_pcie_early_init();
  216. /* Initialize USB2 PHY */
  217. quark_usb_early_init();
  218. /* Initialize thermal sensor */
  219. quark_thermal_early_init();
  220. /* Turn on legacy segments (A/B/E/F) decode to system RAM */
  221. quark_enable_legacy_seg();
  222. unprotect_spi_flash();
  223. return 0;
  224. }
  225. int print_cpuinfo(void)
  226. {
  227. post_code(POST_CPU_INFO);
  228. return default_print_cpuinfo();
  229. }
  230. void reset_cpu(ulong addr)
  231. {
  232. /* cold reset */
  233. x86_full_reset();
  234. }
  235. static void quark_pcie_init(void)
  236. {
  237. u32 val;
  238. /* PCIe upstream non-posted & posted request size */
  239. qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_CCFG,
  240. CCFG_UPRS | CCFG_UNRS);
  241. qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_CCFG,
  242. CCFG_UPRS | CCFG_UNRS);
  243. /* PCIe packet fast transmit mode (IPF) */
  244. qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_MPC2, MPC2_IPF);
  245. qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_MPC2, MPC2_IPF);
  246. /* PCIe message bus idle counter (SBIC) */
  247. qrk_pci_read_config_dword(QUARK_PCIE0, PCIE_RP_MBC, &val);
  248. val |= MBC_SBIC;
  249. qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_MBC, val);
  250. qrk_pci_read_config_dword(QUARK_PCIE1, PCIE_RP_MBC, &val);
  251. val |= MBC_SBIC;
  252. qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_MBC, val);
  253. }
  254. static void quark_usb_init(void)
  255. {
  256. u32 bar;
  257. /* Change USB EHCI packet buffer OUT/IN threshold */
  258. qrk_pci_read_config_dword(QUARK_USB_EHCI, PCI_BASE_ADDRESS_0, &bar);
  259. writel((0x7f << 16) | 0x7f, bar + EHCI_INSNREG01);
  260. /* Disable USB device interrupts */
  261. qrk_pci_read_config_dword(QUARK_USB_DEVICE, PCI_BASE_ADDRESS_0, &bar);
  262. writel(0x7f, bar + USBD_INT_MASK);
  263. writel((0xf << 16) | 0xf, bar + USBD_EP_INT_MASK);
  264. writel((0xf << 16) | 0xf, bar + USBD_EP_INT_STS);
  265. }
  266. int arch_early_init_r(void)
  267. {
  268. quark_pcie_init();
  269. quark_usb_init();
  270. return 0;
  271. }
  272. int cpu_mmc_init(bd_t *bis)
  273. {
  274. return pci_mmc_init("Quark SDHCI", mmc_supported,
  275. ARRAY_SIZE(mmc_supported));
  276. }
  277. void cpu_irq_init(void)
  278. {
  279. struct quark_rcba *rcba;
  280. u32 base;
  281. qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, &base);
  282. base &= ~MEM_BAR_EN;
  283. rcba = (struct quark_rcba *)base;
  284. /*
  285. * Route Quark PCI device interrupt pin to PIRQ
  286. *
  287. * Route device#23's INTA/B/C/D to PIRQA/B/C/D
  288. * Route device#20,21's INTA/B/C/D to PIRQE/F/G/H
  289. */
  290. writew(PIRQC, &rcba->rmu_ir);
  291. writew(PIRQA | (PIRQB << 4) | (PIRQC << 8) | (PIRQD << 12),
  292. &rcba->d23_ir);
  293. writew(PIRQD, &rcba->core_ir);
  294. writew(PIRQE | (PIRQF << 4) | (PIRQG << 8) | (PIRQH << 12),
  295. &rcba->d20d21_ir);
  296. }
  297. int arch_misc_init(void)
  298. {
  299. return pirq_init();
  300. }
  301. void board_final_cleanup(void)
  302. {
  303. struct quark_rcba *rcba;
  304. u32 base, val;
  305. qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, &base);
  306. base &= ~MEM_BAR_EN;
  307. rcba = (struct quark_rcba *)base;
  308. /* Initialize 'Component ID' to zero */
  309. val = readl(&rcba->esd);
  310. val &= ~0xff0000;
  311. writel(val, &rcba->esd);
  312. /* Lock HMBOUND for security */
  313. msg_port_setbits(MSG_PORT_HOST_BRIDGE, HM_BOUND, HM_BOUND_LOCK);
  314. return;
  315. }