Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Simon Glass | e7d04d8 | 2016-03-11 22:07:19 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016 Google, Inc |
Simon Glass | e7d04d8 | 2016-03-11 22:07:19 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 8 | #include <log.h> |
Simon Glass | e7d04d8 | 2016-03-11 22:07:19 -0700 | [diff] [blame] | 9 | #include <pch.h> |
| 10 | #include <asm/cpu.h> |
| 11 | #include <asm/gpio.h> |
| 12 | #include <asm/i8259.h> |
| 13 | #include <asm/intel_regs.h> |
| 14 | #include <asm/io.h> |
| 15 | #include <asm/ioapic.h> |
| 16 | #include <asm/lpc_common.h> |
| 17 | #include <asm/pch_common.h> |
| 18 | #include <asm/arch/cpu.h> |
| 19 | #include <asm/arch/gpio.h> |
| 20 | #include <asm/arch/iomap.h> |
| 21 | #include <asm/arch/pch.h> |
| 22 | #include <asm/arch/pm.h> |
| 23 | #include <asm/arch/rcb.h> |
Simon Glass | 3642ba9 | 2019-02-16 20:25:03 -0700 | [diff] [blame] | 24 | #include <asm/arch/serialio.h> |
Simon Glass | e7d04d8 | 2016-03-11 22:07:19 -0700 | [diff] [blame] | 25 | #include <asm/arch/spi.h> |
Simon Glass | 3642ba9 | 2019-02-16 20:25:03 -0700 | [diff] [blame] | 26 | #include <dm/uclass-internal.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 27 | #include <linux/delay.h> |
Simon Glass | e7d04d8 | 2016-03-11 22:07:19 -0700 | [diff] [blame] | 28 | |
| 29 | #define BIOS_CTRL 0xdc |
| 30 | |
| 31 | bool cpu_is_ult(void) |
| 32 | { |
| 33 | u32 fm = cpu_get_family_model(); |
| 34 | |
| 35 | return fm == BROADWELL_FAMILY_ULT || fm == HASWELL_FAMILY_ULT; |
| 36 | } |
| 37 | |
| 38 | static int broadwell_pch_early_init(struct udevice *dev) |
| 39 | { |
| 40 | struct gpio_desc desc; |
| 41 | struct udevice *bus; |
| 42 | pci_dev_t bdf; |
| 43 | int ret; |
| 44 | |
| 45 | dm_pci_write_config32(dev, PCH_RCBA, RCB_BASE_ADDRESS | 1); |
| 46 | |
| 47 | dm_pci_write_config32(dev, PMBASE, ACPI_BASE_ADDRESS | 1); |
| 48 | dm_pci_write_config8(dev, ACPI_CNTL, ACPI_EN); |
| 49 | dm_pci_write_config32(dev, GPIO_BASE, GPIO_BASE_ADDRESS | 1); |
| 50 | dm_pci_write_config8(dev, GPIO_CNTL, GPIO_EN); |
| 51 | |
| 52 | /* Enable IOAPIC */ |
| 53 | writew(0x1000, RCB_REG(OIC)); |
| 54 | /* Read back for posted write */ |
| 55 | readw(RCB_REG(OIC)); |
| 56 | |
| 57 | /* Set HPET address and enable it */ |
| 58 | clrsetbits_le32(RCB_REG(HPTC), 3, 1 << 7); |
| 59 | /* Read back for posted write */ |
| 60 | readl(RCB_REG(HPTC)); |
| 61 | /* Enable HPET to start counter */ |
| 62 | setbits_le32(HPET_BASE_ADDRESS + 0x10, 1 << 0); |
| 63 | |
| 64 | setbits_le32(RCB_REG(GCS), 1 << 5); |
| 65 | |
| 66 | /* |
| 67 | * Enable PP3300_AUTOBAHN_EN after initial GPIO setup |
| 68 | * to prevent possible brownout. This will cause the GPIOs to be set |
| 69 | * up if it has not been done already. |
| 70 | */ |
| 71 | ret = gpio_request_by_name(dev, "power-enable-gpio", 0, &desc, |
| 72 | GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); |
| 73 | if (ret) |
| 74 | return ret; |
| 75 | |
| 76 | /* 8.14 Additional PCI Express Programming Steps, step #1 */ |
| 77 | bdf = PCI_BDF(0, 0x1c, 0); |
| 78 | bus = pci_get_controller(dev); |
| 79 | pci_bus_clrset_config32(bus, bdf, 0xf4, 0x60, 0); |
| 80 | pci_bus_clrset_config32(bus, bdf, 0xf4, 0x80, 0x80); |
| 81 | pci_bus_clrset_config32(bus, bdf, 0xe2, 0x30, 0x30); |
| 82 | |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | static void pch_misc_init(struct udevice *dev) |
| 87 | { |
| 88 | /* Setup SLP signal assertion, SLP_S4=4s, SLP_S3=50ms */ |
| 89 | dm_pci_clrset_config8(dev, GEN_PMCON_3, 3 << 4 | 1 << 10, |
| 90 | 1 << 3 | 1 << 11 | 1 << 12); |
| 91 | /* Prepare sleep mode */ |
| 92 | clrsetio_32(ACPI_BASE_ADDRESS + PM1_CNT, SLP_TYP, SCI_EN); |
| 93 | |
| 94 | /* Setup NMI on errors, disable SERR */ |
| 95 | clrsetio_8(0x61, 0xf0, 1 << 2); |
| 96 | /* Disable NMI sources */ |
| 97 | setio_8(0x70, 1 << 7); |
| 98 | /* Indicate DRAM init done for MRC */ |
| 99 | dm_pci_clrset_config8(dev, GEN_PMCON_2, 0, 1 << 7); |
| 100 | |
| 101 | /* Clear status bits to prevent unexpected wake */ |
| 102 | setbits_le32(RCB_REG(0x3310), 0x0000002f); |
| 103 | clrsetbits_le32(RCB_REG(0x3f02), 0x0000000f, 0); |
| 104 | /* Enable PCIe Relaxed Order */ |
| 105 | setbits_le32(RCB_REG(0x2314), 1 << 31 | 1 << 7); |
| 106 | setbits_le32(RCB_REG(0x1114), 1 << 15 | 1 << 14); |
| 107 | /* Setup SERIRQ, enable continuous mode */ |
| 108 | dm_pci_clrset_config8(dev, SERIRQ_CNTL, 0, 1 << 7 | 1 << 6); |
| 109 | }; |
| 110 | |
| 111 | static void pch_enable_ioapic(void) |
| 112 | { |
| 113 | u32 reg32; |
| 114 | |
Bin Meng | ff0c478 | 2016-05-22 01:45:35 -0700 | [diff] [blame] | 115 | /* Make sure this is a unique ID within system */ |
| 116 | io_apic_set_id(0x04); |
Simon Glass | e7d04d8 | 2016-03-11 22:07:19 -0700 | [diff] [blame] | 117 | |
| 118 | /* affirm full set of redirection table entries ("write once") */ |
| 119 | reg32 = io_apic_read(0x01); |
| 120 | |
| 121 | /* PCH-LP has 39 redirection entries */ |
| 122 | reg32 &= ~0x00ff0000; |
| 123 | reg32 |= 0x00270000; |
| 124 | |
| 125 | io_apic_write(0x01, reg32); |
| 126 | |
| 127 | /* |
| 128 | * Select Boot Configuration register (0x03) and |
| 129 | * use Processor System Bus (0x01) to deliver interrupts. |
| 130 | */ |
| 131 | io_apic_write(0x03, 0x01); |
| 132 | } |
| 133 | |
| 134 | /* Enable all requested GPE */ |
| 135 | void enable_all_gpe(u32 set1, u32 set2, u32 set3, u32 set4) |
| 136 | { |
| 137 | outl(set1, ACPI_BASE_ADDRESS + GPE0_EN(GPE_31_0)); |
| 138 | outl(set2, ACPI_BASE_ADDRESS + GPE0_EN(GPE_63_32)); |
| 139 | outl(set3, ACPI_BASE_ADDRESS + GPE0_EN(GPE_94_64)); |
| 140 | outl(set4, ACPI_BASE_ADDRESS + GPE0_EN(GPE_STD)); |
| 141 | } |
| 142 | |
| 143 | /* |
| 144 | * Enable GPIO SMI events - it would be good to put this in the GPIO driver |
| 145 | * but it would need a new driver operation. |
| 146 | */ |
| 147 | int enable_alt_smi(struct udevice *pch, u32 mask) |
| 148 | { |
| 149 | struct pch_lp_gpio_regs *regs; |
| 150 | u32 gpiobase; |
| 151 | int ret; |
| 152 | |
| 153 | ret = pch_get_gpio_base(pch, &gpiobase); |
| 154 | if (ret) { |
| 155 | debug("%s: invalid GPIOBASE address (%08x)\n", __func__, |
| 156 | gpiobase); |
| 157 | return -EINVAL; |
| 158 | } |
| 159 | |
| 160 | regs = (struct pch_lp_gpio_regs *)gpiobase; |
| 161 | setio_32(regs->alt_gpi_smi_en, mask); |
| 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | static int pch_power_options(struct udevice *dev) |
| 167 | { |
| 168 | int pwr_on_after_power_fail = MAINBOARD_POWER_OFF; |
| 169 | const char *state; |
| 170 | u32 enable[4]; |
| 171 | u16 reg16; |
| 172 | int ret; |
| 173 | |
| 174 | dm_pci_read_config16(dev, GEN_PMCON_3, ®16); |
| 175 | reg16 &= 0xfffe; |
| 176 | switch (pwr_on_after_power_fail) { |
| 177 | case MAINBOARD_POWER_OFF: |
| 178 | reg16 |= 1; |
| 179 | state = "off"; |
| 180 | break; |
| 181 | case MAINBOARD_POWER_ON: |
| 182 | reg16 &= ~1; |
| 183 | state = "on"; |
| 184 | break; |
| 185 | case MAINBOARD_POWER_KEEP: |
| 186 | reg16 &= ~1; |
| 187 | state = "state keep"; |
| 188 | break; |
| 189 | default: |
| 190 | state = "undefined"; |
| 191 | } |
| 192 | dm_pci_write_config16(dev, GEN_PMCON_3, reg16); |
| 193 | debug("Set power %s after power failure.\n", state); |
| 194 | |
| 195 | /* GPE setup based on device tree configuration */ |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 196 | ret = fdtdec_get_int_array(gd->fdt_blob, dev_of_offset(dev), |
Simon Glass | e7d04d8 | 2016-03-11 22:07:19 -0700 | [diff] [blame] | 197 | "intel,gpe0-en", enable, ARRAY_SIZE(enable)); |
| 198 | if (ret) |
| 199 | return -EINVAL; |
| 200 | enable_all_gpe(enable[0], enable[1], enable[2], enable[3]); |
| 201 | |
| 202 | /* SMI setup based on device tree configuration */ |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 203 | enable_alt_smi(dev, fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), |
Simon Glass | e7d04d8 | 2016-03-11 22:07:19 -0700 | [diff] [blame] | 204 | "intel,alt-gp-smi-enable", 0)); |
| 205 | |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | /* Magic register settings for power management */ |
| 210 | static void pch_pm_init_magic(struct udevice *dev) |
| 211 | { |
| 212 | dm_pci_write_config8(dev, 0xa9, 0x46); |
| 213 | clrbits_le32(RCB_REG(0x232c), 1), |
| 214 | setbits_le32(RCB_REG(0x1100), 0x0000c13f); |
| 215 | clrsetbits_le32(RCB_REG(0x2320), 0x60, 0x10); |
| 216 | writel(0x00012fff, RCB_REG(0x3314)); |
| 217 | clrsetbits_le32(RCB_REG(0x3318), 0x000f0330, 0x0dcf0400); |
| 218 | writel(0x04000000, RCB_REG(0x3324)); |
| 219 | writel(0x00041400, RCB_REG(0x3368)); |
| 220 | writel(0x3f8ddbff, RCB_REG(0x3388)); |
| 221 | writel(0x00007001, RCB_REG(0x33ac)); |
| 222 | writel(0x00181900, RCB_REG(0x33b0)); |
| 223 | writel(0x00060A00, RCB_REG(0x33c0)); |
| 224 | writel(0x06200840, RCB_REG(0x33d0)); |
| 225 | writel(0x01010101, RCB_REG(0x3a28)); |
| 226 | writel(0x040c0404, RCB_REG(0x3a2c)); |
| 227 | writel(0x9000000a, RCB_REG(0x3a9c)); |
| 228 | writel(0x03808033, RCB_REG(0x2b1c)); |
| 229 | writel(0x80000009, RCB_REG(0x2b34)); |
| 230 | writel(0x022ddfff, RCB_REG(0x3348)); |
| 231 | writel(0x00000001, RCB_REG(0x334c)); |
| 232 | writel(0x0001c000, RCB_REG(0x3358)); |
| 233 | writel(0x3f8ddbff, RCB_REG(0x3380)); |
| 234 | writel(0x0001c7e1, RCB_REG(0x3384)); |
| 235 | writel(0x0001c7e1, RCB_REG(0x338c)); |
| 236 | writel(0x0001c000, RCB_REG(0x3398)); |
| 237 | writel(0x00181900, RCB_REG(0x33a8)); |
| 238 | writel(0x00080000, RCB_REG(0x33dc)); |
| 239 | writel(0x00000001, RCB_REG(0x33e0)); |
| 240 | writel(0x0000040c, RCB_REG(0x3a20)); |
| 241 | writel(0x01010101, RCB_REG(0x3a24)); |
| 242 | writel(0x01010101, RCB_REG(0x3a30)); |
| 243 | dm_pci_clrset_config32(dev, 0xac, 0x00200000, 0); |
| 244 | setbits_le32(RCB_REG(0x0410), 0x00000003); |
| 245 | setbits_le32(RCB_REG(0x2618), 0x08000000); |
| 246 | setbits_le32(RCB_REG(0x2300), 0x00000002); |
| 247 | setbits_le32(RCB_REG(0x2600), 0x00000008); |
| 248 | writel(0x00007001, RCB_REG(0x33b4)); |
| 249 | writel(0x022ddfff, RCB_REG(0x3350)); |
| 250 | writel(0x00000001, RCB_REG(0x3354)); |
| 251 | /* Power Optimizer */ |
| 252 | setbits_le32(RCB_REG(0x33d4), 0x08000000); |
| 253 | /* |
| 254 | * This stops the LCD from turning on: |
| 255 | * setbits_le32(RCB_REG(0x33c8), 0x08000080); |
| 256 | */ |
| 257 | writel(0x0000883c, RCB_REG(0x2b10)); |
| 258 | writel(0x1e0a4616, RCB_REG(0x2b14)); |
| 259 | writel(0x40000005, RCB_REG(0x2b24)); |
| 260 | writel(0x0005db01, RCB_REG(0x2b20)); |
| 261 | writel(0x05145005, RCB_REG(0x3a80)); |
| 262 | writel(0x00001005, RCB_REG(0x3a84)); |
| 263 | setbits_le32(RCB_REG(0x33d4), 0x2fff2fb1); |
| 264 | setbits_le32(RCB_REG(0x33c8), 0x00008000); |
| 265 | }; |
| 266 | |
| 267 | static int pch_type(struct udevice *dev) |
| 268 | { |
| 269 | u16 type; |
| 270 | |
| 271 | dm_pci_read_config16(dev, PCI_DEVICE_ID, &type); |
| 272 | |
| 273 | return type; |
| 274 | } |
| 275 | |
| 276 | /* Return 1 if PCH type is WildcatPoint */ |
| 277 | static int pch_is_wpt(struct udevice *dev) |
| 278 | { |
| 279 | return ((pch_type(dev) & 0xfff0) == 0x9cc0) ? 1 : 0; |
| 280 | } |
| 281 | |
| 282 | /* Return 1 if PCH type is WildcatPoint ULX */ |
| 283 | static int pch_is_wpt_ulx(struct udevice *dev) |
| 284 | { |
| 285 | u16 lpcid = pch_type(dev); |
| 286 | |
| 287 | switch (lpcid) { |
| 288 | case PCH_WPT_BDW_Y_SAMPLE: |
| 289 | case PCH_WPT_BDW_Y_PREMIUM: |
| 290 | case PCH_WPT_BDW_Y_BASE: |
| 291 | return 1; |
| 292 | } |
| 293 | |
| 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | static u32 pch_read_soft_strap(int id) |
| 298 | { |
| 299 | clrbits_le32(SPI_REG(SPIBAR_FDOC), 0x00007ffc); |
| 300 | setbits_le32(SPI_REG(SPIBAR_FDOC), 0x00004000 | id * 4); |
| 301 | |
| 302 | return readl(SPI_REG(SPIBAR_FDOD)); |
| 303 | } |
| 304 | |
| 305 | static void pch_enable_mphy(struct udevice *dev) |
| 306 | { |
| 307 | u32 data_and = 0xffffffff; |
| 308 | u32 data_or = (1 << 14) | (1 << 13) | (1 << 12); |
| 309 | |
| 310 | data_or |= (1 << 0); |
| 311 | if (pch_is_wpt(dev)) { |
| 312 | data_and &= ~((1 << 7) | (1 << 6) | (1 << 3)); |
| 313 | data_or |= (1 << 5) | (1 << 4); |
| 314 | |
| 315 | if (pch_is_wpt_ulx(dev)) { |
| 316 | /* Check if SATA and USB3 MPHY are enabled */ |
| 317 | u32 strap19 = pch_read_soft_strap(19); |
| 318 | strap19 &= ((1 << 31) | (1 << 30)); |
| 319 | strap19 >>= 30; |
| 320 | if (strap19 == 3) { |
| 321 | data_or |= (1 << 3); |
| 322 | debug("Enable ULX MPHY PG control in single domain\n"); |
| 323 | } else if (strap19 == 0) { |
| 324 | debug("Enable ULX MPHY PG control in split domains\n"); |
| 325 | } else { |
| 326 | debug("Invalid PCH Soft Strap 19 configuration\n"); |
| 327 | } |
| 328 | } else { |
| 329 | data_or |= (1 << 3); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | pch_iobp_update(0xCF000000, data_and, data_or); |
| 334 | } |
| 335 | |
| 336 | static void pch_init_deep_sx(bool deep_sx_enable_ac, bool deep_sx_enable_dc) |
| 337 | { |
| 338 | if (deep_sx_enable_ac) { |
| 339 | setbits_le32(RCB_REG(DEEP_S3_POL), DEEP_S3_EN_AC); |
| 340 | setbits_le32(RCB_REG(DEEP_S5_POL), DEEP_S5_EN_AC); |
| 341 | } |
| 342 | |
| 343 | if (deep_sx_enable_dc) { |
| 344 | setbits_le32(RCB_REG(DEEP_S3_POL), DEEP_S3_EN_DC); |
| 345 | setbits_le32(RCB_REG(DEEP_S5_POL), DEEP_S5_EN_DC); |
| 346 | } |
| 347 | |
| 348 | if (deep_sx_enable_ac || deep_sx_enable_dc) { |
| 349 | setbits_le32(RCB_REG(DEEP_SX_CONFIG), |
| 350 | DEEP_SX_WAKE_PIN_EN | DEEP_SX_GP27_PIN_EN); |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | /* Power Management init */ |
| 355 | static void pch_pm_init(struct udevice *dev) |
| 356 | { |
| 357 | debug("PCH PM init\n"); |
| 358 | |
| 359 | pch_init_deep_sx(false, false); |
| 360 | pch_enable_mphy(dev); |
| 361 | pch_pm_init_magic(dev); |
| 362 | |
| 363 | if (pch_is_wpt(dev)) { |
| 364 | setbits_le32(RCB_REG(0x33e0), 1 << 4 | 1 << 1); |
| 365 | setbits_le32(RCB_REG(0x2b1c), 1 << 22 | 1 << 14 | 1 << 13); |
| 366 | writel(0x16bf0002, RCB_REG(0x33e4)); |
| 367 | setbits_le32(RCB_REG(0x33e4), 0x1); |
| 368 | } |
| 369 | |
| 370 | pch_iobp_update(0xCA000000, ~0UL, 0x00000009); |
| 371 | |
| 372 | /* Set RCBA 0x2b1c[29]=1 if DSP disabled */ |
| 373 | if (readl(RCB_REG(FD)) & PCH_DISABLE_ADSPD) |
| 374 | setbits_le32(RCB_REG(0x2b1c), 1 << 29); |
| 375 | } |
| 376 | |
| 377 | static void pch_cg_init(struct udevice *dev) |
| 378 | { |
| 379 | struct udevice *bus = pci_get_controller(dev); |
| 380 | u32 reg32; |
| 381 | u16 reg16; |
| 382 | ulong val; |
| 383 | |
| 384 | /* DMI */ |
| 385 | setbits_le32(RCB_REG(0x2234), 0xf); |
| 386 | |
| 387 | dm_pci_read_config16(dev, GEN_PMCON_1, ®16); |
| 388 | reg16 &= ~(1 << 10); /* Disable BIOS_PCI_EXP_EN for native PME */ |
| 389 | if (pch_is_wpt(dev)) |
| 390 | reg16 &= ~(1 << 11); |
| 391 | else |
| 392 | reg16 |= 1 << 11; |
| 393 | reg16 |= 1 << 5 | 1 << 6 | 1 << 7 | 1 << 12; |
| 394 | reg16 |= 1 << 2; /* PCI CLKRUN# Enable */ |
| 395 | dm_pci_write_config16(dev, GEN_PMCON_1, reg16); |
| 396 | |
| 397 | /* |
| 398 | * RCBA + 0x2614[27:25,14:13,10,8] = 101,11,1,1 |
| 399 | * RCBA + 0x2614[23:16] = 0x20 |
| 400 | * RCBA + 0x2614[30:28] = 0x0 |
| 401 | * RCBA + 0x2614[26] = 1 (IF 0:2.0@0x08 >= 0x0b) |
| 402 | */ |
| 403 | clrsetbits_le32(RCB_REG(0x2614), 0x64ff0000, 0x0a206500); |
| 404 | |
| 405 | /* Check for 0:2.0@0x08 >= 0x0b */ |
| 406 | pci_bus_read_config(bus, PCI_BDF(0, 0x2, 0), 0x8, &val, PCI_SIZE_8); |
| 407 | if (pch_is_wpt(dev) || val >= 0x0b) |
| 408 | setbits_le32(RCB_REG(0x2614), 1 << 26); |
| 409 | |
| 410 | setbits_le32(RCB_REG(0x900), 0x0000031f); |
| 411 | |
| 412 | reg32 = readl(RCB_REG(CG)); |
| 413 | if (readl(RCB_REG(0x3454)) & (1 << 4)) |
| 414 | reg32 &= ~(1 << 29); /* LPC Dynamic */ |
| 415 | else |
| 416 | reg32 |= (1 << 29); /* LPC Dynamic */ |
| 417 | reg32 |= 1 << 31; /* LP LPC */ |
| 418 | reg32 |= 1 << 30; /* LP BLA */ |
| 419 | if (readl(RCB_REG(0x3454)) & (1 << 4)) |
| 420 | reg32 &= ~(1 << 29); |
| 421 | else |
| 422 | reg32 |= 1 << 29; |
| 423 | reg32 |= 1 << 28; /* GPIO Dynamic */ |
| 424 | reg32 |= 1 << 27; /* HPET Dynamic */ |
| 425 | reg32 |= 1 << 26; /* Generic Platform Event Clock */ |
| 426 | if (readl(RCB_REG(BUC)) & PCH_DISABLE_GBE) |
| 427 | reg32 |= 1 << 23; /* GbE Static */ |
| 428 | if (readl(RCB_REG(FD)) & PCH_DISABLE_HD_AUDIO) |
| 429 | reg32 |= 1 << 21; /* HDA Static */ |
| 430 | reg32 |= 1 << 22; /* HDA Dynamic */ |
| 431 | writel(reg32, RCB_REG(CG)); |
| 432 | |
| 433 | /* PCH-LP LPC */ |
| 434 | if (pch_is_wpt(dev)) |
| 435 | clrsetbits_le32(RCB_REG(0x3434), 0x1f, 0x17); |
| 436 | else |
| 437 | setbits_le32(RCB_REG(0x3434), 0x7); |
| 438 | |
| 439 | /* SPI */ |
| 440 | setbits_le32(RCB_REG(0x38c0), 0x3c07); |
| 441 | |
| 442 | pch_iobp_update(0xCE00C000, ~1UL, 0x00000000); |
| 443 | } |
| 444 | |
| 445 | static void systemagent_init(void) |
| 446 | { |
| 447 | /* Enable Power Aware Interrupt Routing */ |
| 448 | clrsetbits_8(MCHBAR_REG(MCH_PAIR), 0x7, 0x4); /* Fixed Priority */ |
| 449 | |
| 450 | /* |
| 451 | * Set bits 0+1 of BIOS_RESET_CPL to indicate to the CPU |
| 452 | * that BIOS has initialized memory and power management |
| 453 | */ |
| 454 | setbits_8(MCHBAR_REG(BIOS_RESET_CPL), 3); |
| 455 | debug("Set BIOS_RESET_CPL\n"); |
| 456 | |
| 457 | /* Configure turbo power limits 1ms after reset complete bit */ |
| 458 | mdelay(1); |
| 459 | |
| 460 | cpu_set_power_limits(28); |
| 461 | } |
| 462 | |
Simon Glass | 3642ba9 | 2019-02-16 20:25:03 -0700 | [diff] [blame] | 463 | /* Enable LTR Auto Mode for D21:F1-F6 */ |
| 464 | static void serialio_d21_ltr(u32 bar0) |
| 465 | { |
| 466 | /* 1. Program BAR0 + 808h[2] = 0b */ |
| 467 | clrbits_le32(bar0 + SIO_REG_PPR_GEN, SIO_REG_PPR_GEN_LTR_MODE_MASK); |
| 468 | |
| 469 | /* 2. Program BAR0 + 804h[1:0] = 00b */ |
| 470 | clrbits_le32(bar0 + SIO_REG_PPR_RST, SIO_REG_PPR_RST_ASSERT); |
| 471 | |
| 472 | /* 3. Program BAR0 + 804h[1:0] = 11b */ |
| 473 | setbits_le32(bar0 + SIO_REG_PPR_RST, SIO_REG_PPR_RST_ASSERT); |
| 474 | |
| 475 | /* 4. Program BAR0 + 814h[31:0] = 00000000h */ |
| 476 | writel(0, bar0 + SIO_REG_AUTO_LTR); |
| 477 | } |
| 478 | |
| 479 | /* Select I2C voltage of 1.8V or 3.3V */ |
| 480 | static void serialio_i2c_voltage_sel(u32 bar0, uint voltage) |
| 481 | { |
| 482 | clrsetbits_le32(bar0 + SIO_REG_PPR_GEN, SIO_REG_PPR_GEN_VOLTAGE_MASK, |
| 483 | SIO_REG_PPR_GEN_VOLTAGE(voltage)); |
| 484 | } |
| 485 | |
| 486 | /* Put Serial IO D21:F0-F6 device into desired mode */ |
| 487 | static void serialio_d21_mode(int sio_index, int int_pin, bool acpi_mode) |
| 488 | { |
| 489 | u32 portctrl = SIO_IOBP_PORTCTRL_PM_CAP_PRSNT; |
| 490 | |
| 491 | /* Snoop select 1 */ |
| 492 | portctrl |= SIO_IOBP_PORTCTRL_SNOOP_SELECT(1); |
| 493 | |
| 494 | /* Set interrupt pin */ |
| 495 | portctrl |= SIO_IOBP_PORTCTRL_INT_PIN(int_pin); |
| 496 | |
| 497 | if (acpi_mode) { |
| 498 | /* Enable ACPI interrupt mode */ |
| 499 | portctrl |= SIO_IOBP_PORTCTRL_ACPI_IRQ_EN; |
| 500 | } |
| 501 | |
| 502 | pch_iobp_update(SIO_IOBP_PORTCTRLX(sio_index), 0, portctrl); |
| 503 | } |
| 504 | |
| 505 | /* Init sequence to be run once, done as part of D21:F0 (SDMA) init */ |
| 506 | static void serialio_init_once(bool acpi_mode) |
| 507 | { |
| 508 | if (acpi_mode) { |
| 509 | /* Enable ACPI IRQ for IRQ13, IRQ7, IRQ6, IRQ5 in RCBA */ |
| 510 | setbits_le32(RCB_REG(ACPIIRQEN), |
| 511 | 1 << 13 | 1 << 7 | 1 << 6 | 1 << 5); |
| 512 | } |
| 513 | |
| 514 | /* Program IOBP CB000154h[12,9:8,4:0] = 1001100011111b */ |
| 515 | pch_iobp_update(SIO_IOBP_GPIODF, ~0x0000131f, 0x0000131f); |
| 516 | |
| 517 | /* Program IOBP CB000180h[5:0] = 111111b (undefined register) */ |
| 518 | pch_iobp_update(0xcb000180, ~0x0000003f, 0x0000003f); |
| 519 | } |
| 520 | |
| 521 | /** |
| 522 | * pch_serialio_init() - set up serial I/O devices |
| 523 | * |
| 524 | * @return 0 if OK, -ve on error |
| 525 | */ |
| 526 | static int pch_serialio_init(void) |
| 527 | { |
| 528 | struct udevice *dev, *hda; |
| 529 | bool acpi_mode = true; |
| 530 | u32 bar0, bar1; |
| 531 | int ret; |
| 532 | |
| 533 | ret = uclass_find_first_device(UCLASS_I2C, &dev); |
| 534 | if (ret) |
| 535 | return ret; |
| 536 | bar0 = dm_pci_read_bar32(dev, 0); |
| 537 | if (!bar0) |
| 538 | return -EINVAL; |
| 539 | bar1 = dm_pci_read_bar32(dev, 1); |
| 540 | if (!bar1) |
| 541 | return -EINVAL; |
| 542 | |
| 543 | serialio_init_once(acpi_mode); |
| 544 | serialio_d21_mode(SIO_ID_SDMA, SIO_PIN_INTB, acpi_mode); |
| 545 | |
| 546 | serialio_d21_ltr(bar0); |
| 547 | serialio_i2c_voltage_sel(bar0, 1); /* Select 1.8V always */ |
| 548 | serialio_d21_mode(SIO_ID_I2C0, SIO_PIN_INTC, acpi_mode); |
| 549 | setbits_le32(bar1 + PCH_PCS, PCH_PCS_PS_D3HOT); |
| 550 | |
| 551 | clrbits_le32(bar1 + PCH_PCS, PCH_PCS_PS_D3HOT); |
| 552 | |
| 553 | setbits_le32(bar0 + SIO_REG_PPR_CLOCK, SIO_REG_PPR_CLOCK_EN); |
| 554 | |
| 555 | /* Manually find the High-definition audio, to turn it off */ |
| 556 | ret = dm_pci_bus_find_bdf(PCI_BDF(0, 0x1b, 0), &hda); |
| 557 | if (ret) |
| 558 | return -ENOENT; |
| 559 | dm_pci_clrset_config8(hda, 0x43, 0, 0x6f); |
| 560 | |
| 561 | /* Route I/O buffers to ADSP function */ |
| 562 | dm_pci_clrset_config8(hda, 0x42, 0, 1 << 7 | 1 << 6); |
| 563 | log_debug("HDA disabled, I/O buffers routed to ADSP\n"); |
| 564 | |
| 565 | return 0; |
| 566 | } |
| 567 | |
Simon Glass | e7d04d8 | 2016-03-11 22:07:19 -0700 | [diff] [blame] | 568 | static int broadwell_pch_init(struct udevice *dev) |
| 569 | { |
| 570 | int ret; |
| 571 | |
| 572 | /* Enable upper 128 bytes of CMOS */ |
| 573 | setbits_le32(RCB_REG(RC), 1 << 2); |
| 574 | |
| 575 | /* |
| 576 | * TODO: TCO timer halt - this hangs |
| 577 | * setio_16(ACPI_BASE_ADDRESS + TCO1_CNT, TCO_TMR_HLT); |
| 578 | */ |
| 579 | |
| 580 | /* Disable unused device (always) */ |
| 581 | setbits_le32(RCB_REG(FD), PCH_DISABLE_ALWAYS); |
| 582 | |
| 583 | pch_misc_init(dev); |
| 584 | |
| 585 | /* Interrupt configuration */ |
| 586 | pch_enable_ioapic(); |
| 587 | |
| 588 | /* Initialize power management */ |
| 589 | ret = pch_power_options(dev); |
| 590 | if (ret) |
| 591 | return ret; |
| 592 | pch_pm_init(dev); |
| 593 | pch_cg_init(dev); |
Simon Glass | 3642ba9 | 2019-02-16 20:25:03 -0700 | [diff] [blame] | 594 | ret = pch_serialio_init(); |
| 595 | if (ret) |
| 596 | return ret; |
Simon Glass | e7d04d8 | 2016-03-11 22:07:19 -0700 | [diff] [blame] | 597 | systemagent_init(); |
| 598 | |
| 599 | return 0; |
| 600 | } |
| 601 | |
| 602 | static int broadwell_pch_probe(struct udevice *dev) |
| 603 | { |
Simon Glass | 7beafdf | 2019-05-02 10:52:26 -0600 | [diff] [blame] | 604 | if (CONFIG_IS_ENABLED(X86_32BIT_INIT)) { |
| 605 | if (!(gd->flags & GD_FLG_RELOC)) |
| 606 | return broadwell_pch_early_init(dev); |
| 607 | else |
| 608 | return broadwell_pch_init(dev); |
| 609 | } else if (IS_ENABLED(CONFIG_SPL) && !IS_ENABLED(CONFIG_SPL_BUILD)) { |
Simon Glass | e7d04d8 | 2016-03-11 22:07:19 -0700 | [diff] [blame] | 610 | return broadwell_pch_init(dev); |
Simon Glass | 7beafdf | 2019-05-02 10:52:26 -0600 | [diff] [blame] | 611 | } else { |
| 612 | return 0; |
| 613 | } |
Simon Glass | e7d04d8 | 2016-03-11 22:07:19 -0700 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | static int broadwell_pch_get_spi_base(struct udevice *dev, ulong *sbasep) |
| 617 | { |
| 618 | u32 rcba; |
| 619 | |
| 620 | dm_pci_read_config32(dev, PCH_RCBA, &rcba); |
| 621 | /* Bits 31-14 are the base address, 13-1 are reserved, 0 is enable */ |
| 622 | rcba = rcba & 0xffffc000; |
| 623 | *sbasep = rcba + 0x3800; |
| 624 | |
| 625 | return 0; |
| 626 | } |
| 627 | |
| 628 | static int broadwell_set_spi_protect(struct udevice *dev, bool protect) |
| 629 | { |
| 630 | return lpc_set_spi_protect(dev, BIOS_CTRL, protect); |
| 631 | } |
| 632 | |
| 633 | static int broadwell_get_gpio_base(struct udevice *dev, u32 *gbasep) |
| 634 | { |
| 635 | dm_pci_read_config32(dev, GPIO_BASE, gbasep); |
| 636 | *gbasep &= PCI_BASE_ADDRESS_IO_MASK; |
| 637 | |
| 638 | return 0; |
| 639 | } |
| 640 | |
Simon Glass | f5d1395 | 2019-04-25 21:59:03 -0600 | [diff] [blame] | 641 | static int broadwell_ioctl(struct udevice *dev, enum pch_req_t req, void *data, |
| 642 | int size) |
| 643 | { |
| 644 | switch (req) { |
| 645 | case PCH_REQ_PMBASE_INFO: { |
| 646 | struct pch_pmbase_info *pm = data; |
| 647 | int ret; |
| 648 | |
| 649 | /* Find the base address of the powermanagement registers */ |
| 650 | ret = dm_pci_read_config16(dev, 0x40, &pm->base); |
| 651 | if (ret) |
| 652 | return ret; |
| 653 | pm->base &= 0xfffe; |
| 654 | pm->gpio0_en_ofs = GPE0_EN(0); |
| 655 | pm->pm1_sts_ofs = PM1_STS; |
| 656 | pm->pm1_cnt_ofs = PM1_CNT; |
| 657 | |
| 658 | return 0; |
| 659 | } |
| 660 | default: |
| 661 | return -ENOSYS; |
| 662 | } |
| 663 | } |
| 664 | |
Simon Glass | e7d04d8 | 2016-03-11 22:07:19 -0700 | [diff] [blame] | 665 | static const struct pch_ops broadwell_pch_ops = { |
| 666 | .get_spi_base = broadwell_pch_get_spi_base, |
| 667 | .set_spi_protect = broadwell_set_spi_protect, |
| 668 | .get_gpio_base = broadwell_get_gpio_base, |
Simon Glass | f5d1395 | 2019-04-25 21:59:03 -0600 | [diff] [blame] | 669 | .ioctl = broadwell_ioctl, |
Simon Glass | e7d04d8 | 2016-03-11 22:07:19 -0700 | [diff] [blame] | 670 | }; |
| 671 | |
| 672 | static const struct udevice_id broadwell_pch_ids[] = { |
| 673 | { .compatible = "intel,broadwell-pch" }, |
| 674 | { } |
| 675 | }; |
| 676 | |
| 677 | U_BOOT_DRIVER(broadwell_pch) = { |
| 678 | .name = "broadwell_pch", |
| 679 | .id = UCLASS_PCH, |
| 680 | .of_match = broadwell_pch_ids, |
| 681 | .probe = broadwell_pch_probe, |
| 682 | .ops = &broadwell_pch_ops, |
| 683 | }; |