quark.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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_enable_legacy_seg(void)
  107. {
  108. u32 hmisc2;
  109. hmisc2 = msg_port_read(MSG_PORT_HOST_BRIDGE, HMISC2);
  110. hmisc2 |= (HMISC2_SEGE | HMISC2_SEGF | HMISC2_SEGAB);
  111. msg_port_write(MSG_PORT_HOST_BRIDGE, HMISC2, hmisc2);
  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. /* Turn on legacy segments (A/B/E/F) decode to system RAM */
  139. quark_enable_legacy_seg();
  140. unprotect_spi_flash();
  141. return 0;
  142. }
  143. int print_cpuinfo(void)
  144. {
  145. post_code(POST_CPU_INFO);
  146. return default_print_cpuinfo();
  147. }
  148. void reset_cpu(ulong addr)
  149. {
  150. /* cold reset */
  151. x86_full_reset();
  152. }
  153. int cpu_mmc_init(bd_t *bis)
  154. {
  155. return pci_mmc_init("Quark SDHCI", mmc_supported,
  156. ARRAY_SIZE(mmc_supported));
  157. }
  158. int cpu_eth_init(bd_t *bis)
  159. {
  160. u32 base;
  161. int ret0, ret1;
  162. qrk_pci_read_config_dword(QUARK_EMAC0, PCI_BASE_ADDRESS_0, &base);
  163. ret0 = designware_initialize(base, PHY_INTERFACE_MODE_RMII);
  164. qrk_pci_read_config_dword(QUARK_EMAC1, PCI_BASE_ADDRESS_0, &base);
  165. ret1 = designware_initialize(base, PHY_INTERFACE_MODE_RMII);
  166. if (ret0 < 0 && ret1 < 0)
  167. return -1;
  168. else
  169. return 0;
  170. }
  171. void cpu_irq_init(void)
  172. {
  173. struct quark_rcba *rcba;
  174. u32 base;
  175. qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, &base);
  176. base &= ~MEM_BAR_EN;
  177. rcba = (struct quark_rcba *)base;
  178. /*
  179. * Route Quark PCI device interrupt pin to PIRQ
  180. *
  181. * Route device#23's INTA/B/C/D to PIRQA/B/C/D
  182. * Route device#20,21's INTA/B/C/D to PIRQE/F/G/H
  183. */
  184. writew(PIRQC, &rcba->rmu_ir);
  185. writew(PIRQA | (PIRQB << 4) | (PIRQC << 8) | (PIRQD << 12),
  186. &rcba->d23_ir);
  187. writew(PIRQD, &rcba->core_ir);
  188. writew(PIRQE | (PIRQF << 4) | (PIRQG << 8) | (PIRQH << 12),
  189. &rcba->d20d21_ir);
  190. }
  191. int arch_misc_init(void)
  192. {
  193. return pirq_init();
  194. }