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