Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 coresystems GmbH |
| 5 | * Copyright (C) 2014 Google Inc. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <console/console.h> |
| 18 | #include <delay.h> |
| 19 | #include <device/device.h> |
| 20 | #include <device/pci.h> |
| 21 | #include <device/pci_ids.h> |
| 22 | #include <pc80/mc146818rtc.h> |
| 23 | #include <pc80/isa-dma.h> |
| 24 | #include <pc80/i8259.h> |
Elyes HAOUAS | d2b9ec1 | 2018-10-27 09:41:02 +0200 | [diff] [blame^] | 25 | #include <arch/cpu.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 26 | #include <arch/io.h> |
| 27 | #include <arch/ioapic.h> |
| 28 | #include <arch/acpi.h> |
| 29 | #include <cpu/cpu.h> |
| 30 | #include <cpu/x86/smm.h> |
| 31 | #include <cbmem.h> |
| 32 | #include <reg_script.h> |
| 33 | #include <string.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 34 | #include <soc/gpio.h> |
| 35 | #include <soc/iobp.h> |
| 36 | #include <soc/iomap.h> |
| 37 | #include <soc/lpc.h> |
| 38 | #include <soc/nvs.h> |
| 39 | #include <soc/pch.h> |
| 40 | #include <soc/pci_devs.h> |
| 41 | #include <soc/pm.h> |
| 42 | #include <soc/ramstage.h> |
| 43 | #include <soc/rcba.h> |
| 44 | #include <soc/intel/broadwell/chip.h> |
Vladimir Serbinenko | b219da8 | 2014-11-09 03:29:30 +0100 | [diff] [blame] | 45 | #include <arch/acpi.h> |
| 46 | #include <arch/acpigen.h> |
| 47 | #include <cpu/cpu.h> |
Duncan Laurie | 35dc00f | 2015-01-18 14:06:42 -0800 | [diff] [blame] | 48 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 49 | static void pch_enable_ioapic(struct device *dev) |
| 50 | { |
| 51 | u32 reg32; |
| 52 | |
Matt DeVillier | 81a6f10 | 2018-02-19 17:33:48 -0600 | [diff] [blame] | 53 | /* Assign unique bus/dev/fn for I/O APIC */ |
| 54 | pci_write_config16(dev, LPC_IBDF, |
| 55 | PCH_IOAPIC_PCI_BUS << 8 | PCH_IOAPIC_PCI_SLOT << 3); |
| 56 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 57 | set_ioapic_id(VIO_APIC_VADDR, 0x02); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 58 | |
| 59 | /* affirm full set of redirection table entries ("write once") */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 60 | reg32 = io_apic_read(VIO_APIC_VADDR, 0x01); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 61 | |
| 62 | /* PCH-LP has 39 redirection entries */ |
| 63 | reg32 &= ~0x00ff0000; |
| 64 | reg32 |= 0x00270000; |
| 65 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 66 | io_apic_write(VIO_APIC_VADDR, 0x01, reg32); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 67 | |
| 68 | /* |
| 69 | * Select Boot Configuration register (0x03) and |
| 70 | * use Processor System Bus (0x01) to deliver interrupts. |
| 71 | */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 72 | io_apic_write(VIO_APIC_VADDR, 0x03, 0x01); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Matt DeVillier | 81a6f10 | 2018-02-19 17:33:48 -0600 | [diff] [blame] | 75 | static void enable_hpet(struct device *dev) |
| 76 | { |
| 77 | size_t i; |
| 78 | |
| 79 | /* Assign unique bus/dev/fn for each HPET */ |
| 80 | for (i = 0; i < 8; ++i) |
| 81 | pci_write_config16(dev, LPC_HnBDF(i), |
| 82 | PCH_HPET_PCI_BUS << 8 | PCH_HPET_PCI_SLOT << 3 | i); |
| 83 | } |
| 84 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 85 | /* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control |
| 86 | * 0x00 - 0000 = Reserved |
| 87 | * 0x01 - 0001 = Reserved |
| 88 | * 0x02 - 0010 = Reserved |
| 89 | * 0x03 - 0011 = IRQ3 |
| 90 | * 0x04 - 0100 = IRQ4 |
| 91 | * 0x05 - 0101 = IRQ5 |
| 92 | * 0x06 - 0110 = IRQ6 |
| 93 | * 0x07 - 0111 = IRQ7 |
| 94 | * 0x08 - 1000 = Reserved |
| 95 | * 0x09 - 1001 = IRQ9 |
| 96 | * 0x0A - 1010 = IRQ10 |
| 97 | * 0x0B - 1011 = IRQ11 |
| 98 | * 0x0C - 1100 = IRQ12 |
| 99 | * 0x0D - 1101 = Reserved |
| 100 | * 0x0E - 1110 = IRQ14 |
| 101 | * 0x0F - 1111 = IRQ15 |
| 102 | * PIRQ[n]_ROUT[7] - PIRQ Routing Control |
| 103 | * 0x80 - The PIRQ is not routed. |
| 104 | */ |
| 105 | |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 106 | static void pch_pirq_init(struct device *dev) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 107 | { |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 108 | struct device *irq_dev; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 109 | config_t *config = dev->chip_info; |
| 110 | |
| 111 | pci_write_config8(dev, PIRQA_ROUT, config->pirqa_routing); |
| 112 | pci_write_config8(dev, PIRQB_ROUT, config->pirqb_routing); |
| 113 | pci_write_config8(dev, PIRQC_ROUT, config->pirqc_routing); |
| 114 | pci_write_config8(dev, PIRQD_ROUT, config->pirqd_routing); |
| 115 | |
| 116 | pci_write_config8(dev, PIRQE_ROUT, config->pirqe_routing); |
| 117 | pci_write_config8(dev, PIRQF_ROUT, config->pirqf_routing); |
| 118 | pci_write_config8(dev, PIRQG_ROUT, config->pirqg_routing); |
| 119 | pci_write_config8(dev, PIRQH_ROUT, config->pirqh_routing); |
| 120 | |
Elyes HAOUAS | 4a83f1c | 2016-08-25 21:07:59 +0200 | [diff] [blame] | 121 | for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) { |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 122 | u8 int_pin = 0, int_line = 0; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 123 | |
| 124 | if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI) |
| 125 | continue; |
| 126 | |
| 127 | int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN); |
| 128 | |
| 129 | switch (int_pin) { |
Lee Leahy | 8a9c7dc | 2017-03-17 10:43:25 -0700 | [diff] [blame] | 130 | case 1: /* INTA# */ |
| 131 | int_line = config->pirqa_routing; |
| 132 | break; |
| 133 | case 2: /* INTB# */ |
| 134 | int_line = config->pirqb_routing; |
| 135 | break; |
| 136 | case 3: /* INTC# */ |
| 137 | int_line = config->pirqc_routing; |
| 138 | break; |
| 139 | case 4: /* INTD# */ |
| 140 | int_line = config->pirqd_routing; |
| 141 | break; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | if (!int_line) |
| 145 | continue; |
| 146 | |
| 147 | pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line); |
| 148 | } |
| 149 | } |
| 150 | |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 151 | static void pch_power_options(struct device *dev) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 152 | { |
| 153 | u16 reg16; |
| 154 | const char *state; |
| 155 | /* Get the chip configuration */ |
| 156 | config_t *config = dev->chip_info; |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 157 | int pwr_on = CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 158 | |
| 159 | /* Which state do we want to goto after g3 (power restored)? |
| 160 | * 0 == S0 Full On |
| 161 | * 1 == S5 Soft Off |
| 162 | * |
| 163 | * If the option is not existent (Laptops), use Kconfig setting. |
| 164 | */ |
| 165 | get_option(&pwr_on, "power_on_after_fail"); |
| 166 | |
| 167 | reg16 = pci_read_config16(dev, GEN_PMCON_3); |
| 168 | reg16 &= 0xfffe; |
| 169 | switch (pwr_on) { |
| 170 | case MAINBOARD_POWER_OFF: |
| 171 | reg16 |= 1; |
| 172 | state = "off"; |
| 173 | break; |
| 174 | case MAINBOARD_POWER_ON: |
| 175 | reg16 &= ~1; |
| 176 | state = "on"; |
| 177 | break; |
| 178 | case MAINBOARD_POWER_KEEP: |
| 179 | reg16 &= ~1; |
| 180 | state = "state keep"; |
| 181 | break; |
| 182 | default: |
| 183 | state = "undefined"; |
| 184 | } |
| 185 | pci_write_config16(dev, GEN_PMCON_3, reg16); |
| 186 | printk(BIOS_INFO, "Set power %s after power failure.\n", state); |
| 187 | |
| 188 | /* GPE setup based on device tree configuration */ |
| 189 | enable_all_gpe(config->gpe0_en_1, config->gpe0_en_2, |
| 190 | config->gpe0_en_3, config->gpe0_en_4); |
| 191 | |
| 192 | /* SMI setup based on device tree configuration */ |
| 193 | enable_alt_smi(config->alt_gp_smi_en); |
| 194 | } |
| 195 | |
| 196 | static void pch_rtc_init(struct device *dev) |
| 197 | { |
Aaron Durbin | b9d9b79 | 2017-09-15 11:51:58 -0600 | [diff] [blame] | 198 | cmos_init(rtc_failure()); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | static const struct reg_script pch_misc_init_script[] = { |
| 202 | /* Setup SLP signal assertion, SLP_S4=4s, SLP_S3=50ms */ |
| 203 | REG_PCI_RMW16(GEN_PMCON_3, ~((3 << 4)|(1 << 10)), |
| 204 | (1 << 3)|(1 << 11)|(1 << 12)), |
| 205 | /* Prepare sleep mode */ |
| 206 | REG_IO_RMW32(ACPI_BASE_ADDRESS + PM1_CNT, ~SLP_TYP, SCI_EN), |
| 207 | /* Setup NMI on errors, disable SERR */ |
| 208 | REG_IO_RMW8(0x61, ~0xf0, (1 << 2)), |
| 209 | /* Disable NMI sources */ |
| 210 | REG_IO_OR8(0x70, (1 << 7)), |
| 211 | /* Indicate DRAM init done for MRC */ |
| 212 | REG_PCI_OR8(GEN_PMCON_2, (1 << 7)), |
| 213 | /* Enable BIOS updates outside of SMM */ |
| 214 | REG_PCI_RMW8(0xdc, ~(1 << 5), 0), |
| 215 | /* Clear status bits to prevent unexpected wake */ |
Duncan Laurie | 446fb8e | 2014-08-08 09:59:43 -0700 | [diff] [blame] | 216 | REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x3310, 0x0000002f), |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 217 | REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x3f02, ~0x0000000f, 0), |
Kenji Chen | 074a028 | 2014-09-20 01:39:20 +0800 | [diff] [blame] | 218 | /* Enable PCIe Releaxed Order */ |
| 219 | REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2314, (1 << 31) | (1 << 7)), |
| 220 | REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x1114, (1 << 15) | (1 << 14)), |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 221 | /* Setup SERIRQ, enable continuous mode */ |
| 222 | REG_PCI_OR8(SERIRQ_CNTL, (1 << 7) | (1 << 6)), |
Martin Roth | e6ff159 | 2017-06-24 21:34:29 -0600 | [diff] [blame] | 223 | #if !IS_ENABLED(CONFIG_SERIRQ_CONTINUOUS_MODE) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 224 | REG_PCI_RMW8(SERIRQ_CNTL, ~(1 << 6), 0), |
| 225 | #endif |
| 226 | REG_SCRIPT_END |
| 227 | }; |
| 228 | |
| 229 | /* Magic register settings for power management */ |
| 230 | static const struct reg_script pch_pm_init_script[] = { |
| 231 | REG_PCI_WRITE8(0xa9, 0x46), |
| 232 | REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x232c, ~1, 0), |
| 233 | REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x1100, 0x0000c13f), |
| 234 | REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x2320, ~0x60, 0x10), |
| 235 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3314, 0x00012fff), |
| 236 | REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x3318, ~0x000f0330, 0x0dcf0400), |
| 237 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3324, 0x04000000), |
| 238 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3368, 0x00041400), |
| 239 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3388, 0x3f8ddbff), |
| 240 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33ac, 0x00007001), |
| 241 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33b0, 0x00181900), |
| 242 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33c0, 0x00060A00), |
| 243 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33d0, 0x06200840), |
| 244 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a28, 0x01010101), |
| 245 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a2c, 0x040c0404), |
| 246 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a9c, 0x9000000a), |
| 247 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b1c, 0x03808033), |
| 248 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b34, 0x80000009), |
| 249 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3348, 0x022ddfff), |
| 250 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x334c, 0x00000001), |
| 251 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3358, 0x0001c000), |
| 252 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3380, 0x3f8ddbff), |
| 253 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3384, 0x0001c7e1), |
| 254 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x338c, 0x0001c7e1), |
| 255 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3398, 0x0001c000), |
| 256 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33a8, 0x00181900), |
| 257 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33dc, 0x00080000), |
| 258 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33e0, 0x00000001), |
| 259 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a20, 0x0000040c), |
| 260 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a24, 0x01010101), |
| 261 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a30, 0x01010101), |
| 262 | REG_PCI_RMW32(0xac, ~0x00200000, 0), |
| 263 | REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x0410, 0x00000003), |
| 264 | REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2618, 0x08000000), |
| 265 | REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2300, 0x00000002), |
| 266 | REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2600, 0x00000008), |
| 267 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33b4, 0x00007001), |
| 268 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3350, 0x022ddfff), |
| 269 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3354, 0x00000001), |
Duncan Laurie | 446fb8e | 2014-08-08 09:59:43 -0700 | [diff] [blame] | 270 | /* Power Optimizer */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 271 | REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33d4, 0x08000000), |
Matt DeVillier | c97e042 | 2017-02-16 11:36:16 -0600 | [diff] [blame] | 272 | REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33c8, 0x00000080), |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 273 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b10, 0x0000883c), |
| 274 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b14, 0x1e0a4616), |
| 275 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b24, 0x40000005), |
| 276 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b20, 0x0005db01), |
| 277 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a80, 0x05145005), |
| 278 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a84, 0x00001005), |
| 279 | REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33d4, 0x2fff2fb1), |
| 280 | REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33c8, 0x00008000), |
| 281 | REG_SCRIPT_END |
| 282 | }; |
| 283 | |
| 284 | static void pch_enable_mphy(void) |
| 285 | { |
| 286 | u32 gpio71_native = gpio_is_native(71); |
| 287 | u32 data_and = 0xffffffff; |
| 288 | u32 data_or = (1 << 14) | (1 << 13) | (1 << 12); |
| 289 | |
| 290 | if (gpio71_native) { |
| 291 | data_or |= (1 << 0); |
| 292 | if (pch_is_wpt()) { |
| 293 | data_and &= ~((1 << 7) | (1 << 6) | (1 << 3)); |
| 294 | data_or |= (1 << 5) | (1 << 4); |
| 295 | |
| 296 | if (pch_is_wpt_ulx()) { |
| 297 | /* Check if SATA and USB3 MPHY are enabled */ |
| 298 | u32 strap19 = pch_read_soft_strap(19); |
| 299 | strap19 &= ((1 << 31) | (1 << 30)); |
| 300 | strap19 >>= 30; |
| 301 | if (strap19 == 3) { |
| 302 | data_or |= (1 << 3); |
| 303 | printk(BIOS_DEBUG, "Enable ULX MPHY PG " |
| 304 | "control in single domain\n"); |
| 305 | } else if (strap19 == 0) { |
| 306 | printk(BIOS_DEBUG, "Enable ULX MPHY PG " |
| 307 | "control in split domains\n"); |
| 308 | } else { |
| 309 | printk(BIOS_DEBUG, "Invalid PCH Soft " |
| 310 | "Strap 19 configuration\n"); |
| 311 | } |
| 312 | } else { |
| 313 | data_or |= (1 << 3); |
| 314 | } |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | pch_iobp_update(0xCF000000, data_and, data_or); |
| 319 | } |
| 320 | |
Duncan Laurie | 446fb8e | 2014-08-08 09:59:43 -0700 | [diff] [blame] | 321 | static void pch_init_deep_sx(struct device *dev) |
| 322 | { |
| 323 | config_t *config = dev->chip_info; |
| 324 | |
| 325 | if (config->deep_sx_enable_ac) { |
| 326 | RCBA32_OR(DEEP_S3_POL, DEEP_S3_EN_AC); |
| 327 | RCBA32_OR(DEEP_S5_POL, DEEP_S5_EN_AC); |
| 328 | } |
| 329 | |
| 330 | if (config->deep_sx_enable_dc) { |
| 331 | RCBA32_OR(DEEP_S3_POL, DEEP_S3_EN_DC); |
| 332 | RCBA32_OR(DEEP_S5_POL, DEEP_S5_EN_DC); |
| 333 | } |
| 334 | |
| 335 | if (config->deep_sx_enable_ac || config->deep_sx_enable_dc) |
| 336 | RCBA32_OR(DEEP_SX_CONFIG, |
| 337 | DEEP_SX_WAKE_PIN_EN | DEEP_SX_GP27_PIN_EN); |
| 338 | } |
| 339 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 340 | /* Power Management init */ |
| 341 | static void pch_pm_init(struct device *dev) |
| 342 | { |
| 343 | printk(BIOS_DEBUG, "PCH PM init\n"); |
| 344 | |
Duncan Laurie | 446fb8e | 2014-08-08 09:59:43 -0700 | [diff] [blame] | 345 | pch_init_deep_sx(dev); |
| 346 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 347 | pch_enable_mphy(); |
| 348 | |
| 349 | reg_script_run_on_dev(dev, pch_pm_init_script); |
| 350 | |
Duncan Laurie | 446fb8e | 2014-08-08 09:59:43 -0700 | [diff] [blame] | 351 | if (pch_is_wpt()) { |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 352 | RCBA32_OR(0x33e0, (1 << 4) | (1 << 1)); |
Duncan Laurie | 446fb8e | 2014-08-08 09:59:43 -0700 | [diff] [blame] | 353 | RCBA32_OR(0x2b1c, (1 << 22) | (1 << 14) | (1 << 13)); |
| 354 | RCBA32(0x33e4) = 0x16bf0002; |
| 355 | RCBA32_OR(0x33e4, 0x1); |
| 356 | } |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 357 | |
| 358 | pch_iobp_update(0xCA000000, ~0UL, 0x00000009); |
| 359 | |
| 360 | /* Set RCBA 0x2b1c[29]=1 if DSP disabled */ |
| 361 | if (RCBA32(FD) & PCH_DISABLE_ADSPD) |
| 362 | RCBA32_OR(0x2b1c, (1 << 29)); |
| 363 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 366 | static void pch_cg_init(struct device *dev) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 367 | { |
| 368 | u32 reg32; |
| 369 | u16 reg16; |
| 370 | |
| 371 | /* DMI */ |
| 372 | RCBA32_OR(0x2234, 0xf); |
| 373 | |
| 374 | reg16 = pci_read_config16(dev, GEN_PMCON_1); |
| 375 | reg16 &= ~(1 << 10); /* Disable BIOS_PCI_EXP_EN for native PME */ |
| 376 | if (pch_is_wpt()) |
| 377 | reg16 &= ~(1 << 11); |
| 378 | else |
| 379 | reg16 |= (1 << 11); |
| 380 | reg16 |= (1 << 5) | (1 << 6) | (1 << 7) | (1 << 12); |
| 381 | reg16 |= (1 << 2); // PCI CLKRUN# Enable |
| 382 | pci_write_config16(dev, GEN_PMCON_1, reg16); |
| 383 | |
| 384 | /* |
| 385 | * RCBA + 0x2614[27:25,14:13,10,8] = 101,11,1,1 |
| 386 | * RCBA + 0x2614[23:16] = 0x20 |
| 387 | * RCBA + 0x2614[30:28] = 0x0 |
| 388 | * RCBA + 0x2614[26] = 1 (IF 0:2.0@0x08 >= 0x0b) |
| 389 | */ |
Duncan Laurie | 446fb8e | 2014-08-08 09:59:43 -0700 | [diff] [blame] | 390 | RCBA32_AND_OR(0x2614, ~0x64ff0000, 0x0a206500); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 391 | |
| 392 | /* Check for 0:2.0@0x08 >= 0x0b */ |
Duncan Laurie | 446fb8e | 2014-08-08 09:59:43 -0700 | [diff] [blame] | 393 | if (pch_is_wpt() || pci_read_config8(SA_DEV_IGD, 0x8) >= 0x0b) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 394 | RCBA32_OR(0x2614, (1 << 26)); |
| 395 | |
| 396 | RCBA32_OR(0x900, 0x0000031f); |
| 397 | |
| 398 | reg32 = RCBA32(CG); |
| 399 | if (RCBA32(0x3454) & (1 << 4)) |
| 400 | reg32 &= ~(1 << 29); // LPC Dynamic |
| 401 | else |
| 402 | reg32 |= (1 << 29); // LPC Dynamic |
| 403 | reg32 |= (1 << 31); // LP LPC |
| 404 | reg32 |= (1 << 30); // LP BLA |
Duncan Laurie | 446fb8e | 2014-08-08 09:59:43 -0700 | [diff] [blame] | 405 | if (RCBA32(0x3454) & (1 << 4)) |
| 406 | reg32 &= ~(1 << 29); |
| 407 | else |
| 408 | reg32 |= (1 << 29); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 409 | reg32 |= (1 << 28); // GPIO Dynamic |
| 410 | reg32 |= (1 << 27); // HPET Dynamic |
| 411 | reg32 |= (1 << 26); // Generic Platform Event Clock |
| 412 | if (RCBA32(BUC) & PCH_DISABLE_GBE) |
| 413 | reg32 |= (1 << 23); // GbE Static |
Duncan Laurie | 446fb8e | 2014-08-08 09:59:43 -0700 | [diff] [blame] | 414 | if (RCBA32(FD) & PCH_DISABLE_HD_AUDIO) |
| 415 | reg32 |= (1 << 21); // HDA Static |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 416 | reg32 |= (1 << 22); // HDA Dynamic |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 417 | RCBA32(CG) = reg32; |
| 418 | |
| 419 | /* PCH-LP LPC */ |
| 420 | if (pch_is_wpt()) |
| 421 | RCBA32_AND_OR(0x3434, ~0x1f, 0x17); |
| 422 | else |
| 423 | RCBA32_OR(0x3434, 0x7); |
| 424 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 425 | /* SPI */ |
| 426 | RCBA32_OR(0x38c0, 0x3c07); |
| 427 | |
| 428 | pch_iobp_update(0xCE00C000, ~1UL, 0x00000000); |
| 429 | } |
| 430 | |
| 431 | static void pch_set_acpi_mode(void) |
| 432 | { |
Martin Roth | e6ff159 | 2017-06-24 21:34:29 -0600 | [diff] [blame] | 433 | #if IS_ENABLED(CONFIG_HAVE_SMI_HANDLER) |
Kyösti Mälkki | 9e94dbf | 2015-01-08 20:03:18 +0200 | [diff] [blame] | 434 | if (!acpi_is_wakeup_s3()) { |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 435 | printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n"); |
| 436 | outb(APM_CNT_ACPI_DISABLE, APM_CNT); |
| 437 | printk(BIOS_DEBUG, "done.\n"); |
| 438 | } |
| 439 | #endif /* CONFIG_HAVE_SMI_HANDLER */ |
| 440 | } |
| 441 | |
| 442 | static void lpc_init(struct device *dev) |
| 443 | { |
| 444 | /* Legacy initialization */ |
| 445 | isa_dma_init(); |
| 446 | pch_rtc_init(dev); |
| 447 | reg_script_run_on_dev(dev, pch_misc_init_script); |
| 448 | |
| 449 | /* Interrupt configuration */ |
| 450 | pch_enable_ioapic(dev); |
| 451 | pch_pirq_init(dev); |
| 452 | setup_i8259(); |
| 453 | i8259_configure_irq_trigger(9, 1); |
Matt DeVillier | 81a6f10 | 2018-02-19 17:33:48 -0600 | [diff] [blame] | 454 | enable_hpet(dev); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 455 | |
| 456 | /* Initialize power management */ |
| 457 | pch_power_options(dev); |
| 458 | pch_pm_init(dev); |
| 459 | pch_cg_init(dev); |
| 460 | |
| 461 | pch_set_acpi_mode(); |
| 462 | } |
| 463 | |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 464 | static void pch_lpc_add_mmio_resources(struct device *dev) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 465 | { |
| 466 | u32 reg; |
| 467 | struct resource *res; |
| 468 | const u32 default_decode_base = IO_APIC_ADDR; |
| 469 | |
| 470 | /* |
| 471 | * Just report all resources from IO-APIC base to 4GiB. Don't mark |
| 472 | * them reserved as that may upset the OS if this range is marked |
| 473 | * as reserved in the e820. |
| 474 | */ |
| 475 | res = new_resource(dev, OIC); |
| 476 | res->base = default_decode_base; |
| 477 | res->size = 0 - default_decode_base; |
| 478 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 479 | |
| 480 | /* RCBA */ |
Lee Leahy | 6ef5192 | 2017-03-17 10:56:08 -0700 | [diff] [blame] | 481 | if (default_decode_base > RCBA_BASE_ADDRESS) { |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 482 | res = new_resource(dev, RCBA); |
| 483 | res->base = RCBA_BASE_ADDRESS; |
| 484 | res->size = 16 * 1024; |
| 485 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 486 | IORESOURCE_FIXED | IORESOURCE_RESERVE; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | /* Check LPC Memory Decode register. */ |
| 490 | reg = pci_read_config32(dev, LGMR); |
| 491 | if (reg & 1) { |
| 492 | reg &= ~0xffff; |
| 493 | if (reg < default_decode_base) { |
| 494 | res = new_resource(dev, LGMR); |
| 495 | res->base = reg; |
| 496 | res->size = 16 * 1024; |
| 497 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 498 | IORESOURCE_FIXED | IORESOURCE_RESERVE; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 499 | } |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | /* Default IO range claimed by the LPC device. The upper bound is exclusive. */ |
| 504 | #define LPC_DEFAULT_IO_RANGE_LOWER 0 |
| 505 | #define LPC_DEFAULT_IO_RANGE_UPPER 0x1000 |
| 506 | |
| 507 | static inline int pch_io_range_in_default(u16 base, u16 size) |
| 508 | { |
| 509 | /* Does it start above the range? */ |
| 510 | if (base >= LPC_DEFAULT_IO_RANGE_UPPER) |
| 511 | return 0; |
| 512 | |
| 513 | /* Is it entirely contained? */ |
| 514 | if (base >= LPC_DEFAULT_IO_RANGE_LOWER && |
| 515 | (base + size) < LPC_DEFAULT_IO_RANGE_UPPER) |
| 516 | return 1; |
| 517 | |
| 518 | /* This will return not in range for partial overlaps. */ |
| 519 | return 0; |
| 520 | } |
| 521 | |
| 522 | /* |
| 523 | * Note: this function assumes there is no overlap with the default LPC device's |
| 524 | * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER. |
| 525 | */ |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 526 | static void pch_lpc_add_io_resource(struct device *dev, u16 base, u16 size, |
| 527 | int index) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 528 | { |
| 529 | struct resource *res; |
| 530 | |
| 531 | if (pch_io_range_in_default(base, size)) |
| 532 | return; |
| 533 | |
| 534 | res = new_resource(dev, index); |
| 535 | res->base = base; |
| 536 | res->size = size; |
| 537 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 538 | } |
| 539 | |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 540 | static void pch_lpc_add_gen_io_resources(struct device *dev, int reg_value, |
| 541 | int index) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 542 | { |
| 543 | /* |
| 544 | * Check if the register is enabled. If so and the base exceeds the |
Martin Roth | de7ed6f | 2014-12-07 14:58:18 -0700 | [diff] [blame] | 545 | * device's default claim range add the resource. |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 546 | */ |
| 547 | if (reg_value & 1) { |
| 548 | u16 base = reg_value & 0xfffc; |
| 549 | u16 size = (0x3 | ((reg_value >> 16) & 0xfc)) + 1; |
| 550 | pch_lpc_add_io_resource(dev, base, size, index); |
| 551 | } |
| 552 | } |
| 553 | |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 554 | static void pch_lpc_add_io_resources(struct device *dev) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 555 | { |
| 556 | struct resource *res; |
| 557 | config_t *config = dev->chip_info; |
| 558 | |
| 559 | /* Add the default claimed IO range for the LPC device. */ |
| 560 | res = new_resource(dev, 0); |
| 561 | res->base = LPC_DEFAULT_IO_RANGE_LOWER; |
| 562 | res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER; |
| 563 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 564 | |
| 565 | /* GPIOBASE */ |
| 566 | pch_lpc_add_io_resource(dev, GPIO_BASE_ADDRESS, |
| 567 | GPIO_BASE_SIZE, GPIO_BASE); |
| 568 | |
| 569 | /* PMBASE */ |
| 570 | pch_lpc_add_io_resource(dev, ACPI_BASE_ADDRESS, ACPI_BASE_SIZE, PMBASE); |
| 571 | |
| 572 | /* LPC Generic IO Decode range. */ |
| 573 | pch_lpc_add_gen_io_resources(dev, config->gen1_dec, LPC_GEN1_DEC); |
| 574 | pch_lpc_add_gen_io_resources(dev, config->gen2_dec, LPC_GEN2_DEC); |
| 575 | pch_lpc_add_gen_io_resources(dev, config->gen3_dec, LPC_GEN3_DEC); |
| 576 | pch_lpc_add_gen_io_resources(dev, config->gen4_dec, LPC_GEN4_DEC); |
| 577 | } |
| 578 | |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 579 | static void pch_lpc_read_resources(struct device *dev) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 580 | { |
| 581 | global_nvs_t *gnvs; |
| 582 | |
| 583 | /* Get the normal PCI resources of this device. */ |
| 584 | pci_dev_read_resources(dev); |
| 585 | |
| 586 | /* Add non-standard MMIO resources. */ |
| 587 | pch_lpc_add_mmio_resources(dev); |
| 588 | |
| 589 | /* Add IO resources. */ |
| 590 | pch_lpc_add_io_resources(dev); |
| 591 | |
| 592 | /* Allocate ACPI NVS in CBMEM */ |
| 593 | gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(global_nvs_t)); |
Kyösti Mälkki | 9e94dbf | 2015-01-08 20:03:18 +0200 | [diff] [blame] | 594 | if (!acpi_is_wakeup_s3() && gnvs) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 595 | memset(gnvs, 0, sizeof(global_nvs_t)); |
| 596 | } |
| 597 | |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 598 | static void southcluster_inject_dsdt(struct device *device) |
Vladimir Serbinenko | b219da8 | 2014-11-09 03:29:30 +0100 | [diff] [blame] | 599 | { |
| 600 | global_nvs_t *gnvs; |
| 601 | |
| 602 | gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 603 | if (!gnvs) { |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 604 | gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(*gnvs)); |
Vladimir Serbinenko | b219da8 | 2014-11-09 03:29:30 +0100 | [diff] [blame] | 605 | if (gnvs) |
| 606 | memset(gnvs, 0, sizeof(*gnvs)); |
| 607 | } |
| 608 | |
| 609 | if (gnvs) { |
Vladimir Serbinenko | b219da8 | 2014-11-09 03:29:30 +0100 | [diff] [blame] | 610 | acpi_create_gnvs(gnvs); |
Vladimir Serbinenko | b219da8 | 2014-11-09 03:29:30 +0100 | [diff] [blame] | 611 | /* And tell SMI about it */ |
| 612 | smm_setup_structures(gnvs, NULL, NULL); |
| 613 | |
| 614 | /* Add it to DSDT. */ |
| 615 | acpigen_write_scope("\\"); |
| 616 | acpigen_write_name_dword("NVSA", (u32) gnvs); |
| 617 | acpigen_pop_len(); |
| 618 | } |
| 619 | } |
| 620 | |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 621 | static unsigned long broadwell_write_acpi_tables(struct device *device, |
Duncan Laurie | 93bbd41 | 2017-11-11 20:03:29 -0800 | [diff] [blame] | 622 | unsigned long current, |
| 623 | struct acpi_rsdp *rsdp) |
| 624 | { |
| 625 | if (IS_ENABLED(CONFIG_INTEL_PCH_UART_CONSOLE)) |
| 626 | current = acpi_write_dbg2_pci_uart(rsdp, current, |
| 627 | (CONFIG_INTEL_PCH_UART_CONSOLE_NUMBER == 1) ? |
| 628 | PCH_DEV_UART1 : PCH_DEV_UART0, |
| 629 | ACPI_ACCESS_SIZE_BYTE_ACCESS); |
| 630 | return acpi_write_hpet(device, current, rsdp); |
| 631 | } |
| 632 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 633 | static struct device_operations device_ops = { |
| 634 | .read_resources = &pch_lpc_read_resources, |
| 635 | .set_resources = &pci_dev_set_resources, |
| 636 | .enable_resources = &pci_dev_enable_resources, |
Vladimir Serbinenko | b219da8 | 2014-11-09 03:29:30 +0100 | [diff] [blame] | 637 | .acpi_inject_dsdt_generator = southcluster_inject_dsdt, |
Duncan Laurie | 93bbd41 | 2017-11-11 20:03:29 -0800 | [diff] [blame] | 638 | .write_acpi_tables = broadwell_write_acpi_tables, |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 639 | .init = &lpc_init, |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 640 | .scan_bus = &scan_lpc_bus, |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 641 | .ops_pci = &broadwell_pci_ops, |
| 642 | }; |
| 643 | |
| 644 | static const unsigned short pci_device_ids[] = { |
| 645 | PCH_LPT_LP_SAMPLE, |
| 646 | PCH_LPT_LP_PREMIUM, |
| 647 | PCH_LPT_LP_MAINSTREAM, |
| 648 | PCH_LPT_LP_VALUE, |
| 649 | PCH_WPT_HSW_U_SAMPLE, |
| 650 | PCH_WPT_BDW_U_SAMPLE, |
| 651 | PCH_WPT_BDW_U_PREMIUM, |
| 652 | PCH_WPT_BDW_U_BASE, |
| 653 | PCH_WPT_BDW_Y_SAMPLE, |
| 654 | PCH_WPT_BDW_Y_PREMIUM, |
| 655 | PCH_WPT_BDW_Y_BASE, |
| 656 | PCH_WPT_BDW_H, |
| 657 | 0 |
| 658 | }; |
| 659 | |
| 660 | static const struct pci_driver pch_lpc __pci_driver = { |
| 661 | .ops = &device_ops, |
| 662 | .vendor = PCI_VENDOR_ID_INTEL, |
| 663 | .devices = pci_device_ids, |
| 664 | }; |