quark.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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 <netdev.h>
  9. #include <phy.h>
  10. #include <asm/io.h>
  11. #include <asm/irq.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_bars(void)
  35. {
  36. /* GPIO - D31:F0:R44h */
  37. qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_GBA,
  38. CONFIG_GPIO_BASE | IO_BAR_EN);
  39. /* ACPI PM1 Block - D31:F0:R48h */
  40. qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_PM1BLK,
  41. CONFIG_ACPI_PM1_BASE | IO_BAR_EN);
  42. /* GPE0 - D31:F0:R4Ch */
  43. qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_GPE0BLK,
  44. CONFIG_ACPI_GPE0_BASE | IO_BAR_EN);
  45. /* WDT - D31:F0:R84h */
  46. qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_WDTBA,
  47. CONFIG_WDT_BASE | IO_BAR_EN);
  48. /* RCBA - D31:F0:RF0h */
  49. qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA,
  50. CONFIG_RCBA_BASE | MEM_BAR_EN);
  51. /* ACPI P Block - Msg Port 04:R70h */
  52. msg_port_write(MSG_PORT_RMU, PBLK_BA,
  53. CONFIG_ACPI_PBLK_BASE | IO_BAR_EN);
  54. /* SPI DMA - Msg Port 04:R7Ah */
  55. msg_port_write(MSG_PORT_RMU, SPI_DMA_BA,
  56. CONFIG_SPI_DMA_BASE | IO_BAR_EN);
  57. /* PCIe ECAM */
  58. msg_port_write(MSG_PORT_MEM_ARBITER, AEC_CTRL,
  59. CONFIG_PCIE_ECAM_BASE | MEM_BAR_EN);
  60. msg_port_write(MSG_PORT_HOST_BRIDGE, HEC_REG,
  61. CONFIG_PCIE_ECAM_BASE | MEM_BAR_EN);
  62. }
  63. static void quark_pcie_early_init(void)
  64. {
  65. u32 pcie_cfg;
  66. /*
  67. * Step1: Assert PCIe signal PERST#
  68. *
  69. * The CPU interface to the PERST# signal is platform dependent.
  70. * Call the board-specific codes to perform this task.
  71. */
  72. board_assert_perst();
  73. /* Step2: PHY common lane reset */
  74. pcie_cfg = msg_port_alt_read(MSG_PORT_SOC_UNIT, PCIE_CFG);
  75. pcie_cfg |= PCIE_PHY_LANE_RST;
  76. msg_port_alt_write(MSG_PORT_SOC_UNIT, PCIE_CFG, pcie_cfg);
  77. /* wait 1 ms for PHY common lane reset */
  78. mdelay(1);
  79. /* Step3: PHY sideband interface reset and controller main reset */
  80. pcie_cfg = msg_port_alt_read(MSG_PORT_SOC_UNIT, PCIE_CFG);
  81. pcie_cfg |= (PCIE_PHY_SB_RST | PCIE_CTLR_MAIN_RST);
  82. msg_port_alt_write(MSG_PORT_SOC_UNIT, PCIE_CFG, pcie_cfg);
  83. /* wait 80ms for PLL to lock */
  84. mdelay(80);
  85. /* Step4: Controller sideband interface reset */
  86. pcie_cfg = msg_port_alt_read(MSG_PORT_SOC_UNIT, PCIE_CFG);
  87. pcie_cfg |= PCIE_CTLR_SB_RST;
  88. msg_port_alt_write(MSG_PORT_SOC_UNIT, PCIE_CFG, pcie_cfg);
  89. /* wait 20ms for controller sideband interface reset */
  90. mdelay(20);
  91. /* Step5: De-assert PERST# */
  92. board_deassert_perst();
  93. /* Step6: Controller primary interface reset */
  94. pcie_cfg = msg_port_alt_read(MSG_PORT_SOC_UNIT, PCIE_CFG);
  95. pcie_cfg |= PCIE_CTLR_PRI_RST;
  96. msg_port_alt_write(MSG_PORT_SOC_UNIT, PCIE_CFG, pcie_cfg);
  97. /* Mixer Load Lane 0 */
  98. pcie_cfg = msg_port_io_read(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L0);
  99. pcie_cfg &= ~((1 << 6) | (1 << 7));
  100. msg_port_io_write(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L0, pcie_cfg);
  101. /* Mixer Load Lane 1 */
  102. pcie_cfg = msg_port_io_read(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L1);
  103. pcie_cfg &= ~((1 << 6) | (1 << 7));
  104. msg_port_io_write(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L1, pcie_cfg);
  105. }
  106. static void quark_usb_early_init(void)
  107. {
  108. u32 usb;
  109. /* The sequence below comes from Quark firmware writer guide */
  110. usb = msg_port_alt_read(MSG_PORT_USB_AFE, USB2_GLOBAL_PORT);
  111. usb &= ~(1 << 1);
  112. usb |= ((1 << 6) | (1 << 7));
  113. msg_port_alt_write(MSG_PORT_USB_AFE, USB2_GLOBAL_PORT, usb);
  114. usb = msg_port_alt_read(MSG_PORT_USB_AFE, USB2_COMPBG);
  115. usb &= ~((1 << 8) | (1 << 9));
  116. usb |= ((1 << 7) | (1 << 10));
  117. msg_port_alt_write(MSG_PORT_USB_AFE, USB2_COMPBG, usb);
  118. usb = msg_port_alt_read(MSG_PORT_USB_AFE, USB2_PLL2);
  119. usb |= (1 << 29);
  120. msg_port_alt_write(MSG_PORT_USB_AFE, USB2_PLL2, usb);
  121. usb = msg_port_alt_read(MSG_PORT_USB_AFE, USB2_PLL1);
  122. usb |= (1 << 1);
  123. msg_port_alt_write(MSG_PORT_USB_AFE, USB2_PLL1, usb);
  124. usb = msg_port_alt_read(MSG_PORT_USB_AFE, USB2_PLL1);
  125. usb &= ~((1 << 3) | (1 << 4) | (1 << 5));
  126. usb |= (1 << 6);
  127. msg_port_alt_write(MSG_PORT_USB_AFE, USB2_PLL1, usb);
  128. usb = msg_port_alt_read(MSG_PORT_USB_AFE, USB2_PLL2);
  129. usb &= ~(1 << 29);
  130. msg_port_alt_write(MSG_PORT_USB_AFE, USB2_PLL2, usb);
  131. usb = msg_port_alt_read(MSG_PORT_USB_AFE, USB2_PLL2);
  132. usb |= (1 << 24);
  133. msg_port_alt_write(MSG_PORT_USB_AFE, USB2_PLL2, usb);
  134. }
  135. static void quark_enable_legacy_seg(void)
  136. {
  137. u32 hmisc2;
  138. hmisc2 = msg_port_read(MSG_PORT_HOST_BRIDGE, HMISC2);
  139. hmisc2 |= (HMISC2_SEGE | HMISC2_SEGF | HMISC2_SEGAB);
  140. msg_port_write(MSG_PORT_HOST_BRIDGE, HMISC2, hmisc2);
  141. }
  142. int arch_cpu_init(void)
  143. {
  144. int ret;
  145. post_code(POST_CPU_INIT);
  146. #ifdef CONFIG_SYS_X86_TSC_TIMER
  147. timer_set_base(rdtsc());
  148. #endif
  149. ret = x86_cpu_init_f();
  150. if (ret)
  151. return ret;
  152. /*
  153. * Quark SoC has some non-standard BARs (excluding PCI standard BARs)
  154. * which need be initialized with suggested values
  155. */
  156. quark_setup_bars();
  157. /*
  158. * Initialize PCIe controller
  159. *
  160. * Quark SoC holds the PCIe controller in reset following a power on.
  161. * U-Boot needs to release the PCIe controller from reset. The PCIe
  162. * controller (D23:F0/F1) will not be visible in PCI configuration
  163. * space and any access to its PCI configuration registers will cause
  164. * system hang while it is held in reset.
  165. */
  166. quark_pcie_early_init();
  167. /* Initialize USB2 PHY */
  168. quark_usb_early_init();
  169. /* Turn on legacy segments (A/B/E/F) decode to system RAM */
  170. quark_enable_legacy_seg();
  171. unprotect_spi_flash();
  172. return 0;
  173. }
  174. int print_cpuinfo(void)
  175. {
  176. post_code(POST_CPU_INFO);
  177. return default_print_cpuinfo();
  178. }
  179. void reset_cpu(ulong addr)
  180. {
  181. /* cold reset */
  182. x86_full_reset();
  183. }
  184. int cpu_mmc_init(bd_t *bis)
  185. {
  186. return pci_mmc_init("Quark SDHCI", mmc_supported,
  187. ARRAY_SIZE(mmc_supported));
  188. }
  189. int cpu_eth_init(bd_t *bis)
  190. {
  191. u32 base;
  192. int ret0, ret1;
  193. qrk_pci_read_config_dword(QUARK_EMAC0, PCI_BASE_ADDRESS_0, &base);
  194. ret0 = designware_initialize(base, PHY_INTERFACE_MODE_RMII);
  195. qrk_pci_read_config_dword(QUARK_EMAC1, PCI_BASE_ADDRESS_0, &base);
  196. ret1 = designware_initialize(base, PHY_INTERFACE_MODE_RMII);
  197. if (ret0 < 0 && ret1 < 0)
  198. return -1;
  199. else
  200. return 0;
  201. }
  202. void cpu_irq_init(void)
  203. {
  204. struct quark_rcba *rcba;
  205. u32 base;
  206. qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, &base);
  207. base &= ~MEM_BAR_EN;
  208. rcba = (struct quark_rcba *)base;
  209. /*
  210. * Route Quark PCI device interrupt pin to PIRQ
  211. *
  212. * Route device#23's INTA/B/C/D to PIRQA/B/C/D
  213. * Route device#20,21's INTA/B/C/D to PIRQE/F/G/H
  214. */
  215. writew(PIRQC, &rcba->rmu_ir);
  216. writew(PIRQA | (PIRQB << 4) | (PIRQC << 8) | (PIRQD << 12),
  217. &rcba->d23_ir);
  218. writew(PIRQD, &rcba->core_ir);
  219. writew(PIRQE | (PIRQF << 4) | (PIRQG << 8) | (PIRQH << 12),
  220. &rcba->d20d21_ir);
  221. }
  222. int arch_misc_init(void)
  223. {
  224. return pirq_init();
  225. }