quark.c 10 KB

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