quark.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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/pci.h>
  11. #include <asm/post.h>
  12. #include <asm/processor.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. * TODO:
  21. *
  22. * This whole routine should be removed until we fully convert the ICH SPI
  23. * driver to DM and make use of DT to pass the bios control register offset
  24. */
  25. static void unprotect_spi_flash(void)
  26. {
  27. u32 bc;
  28. qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, 0xd8, &bc);
  29. bc |= 0x1; /* unprotect the flash */
  30. qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, 0xd8, bc);
  31. }
  32. static void quark_setup_bars(void)
  33. {
  34. /* GPIO - D31:F0:R44h */
  35. qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_GBA,
  36. CONFIG_GPIO_BASE | IO_BAR_EN);
  37. /* ACPI PM1 Block - D31:F0:R48h */
  38. qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_PM1BLK,
  39. CONFIG_ACPI_PM1_BASE | IO_BAR_EN);
  40. /* GPE0 - D31:F0:R4Ch */
  41. qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_GPE0BLK,
  42. CONFIG_ACPI_GPE0_BASE | IO_BAR_EN);
  43. /* WDT - D31:F0:R84h */
  44. qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_WDTBA,
  45. CONFIG_WDT_BASE | IO_BAR_EN);
  46. /* RCBA - D31:F0:RF0h */
  47. qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA,
  48. CONFIG_RCBA_BASE | MEM_BAR_EN);
  49. /* ACPI P Block - Msg Port 04:R70h */
  50. msg_port_write(MSG_PORT_RMU, PBLK_BA,
  51. CONFIG_ACPI_PBLK_BASE | IO_BAR_EN);
  52. /* SPI DMA - Msg Port 04:R7Ah */
  53. msg_port_write(MSG_PORT_RMU, SPI_DMA_BA,
  54. CONFIG_SPI_DMA_BASE | IO_BAR_EN);
  55. /* PCIe ECAM */
  56. msg_port_write(MSG_PORT_MEM_ARBITER, AEC_CTRL,
  57. CONFIG_PCIE_ECAM_BASE | MEM_BAR_EN);
  58. msg_port_write(MSG_PORT_HOST_BRIDGE, HEC_REG,
  59. CONFIG_PCIE_ECAM_BASE | MEM_BAR_EN);
  60. }
  61. static void quark_pcie_early_init(void)
  62. {
  63. /*
  64. * Step1: Assert PCIe signal PERST#
  65. *
  66. * The CPU interface to the PERST# signal is platform dependent.
  67. * Call the board-specific codes to perform this task.
  68. */
  69. board_assert_perst();
  70. /* Step2: PHY common lane reset */
  71. msg_port_alt_setbits(MSG_PORT_SOC_UNIT, PCIE_CFG, PCIE_PHY_LANE_RST);
  72. /* wait 1 ms for PHY common lane reset */
  73. mdelay(1);
  74. /* Step3: PHY sideband interface reset and controller main reset */
  75. msg_port_alt_setbits(MSG_PORT_SOC_UNIT, PCIE_CFG,
  76. PCIE_PHY_SB_RST | PCIE_CTLR_MAIN_RST);
  77. /* wait 80ms for PLL to lock */
  78. mdelay(80);
  79. /* Step4: Controller sideband interface reset */
  80. msg_port_alt_setbits(MSG_PORT_SOC_UNIT, PCIE_CFG, PCIE_CTLR_SB_RST);
  81. /* wait 20ms for controller sideband interface reset */
  82. mdelay(20);
  83. /* Step5: De-assert PERST# */
  84. board_deassert_perst();
  85. /* Step6: Controller primary interface reset */
  86. msg_port_alt_setbits(MSG_PORT_SOC_UNIT, PCIE_CFG, PCIE_CTLR_PRI_RST);
  87. /* Mixer Load Lane 0 */
  88. msg_port_io_clrbits(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L0,
  89. (1 << 6) | (1 << 7));
  90. /* Mixer Load Lane 1 */
  91. msg_port_io_clrbits(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L1,
  92. (1 << 6) | (1 << 7));
  93. }
  94. static void quark_usb_early_init(void)
  95. {
  96. /* The sequence below comes from Quark firmware writer guide */
  97. msg_port_alt_clrsetbits(MSG_PORT_USB_AFE, USB2_GLOBAL_PORT,
  98. 1 << 1, (1 << 6) | (1 << 7));
  99. msg_port_alt_clrsetbits(MSG_PORT_USB_AFE, USB2_COMPBG,
  100. (1 << 8) | (1 << 9), (1 << 7) | (1 << 10));
  101. msg_port_alt_setbits(MSG_PORT_USB_AFE, USB2_PLL2, 1 << 29);
  102. msg_port_alt_setbits(MSG_PORT_USB_AFE, USB2_PLL1, 1 << 1);
  103. msg_port_alt_clrsetbits(MSG_PORT_USB_AFE, USB2_PLL1,
  104. (1 << 3) | (1 << 4) | (1 << 5), 1 << 6);
  105. msg_port_alt_clrbits(MSG_PORT_USB_AFE, USB2_PLL2, 1 << 29);
  106. msg_port_alt_setbits(MSG_PORT_USB_AFE, USB2_PLL2, 1 << 24);
  107. }
  108. static void quark_enable_legacy_seg(void)
  109. {
  110. msg_port_setbits(MSG_PORT_HOST_BRIDGE, HMISC2,
  111. HMISC2_SEGE | HMISC2_SEGF | HMISC2_SEGAB);
  112. }
  113. int arch_cpu_init(void)
  114. {
  115. int ret;
  116. post_code(POST_CPU_INIT);
  117. #ifdef CONFIG_SYS_X86_TSC_TIMER
  118. timer_set_base(rdtsc());
  119. #endif
  120. ret = x86_cpu_init_f();
  121. if (ret)
  122. return ret;
  123. /*
  124. * Quark SoC has some non-standard BARs (excluding PCI standard BARs)
  125. * which need be initialized with suggested values
  126. */
  127. quark_setup_bars();
  128. /*
  129. * Initialize PCIe controller
  130. *
  131. * Quark SoC holds the PCIe controller in reset following a power on.
  132. * U-Boot needs to release the PCIe controller from reset. The PCIe
  133. * controller (D23:F0/F1) will not be visible in PCI configuration
  134. * space and any access to its PCI configuration registers will cause
  135. * system hang while it is held in reset.
  136. */
  137. quark_pcie_early_init();
  138. /* Initialize USB2 PHY */
  139. quark_usb_early_init();
  140. /* Turn on legacy segments (A/B/E/F) decode to system RAM */
  141. quark_enable_legacy_seg();
  142. unprotect_spi_flash();
  143. return 0;
  144. }
  145. int print_cpuinfo(void)
  146. {
  147. post_code(POST_CPU_INFO);
  148. return default_print_cpuinfo();
  149. }
  150. void reset_cpu(ulong addr)
  151. {
  152. /* cold reset */
  153. x86_full_reset();
  154. }
  155. static void quark_pcie_init(void)
  156. {
  157. u32 val;
  158. /* PCIe upstream non-posted & posted request size */
  159. qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_CCFG,
  160. CCFG_UPRS | CCFG_UNRS);
  161. qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_CCFG,
  162. CCFG_UPRS | CCFG_UNRS);
  163. /* PCIe packet fast transmit mode (IPF) */
  164. qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_MPC2, MPC2_IPF);
  165. qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_MPC2, MPC2_IPF);
  166. /* PCIe message bus idle counter (SBIC) */
  167. qrk_pci_read_config_dword(QUARK_PCIE0, PCIE_RP_MBC, &val);
  168. val |= MBC_SBIC;
  169. qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_MBC, val);
  170. qrk_pci_read_config_dword(QUARK_PCIE1, PCIE_RP_MBC, &val);
  171. val |= MBC_SBIC;
  172. qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_MBC, val);
  173. }
  174. static void quark_usb_init(void)
  175. {
  176. u32 bar;
  177. /* Change USB EHCI packet buffer OUT/IN threshold */
  178. qrk_pci_read_config_dword(QUARK_USB_EHCI, PCI_BASE_ADDRESS_0, &bar);
  179. writel((0x7f << 16) | 0x7f, bar + EHCI_INSNREG01);
  180. /* Disable USB device interrupts */
  181. qrk_pci_read_config_dword(QUARK_USB_DEVICE, PCI_BASE_ADDRESS_0, &bar);
  182. writel(0x7f, bar + USBD_INT_MASK);
  183. writel((0xf << 16) | 0xf, bar + USBD_EP_INT_MASK);
  184. writel((0xf << 16) | 0xf, bar + USBD_EP_INT_STS);
  185. }
  186. int arch_early_init_r(void)
  187. {
  188. quark_pcie_init();
  189. quark_usb_init();
  190. return 0;
  191. }
  192. int cpu_mmc_init(bd_t *bis)
  193. {
  194. return pci_mmc_init("Quark SDHCI", mmc_supported,
  195. ARRAY_SIZE(mmc_supported));
  196. }
  197. void cpu_irq_init(void)
  198. {
  199. struct quark_rcba *rcba;
  200. u32 base;
  201. qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, &base);
  202. base &= ~MEM_BAR_EN;
  203. rcba = (struct quark_rcba *)base;
  204. /*
  205. * Route Quark PCI device interrupt pin to PIRQ
  206. *
  207. * Route device#23's INTA/B/C/D to PIRQA/B/C/D
  208. * Route device#20,21's INTA/B/C/D to PIRQE/F/G/H
  209. */
  210. writew(PIRQC, &rcba->rmu_ir);
  211. writew(PIRQA | (PIRQB << 4) | (PIRQC << 8) | (PIRQD << 12),
  212. &rcba->d23_ir);
  213. writew(PIRQD, &rcba->core_ir);
  214. writew(PIRQE | (PIRQF << 4) | (PIRQG << 8) | (PIRQH << 12),
  215. &rcba->d20d21_ir);
  216. }
  217. int arch_misc_init(void)
  218. {
  219. return pirq_init();
  220. }
  221. void board_final_cleanup(void)
  222. {
  223. struct quark_rcba *rcba;
  224. u32 base, val;
  225. qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, &base);
  226. base &= ~MEM_BAR_EN;
  227. rcba = (struct quark_rcba *)base;
  228. /* Initialize 'Component ID' to zero */
  229. val = readl(&rcba->esd);
  230. val &= ~0xff0000;
  231. writel(val, &rcba->esd);
  232. return;
  233. }