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 | 4c2af8b | 2015-10-12 01:30:42 -0700 | [diff] [blame] | 11 | #include <asm/mrccache.h> |
Bin Meng | 0244ef4 | 2015-09-14 00:07:41 -0700 | [diff] [blame] | 12 | #include <asm/mtrr.h> |
Bin Meng | 81da5a8 | 2015-02-02 22:35:27 +0800 | [diff] [blame] | 13 | #include <asm/pci.h> |
| 14 | #include <asm/post.h> |
| 15 | #include <asm/processor.h> |
Bin Meng | 3446986 | 2015-02-04 16:26:09 +0800 | [diff] [blame] | 16 | #include <asm/arch/device.h> |
| 17 | #include <asm/arch/msg_port.h> |
| 18 | #include <asm/arch/quark.h> |
| 19 | |
Bin Meng | d79593b | 2015-02-04 16:26:13 +0800 | [diff] [blame] | 20 | static struct pci_device_id mmc_supported[] = { |
| 21 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QRK_SDIO }, |
Simon Glass | 0b61928 | 2015-11-29 13:18:08 -0700 | [diff] [blame] | 22 | {}, |
Bin Meng | d79593b | 2015-02-04 16:26:13 +0800 | [diff] [blame] | 23 | }; |
| 24 | |
Bin Meng | ba6faff | 2015-02-04 16:26:12 +0800 | [diff] [blame] | 25 | /* |
| 26 | * TODO: |
| 27 | * |
| 28 | * This whole routine should be removed until we fully convert the ICH SPI |
| 29 | * driver to DM and make use of DT to pass the bios control register offset |
| 30 | */ |
| 31 | static void unprotect_spi_flash(void) |
| 32 | { |
| 33 | u32 bc; |
| 34 | |
Bin Meng | 9cdcfd7 | 2015-09-03 05:37:24 -0700 | [diff] [blame] | 35 | qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, 0xd8, &bc); |
Bin Meng | ba6faff | 2015-02-04 16:26:12 +0800 | [diff] [blame] | 36 | bc |= 0x1; /* unprotect the flash */ |
Bin Meng | 9cdcfd7 | 2015-09-03 05:37:24 -0700 | [diff] [blame] | 37 | qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, 0xd8, bc); |
Bin Meng | ba6faff | 2015-02-04 16:26:12 +0800 | [diff] [blame] | 38 | } |
| 39 | |
Bin Meng | 0244ef4 | 2015-09-14 00:07:41 -0700 | [diff] [blame] | 40 | static void quark_setup_mtrr(void) |
| 41 | { |
| 42 | u32 base, mask; |
| 43 | int i; |
| 44 | |
| 45 | disable_caches(); |
| 46 | |
| 47 | /* mark the VGA RAM area as uncacheable */ |
| 48 | msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_16K_A0000, |
| 49 | MTRR_FIX_TYPE(MTRR_TYPE_UNCACHEABLE)); |
| 50 | msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_16K_B0000, |
| 51 | MTRR_FIX_TYPE(MTRR_TYPE_UNCACHEABLE)); |
| 52 | |
| 53 | /* mark other fixed range areas as cacheable */ |
| 54 | msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_64K_00000, |
| 55 | MTRR_FIX_TYPE(MTRR_TYPE_WRBACK)); |
| 56 | msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_64K_40000, |
| 57 | MTRR_FIX_TYPE(MTRR_TYPE_WRBACK)); |
| 58 | msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_16K_80000, |
| 59 | MTRR_FIX_TYPE(MTRR_TYPE_WRBACK)); |
| 60 | msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_16K_90000, |
| 61 | MTRR_FIX_TYPE(MTRR_TYPE_WRBACK)); |
| 62 | for (i = MTRR_FIX_4K_C0000; i <= MTRR_FIX_4K_FC000; i++) |
| 63 | msg_port_write(MSG_PORT_HOST_BRIDGE, i, |
| 64 | MTRR_FIX_TYPE(MTRR_TYPE_WRBACK)); |
| 65 | |
| 66 | /* variable range MTRR#0: ROM area */ |
| 67 | mask = ~(CONFIG_SYS_MONITOR_LEN - 1); |
| 68 | base = CONFIG_SYS_TEXT_BASE & mask; |
| 69 | msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_VAR_PHYBASE(MTRR_VAR_ROM), |
| 70 | base | MTRR_TYPE_WRBACK); |
| 71 | msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_VAR_PHYMASK(MTRR_VAR_ROM), |
| 72 | mask | MTRR_PHYS_MASK_VALID); |
| 73 | |
| 74 | /* variable range MTRR#1: eSRAM area */ |
| 75 | mask = ~(ESRAM_SIZE - 1); |
| 76 | base = CONFIG_ESRAM_BASE & mask; |
| 77 | msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_VAR_PHYBASE(MTRR_VAR_ESRAM), |
| 78 | base | MTRR_TYPE_WRBACK); |
| 79 | msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_VAR_PHYMASK(MTRR_VAR_ESRAM), |
| 80 | mask | MTRR_PHYS_MASK_VALID); |
| 81 | |
| 82 | /* enable both variable and fixed range MTRRs */ |
| 83 | msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_DEF_TYPE, |
| 84 | MTRR_DEF_TYPE_EN | MTRR_DEF_TYPE_FIX_EN); |
| 85 | |
| 86 | enable_caches(); |
| 87 | } |
| 88 | |
Bin Meng | 3446986 | 2015-02-04 16:26:09 +0800 | [diff] [blame] | 89 | static void quark_setup_bars(void) |
| 90 | { |
| 91 | /* GPIO - D31:F0:R44h */ |
Bin Meng | 9cdcfd7 | 2015-09-03 05:37:24 -0700 | [diff] [blame] | 92 | qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_GBA, |
| 93 | CONFIG_GPIO_BASE | IO_BAR_EN); |
Bin Meng | 3446986 | 2015-02-04 16:26:09 +0800 | [diff] [blame] | 94 | |
| 95 | /* ACPI PM1 Block - D31:F0:R48h */ |
Bin Meng | 9cdcfd7 | 2015-09-03 05:37:24 -0700 | [diff] [blame] | 96 | qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_PM1BLK, |
| 97 | CONFIG_ACPI_PM1_BASE | IO_BAR_EN); |
Bin Meng | 3446986 | 2015-02-04 16:26:09 +0800 | [diff] [blame] | 98 | |
| 99 | /* GPE0 - D31:F0:R4Ch */ |
Bin Meng | 9cdcfd7 | 2015-09-03 05:37:24 -0700 | [diff] [blame] | 100 | qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_GPE0BLK, |
| 101 | CONFIG_ACPI_GPE0_BASE | IO_BAR_EN); |
Bin Meng | 3446986 | 2015-02-04 16:26:09 +0800 | [diff] [blame] | 102 | |
| 103 | /* WDT - D31:F0:R84h */ |
Bin Meng | 9cdcfd7 | 2015-09-03 05:37:24 -0700 | [diff] [blame] | 104 | qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_WDTBA, |
| 105 | CONFIG_WDT_BASE | IO_BAR_EN); |
Bin Meng | 3446986 | 2015-02-04 16:26:09 +0800 | [diff] [blame] | 106 | |
| 107 | /* RCBA - D31:F0:RF0h */ |
Bin Meng | 9cdcfd7 | 2015-09-03 05:37:24 -0700 | [diff] [blame] | 108 | qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, |
| 109 | CONFIG_RCBA_BASE | MEM_BAR_EN); |
Bin Meng | 3446986 | 2015-02-04 16:26:09 +0800 | [diff] [blame] | 110 | |
| 111 | /* ACPI P Block - Msg Port 04:R70h */ |
| 112 | msg_port_write(MSG_PORT_RMU, PBLK_BA, |
| 113 | CONFIG_ACPI_PBLK_BASE | IO_BAR_EN); |
| 114 | |
| 115 | /* SPI DMA - Msg Port 04:R7Ah */ |
| 116 | msg_port_write(MSG_PORT_RMU, SPI_DMA_BA, |
| 117 | CONFIG_SPI_DMA_BASE | IO_BAR_EN); |
| 118 | |
| 119 | /* PCIe ECAM */ |
| 120 | msg_port_write(MSG_PORT_MEM_ARBITER, AEC_CTRL, |
| 121 | CONFIG_PCIE_ECAM_BASE | MEM_BAR_EN); |
| 122 | msg_port_write(MSG_PORT_HOST_BRIDGE, HEC_REG, |
| 123 | CONFIG_PCIE_ECAM_BASE | MEM_BAR_EN); |
| 124 | } |
Bin Meng | 81da5a8 | 2015-02-02 22:35:27 +0800 | [diff] [blame] | 125 | |
Bin Meng | 4756cac | 2015-09-03 05:37:25 -0700 | [diff] [blame] | 126 | static void quark_pcie_early_init(void) |
| 127 | { |
Bin Meng | 4756cac | 2015-09-03 05:37:25 -0700 | [diff] [blame] | 128 | /* |
| 129 | * Step1: Assert PCIe signal PERST# |
| 130 | * |
| 131 | * The CPU interface to the PERST# signal is platform dependent. |
| 132 | * Call the board-specific codes to perform this task. |
| 133 | */ |
| 134 | board_assert_perst(); |
| 135 | |
| 136 | /* Step2: PHY common lane reset */ |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 137 | 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] | 138 | /* wait 1 ms for PHY common lane reset */ |
| 139 | mdelay(1); |
| 140 | |
| 141 | /* Step3: PHY sideband interface reset and controller main reset */ |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 142 | msg_port_alt_setbits(MSG_PORT_SOC_UNIT, PCIE_CFG, |
| 143 | PCIE_PHY_SB_RST | PCIE_CTLR_MAIN_RST); |
Bin Meng | 4756cac | 2015-09-03 05:37:25 -0700 | [diff] [blame] | 144 | /* wait 80ms for PLL to lock */ |
| 145 | mdelay(80); |
| 146 | |
| 147 | /* Step4: Controller sideband interface reset */ |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 148 | 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] | 149 | /* wait 20ms for controller sideband interface reset */ |
| 150 | mdelay(20); |
| 151 | |
| 152 | /* Step5: De-assert PERST# */ |
| 153 | board_deassert_perst(); |
| 154 | |
| 155 | /* Step6: Controller primary interface reset */ |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 156 | 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] | 157 | |
| 158 | /* Mixer Load Lane 0 */ |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 159 | msg_port_io_clrbits(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L0, |
| 160 | (1 << 6) | (1 << 7)); |
Bin Meng | 4756cac | 2015-09-03 05:37:25 -0700 | [diff] [blame] | 161 | |
| 162 | /* Mixer Load Lane 1 */ |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 163 | msg_port_io_clrbits(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L1, |
| 164 | (1 << 6) | (1 << 7)); |
Bin Meng | 4756cac | 2015-09-03 05:37:25 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Bin Meng | f376372 | 2015-09-03 05:37:27 -0700 | [diff] [blame] | 167 | static void quark_usb_early_init(void) |
| 168 | { |
Bin Meng | f376372 | 2015-09-03 05:37:27 -0700 | [diff] [blame] | 169 | /* The sequence below comes from Quark firmware writer guide */ |
| 170 | |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 171 | msg_port_alt_clrsetbits(MSG_PORT_USB_AFE, USB2_GLOBAL_PORT, |
| 172 | 1 << 1, (1 << 6) | (1 << 7)); |
Bin Meng | f376372 | 2015-09-03 05:37:27 -0700 | [diff] [blame] | 173 | |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 174 | msg_port_alt_clrsetbits(MSG_PORT_USB_AFE, USB2_COMPBG, |
| 175 | (1 << 8) | (1 << 9), (1 << 7) | (1 << 10)); |
Bin Meng | f376372 | 2015-09-03 05:37:27 -0700 | [diff] [blame] | 176 | |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 177 | msg_port_alt_setbits(MSG_PORT_USB_AFE, USB2_PLL2, 1 << 29); |
Bin Meng | f376372 | 2015-09-03 05:37:27 -0700 | [diff] [blame] | 178 | |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 179 | msg_port_alt_setbits(MSG_PORT_USB_AFE, USB2_PLL1, 1 << 1); |
Bin Meng | f376372 | 2015-09-03 05:37:27 -0700 | [diff] [blame] | 180 | |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 181 | msg_port_alt_clrsetbits(MSG_PORT_USB_AFE, USB2_PLL1, |
| 182 | (1 << 3) | (1 << 4) | (1 << 5), 1 << 6); |
Bin Meng | f376372 | 2015-09-03 05:37:27 -0700 | [diff] [blame] | 183 | |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 184 | msg_port_alt_clrbits(MSG_PORT_USB_AFE, USB2_PLL2, 1 << 29); |
Bin Meng | f376372 | 2015-09-03 05:37:27 -0700 | [diff] [blame] | 185 | |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 186 | msg_port_alt_setbits(MSG_PORT_USB_AFE, USB2_PLL2, 1 << 24); |
Bin Meng | f376372 | 2015-09-03 05:37:27 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Bin Meng | 8f578db | 2015-09-09 23:20:27 -0700 | [diff] [blame] | 189 | static void quark_thermal_early_init(void) |
| 190 | { |
| 191 | /* The sequence below comes from Quark firmware writer guide */ |
| 192 | |
| 193 | /* thermal sensor mode config */ |
| 194 | msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG1, |
| 195 | (1 << 3) | (1 << 4) | (1 << 5), 1 << 5); |
| 196 | msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG1, |
| 197 | (1 << 8) | (1 << 9) | (1 << 10) | (1 << 11) | |
| 198 | (1 << 12), 1 << 9); |
| 199 | msg_port_alt_setbits(MSG_PORT_SOC_UNIT, TS_CFG1, 1 << 14); |
| 200 | msg_port_alt_clrbits(MSG_PORT_SOC_UNIT, TS_CFG1, 1 << 17); |
| 201 | msg_port_alt_clrbits(MSG_PORT_SOC_UNIT, TS_CFG1, 1 << 18); |
| 202 | msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG2, 0xffff, 0x011f); |
| 203 | msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG3, 0xff, 0x17); |
| 204 | msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG3, |
| 205 | (1 << 8) | (1 << 9), 1 << 8); |
| 206 | msg_port_alt_clrbits(MSG_PORT_SOC_UNIT, TS_CFG3, 0xff000000); |
| 207 | msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG4, |
| 208 | 0x7ff800, 0xc8 << 11); |
| 209 | |
| 210 | /* thermal monitor catastrophic trip set point (105 celsius) */ |
| 211 | msg_port_clrsetbits(MSG_PORT_RMU, TS_TRIP, 0xff, 155); |
| 212 | |
| 213 | /* thermal monitor catastrophic trip clear point (0 celsius) */ |
| 214 | msg_port_clrsetbits(MSG_PORT_RMU, TS_TRIP, 0xff0000, 50 << 16); |
| 215 | |
| 216 | /* take thermal sensor out of reset */ |
| 217 | msg_port_alt_clrbits(MSG_PORT_SOC_UNIT, TS_CFG4, 1 << 0); |
| 218 | |
| 219 | /* enable thermal monitor */ |
| 220 | msg_port_setbits(MSG_PORT_RMU, TS_MODE, 1 << 15); |
| 221 | |
| 222 | /* lock all thermal configuration */ |
| 223 | msg_port_setbits(MSG_PORT_RMU, RMU_CTRL, (1 << 5) | (1 << 6)); |
| 224 | } |
| 225 | |
Bin Meng | 6db1448 | 2015-04-27 14:16:02 +0800 | [diff] [blame] | 226 | static void quark_enable_legacy_seg(void) |
| 227 | { |
Bin Meng | d863026 | 2015-09-09 23:20:25 -0700 | [diff] [blame] | 228 | msg_port_setbits(MSG_PORT_HOST_BRIDGE, HMISC2, |
| 229 | HMISC2_SEGE | HMISC2_SEGF | HMISC2_SEGAB); |
Bin Meng | 6db1448 | 2015-04-27 14:16:02 +0800 | [diff] [blame] | 230 | } |
| 231 | |
Bin Meng | 81da5a8 | 2015-02-02 22:35:27 +0800 | [diff] [blame] | 232 | int arch_cpu_init(void) |
| 233 | { |
Bin Meng | 81da5a8 | 2015-02-02 22:35:27 +0800 | [diff] [blame] | 234 | int ret; |
| 235 | |
| 236 | post_code(POST_CPU_INIT); |
Bin Meng | 81da5a8 | 2015-02-02 22:35:27 +0800 | [diff] [blame] | 237 | |
| 238 | ret = x86_cpu_init_f(); |
| 239 | if (ret) |
| 240 | return ret; |
| 241 | |
Bin Meng | 3446986 | 2015-02-04 16:26:09 +0800 | [diff] [blame] | 242 | /* |
Bin Meng | 0244ef4 | 2015-09-14 00:07:41 -0700 | [diff] [blame] | 243 | * Quark SoC does not support MSR MTRRs. Fixed and variable range MTRRs |
| 244 | * are accessed indirectly via the message port and not the traditional |
| 245 | * MSR mechanism. Only UC, WT and WB cache types are supported. |
| 246 | */ |
| 247 | quark_setup_mtrr(); |
| 248 | |
| 249 | /* |
Bin Meng | 3446986 | 2015-02-04 16:26:09 +0800 | [diff] [blame] | 250 | * Quark SoC has some non-standard BARs (excluding PCI standard BARs) |
| 251 | * which need be initialized with suggested values |
| 252 | */ |
| 253 | quark_setup_bars(); |
| 254 | |
Bin Meng | f376372 | 2015-09-03 05:37:27 -0700 | [diff] [blame] | 255 | /* Initialize USB2 PHY */ |
| 256 | quark_usb_early_init(); |
| 257 | |
Bin Meng | 8f578db | 2015-09-09 23:20:27 -0700 | [diff] [blame] | 258 | /* Initialize thermal sensor */ |
| 259 | quark_thermal_early_init(); |
| 260 | |
Bin Meng | 6db1448 | 2015-04-27 14:16:02 +0800 | [diff] [blame] | 261 | /* Turn on legacy segments (A/B/E/F) decode to system RAM */ |
| 262 | quark_enable_legacy_seg(); |
| 263 | |
Bin Meng | ba6faff | 2015-02-04 16:26:12 +0800 | [diff] [blame] | 264 | unprotect_spi_flash(); |
| 265 | |
Bin Meng | 81da5a8 | 2015-02-02 22:35:27 +0800 | [diff] [blame] | 266 | return 0; |
| 267 | } |
| 268 | |
Bin Meng | 294191c | 2016-01-18 07:29:32 -0800 | [diff] [blame^] | 269 | int arch_cpu_init_dm(void) |
| 270 | { |
| 271 | /* |
| 272 | * Initialize PCIe controller |
| 273 | * |
| 274 | * Quark SoC holds the PCIe controller in reset following a power on. |
| 275 | * U-Boot needs to release the PCIe controller from reset. The PCIe |
| 276 | * controller (D23:F0/F1) will not be visible in PCI configuration |
| 277 | * space and any access to its PCI configuration registers will cause |
| 278 | * system hang while it is held in reset. |
| 279 | */ |
| 280 | quark_pcie_early_init(); |
| 281 | |
| 282 | return 0; |
| 283 | } |
| 284 | |
Bin Meng | 81da5a8 | 2015-02-02 22:35:27 +0800 | [diff] [blame] | 285 | int print_cpuinfo(void) |
| 286 | { |
| 287 | post_code(POST_CPU_INFO); |
| 288 | return default_print_cpuinfo(); |
| 289 | } |
| 290 | |
| 291 | void reset_cpu(ulong addr) |
| 292 | { |
| 293 | /* cold reset */ |
Simon Glass | d0963d4 | 2015-04-28 20:11:31 -0600 | [diff] [blame] | 294 | x86_full_reset(); |
Bin Meng | 81da5a8 | 2015-02-02 22:35:27 +0800 | [diff] [blame] | 295 | } |
Bin Meng | d79593b | 2015-02-04 16:26:13 +0800 | [diff] [blame] | 296 | |
Bin Meng | 4e19d7c | 2015-09-11 03:24:37 -0700 | [diff] [blame] | 297 | static void quark_pcie_init(void) |
| 298 | { |
| 299 | u32 val; |
| 300 | |
| 301 | /* PCIe upstream non-posted & posted request size */ |
| 302 | qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_CCFG, |
| 303 | CCFG_UPRS | CCFG_UNRS); |
| 304 | qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_CCFG, |
| 305 | CCFG_UPRS | CCFG_UNRS); |
| 306 | |
| 307 | /* PCIe packet fast transmit mode (IPF) */ |
| 308 | qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_MPC2, MPC2_IPF); |
| 309 | qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_MPC2, MPC2_IPF); |
| 310 | |
| 311 | /* PCIe message bus idle counter (SBIC) */ |
| 312 | qrk_pci_read_config_dword(QUARK_PCIE0, PCIE_RP_MBC, &val); |
| 313 | val |= MBC_SBIC; |
| 314 | qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_MBC, val); |
| 315 | qrk_pci_read_config_dword(QUARK_PCIE1, PCIE_RP_MBC, &val); |
| 316 | val |= MBC_SBIC; |
| 317 | qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_MBC, val); |
| 318 | } |
| 319 | |
| 320 | static void quark_usb_init(void) |
| 321 | { |
| 322 | u32 bar; |
| 323 | |
| 324 | /* Change USB EHCI packet buffer OUT/IN threshold */ |
| 325 | qrk_pci_read_config_dword(QUARK_USB_EHCI, PCI_BASE_ADDRESS_0, &bar); |
| 326 | writel((0x7f << 16) | 0x7f, bar + EHCI_INSNREG01); |
| 327 | |
| 328 | /* Disable USB device interrupts */ |
| 329 | qrk_pci_read_config_dword(QUARK_USB_DEVICE, PCI_BASE_ADDRESS_0, &bar); |
| 330 | writel(0x7f, bar + USBD_INT_MASK); |
| 331 | writel((0xf << 16) | 0xf, bar + USBD_EP_INT_MASK); |
| 332 | writel((0xf << 16) | 0xf, bar + USBD_EP_INT_STS); |
| 333 | } |
| 334 | |
| 335 | int arch_early_init_r(void) |
| 336 | { |
| 337 | quark_pcie_init(); |
| 338 | |
| 339 | quark_usb_init(); |
| 340 | |
| 341 | return 0; |
| 342 | } |
| 343 | |
Bin Meng | d79593b | 2015-02-04 16:26:13 +0800 | [diff] [blame] | 344 | int cpu_mmc_init(bd_t *bis) |
| 345 | { |
Simon Glass | 0b61928 | 2015-11-29 13:18:08 -0700 | [diff] [blame] | 346 | return pci_mmc_init("Quark SDHCI", mmc_supported); |
Bin Meng | d79593b | 2015-02-04 16:26:13 +0800 | [diff] [blame] | 347 | } |
Bin Meng | 7e96d31 | 2015-03-11 11:25:56 +0800 | [diff] [blame] | 348 | |
Bin Meng | ef9e9f9 | 2015-05-25 22:35:06 +0800 | [diff] [blame] | 349 | void cpu_irq_init(void) |
| 350 | { |
| 351 | struct quark_rcba *rcba; |
| 352 | u32 base; |
| 353 | |
Bin Meng | 9cdcfd7 | 2015-09-03 05:37:24 -0700 | [diff] [blame] | 354 | qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, &base); |
Bin Meng | ef9e9f9 | 2015-05-25 22:35:06 +0800 | [diff] [blame] | 355 | base &= ~MEM_BAR_EN; |
| 356 | rcba = (struct quark_rcba *)base; |
| 357 | |
| 358 | /* |
| 359 | * Route Quark PCI device interrupt pin to PIRQ |
| 360 | * |
| 361 | * Route device#23's INTA/B/C/D to PIRQA/B/C/D |
| 362 | * Route device#20,21's INTA/B/C/D to PIRQE/F/G/H |
| 363 | */ |
| 364 | writew(PIRQC, &rcba->rmu_ir); |
| 365 | writew(PIRQA | (PIRQB << 4) | (PIRQC << 8) | (PIRQD << 12), |
| 366 | &rcba->d23_ir); |
| 367 | writew(PIRQD, &rcba->core_ir); |
| 368 | writew(PIRQE | (PIRQF << 4) | (PIRQG << 8) | (PIRQH << 12), |
| 369 | &rcba->d20d21_ir); |
| 370 | } |
| 371 | |
| 372 | int arch_misc_init(void) |
| 373 | { |
Bin Meng | 4c2af8b | 2015-10-12 01:30:42 -0700 | [diff] [blame] | 374 | #ifdef CONFIG_ENABLE_MRC_CACHE |
| 375 | /* |
| 376 | * We intend not to check any return value here, as even MRC cache |
| 377 | * is not saved successfully, it is not a severe error that will |
| 378 | * prevent system from continuing to boot. |
| 379 | */ |
| 380 | mrccache_save(); |
| 381 | #endif |
| 382 | |
Simon Glass | af1c2d68 | 2015-08-10 07:05:08 -0600 | [diff] [blame] | 383 | return pirq_init(); |
Bin Meng | ef9e9f9 | 2015-05-25 22:35:06 +0800 | [diff] [blame] | 384 | } |
Bin Meng | 4e19d7c | 2015-09-11 03:24:37 -0700 | [diff] [blame] | 385 | |
| 386 | void board_final_cleanup(void) |
| 387 | { |
| 388 | struct quark_rcba *rcba; |
| 389 | u32 base, val; |
| 390 | |
| 391 | qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, &base); |
| 392 | base &= ~MEM_BAR_EN; |
| 393 | rcba = (struct quark_rcba *)base; |
| 394 | |
| 395 | /* Initialize 'Component ID' to zero */ |
| 396 | val = readl(&rcba->esd); |
| 397 | val &= ~0xff0000; |
| 398 | writel(val, &rcba->esd); |
| 399 | |
Bin Meng | 619c90a | 2015-09-09 23:20:26 -0700 | [diff] [blame] | 400 | /* Lock HMBOUND for security */ |
| 401 | msg_port_setbits(MSG_PORT_HOST_BRIDGE, HM_BOUND, HM_BOUND_LOCK); |
| 402 | |
Bin Meng | 4e19d7c | 2015-09-11 03:24:37 -0700 | [diff] [blame] | 403 | return; |
| 404 | } |
Bin Meng | 4c2af8b | 2015-10-12 01:30:42 -0700 | [diff] [blame] | 405 | |
| 406 | int reserve_arch(void) |
| 407 | { |
| 408 | #ifdef CONFIG_ENABLE_MRC_CACHE |
| 409 | return mrccache_reserve(); |
| 410 | #else |
| 411 | return 0; |
| 412 | #endif |
| 413 | } |