2 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0+
13 #include <asm/processor.h>
14 #include <asm/arch/device.h>
15 #include <asm/arch/msg_port.h>
16 #include <asm/arch/quark.h>
18 static struct pci_device_id mmc_supported[] = {
19 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QRK_SDIO },
25 * This whole routine should be removed until we fully convert the ICH SPI
26 * driver to DM and make use of DT to pass the bios control register offset
28 static void unprotect_spi_flash(void)
32 qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, 0xd8, &bc);
33 bc |= 0x1; /* unprotect the flash */
34 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, 0xd8, bc);
37 static void quark_setup_bars(void)
39 /* GPIO - D31:F0:R44h */
40 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_GBA,
41 CONFIG_GPIO_BASE | IO_BAR_EN);
43 /* ACPI PM1 Block - D31:F0:R48h */
44 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_PM1BLK,
45 CONFIG_ACPI_PM1_BASE | IO_BAR_EN);
47 /* GPE0 - D31:F0:R4Ch */
48 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_GPE0BLK,
49 CONFIG_ACPI_GPE0_BASE | IO_BAR_EN);
51 /* WDT - D31:F0:R84h */
52 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_WDTBA,
53 CONFIG_WDT_BASE | IO_BAR_EN);
55 /* RCBA - D31:F0:RF0h */
56 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA,
57 CONFIG_RCBA_BASE | MEM_BAR_EN);
59 /* ACPI P Block - Msg Port 04:R70h */
60 msg_port_write(MSG_PORT_RMU, PBLK_BA,
61 CONFIG_ACPI_PBLK_BASE | IO_BAR_EN);
63 /* SPI DMA - Msg Port 04:R7Ah */
64 msg_port_write(MSG_PORT_RMU, SPI_DMA_BA,
65 CONFIG_SPI_DMA_BASE | IO_BAR_EN);
68 msg_port_write(MSG_PORT_MEM_ARBITER, AEC_CTRL,
69 CONFIG_PCIE_ECAM_BASE | MEM_BAR_EN);
70 msg_port_write(MSG_PORT_HOST_BRIDGE, HEC_REG,
71 CONFIG_PCIE_ECAM_BASE | MEM_BAR_EN);
74 static void quark_pcie_early_init(void)
79 * Step1: Assert PCIe signal PERST#
81 * The CPU interface to the PERST# signal is platform dependent.
82 * Call the board-specific codes to perform this task.
86 /* Step2: PHY common lane reset */
87 pcie_cfg = msg_port_alt_read(MSG_PORT_SOC_UNIT, PCIE_CFG);
88 pcie_cfg |= PCIE_PHY_LANE_RST;
89 msg_port_alt_write(MSG_PORT_SOC_UNIT, PCIE_CFG, pcie_cfg);
90 /* wait 1 ms for PHY common lane reset */
93 /* Step3: PHY sideband interface reset and controller main reset */
94 pcie_cfg = msg_port_alt_read(MSG_PORT_SOC_UNIT, PCIE_CFG);
95 pcie_cfg |= (PCIE_PHY_SB_RST | PCIE_CTLR_MAIN_RST);
96 msg_port_alt_write(MSG_PORT_SOC_UNIT, PCIE_CFG, pcie_cfg);
97 /* wait 80ms for PLL to lock */
100 /* Step4: Controller sideband interface reset */
101 pcie_cfg = msg_port_alt_read(MSG_PORT_SOC_UNIT, PCIE_CFG);
102 pcie_cfg |= PCIE_CTLR_SB_RST;
103 msg_port_alt_write(MSG_PORT_SOC_UNIT, PCIE_CFG, pcie_cfg);
104 /* wait 20ms for controller sideband interface reset */
107 /* Step5: De-assert PERST# */
108 board_deassert_perst();
110 /* Step6: Controller primary interface reset */
111 pcie_cfg = msg_port_alt_read(MSG_PORT_SOC_UNIT, PCIE_CFG);
112 pcie_cfg |= PCIE_CTLR_PRI_RST;
113 msg_port_alt_write(MSG_PORT_SOC_UNIT, PCIE_CFG, pcie_cfg);
115 /* Mixer Load Lane 0 */
116 pcie_cfg = msg_port_io_read(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L0);
117 pcie_cfg &= ~((1 << 6) | (1 << 7));
118 msg_port_io_write(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L0, pcie_cfg);
120 /* Mixer Load Lane 1 */
121 pcie_cfg = msg_port_io_read(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L1);
122 pcie_cfg &= ~((1 << 6) | (1 << 7));
123 msg_port_io_write(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L1, pcie_cfg);
126 static void quark_usb_early_init(void)
130 /* The sequence below comes from Quark firmware writer guide */
132 usb = msg_port_alt_read(MSG_PORT_USB_AFE, USB2_GLOBAL_PORT);
134 usb |= ((1 << 6) | (1 << 7));
135 msg_port_alt_write(MSG_PORT_USB_AFE, USB2_GLOBAL_PORT, usb);
137 usb = msg_port_alt_read(MSG_PORT_USB_AFE, USB2_COMPBG);
138 usb &= ~((1 << 8) | (1 << 9));
139 usb |= ((1 << 7) | (1 << 10));
140 msg_port_alt_write(MSG_PORT_USB_AFE, USB2_COMPBG, usb);
142 usb = msg_port_alt_read(MSG_PORT_USB_AFE, USB2_PLL2);
144 msg_port_alt_write(MSG_PORT_USB_AFE, USB2_PLL2, usb);
146 usb = msg_port_alt_read(MSG_PORT_USB_AFE, USB2_PLL1);
148 msg_port_alt_write(MSG_PORT_USB_AFE, USB2_PLL1, usb);
150 usb = msg_port_alt_read(MSG_PORT_USB_AFE, USB2_PLL1);
151 usb &= ~((1 << 3) | (1 << 4) | (1 << 5));
153 msg_port_alt_write(MSG_PORT_USB_AFE, USB2_PLL1, usb);
155 usb = msg_port_alt_read(MSG_PORT_USB_AFE, USB2_PLL2);
157 msg_port_alt_write(MSG_PORT_USB_AFE, USB2_PLL2, usb);
159 usb = msg_port_alt_read(MSG_PORT_USB_AFE, USB2_PLL2);
161 msg_port_alt_write(MSG_PORT_USB_AFE, USB2_PLL2, usb);
164 static void quark_enable_legacy_seg(void)
168 hmisc2 = msg_port_read(MSG_PORT_HOST_BRIDGE, HMISC2);
169 hmisc2 |= (HMISC2_SEGE | HMISC2_SEGF | HMISC2_SEGAB);
170 msg_port_write(MSG_PORT_HOST_BRIDGE, HMISC2, hmisc2);
173 int arch_cpu_init(void)
177 post_code(POST_CPU_INIT);
178 #ifdef CONFIG_SYS_X86_TSC_TIMER
179 timer_set_base(rdtsc());
182 ret = x86_cpu_init_f();
187 * Quark SoC has some non-standard BARs (excluding PCI standard BARs)
188 * which need be initialized with suggested values
193 * Initialize PCIe controller
195 * Quark SoC holds the PCIe controller in reset following a power on.
196 * U-Boot needs to release the PCIe controller from reset. The PCIe
197 * controller (D23:F0/F1) will not be visible in PCI configuration
198 * space and any access to its PCI configuration registers will cause
199 * system hang while it is held in reset.
201 quark_pcie_early_init();
203 /* Initialize USB2 PHY */
204 quark_usb_early_init();
206 /* Turn on legacy segments (A/B/E/F) decode to system RAM */
207 quark_enable_legacy_seg();
209 unprotect_spi_flash();
214 int print_cpuinfo(void)
216 post_code(POST_CPU_INFO);
217 return default_print_cpuinfo();
220 void reset_cpu(ulong addr)
226 int cpu_mmc_init(bd_t *bis)
228 return pci_mmc_init("Quark SDHCI", mmc_supported,
229 ARRAY_SIZE(mmc_supported));
232 void cpu_irq_init(void)
234 struct quark_rcba *rcba;
237 qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, &base);
239 rcba = (struct quark_rcba *)base;
242 * Route Quark PCI device interrupt pin to PIRQ
244 * Route device#23's INTA/B/C/D to PIRQA/B/C/D
245 * Route device#20,21's INTA/B/C/D to PIRQE/F/G/H
247 writew(PIRQC, &rcba->rmu_ir);
248 writew(PIRQA | (PIRQB << 4) | (PIRQC << 8) | (PIRQD << 12),
250 writew(PIRQD, &rcba->core_ir);
251 writew(PIRQE | (PIRQF << 4) | (PIRQG << 8) | (PIRQH << 12),
255 int arch_misc_init(void)