Bin Meng | 81da5a8 | 2015-02-02 22:35:27 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Bin Meng | d79593b | 2015-02-04 16:26:13 +0800 | [diff] [blame] | 8 | #include <mmc.h> |
Bin Meng | 81da5a8 | 2015-02-02 22:35:27 +0800 | [diff] [blame] | 9 | #include <asm/io.h> |
Bin Meng | ef9e9f9 | 2015-05-25 22:35:06 +0800 | [diff] [blame] | 10 | #include <asm/irq.h> |
Bin Meng | 81da5a8 | 2015-02-02 22:35:27 +0800 | [diff] [blame] | 11 | #include <asm/pci.h> |
| 12 | #include <asm/post.h> |
| 13 | #include <asm/processor.h> |
Bin Meng | 3446986 | 2015-02-04 16:26:09 +0800 | [diff] [blame] | 14 | #include <asm/arch/device.h> |
| 15 | #include <asm/arch/msg_port.h> |
| 16 | #include <asm/arch/quark.h> |
| 17 | |
Bin Meng | d79593b | 2015-02-04 16:26:13 +0800 | [diff] [blame] | 18 | static struct pci_device_id mmc_supported[] = { |
| 19 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QRK_SDIO }, |
| 20 | }; |
| 21 | |
Bin Meng | ba6faff | 2015-02-04 16:26:12 +0800 | [diff] [blame] | 22 | /* |
| 23 | * TODO: |
| 24 | * |
| 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 |
| 27 | */ |
| 28 | static void unprotect_spi_flash(void) |
| 29 | { |
| 30 | u32 bc; |
| 31 | |
Bin Meng | 9cdcfd7 | 2015-09-03 05:37:24 -0700 | [diff] [blame] | 32 | qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, 0xd8, &bc); |
Bin Meng | ba6faff | 2015-02-04 16:26:12 +0800 | [diff] [blame] | 33 | bc |= 0x1; /* unprotect the flash */ |
Bin Meng | 9cdcfd7 | 2015-09-03 05:37:24 -0700 | [diff] [blame] | 34 | qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, 0xd8, bc); |
Bin Meng | ba6faff | 2015-02-04 16:26:12 +0800 | [diff] [blame] | 35 | } |
| 36 | |
Bin Meng | 3446986 | 2015-02-04 16:26:09 +0800 | [diff] [blame] | 37 | static void quark_setup_bars(void) |
| 38 | { |
| 39 | /* GPIO - D31:F0:R44h */ |
Bin Meng | 9cdcfd7 | 2015-09-03 05:37:24 -0700 | [diff] [blame] | 40 | qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_GBA, |
| 41 | CONFIG_GPIO_BASE | IO_BAR_EN); |
Bin Meng | 3446986 | 2015-02-04 16:26:09 +0800 | [diff] [blame] | 42 | |
| 43 | /* ACPI PM1 Block - D31:F0:R48h */ |
Bin Meng | 9cdcfd7 | 2015-09-03 05:37:24 -0700 | [diff] [blame] | 44 | qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_PM1BLK, |
| 45 | CONFIG_ACPI_PM1_BASE | IO_BAR_EN); |
Bin Meng | 3446986 | 2015-02-04 16:26:09 +0800 | [diff] [blame] | 46 | |
| 47 | /* GPE0 - D31:F0:R4Ch */ |
Bin Meng | 9cdcfd7 | 2015-09-03 05:37:24 -0700 | [diff] [blame] | 48 | qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_GPE0BLK, |
| 49 | CONFIG_ACPI_GPE0_BASE | IO_BAR_EN); |
Bin Meng | 3446986 | 2015-02-04 16:26:09 +0800 | [diff] [blame] | 50 | |
| 51 | /* WDT - D31:F0:R84h */ |
Bin Meng | 9cdcfd7 | 2015-09-03 05:37:24 -0700 | [diff] [blame] | 52 | qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_WDTBA, |
| 53 | CONFIG_WDT_BASE | IO_BAR_EN); |
Bin Meng | 3446986 | 2015-02-04 16:26:09 +0800 | [diff] [blame] | 54 | |
| 55 | /* RCBA - D31:F0:RF0h */ |
Bin Meng | 9cdcfd7 | 2015-09-03 05:37:24 -0700 | [diff] [blame] | 56 | qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, |
| 57 | CONFIG_RCBA_BASE | MEM_BAR_EN); |
Bin Meng | 3446986 | 2015-02-04 16:26:09 +0800 | [diff] [blame] | 58 | |
| 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); |
| 62 | |
| 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); |
| 66 | |
| 67 | /* PCIe ECAM */ |
| 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); |
| 72 | } |
Bin Meng | 81da5a8 | 2015-02-02 22:35:27 +0800 | [diff] [blame] | 73 | |
Bin Meng | 4756cac | 2015-09-03 05:37:25 -0700 | [diff] [blame] | 74 | static void quark_pcie_early_init(void) |
| 75 | { |
Bin Meng | 4756cac | 2015-09-03 05:37:25 -0700 | [diff] [blame] | 76 | /* |
| 77 | * Step1: Assert PCIe signal PERST# |
| 78 | * |
| 79 | * The CPU interface to the PERST# signal is platform dependent. |
| 80 | * Call the board-specific codes to perform this task. |
| 81 | */ |
| 82 | board_assert_perst(); |
| 83 | |
| 84 | /* Step2: PHY common lane reset */ |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 85 | msg_port_alt_setbits(MSG_PORT_SOC_UNIT, PCIE_CFG, PCIE_PHY_LANE_RST); |
Bin Meng | 4756cac | 2015-09-03 05:37:25 -0700 | [diff] [blame] | 86 | /* wait 1 ms for PHY common lane reset */ |
| 87 | mdelay(1); |
| 88 | |
| 89 | /* Step3: PHY sideband interface reset and controller main reset */ |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 90 | msg_port_alt_setbits(MSG_PORT_SOC_UNIT, PCIE_CFG, |
| 91 | PCIE_PHY_SB_RST | PCIE_CTLR_MAIN_RST); |
Bin Meng | 4756cac | 2015-09-03 05:37:25 -0700 | [diff] [blame] | 92 | /* wait 80ms for PLL to lock */ |
| 93 | mdelay(80); |
| 94 | |
| 95 | /* Step4: Controller sideband interface reset */ |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 96 | msg_port_alt_setbits(MSG_PORT_SOC_UNIT, PCIE_CFG, PCIE_CTLR_SB_RST); |
Bin Meng | 4756cac | 2015-09-03 05:37:25 -0700 | [diff] [blame] | 97 | /* wait 20ms for controller sideband interface reset */ |
| 98 | mdelay(20); |
| 99 | |
| 100 | /* Step5: De-assert PERST# */ |
| 101 | board_deassert_perst(); |
| 102 | |
| 103 | /* Step6: Controller primary interface reset */ |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 104 | msg_port_alt_setbits(MSG_PORT_SOC_UNIT, PCIE_CFG, PCIE_CTLR_PRI_RST); |
Bin Meng | 4756cac | 2015-09-03 05:37:25 -0700 | [diff] [blame] | 105 | |
| 106 | /* Mixer Load Lane 0 */ |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 107 | msg_port_io_clrbits(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L0, |
| 108 | (1 << 6) | (1 << 7)); |
Bin Meng | 4756cac | 2015-09-03 05:37:25 -0700 | [diff] [blame] | 109 | |
| 110 | /* Mixer Load Lane 1 */ |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 111 | msg_port_io_clrbits(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L1, |
| 112 | (1 << 6) | (1 << 7)); |
Bin Meng | 4756cac | 2015-09-03 05:37:25 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Bin Meng | f376372 | 2015-09-03 05:37:27 -0700 | [diff] [blame] | 115 | static void quark_usb_early_init(void) |
| 116 | { |
Bin Meng | f376372 | 2015-09-03 05:37:27 -0700 | [diff] [blame] | 117 | /* The sequence below comes from Quark firmware writer guide */ |
| 118 | |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 119 | msg_port_alt_clrsetbits(MSG_PORT_USB_AFE, USB2_GLOBAL_PORT, |
| 120 | 1 << 1, (1 << 6) | (1 << 7)); |
Bin Meng | f376372 | 2015-09-03 05:37:27 -0700 | [diff] [blame] | 121 | |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 122 | msg_port_alt_clrsetbits(MSG_PORT_USB_AFE, USB2_COMPBG, |
| 123 | (1 << 8) | (1 << 9), (1 << 7) | (1 << 10)); |
Bin Meng | f376372 | 2015-09-03 05:37:27 -0700 | [diff] [blame] | 124 | |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 125 | msg_port_alt_setbits(MSG_PORT_USB_AFE, USB2_PLL2, 1 << 29); |
Bin Meng | f376372 | 2015-09-03 05:37:27 -0700 | [diff] [blame] | 126 | |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 127 | msg_port_alt_setbits(MSG_PORT_USB_AFE, USB2_PLL1, 1 << 1); |
Bin Meng | f376372 | 2015-09-03 05:37:27 -0700 | [diff] [blame] | 128 | |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 129 | msg_port_alt_clrsetbits(MSG_PORT_USB_AFE, USB2_PLL1, |
| 130 | (1 << 3) | (1 << 4) | (1 << 5), 1 << 6); |
Bin Meng | f376372 | 2015-09-03 05:37:27 -0700 | [diff] [blame] | 131 | |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 132 | msg_port_alt_clrbits(MSG_PORT_USB_AFE, USB2_PLL2, 1 << 29); |
Bin Meng | f376372 | 2015-09-03 05:37:27 -0700 | [diff] [blame] | 133 | |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 134 | msg_port_alt_setbits(MSG_PORT_USB_AFE, USB2_PLL2, 1 << 24); |
Bin Meng | f376372 | 2015-09-03 05:37:27 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Bin Meng | 6db1448 | 2015-04-27 14:16:02 +0800 | [diff] [blame] | 137 | static void quark_enable_legacy_seg(void) |
| 138 | { |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 139 | msg_port_setbits(MSG_PORT_HOST_BRIDGE, HMISC2, |
| 140 | HMISC2_SEGE | HMISC2_SEGF | HMISC2_SEGAB); |
Bin Meng | 6db1448 | 2015-04-27 14:16:02 +0800 | [diff] [blame] | 141 | } |
| 142 | |
Bin Meng | 81da5a8 | 2015-02-02 22:35:27 +0800 | [diff] [blame] | 143 | int arch_cpu_init(void) |
| 144 | { |
Bin Meng | 81da5a8 | 2015-02-02 22:35:27 +0800 | [diff] [blame] | 145 | int ret; |
| 146 | |
| 147 | post_code(POST_CPU_INIT); |
| 148 | #ifdef CONFIG_SYS_X86_TSC_TIMER |
| 149 | timer_set_base(rdtsc()); |
| 150 | #endif |
| 151 | |
| 152 | ret = x86_cpu_init_f(); |
| 153 | if (ret) |
| 154 | return ret; |
| 155 | |
Bin Meng | 3446986 | 2015-02-04 16:26:09 +0800 | [diff] [blame] | 156 | /* |
| 157 | * Quark SoC has some non-standard BARs (excluding PCI standard BARs) |
| 158 | * which need be initialized with suggested values |
| 159 | */ |
| 160 | quark_setup_bars(); |
| 161 | |
Bin Meng | 4756cac | 2015-09-03 05:37:25 -0700 | [diff] [blame] | 162 | /* |
| 163 | * Initialize PCIe controller |
| 164 | * |
| 165 | * Quark SoC holds the PCIe controller in reset following a power on. |
| 166 | * U-Boot needs to release the PCIe controller from reset. The PCIe |
| 167 | * controller (D23:F0/F1) will not be visible in PCI configuration |
| 168 | * space and any access to its PCI configuration registers will cause |
| 169 | * system hang while it is held in reset. |
| 170 | */ |
| 171 | quark_pcie_early_init(); |
| 172 | |
Bin Meng | f376372 | 2015-09-03 05:37:27 -0700 | [diff] [blame] | 173 | /* Initialize USB2 PHY */ |
| 174 | quark_usb_early_init(); |
| 175 | |
Bin Meng | 6db1448 | 2015-04-27 14:16:02 +0800 | [diff] [blame] | 176 | /* Turn on legacy segments (A/B/E/F) decode to system RAM */ |
| 177 | quark_enable_legacy_seg(); |
| 178 | |
Bin Meng | ba6faff | 2015-02-04 16:26:12 +0800 | [diff] [blame] | 179 | unprotect_spi_flash(); |
| 180 | |
Bin Meng | 81da5a8 | 2015-02-02 22:35:27 +0800 | [diff] [blame] | 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | int print_cpuinfo(void) |
| 185 | { |
| 186 | post_code(POST_CPU_INFO); |
| 187 | return default_print_cpuinfo(); |
| 188 | } |
| 189 | |
| 190 | void reset_cpu(ulong addr) |
| 191 | { |
| 192 | /* cold reset */ |
Simon Glass | d0963d4 | 2015-04-28 20:11:31 -0600 | [diff] [blame] | 193 | x86_full_reset(); |
Bin Meng | 81da5a8 | 2015-02-02 22:35:27 +0800 | [diff] [blame] | 194 | } |
Bin Meng | d79593b | 2015-02-04 16:26:13 +0800 | [diff] [blame] | 195 | |
Bin Meng | 4e19d7c | 2015-09-11 03:24:37 -0700 | [diff] [blame] | 196 | static void quark_pcie_init(void) |
| 197 | { |
| 198 | u32 val; |
| 199 | |
| 200 | /* PCIe upstream non-posted & posted request size */ |
| 201 | qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_CCFG, |
| 202 | CCFG_UPRS | CCFG_UNRS); |
| 203 | qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_CCFG, |
| 204 | CCFG_UPRS | CCFG_UNRS); |
| 205 | |
| 206 | /* PCIe packet fast transmit mode (IPF) */ |
| 207 | qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_MPC2, MPC2_IPF); |
| 208 | qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_MPC2, MPC2_IPF); |
| 209 | |
| 210 | /* PCIe message bus idle counter (SBIC) */ |
| 211 | qrk_pci_read_config_dword(QUARK_PCIE0, PCIE_RP_MBC, &val); |
| 212 | val |= MBC_SBIC; |
| 213 | qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_MBC, val); |
| 214 | qrk_pci_read_config_dword(QUARK_PCIE1, PCIE_RP_MBC, &val); |
| 215 | val |= MBC_SBIC; |
| 216 | qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_MBC, val); |
| 217 | } |
| 218 | |
| 219 | static void quark_usb_init(void) |
| 220 | { |
| 221 | u32 bar; |
| 222 | |
| 223 | /* Change USB EHCI packet buffer OUT/IN threshold */ |
| 224 | qrk_pci_read_config_dword(QUARK_USB_EHCI, PCI_BASE_ADDRESS_0, &bar); |
| 225 | writel((0x7f << 16) | 0x7f, bar + EHCI_INSNREG01); |
| 226 | |
| 227 | /* Disable USB device interrupts */ |
| 228 | qrk_pci_read_config_dword(QUARK_USB_DEVICE, PCI_BASE_ADDRESS_0, &bar); |
| 229 | writel(0x7f, bar + USBD_INT_MASK); |
| 230 | writel((0xf << 16) | 0xf, bar + USBD_EP_INT_MASK); |
| 231 | writel((0xf << 16) | 0xf, bar + USBD_EP_INT_STS); |
| 232 | } |
| 233 | |
| 234 | int arch_early_init_r(void) |
| 235 | { |
| 236 | quark_pcie_init(); |
| 237 | |
| 238 | quark_usb_init(); |
| 239 | |
| 240 | return 0; |
| 241 | } |
| 242 | |
Bin Meng | d79593b | 2015-02-04 16:26:13 +0800 | [diff] [blame] | 243 | int cpu_mmc_init(bd_t *bis) |
| 244 | { |
| 245 | return pci_mmc_init("Quark SDHCI", mmc_supported, |
| 246 | ARRAY_SIZE(mmc_supported)); |
| 247 | } |
Bin Meng | 7e96d31 | 2015-03-11 11:25:56 +0800 | [diff] [blame] | 248 | |
Bin Meng | ef9e9f9 | 2015-05-25 22:35:06 +0800 | [diff] [blame] | 249 | void cpu_irq_init(void) |
| 250 | { |
| 251 | struct quark_rcba *rcba; |
| 252 | u32 base; |
| 253 | |
Bin Meng | 9cdcfd7 | 2015-09-03 05:37:24 -0700 | [diff] [blame] | 254 | qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, &base); |
Bin Meng | ef9e9f9 | 2015-05-25 22:35:06 +0800 | [diff] [blame] | 255 | base &= ~MEM_BAR_EN; |
| 256 | rcba = (struct quark_rcba *)base; |
| 257 | |
| 258 | /* |
| 259 | * Route Quark PCI device interrupt pin to PIRQ |
| 260 | * |
| 261 | * Route device#23's INTA/B/C/D to PIRQA/B/C/D |
| 262 | * Route device#20,21's INTA/B/C/D to PIRQE/F/G/H |
| 263 | */ |
| 264 | writew(PIRQC, &rcba->rmu_ir); |
| 265 | writew(PIRQA | (PIRQB << 4) | (PIRQC << 8) | (PIRQD << 12), |
| 266 | &rcba->d23_ir); |
| 267 | writew(PIRQD, &rcba->core_ir); |
| 268 | writew(PIRQE | (PIRQF << 4) | (PIRQG << 8) | (PIRQH << 12), |
| 269 | &rcba->d20d21_ir); |
| 270 | } |
| 271 | |
| 272 | int arch_misc_init(void) |
| 273 | { |
Simon Glass | af1c2d68 | 2015-08-10 07:05:08 -0600 | [diff] [blame] | 274 | return pirq_init(); |
Bin Meng | ef9e9f9 | 2015-05-25 22:35:06 +0800 | [diff] [blame] | 275 | } |
Bin Meng | 4e19d7c | 2015-09-11 03:24:37 -0700 | [diff] [blame] | 276 | |
| 277 | void board_final_cleanup(void) |
| 278 | { |
| 279 | struct quark_rcba *rcba; |
| 280 | u32 base, val; |
| 281 | |
| 282 | qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, &base); |
| 283 | base &= ~MEM_BAR_EN; |
| 284 | rcba = (struct quark_rcba *)base; |
| 285 | |
| 286 | /* Initialize 'Component ID' to zero */ |
| 287 | val = readl(&rcba->esd); |
| 288 | val &= ~0xff0000; |
| 289 | writel(val, &rcba->esd); |
| 290 | |
Bin Meng | 619c90a | 2015-09-09 23:20:26 -0700 | [diff] [blame^] | 291 | /* Lock HMBOUND for security */ |
| 292 | msg_port_setbits(MSG_PORT_HOST_BRIDGE, HM_BOUND, HM_BOUND_LOCK); |
| 293 | |
Bin Meng | 4e19d7c | 2015-09-11 03:24:37 -0700 | [diff] [blame] | 294 | return; |
| 295 | } |