quark.c 10 KB

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