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