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