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