Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 2 | |
| 3 | #include <console/console.h> |
| 4 | #include <device/device.h> |
| 5 | #include <device/pci.h> |
| 6 | #include <device/pci_ids.h> |
Patrick Rudolph | e56189c | 2018-04-18 10:11:59 +0200 | [diff] [blame] | 7 | #include <device/pci_ops.h> |
Kyösti Mälkki | cbf9571 | 2020-01-05 08:05:45 +0200 | [diff] [blame] | 8 | #include <option.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 9 | #include <pc80/isa-dma.h> |
| 10 | #include <pc80/i8259.h> |
| 11 | #include <arch/io.h> |
| 12 | #include <arch/ioapic.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 13 | #include <acpi/acpi.h> |
Kyösti Mälkki | 0c1dd9c | 2020-06-17 23:37:49 +0300 | [diff] [blame] | 14 | #include <acpi/acpi_gnvs.h> |
Aaron Durbin | 29ffa54 | 2012-12-21 21:21:48 -0600 | [diff] [blame] | 15 | #include <cpu/x86/smm.h> |
Duncan Laurie | 9c07c8f | 2013-03-22 11:08:39 -0700 | [diff] [blame] | 16 | #include <cbmem.h> |
| 17 | #include <string.h> |
Kyösti Mälkki | 12b121c | 2019-08-18 16:33:39 +0300 | [diff] [blame] | 18 | #include "chip.h" |
Angel Pons | 2178b72 | 2020-05-31 00:55:35 +0200 | [diff] [blame] | 19 | #include "iobp.h" |
Duncan Laurie | 9c07c8f | 2013-03-22 11:08:39 -0700 | [diff] [blame] | 20 | #include "nvs.h" |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 21 | #include "pch.h" |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 22 | #include <acpi/acpigen.h> |
Tristan Corrick | f3127d4 | 2018-10-31 02:25:54 +1300 | [diff] [blame] | 23 | #include <southbridge/intel/common/acpi_pirq_gen.h> |
Patrick Rudolph | 6b93112 | 2018-11-01 17:48:37 +0100 | [diff] [blame] | 24 | #include <southbridge/intel/common/rtc.h> |
Arthur Heymans | a3121b0 | 2019-05-28 13:46:49 +0200 | [diff] [blame] | 25 | #include <southbridge/intel/common/spi.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 26 | |
| 27 | #define NMI_OFF 0 |
| 28 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 29 | typedef struct southbridge_intel_lynxpoint_config config_t; |
| 30 | |
Paul Menzel | 373a20c | 2013-05-03 12:17:02 +0200 | [diff] [blame] | 31 | /** |
| 32 | * Set miscellanous static southbridge features. |
| 33 | * |
| 34 | * @param dev PCI device with I/O APIC control registers |
| 35 | */ |
| 36 | static void pch_enable_ioapic(struct device *dev) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 37 | { |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 38 | u32 reg32; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 39 | |
Matt DeVillier | a51e379 | 2018-03-04 01:44:15 -0600 | [diff] [blame] | 40 | /* Assign unique bus/dev/fn for I/O APIC */ |
| 41 | pci_write_config16(dev, LPC_IBDF, |
| 42 | PCH_IOAPIC_PCI_BUS << 8 | PCH_IOAPIC_PCI_SLOT << 3); |
| 43 | |
Paul Menzel | 373a20c | 2013-05-03 12:17:02 +0200 | [diff] [blame] | 44 | /* Enable ACPI I/O range decode */ |
| 45 | pci_write_config8(dev, ACPI_CNTL, ACPI_EN); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 46 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 47 | set_ioapic_id(VIO_APIC_VADDR, 0x02); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 48 | |
| 49 | /* affirm full set of redirection table entries ("write once") */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 50 | reg32 = io_apic_read(VIO_APIC_VADDR, 0x01); |
Duncan Laurie | c593999 | 2013-05-24 11:06:49 -0700 | [diff] [blame] | 51 | if (pch_is_lp()) { |
| 52 | /* PCH-LP has 39 redirection entries */ |
| 53 | reg32 &= ~0x00ff0000; |
| 54 | reg32 |= 0x00270000; |
| 55 | } |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 56 | io_apic_write(VIO_APIC_VADDR, 0x01, reg32); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 57 | |
Paul Menzel | 373a20c | 2013-05-03 12:17:02 +0200 | [diff] [blame] | 58 | /* |
| 59 | * Select Boot Configuration register (0x03) and |
| 60 | * use Processor System Bus (0x01) to deliver interrupts. |
| 61 | */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 62 | io_apic_write(VIO_APIC_VADDR, 0x03, 0x01); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | static void pch_enable_serial_irqs(struct device *dev) |
| 66 | { |
| 67 | /* Set packet length and toggle silent mode bit for one frame. */ |
| 68 | pci_write_config8(dev, SERIRQ_CNTL, |
| 69 | (1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0)); |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 70 | #if !CONFIG(SERIRQ_CONTINUOUS_MODE) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 71 | pci_write_config8(dev, SERIRQ_CNTL, |
| 72 | (1 << 7) | (0 << 6) | ((21 - 17) << 2) | (0 << 0)); |
| 73 | #endif |
| 74 | } |
| 75 | |
| 76 | /* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control |
| 77 | * 0x00 - 0000 = Reserved |
| 78 | * 0x01 - 0001 = Reserved |
| 79 | * 0x02 - 0010 = Reserved |
| 80 | * 0x03 - 0011 = IRQ3 |
| 81 | * 0x04 - 0100 = IRQ4 |
| 82 | * 0x05 - 0101 = IRQ5 |
| 83 | * 0x06 - 0110 = IRQ6 |
| 84 | * 0x07 - 0111 = IRQ7 |
| 85 | * 0x08 - 1000 = Reserved |
| 86 | * 0x09 - 1001 = IRQ9 |
| 87 | * 0x0A - 1010 = IRQ10 |
| 88 | * 0x0B - 1011 = IRQ11 |
| 89 | * 0x0C - 1100 = IRQ12 |
| 90 | * 0x0D - 1101 = Reserved |
| 91 | * 0x0E - 1110 = IRQ14 |
| 92 | * 0x0F - 1111 = IRQ15 |
| 93 | * PIRQ[n]_ROUT[7] - PIRQ Routing Control |
| 94 | * 0x80 - The PIRQ is not routed. |
| 95 | */ |
| 96 | |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame] | 97 | static void pch_pirq_init(struct device *dev) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 98 | { |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame] | 99 | struct device *irq_dev; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 100 | |
Angel Pons | 9f78127 | 2020-07-25 14:03:40 +0200 | [diff] [blame] | 101 | const uint8_t pirq = 0x80; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 102 | |
Angel Pons | 9f78127 | 2020-07-25 14:03:40 +0200 | [diff] [blame] | 103 | pci_write_config8(dev, PIRQA_ROUT, pirq); |
| 104 | pci_write_config8(dev, PIRQB_ROUT, pirq); |
| 105 | pci_write_config8(dev, PIRQC_ROUT, pirq); |
| 106 | pci_write_config8(dev, PIRQD_ROUT, pirq); |
| 107 | |
| 108 | pci_write_config8(dev, PIRQE_ROUT, pirq); |
| 109 | pci_write_config8(dev, PIRQF_ROUT, pirq); |
| 110 | pci_write_config8(dev, PIRQG_ROUT, pirq); |
| 111 | pci_write_config8(dev, PIRQH_ROUT, pirq); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 112 | |
| 113 | /* Eric Biederman once said we should let the OS do this. |
| 114 | * I am not so sure anymore he was right. |
| 115 | */ |
| 116 | |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 117 | for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) { |
Angel Pons | 2aaf7c0 | 2020-09-24 18:03:18 +0200 | [diff] [blame] | 118 | u8 int_pin = 0, int_line = 0; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 119 | |
| 120 | if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI) |
| 121 | continue; |
| 122 | |
| 123 | int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN); |
| 124 | |
| 125 | switch (int_pin) { |
Angel Pons | 9f78127 | 2020-07-25 14:03:40 +0200 | [diff] [blame] | 126 | case 1: /* INTA# */ |
| 127 | case 2: /* INTB# */ |
| 128 | case 3: /* INTC# */ |
| 129 | case 4: /* INTD# */ |
| 130 | int_line = pirq; |
| 131 | break; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | if (!int_line) |
| 135 | continue; |
| 136 | |
| 137 | pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line); |
| 138 | } |
| 139 | } |
| 140 | |
Angel Pons | cbcbb67 | 2020-10-23 00:11:26 +0200 | [diff] [blame] | 141 | static void pch_gpi_routing(struct device *dev, config_t *config) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 142 | { |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 143 | u32 reg32 = 0; |
| 144 | |
| 145 | /* An array would be much nicer here, or some |
| 146 | * other method of doing this. |
| 147 | */ |
| 148 | reg32 |= (config->gpi0_routing & 0x03) << 0; |
| 149 | reg32 |= (config->gpi1_routing & 0x03) << 2; |
| 150 | reg32 |= (config->gpi2_routing & 0x03) << 4; |
| 151 | reg32 |= (config->gpi3_routing & 0x03) << 6; |
| 152 | reg32 |= (config->gpi4_routing & 0x03) << 8; |
| 153 | reg32 |= (config->gpi5_routing & 0x03) << 10; |
| 154 | reg32 |= (config->gpi6_routing & 0x03) << 12; |
| 155 | reg32 |= (config->gpi7_routing & 0x03) << 14; |
| 156 | reg32 |= (config->gpi8_routing & 0x03) << 16; |
| 157 | reg32 |= (config->gpi9_routing & 0x03) << 18; |
| 158 | reg32 |= (config->gpi10_routing & 0x03) << 20; |
| 159 | reg32 |= (config->gpi11_routing & 0x03) << 22; |
| 160 | reg32 |= (config->gpi12_routing & 0x03) << 24; |
| 161 | reg32 |= (config->gpi13_routing & 0x03) << 26; |
| 162 | reg32 |= (config->gpi14_routing & 0x03) << 28; |
| 163 | reg32 |= (config->gpi15_routing & 0x03) << 30; |
| 164 | |
Kyösti Mälkki | b85a87b | 2014-12-29 11:32:27 +0200 | [diff] [blame] | 165 | pci_write_config32(dev, GPIO_ROUT, reg32); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 166 | } |
| 167 | |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame] | 168 | static void pch_power_options(struct device *dev) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 169 | { |
| 170 | u8 reg8; |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 171 | u16 reg16; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 172 | u32 reg32; |
| 173 | const char *state; |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame] | 174 | u16 pmbase = get_pmbase(); |
Nico Huber | 9faae2b | 2018-11-14 00:00:35 +0100 | [diff] [blame] | 175 | int pwr_on = CONFIG_MAINBOARD_POWER_FAILURE_STATE; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 176 | int nmi_option; |
| 177 | |
| 178 | /* Which state do we want to goto after g3 (power restored)? |
| 179 | * 0 == S0 Full On |
| 180 | * 1 == S5 Soft Off |
| 181 | * |
| 182 | * If the option is not existent (Laptops), use Kconfig setting. |
| 183 | */ |
| 184 | get_option(&pwr_on, "power_on_after_fail"); |
| 185 | |
| 186 | reg16 = pci_read_config16(dev, GEN_PMCON_3); |
| 187 | reg16 &= 0xfffe; |
| 188 | switch (pwr_on) { |
| 189 | case MAINBOARD_POWER_OFF: |
| 190 | reg16 |= 1; |
| 191 | state = "off"; |
| 192 | break; |
| 193 | case MAINBOARD_POWER_ON: |
| 194 | reg16 &= ~1; |
| 195 | state = "on"; |
| 196 | break; |
| 197 | case MAINBOARD_POWER_KEEP: |
| 198 | reg16 &= ~1; |
| 199 | state = "state keep"; |
| 200 | break; |
| 201 | default: |
| 202 | state = "undefined"; |
| 203 | } |
| 204 | |
| 205 | reg16 &= ~(3 << 4); /* SLP_S4# Assertion Stretch 4s */ |
| 206 | reg16 |= (1 << 3); /* SLP_S4# Assertion Stretch Enable */ |
| 207 | |
| 208 | reg16 &= ~(1 << 10); |
| 209 | reg16 |= (1 << 11); /* SLP_S3# Min Assertion Width 50ms */ |
| 210 | |
| 211 | reg16 |= (1 << 12); /* Disable SLP stretch after SUS well */ |
| 212 | |
| 213 | pci_write_config16(dev, GEN_PMCON_3, reg16); |
| 214 | printk(BIOS_INFO, "Set power %s after power failure.\n", state); |
| 215 | |
| 216 | /* Set up NMI on errors. */ |
| 217 | reg8 = inb(0x61); |
| 218 | reg8 &= 0x0f; /* Higher Nibble must be 0 */ |
| 219 | reg8 &= ~(1 << 3); /* IOCHK# NMI Enable */ |
| 220 | // reg8 &= ~(1 << 2); /* PCI SERR# Enable */ |
| 221 | reg8 |= (1 << 2); /* PCI SERR# Disable for now */ |
| 222 | outb(reg8, 0x61); |
| 223 | |
| 224 | reg8 = inb(0x70); |
| 225 | nmi_option = NMI_OFF; |
| 226 | get_option(&nmi_option, "nmi"); |
| 227 | if (nmi_option) { |
| 228 | printk(BIOS_INFO, "NMI sources enabled.\n"); |
| 229 | reg8 &= ~(1 << 7); /* Set NMI. */ |
| 230 | } else { |
| 231 | printk(BIOS_INFO, "NMI sources disabled.\n"); |
Elyes HAOUAS | 9c5d463 | 2018-04-26 22:21:21 +0200 | [diff] [blame] | 232 | reg8 |= (1 << 7); /* Can't mask NMI from PCI-E and NMI_NOW */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 233 | } |
| 234 | outb(reg8, 0x70); |
| 235 | |
| 236 | /* Enable CPU_SLP# and Intel Speedstep, set SMI# rate down */ |
| 237 | reg16 = pci_read_config16(dev, GEN_PMCON_1); |
| 238 | reg16 &= ~(3 << 0); // SMI# rate 1 minute |
| 239 | reg16 &= ~(1 << 10); // Disable BIOS_PCI_EXP_EN for native PME |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 240 | pci_write_config16(dev, GEN_PMCON_1, reg16); |
| 241 | |
Angel Pons | cbcbb67 | 2020-10-23 00:11:26 +0200 | [diff] [blame] | 242 | if (dev->chip_info) { |
| 243 | config_t *config = dev->chip_info; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 244 | |
Angel Pons | cbcbb67 | 2020-10-23 00:11:26 +0200 | [diff] [blame] | 245 | /* |
| 246 | * Set the board's GPI routing on LynxPoint-H. |
| 247 | * This is done as part of GPIO configuration on LynxPoint-LP. |
| 248 | */ |
| 249 | if (pch_is_lp()) |
| 250 | pch_gpi_routing(dev, config); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 251 | |
Angel Pons | cbcbb67 | 2020-10-23 00:11:26 +0200 | [diff] [blame] | 252 | /* GPE setup based on device tree configuration */ |
| 253 | enable_all_gpe(config->gpe0_en_1, config->gpe0_en_2, |
| 254 | config->gpe0_en_3, config->gpe0_en_4); |
| 255 | |
| 256 | /* SMI setup based on device tree configuration */ |
| 257 | enable_alt_smi(config->alt_gp_smi_en); |
| 258 | } |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 259 | |
| 260 | /* Set up power management block and determine sleep mode */ |
| 261 | reg32 = inl(pmbase + 0x04); // PM1_CNT |
| 262 | reg32 &= ~(7 << 10); // SLP_TYP |
| 263 | reg32 |= (1 << 0); // SCI_EN |
| 264 | outl(reg32, pmbase + 0x04); |
| 265 | |
| 266 | /* Clear magic status bits to prevent unexpected wake */ |
| 267 | reg32 = RCBA32(0x3310); |
Angel Pons | 84fa224 | 2020-10-24 11:53:47 +0200 | [diff] [blame] | 268 | reg32 |= (1 << 4) | (1 << 5) | (1 << 0); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 269 | RCBA32(0x3310) = reg32; |
| 270 | |
Ryan Salsamendi | 889ce9c | 2017-06-30 17:45:14 -0700 | [diff] [blame] | 271 | reg16 = RCBA16(0x3f02); |
| 272 | reg16 &= ~0xf; |
| 273 | RCBA16(0x3f02) = reg16; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 274 | } |
| 275 | |
Duncan Laurie | deb90f4 | 2013-03-08 17:22:37 -0800 | [diff] [blame] | 276 | /* LynxPoint PCH Power Management init */ |
| 277 | static void lpt_pm_init(struct device *dev) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 278 | { |
Duncan Laurie | deb90f4 | 2013-03-08 17:22:37 -0800 | [diff] [blame] | 279 | printk(BIOS_DEBUG, "LynxPoint PM init\n"); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 280 | } |
Duncan Laurie | deb90f4 | 2013-03-08 17:22:37 -0800 | [diff] [blame] | 281 | |
Duncan Laurie | deb90f4 | 2013-03-08 17:22:37 -0800 | [diff] [blame] | 282 | /* LynxPoint LP PCH Power Management init */ |
| 283 | static void lpt_lp_pm_init(struct device *dev) |
| 284 | { |
| 285 | struct southbridge_intel_lynxpoint_config *config = dev->chip_info; |
| 286 | u32 data; |
| 287 | |
| 288 | printk(BIOS_DEBUG, "LynxPoint LP PM init\n"); |
| 289 | |
| 290 | pci_write_config8(dev, 0xa9, 0x46); |
| 291 | |
Angel Pons | 90cdf70 | 2020-10-24 23:00:34 +0200 | [diff] [blame^] | 292 | RCBA32_AND_OR(0x232c, ~1, 0); |
| 293 | |
Angel Pons | 725657a | 2020-07-03 13:15:00 +0200 | [diff] [blame] | 294 | RCBA32_AND_OR(0x1100, ~0xc000, 0xc000); |
Angel Pons | 4fe4661 | 2020-10-24 22:22:04 +0200 | [diff] [blame] | 295 | RCBA32_OR(0x1100, 0x00000100); |
| 296 | RCBA32_OR(0x1100, 0x0000003f); |
Angel Pons | 90cdf70 | 2020-10-24 23:00:34 +0200 | [diff] [blame^] | 297 | |
Angel Pons | 725657a | 2020-07-03 13:15:00 +0200 | [diff] [blame] | 298 | RCBA32_AND_OR(0x2320, ~0x60, 0x10); |
Angel Pons | 90cdf70 | 2020-10-24 23:00:34 +0200 | [diff] [blame^] | 299 | |
Angel Pons | 4fe4661 | 2020-10-24 22:22:04 +0200 | [diff] [blame] | 300 | RCBA32(0x3314) = 0x00012fff; |
| 301 | RCBA32(0x3318) = 0x0dcf0400; |
| 302 | RCBA32(0x3324) = 0x04000000; |
| 303 | RCBA32(0x3368) = 0x00041400; |
| 304 | RCBA32(0x3388) = 0x3f8ddbff; |
| 305 | RCBA32(0x33ac) = 0x00007001; |
| 306 | RCBA32(0x33b0) = 0x00181900; |
| 307 | RCBA32(0x33c0) = 0x00060A00; |
| 308 | RCBA32(0x33d0) = 0x06200840; |
| 309 | RCBA32(0x3a28) = 0x01010101; |
| 310 | RCBA32(0x3a2c) = 0x04040404; |
| 311 | RCBA32(0x2b1c) = 0x03808033; |
| 312 | RCBA32(0x2b34) = 0x80000009; |
| 313 | RCBA32(0x3348) = 0x022ddfff; |
| 314 | RCBA32(0x334c) = 0x00000001; |
| 315 | RCBA32(0x3358) = 0x0001c000; |
| 316 | RCBA32(0x3380) = 0x3f8ddbff; |
| 317 | RCBA32(0x3384) = 0x0001c7e1; |
| 318 | RCBA32(0x338c) = 0x0001c7e1; |
| 319 | RCBA32(0x3398) = 0x0001c000; |
| 320 | RCBA32(0x33a8) = 0x00181900; |
| 321 | RCBA32(0x33dc) = 0x00080000; |
| 322 | RCBA32(0x33e0) = 0x00000001; |
| 323 | RCBA32(0x3a20) = 0x00000404; |
| 324 | RCBA32(0x3a24) = 0x01010101; |
| 325 | RCBA32(0x3a30) = 0x01010101; |
Angel Pons | 90cdf70 | 2020-10-24 23:00:34 +0200 | [diff] [blame^] | 326 | |
Angel Pons | 4fe4661 | 2020-10-24 22:22:04 +0200 | [diff] [blame] | 327 | RCBA32_OR(0x0410, 0x00000003); |
| 328 | RCBA32_OR(0x2618, 0x08000000); |
| 329 | RCBA32_OR(0x2300, 0x00000002); |
| 330 | RCBA32_OR(0x2600, 0x00000008); |
Angel Pons | 90cdf70 | 2020-10-24 23:00:34 +0200 | [diff] [blame^] | 331 | |
Angel Pons | 4fe4661 | 2020-10-24 22:22:04 +0200 | [diff] [blame] | 332 | RCBA32(0x33b4) = 0x00007001; |
| 333 | RCBA32(0x3350) = 0x022ddfff; |
| 334 | RCBA32(0x3354) = 0x00000001; |
Angel Pons | 90cdf70 | 2020-10-24 23:00:34 +0200 | [diff] [blame^] | 335 | |
| 336 | /* Power Optimizer */ |
| 337 | RCBA32_OR(0x33d4, 0x08000000); |
| 338 | RCBA32_OR(0x33c8, 0x00000080); |
| 339 | |
| 340 | RCBA32(0x2b10) = 0x0000883c; |
| 341 | RCBA32(0x2b14) = 0x1e0a4616; |
| 342 | RCBA32(0x2b24) = 0x40000005; |
| 343 | RCBA32(0x2b20) = 0x0005db01; |
Angel Pons | 4fe4661 | 2020-10-24 22:22:04 +0200 | [diff] [blame] | 344 | RCBA32(0x3a80) = 0x05145005; |
Duncan Laurie | deb90f4 | 2013-03-08 17:22:37 -0800 | [diff] [blame] | 345 | |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 346 | pci_or_config32(dev, 0xac, 1 << 21); |
Duncan Laurie | deb90f4 | 2013-03-08 17:22:37 -0800 | [diff] [blame] | 347 | |
Elyes HAOUAS | a0aea56 | 2017-07-03 21:38:53 +0200 | [diff] [blame] | 348 | pch_iobp_update(0xED00015C, ~(1 << 11), 0x00003700); |
Angel Pons | 8963f7d | 2020-10-24 12:20:28 +0200 | [diff] [blame] | 349 | pch_iobp_update(0xED000118, ~0, 0x00c00000); |
| 350 | pch_iobp_update(0xED000120, ~0, 0x00240000); |
| 351 | pch_iobp_update(0xCA000000, ~0, 0x00000009); |
Duncan Laurie | deb90f4 | 2013-03-08 17:22:37 -0800 | [diff] [blame] | 352 | |
| 353 | /* Set RCBA CIR28 0x3A84 based on SATA port enables */ |
| 354 | data = 0x00001005; |
| 355 | /* Port 3 and 2 disabled */ |
Angel Pons | cbcbb67 | 2020-10-23 00:11:26 +0200 | [diff] [blame] | 356 | if (config && (config->sata_port_map & ((1 << 3) | (1 << 2))) == 0) |
Duncan Laurie | deb90f4 | 2013-03-08 17:22:37 -0800 | [diff] [blame] | 357 | data |= (1 << 24) | (1 << 26); |
| 358 | /* Port 1 and 0 disabled */ |
Angel Pons | cbcbb67 | 2020-10-23 00:11:26 +0200 | [diff] [blame] | 359 | if (config && (config->sata_port_map & ((1 << 1) | (1 << 0))) == 0) |
Duncan Laurie | deb90f4 | 2013-03-08 17:22:37 -0800 | [diff] [blame] | 360 | data |= (1 << 20) | (1 << 18); |
| 361 | RCBA32(0x3a84) = data; |
| 362 | |
Duncan Laurie | 5cf34ce | 2013-04-26 10:41:33 -0700 | [diff] [blame] | 363 | /* Set RCBA 0x2b1c[29]=1 if DSP disabled */ |
| 364 | if (RCBA32(FD) & PCH_DISABLE_ADSPD) |
| 365 | RCBA32_OR(0x2b1c, (1 << 29)); |
| 366 | |
Duncan Laurie | deb90f4 | 2013-03-08 17:22:37 -0800 | [diff] [blame] | 367 | /* Lock */ |
| 368 | RCBA32_OR(0x3a6c, 0x00000001); |
| 369 | |
| 370 | /* Set RCBA 0x33D4 after other setup */ |
| 371 | RCBA32_OR(0x33d4, 0x2fff2fb1); |
| 372 | |
| 373 | /* Set RCBA 0x33C8[15]=1 as last step */ |
| 374 | RCBA32_OR(0x33c8, (1 << 15)); |
| 375 | } |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 376 | |
Matt DeVillier | a51e379 | 2018-03-04 01:44:15 -0600 | [diff] [blame] | 377 | static void enable_hpet(struct device *const dev) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 378 | { |
| 379 | u32 reg32; |
Matt DeVillier | a51e379 | 2018-03-04 01:44:15 -0600 | [diff] [blame] | 380 | size_t i; |
| 381 | |
| 382 | /* Assign unique bus/dev/fn for each HPET */ |
| 383 | for (i = 0; i < 8; ++i) |
| 384 | pci_write_config16(dev, LPC_HnBDF(i), |
| 385 | PCH_HPET_PCI_BUS << 8 | PCH_HPET_PCI_SLOT << 3 | i); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 386 | |
| 387 | /* Move HPET to default address 0xfed00000 and enable it */ |
| 388 | reg32 = RCBA32(HPTC); |
| 389 | reg32 |= (1 << 7); // HPET Address Enable |
| 390 | reg32 &= ~(3 << 0); |
| 391 | RCBA32(HPTC) = reg32; |
| 392 | /* Read it back to stick. It's affected by posted write syndrome. */ |
Elyes HAOUAS | 6de151e | 2019-10-18 16:43:30 +0200 | [diff] [blame] | 393 | RCBA32(HPTC); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 394 | } |
| 395 | |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame] | 396 | static void enable_clock_gating(struct device *dev) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 397 | { |
Duncan Laurie | 74c0d05 | 2012-12-17 11:31:40 -0800 | [diff] [blame] | 398 | /* LynxPoint Mobile */ |
| 399 | u32 reg32; |
| 400 | u16 reg16; |
| 401 | |
| 402 | /* DMI */ |
Angel Pons | 8963f7d | 2020-10-24 12:20:28 +0200 | [diff] [blame] | 403 | RCBA32_AND_OR(0x2234, ~0, 0xf); |
Duncan Laurie | 74c0d05 | 2012-12-17 11:31:40 -0800 | [diff] [blame] | 404 | reg16 = pci_read_config16(dev, GEN_PMCON_1); |
| 405 | reg16 |= (1 << 11) | (1 << 12) | (1 << 14); |
| 406 | reg16 |= (1 << 2); // PCI CLKRUN# Enable |
| 407 | pci_write_config16(dev, GEN_PMCON_1, reg16); |
| 408 | RCBA32_OR(0x900, (1 << 14)); |
| 409 | |
| 410 | reg32 = RCBA32(CG); |
| 411 | reg32 |= (1 << 22); // HDA Dynamic |
Angel Pons | 8963f7d | 2020-10-24 12:20:28 +0200 | [diff] [blame] | 412 | reg32 |= (1 << 31); // LPC Dynamic |
Duncan Laurie | 74c0d05 | 2012-12-17 11:31:40 -0800 | [diff] [blame] | 413 | reg32 |= (1 << 16); // PCIe Dynamic |
| 414 | reg32 |= (1 << 27); // HPET Dynamic |
| 415 | reg32 |= (1 << 28); // GPIO Dynamic |
| 416 | RCBA32(CG) = reg32; |
| 417 | |
| 418 | RCBA32_OR(0x38c0, 0x7); // SPI Dynamic |
Duncan Laurie | deb90f4 | 2013-03-08 17:22:37 -0800 | [diff] [blame] | 419 | } |
| 420 | |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame] | 421 | static void enable_lp_clock_gating(struct device *dev) |
Duncan Laurie | deb90f4 | 2013-03-08 17:22:37 -0800 | [diff] [blame] | 422 | { |
| 423 | /* LynxPoint LP */ |
| 424 | u32 reg32; |
| 425 | u16 reg16; |
| 426 | |
| 427 | /* DMI */ |
Angel Pons | 8963f7d | 2020-10-24 12:20:28 +0200 | [diff] [blame] | 428 | RCBA32_AND_OR(0x2234, ~0, 0xf); |
Duncan Laurie | deb90f4 | 2013-03-08 17:22:37 -0800 | [diff] [blame] | 429 | reg16 = pci_read_config16(dev, GEN_PMCON_1); |
| 430 | reg16 &= ~((1 << 11) | (1 << 14)); |
| 431 | reg16 |= (1 << 5) | (1 << 6) | (1 << 7) | (1 << 12) | (1 << 13); |
| 432 | reg16 |= (1 << 2); // PCI CLKRUN# Enable |
| 433 | pci_write_config16(dev, GEN_PMCON_1, reg16); |
| 434 | |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 435 | pci_or_config32(dev, 0x64, 1 << 6); |
Duncan Laurie | deb90f4 | 2013-03-08 17:22:37 -0800 | [diff] [blame] | 436 | |
Duncan Laurie | 4bc107b | 2013-06-24 13:14:44 -0700 | [diff] [blame] | 437 | /* |
| 438 | * RCBA + 0x2614[27:25,14:13,10,8] = 101,11,1,1 |
| 439 | * RCBA + 0x2614[23:16] = 0x20 |
| 440 | * RCBA + 0x2614[30:28] = 0x0 |
Duncan Laurie | d8c7d73 | 2013-07-16 09:01:43 -0700 | [diff] [blame] | 441 | * RCBA + 0x2614[26] = 1 (IF 0:2.0@0x08 >= 0x0b) |
Duncan Laurie | 4bc107b | 2013-06-24 13:14:44 -0700 | [diff] [blame] | 442 | */ |
Angel Pons | 90cdf70 | 2020-10-24 23:00:34 +0200 | [diff] [blame^] | 443 | RCBA32_AND_OR(0x2614, ~0x74000000, 0x0a206500); |
Duncan Laurie | 4bc107b | 2013-06-24 13:14:44 -0700 | [diff] [blame] | 444 | |
| 445 | /* Check for LPT-LP B2 stepping and 0:31.0@0xFA > 4 */ |
Nico Huber | 744d6bd | 2019-01-12 14:58:20 +0100 | [diff] [blame] | 446 | struct device *const gma = pcidev_on_root(2, 0); |
| 447 | if (gma && pci_read_config8(gma, 0x8) >= 0x0b) |
Elyes HAOUAS | a0aea56 | 2017-07-03 21:38:53 +0200 | [diff] [blame] | 448 | RCBA32_OR(0x2614, (1 << 26)); |
Duncan Laurie | 4bc107b | 2013-06-24 13:14:44 -0700 | [diff] [blame] | 449 | |
Duncan Laurie | deb90f4 | 2013-03-08 17:22:37 -0800 | [diff] [blame] | 450 | RCBA32_OR(0x900, 0x0000031f); |
| 451 | |
| 452 | reg32 = RCBA32(CG); |
Duncan Laurie | a2d6a40 | 2013-03-22 11:24:45 -0700 | [diff] [blame] | 453 | if (RCBA32(0x3454) & (1 << 4)) |
| 454 | reg32 &= ~(1 << 29); // LPC Dynamic |
| 455 | else |
| 456 | reg32 |= (1 << 29); // LPC Dynamic |
Angel Pons | 2aaf7c0 | 2020-09-24 18:03:18 +0200 | [diff] [blame] | 457 | reg32 |= (1 << 31); // LP LPC |
Duncan Laurie | 5cf34ce | 2013-04-26 10:41:33 -0700 | [diff] [blame] | 458 | reg32 |= (1 << 30); // LP BLA |
Duncan Laurie | deb90f4 | 2013-03-08 17:22:37 -0800 | [diff] [blame] | 459 | reg32 |= (1 << 28); // GPIO Dynamic |
| 460 | reg32 |= (1 << 27); // HPET Dynamic |
Duncan Laurie | 5cf34ce | 2013-04-26 10:41:33 -0700 | [diff] [blame] | 461 | reg32 |= (1 << 26); // Generic Platform Event Clock |
| 462 | if (RCBA32(BUC) & PCH_DISABLE_GBE) |
| 463 | reg32 |= (1 << 23); // GbE Static |
Duncan Laurie | deb90f4 | 2013-03-08 17:22:37 -0800 | [diff] [blame] | 464 | reg32 |= (1 << 22); // HDA Dynamic |
Duncan Laurie | 5cf34ce | 2013-04-26 10:41:33 -0700 | [diff] [blame] | 465 | reg32 |= (1 << 16); // PCI Dynamic |
Duncan Laurie | deb90f4 | 2013-03-08 17:22:37 -0800 | [diff] [blame] | 466 | RCBA32(CG) = reg32; |
| 467 | |
| 468 | RCBA32_OR(0x3434, 0x7); // LP LPC |
| 469 | |
| 470 | RCBA32_AND_OR(0x333c, 0xffcfffff, 0x00c00000); // SATA |
| 471 | |
| 472 | RCBA32_OR(0x38c0, 0x3c07); // SPI Dynamic |
| 473 | |
Angel Pons | 8963f7d | 2020-10-24 12:20:28 +0200 | [diff] [blame] | 474 | pch_iobp_update(0xCF000000, ~0, 0x00007001); |
| 475 | pch_iobp_update(0xCE00C000, ~1, 0x00000000); // bit0=0 in BWG 1.4.0 |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 476 | } |
| 477 | |
Aaron Durbin | 29ffa54 | 2012-12-21 21:21:48 -0600 | [diff] [blame] | 478 | static void pch_set_acpi_mode(void) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 479 | { |
Kyösti Mälkki | ad882c3 | 2020-06-02 05:05:30 +0300 | [diff] [blame] | 480 | if (!acpi_is_wakeup_s3()) |
Kyösti Mälkki | b658548 | 2020-06-01 15:11:14 +0300 | [diff] [blame] | 481 | apm_control(APM_CNT_ACPI_DISABLE); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 482 | } |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 483 | |
| 484 | static void pch_disable_smm_only_flashing(struct device *dev) |
| 485 | { |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 486 | printk(BIOS_SPEW, "Enabling BIOS updates outside of SMM... "); |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 487 | |
| 488 | pci_and_config8(dev, BIOS_CNTL, ~(1 << 5)); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | static void pch_fixups(struct device *dev) |
| 492 | { |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 493 | /* Indicate DRAM init done for MRC S3 to know it can resume */ |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 494 | pci_or_config8(dev, GEN_PMCON_2, 1 << 7); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 495 | |
| 496 | /* |
| 497 | * Enable DMI ASPM in the PCH |
| 498 | */ |
| 499 | RCBA32_AND_OR(0x2304, ~(1 << 10), 0); |
Angel Pons | 84fa224 | 2020-10-24 11:53:47 +0200 | [diff] [blame] | 500 | RCBA32_OR(0x21a4, (1 << 11) | (1 << 10)); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 501 | RCBA32_OR(0x21a8, 0x3); |
| 502 | } |
| 503 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 504 | static void lpc_init(struct device *dev) |
| 505 | { |
Elyes HAOUAS | bfc255a | 2020-03-07 13:05:14 +0100 | [diff] [blame] | 506 | printk(BIOS_DEBUG, "pch: %s\n", __func__); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 507 | |
| 508 | /* Set the value for PCI command register. */ |
Angel Pons | 89739ba | 2020-07-25 02:46:39 +0200 | [diff] [blame] | 509 | pci_write_config16(dev, PCI_COMMAND, |
| 510 | PCI_COMMAND_MASTER | PCI_COMMAND_SPECIAL | |
| 511 | PCI_COMMAND_MEMORY | PCI_COMMAND_IO); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 512 | |
| 513 | /* IO APIC initialization. */ |
Paul Menzel | 373a20c | 2013-05-03 12:17:02 +0200 | [diff] [blame] | 514 | pch_enable_ioapic(dev); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 515 | |
| 516 | pch_enable_serial_irqs(dev); |
| 517 | |
| 518 | /* Setup the PIRQ. */ |
| 519 | pch_pirq_init(dev); |
| 520 | |
| 521 | /* Setup power options. */ |
| 522 | pch_power_options(dev); |
| 523 | |
| 524 | /* Initialize power management */ |
Duncan Laurie | deb90f4 | 2013-03-08 17:22:37 -0800 | [diff] [blame] | 525 | if (pch_is_lp()) { |
| 526 | lpt_lp_pm_init(dev); |
| 527 | enable_lp_clock_gating(dev); |
| 528 | } else { |
| 529 | lpt_pm_init(dev); |
| 530 | enable_clock_gating(dev); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 531 | } |
| 532 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 533 | /* Initialize the real time clock. */ |
Patrick Rudolph | 6b93112 | 2018-11-01 17:48:37 +0100 | [diff] [blame] | 534 | sb_rtc_init(); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 535 | |
| 536 | /* Initialize ISA DMA. */ |
| 537 | isa_dma_init(); |
| 538 | |
| 539 | /* Initialize the High Precision Event Timers, if present. */ |
Matt DeVillier | a51e379 | 2018-03-04 01:44:15 -0600 | [diff] [blame] | 540 | enable_hpet(dev); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 541 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 542 | setup_i8259(); |
| 543 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 544 | /* Interrupt 9 should be level triggered (SCI) */ |
| 545 | i8259_configure_irq_trigger(9, 1); |
| 546 | |
| 547 | pch_disable_smm_only_flashing(dev); |
| 548 | |
Aaron Durbin | 29ffa54 | 2012-12-21 21:21:48 -0600 | [diff] [blame] | 549 | pch_set_acpi_mode(); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 550 | |
| 551 | pch_fixups(dev); |
| 552 | } |
| 553 | |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame] | 554 | static void pch_lpc_add_mmio_resources(struct device *dev) |
Aaron Durbin | 6f561af | 2012-12-19 14:38:01 -0600 | [diff] [blame] | 555 | { |
| 556 | u32 reg; |
| 557 | struct resource *res; |
| 558 | const u32 default_decode_base = IO_APIC_ADDR; |
| 559 | |
| 560 | /* |
| 561 | * Just report all resources from IO-APIC base to 4GiB. Don't mark |
| 562 | * them reserved as that may upset the OS if this range is marked |
| 563 | * as reserved in the e820. |
| 564 | */ |
| 565 | res = new_resource(dev, OIC); |
| 566 | res->base = default_decode_base; |
| 567 | res->size = 0 - default_decode_base; |
| 568 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 569 | |
| 570 | /* RCBA */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 571 | if ((uintptr_t)DEFAULT_RCBA < default_decode_base) { |
Aaron Durbin | 6f561af | 2012-12-19 14:38:01 -0600 | [diff] [blame] | 572 | res = new_resource(dev, RCBA); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 573 | res->base = (resource_t)(uintptr_t)DEFAULT_RCBA; |
Aaron Durbin | 6f561af | 2012-12-19 14:38:01 -0600 | [diff] [blame] | 574 | res->size = 16 * 1024; |
| 575 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | |
Angel Pons | 2aaf7c0 | 2020-09-24 18:03:18 +0200 | [diff] [blame] | 576 | IORESOURCE_FIXED | IORESOURCE_RESERVE; |
Aaron Durbin | 6f561af | 2012-12-19 14:38:01 -0600 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | /* Check LPC Memory Decode register. */ |
| 580 | reg = pci_read_config32(dev, LGMR); |
| 581 | if (reg & 1) { |
| 582 | reg &= ~0xffff; |
| 583 | if (reg < default_decode_base) { |
| 584 | res = new_resource(dev, LGMR); |
| 585 | res->base = reg; |
| 586 | res->size = 16 * 1024; |
| 587 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | |
Angel Pons | 2aaf7c0 | 2020-09-24 18:03:18 +0200 | [diff] [blame] | 588 | IORESOURCE_FIXED | IORESOURCE_RESERVE; |
Aaron Durbin | 6f561af | 2012-12-19 14:38:01 -0600 | [diff] [blame] | 589 | } |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | /* Default IO range claimed by the LPC device. The upper bound is exclusive. */ |
| 594 | #define LPC_DEFAULT_IO_RANGE_LOWER 0 |
| 595 | #define LPC_DEFAULT_IO_RANGE_UPPER 0x1000 |
| 596 | |
Julius Werner | 7c712bb | 2019-05-01 16:51:20 -0700 | [diff] [blame] | 597 | static inline int pch_io_range_in_default(int base, int size) |
Aaron Durbin | 6f561af | 2012-12-19 14:38:01 -0600 | [diff] [blame] | 598 | { |
| 599 | /* Does it start above the range? */ |
| 600 | if (base >= LPC_DEFAULT_IO_RANGE_UPPER) |
| 601 | return 0; |
| 602 | |
| 603 | /* Is it entirely contained? */ |
| 604 | if (base >= LPC_DEFAULT_IO_RANGE_LOWER && |
| 605 | (base + size) < LPC_DEFAULT_IO_RANGE_UPPER) |
| 606 | return 1; |
| 607 | |
| 608 | /* This will return not in range for partial overlaps. */ |
| 609 | return 0; |
| 610 | } |
| 611 | |
| 612 | /* |
| 613 | * Note: this function assumes there is no overlap with the default LPC device's |
| 614 | * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER. |
| 615 | */ |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame] | 616 | static void pch_lpc_add_io_resource(struct device *dev, u16 base, u16 size, |
| 617 | int index) |
Aaron Durbin | 6f561af | 2012-12-19 14:38:01 -0600 | [diff] [blame] | 618 | { |
| 619 | struct resource *res; |
| 620 | |
| 621 | if (pch_io_range_in_default(base, size)) |
| 622 | return; |
| 623 | |
| 624 | res = new_resource(dev, index); |
| 625 | res->base = base; |
| 626 | res->size = size; |
| 627 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 628 | } |
| 629 | |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame] | 630 | static void pch_lpc_add_gen_io_resources(struct device *dev, int reg_value, |
| 631 | int index) |
Aaron Durbin | 6f561af | 2012-12-19 14:38:01 -0600 | [diff] [blame] | 632 | { |
| 633 | /* |
| 634 | * Check if the register is enabled. If so and the base exceeds the |
Kyösti Mälkki | b544c00 | 2019-01-06 10:41:41 +0200 | [diff] [blame] | 635 | * device's default, claim range and add the resource. |
Aaron Durbin | 6f561af | 2012-12-19 14:38:01 -0600 | [diff] [blame] | 636 | */ |
| 637 | if (reg_value & 1) { |
| 638 | u16 base = reg_value & 0xfffc; |
| 639 | u16 size = (0x3 | ((reg_value >> 16) & 0xfc)) + 1; |
| 640 | pch_lpc_add_io_resource(dev, base, size, index); |
| 641 | } |
| 642 | } |
| 643 | |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame] | 644 | static void pch_lpc_add_io_resources(struct device *dev) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 645 | { |
| 646 | struct resource *res; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 647 | |
Aaron Durbin | 6f561af | 2012-12-19 14:38:01 -0600 | [diff] [blame] | 648 | /* Add the default claimed IO range for the LPC device. */ |
| 649 | res = new_resource(dev, 0); |
| 650 | res->base = LPC_DEFAULT_IO_RANGE_LOWER; |
| 651 | res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER; |
| 652 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 653 | |
| 654 | /* GPIOBASE */ |
Angel Pons | 2aaf7c0 | 2020-09-24 18:03:18 +0200 | [diff] [blame] | 655 | pch_lpc_add_io_resource(dev, get_gpiobase(), DEFAULT_GPIOSIZE, GPIO_BASE); |
Aaron Durbin | 6f561af | 2012-12-19 14:38:01 -0600 | [diff] [blame] | 656 | |
| 657 | /* PMBASE */ |
Duncan Laurie | 7922b46 | 2013-03-08 16:34:33 -0800 | [diff] [blame] | 658 | pch_lpc_add_io_resource(dev, get_pmbase(), 256, PMBASE); |
Aaron Durbin | 6f561af | 2012-12-19 14:38:01 -0600 | [diff] [blame] | 659 | |
| 660 | /* LPC Generic IO Decode range. */ |
Angel Pons | cbcbb67 | 2020-10-23 00:11:26 +0200 | [diff] [blame] | 661 | if (dev->chip_info) { |
| 662 | config_t *config = dev->chip_info; |
| 663 | pch_lpc_add_gen_io_resources(dev, config->gen1_dec, LPC_GEN1_DEC); |
| 664 | pch_lpc_add_gen_io_resources(dev, config->gen2_dec, LPC_GEN2_DEC); |
| 665 | pch_lpc_add_gen_io_resources(dev, config->gen3_dec, LPC_GEN3_DEC); |
| 666 | pch_lpc_add_gen_io_resources(dev, config->gen4_dec, LPC_GEN4_DEC); |
| 667 | } |
Aaron Durbin | 6f561af | 2012-12-19 14:38:01 -0600 | [diff] [blame] | 668 | } |
| 669 | |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame] | 670 | static void pch_lpc_read_resources(struct device *dev) |
Aaron Durbin | 6f561af | 2012-12-19 14:38:01 -0600 | [diff] [blame] | 671 | { |
Kyösti Mälkki | 0c1dd9c | 2020-06-17 23:37:49 +0300 | [diff] [blame] | 672 | struct global_nvs *gnvs; |
Duncan Laurie | 9c07c8f | 2013-03-22 11:08:39 -0700 | [diff] [blame] | 673 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 674 | /* Get the normal PCI resources of this device. */ |
| 675 | pci_dev_read_resources(dev); |
| 676 | |
Aaron Durbin | 6f561af | 2012-12-19 14:38:01 -0600 | [diff] [blame] | 677 | /* Add non-standard MMIO resources. */ |
| 678 | pch_lpc_add_mmio_resources(dev); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 679 | |
Aaron Durbin | 6f561af | 2012-12-19 14:38:01 -0600 | [diff] [blame] | 680 | /* Add IO resources. */ |
| 681 | pch_lpc_add_io_resources(dev); |
Duncan Laurie | 9c07c8f | 2013-03-22 11:08:39 -0700 | [diff] [blame] | 682 | |
| 683 | /* Allocate ACPI NVS in CBMEM */ |
Kyösti Mälkki | 0c1dd9c | 2020-06-17 23:37:49 +0300 | [diff] [blame] | 684 | gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(struct global_nvs)); |
Kyösti Mälkki | c3ed886 | 2014-06-19 19:50:51 +0300 | [diff] [blame] | 685 | if (!acpi_is_wakeup_s3() && gnvs) |
Kyösti Mälkki | 0c1dd9c | 2020-06-17 23:37:49 +0300 | [diff] [blame] | 686 | memset(gnvs, 0, sizeof(struct global_nvs)); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 687 | } |
| 688 | |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame] | 689 | static void pch_lpc_enable(struct device *dev) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 690 | { |
| 691 | /* Enable PCH Display Port */ |
| 692 | RCBA16(DISPBDF) = 0x0010; |
| 693 | RCBA32_OR(FD2, PCH_ENABLE_DBDF); |
| 694 | |
| 695 | pch_enable(dev); |
| 696 | } |
| 697 | |
Kyösti Mälkki | 0c1dd9c | 2020-06-17 23:37:49 +0300 | [diff] [blame] | 698 | void southbridge_inject_dsdt(const struct device *dev) |
Vladimir Serbinenko | c6e566a | 2014-08-31 17:43:51 +0200 | [diff] [blame] | 699 | { |
Kyösti Mälkki | 0c1dd9c | 2020-06-17 23:37:49 +0300 | [diff] [blame] | 700 | struct global_nvs *gnvs; |
Vladimir Serbinenko | 7309c64 | 2014-10-05 11:07:33 +0200 | [diff] [blame] | 701 | |
| 702 | gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 703 | if (!gnvs) { |
Elyes HAOUAS | 035df00 | 2016-10-03 21:54:16 +0200 | [diff] [blame] | 704 | gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(*gnvs)); |
Vladimir Serbinenko | 7309c64 | 2014-10-05 11:07:33 +0200 | [diff] [blame] | 705 | if (gnvs) |
| 706 | memset(gnvs, 0, sizeof(*gnvs)); |
| 707 | } |
Vladimir Serbinenko | c6e566a | 2014-08-31 17:43:51 +0200 | [diff] [blame] | 708 | |
| 709 | if (gnvs) { |
Vladimir Serbinenko | c6e566a | 2014-08-31 17:43:51 +0200 | [diff] [blame] | 710 | acpi_create_gnvs(gnvs); |
Vladimir Serbinenko | 1b409fd | 2014-10-12 00:26:21 +0200 | [diff] [blame] | 711 | |
| 712 | gnvs->apic = 1; |
| 713 | gnvs->mpen = 1; /* Enable Multi Processing */ |
| 714 | gnvs->pcnt = dev_count_cpu(); |
| 715 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 716 | #if CONFIG(CHROMEOS) |
Joel Kitching | 6fbd874 | 2018-08-23 14:56:25 +0800 | [diff] [blame] | 717 | chromeos_init_chromeos_acpi(&(gnvs->chromeos)); |
Vladimir Serbinenko | 1b409fd | 2014-10-12 00:26:21 +0200 | [diff] [blame] | 718 | #endif |
| 719 | |
| 720 | /* Update the mem console pointer. */ |
| 721 | gnvs->cbmc = (u32)cbmem_find(CBMEM_ID_CONSOLE); |
| 722 | |
Vladimir Serbinenko | c6e566a | 2014-08-31 17:43:51 +0200 | [diff] [blame] | 723 | /* And tell SMI about it */ |
Kyösti Mälkki | c3c5521 | 2020-06-17 10:34:26 +0300 | [diff] [blame] | 724 | apm_control(APM_CNT_GNVS_UPDATE); |
Vladimir Serbinenko | c6e566a | 2014-08-31 17:43:51 +0200 | [diff] [blame] | 725 | |
Vladimir Serbinenko | 334fd8e | 2014-10-05 11:10:35 +0200 | [diff] [blame] | 726 | /* Add it to DSDT. */ |
Vladimir Serbinenko | be0fd0a | 2014-11-04 21:10:59 +0100 | [diff] [blame] | 727 | acpigen_write_scope("\\"); |
Angel Pons | 8cb8374 | 2020-10-17 18:28:29 +0200 | [diff] [blame] | 728 | acpigen_write_name_dword("NVSA", (u32)gnvs); |
Vladimir Serbinenko | be0fd0a | 2014-11-04 21:10:59 +0100 | [diff] [blame] | 729 | acpigen_pop_len(); |
Vladimir Serbinenko | c6e566a | 2014-08-31 17:43:51 +0200 | [diff] [blame] | 730 | } |
Vladimir Serbinenko | c6e566a | 2014-08-31 17:43:51 +0200 | [diff] [blame] | 731 | } |
| 732 | |
Tristan Corrick | f3127d4 | 2018-10-31 02:25:54 +1300 | [diff] [blame] | 733 | static const char *lpc_acpi_name(const struct device *dev) |
| 734 | { |
| 735 | return "LPCB"; |
| 736 | } |
| 737 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 738 | static void southbridge_fill_ssdt(const struct device *dev) |
Tristan Corrick | f3127d4 | 2018-10-31 02:25:54 +1300 | [diff] [blame] | 739 | { |
| 740 | intel_acpi_gen_def_acpi_pirq(dev); |
| 741 | } |
| 742 | |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 743 | static unsigned long southbridge_write_acpi_tables(const struct device *device, |
Alexander Couzens | 83fc32f | 2015-04-12 22:28:37 +0200 | [diff] [blame] | 744 | unsigned long start, |
| 745 | struct acpi_rsdp *rsdp) |
Vladimir Serbinenko | c6e566a | 2014-08-31 17:43:51 +0200 | [diff] [blame] | 746 | { |
| 747 | unsigned long current; |
Vladimir Serbinenko | c6e566a | 2014-08-31 17:43:51 +0200 | [diff] [blame] | 748 | acpi_header_t *ssdt; |
| 749 | |
| 750 | current = start; |
| 751 | |
| 752 | /* Align ACPI tables to 16byte */ |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 753 | current = acpi_align_current(current); |
Vladimir Serbinenko | c6e566a | 2014-08-31 17:43:51 +0200 | [diff] [blame] | 754 | |
| 755 | /* |
| 756 | * We explicitly add these tables later on: |
| 757 | */ |
Angel Pons | 2d35cf8 | 2020-10-29 19:28:44 +0100 | [diff] [blame] | 758 | current = acpi_write_hpet(device, current, rsdp); |
Vladimir Serbinenko | c6e566a | 2014-08-31 17:43:51 +0200 | [diff] [blame] | 759 | |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 760 | current = acpi_align_current(current); |
Vladimir Serbinenko | c6e566a | 2014-08-31 17:43:51 +0200 | [diff] [blame] | 761 | |
| 762 | printk(BIOS_DEBUG, "ACPI: * SSDT2\n"); |
| 763 | ssdt = (acpi_header_t *)current; |
| 764 | acpi_create_serialio_ssdt(ssdt); |
| 765 | current += ssdt->length; |
| 766 | acpi_add_table(rsdp, ssdt); |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 767 | current = acpi_align_current(current); |
Vladimir Serbinenko | c6e566a | 2014-08-31 17:43:51 +0200 | [diff] [blame] | 768 | |
| 769 | printk(BIOS_DEBUG, "current = %lx\n", current); |
| 770 | return current; |
| 771 | } |
| 772 | |
Tristan Corrick | 32ceed8 | 2018-11-30 22:53:27 +1300 | [diff] [blame] | 773 | static void lpc_final(struct device *dev) |
| 774 | { |
Arthur Heymans | a3121b0 | 2019-05-28 13:46:49 +0200 | [diff] [blame] | 775 | spi_finalize_ops(); |
Tristan Corrick | 63626b1 | 2018-11-30 22:53:50 +1300 | [diff] [blame] | 776 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 777 | if (acpi_is_wakeup_s3() || CONFIG(INTEL_CHIPSET_LOCKDOWN)) |
Kyösti Mälkki | b658548 | 2020-06-01 15:11:14 +0300 | [diff] [blame] | 778 | apm_control(APM_CNT_FINALIZE); |
Tristan Corrick | 32ceed8 | 2018-11-30 22:53:27 +1300 | [diff] [blame] | 779 | } |
Vladimir Serbinenko | c6e566a | 2014-08-31 17:43:51 +0200 | [diff] [blame] | 780 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 781 | static struct device_operations device_ops = { |
| 782 | .read_resources = pch_lpc_read_resources, |
| 783 | .set_resources = pci_dev_set_resources, |
Duncan Laurie | 8d783b8 | 2013-05-14 11:16:34 -0700 | [diff] [blame] | 784 | .enable_resources = pci_dev_enable_resources, |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 785 | .acpi_fill_ssdt = southbridge_fill_ssdt, |
| 786 | .acpi_inject_dsdt = southbridge_inject_dsdt, |
Tristan Corrick | f3127d4 | 2018-10-31 02:25:54 +1300 | [diff] [blame] | 787 | .acpi_name = lpc_acpi_name, |
Vladimir Serbinenko | c6e566a | 2014-08-31 17:43:51 +0200 | [diff] [blame] | 788 | .write_acpi_tables = southbridge_write_acpi_tables, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 789 | .init = lpc_init, |
Tristan Corrick | 32ceed8 | 2018-11-30 22:53:27 +1300 | [diff] [blame] | 790 | .final = lpc_final, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 791 | .enable = pch_lpc_enable, |
Nico Huber | 51b75ae | 2019-03-14 16:02:05 +0100 | [diff] [blame] | 792 | .scan_bus = scan_static_bus, |
Angel Pons | 1fc0edd | 2020-05-31 00:03:28 +0200 | [diff] [blame] | 793 | .ops_pci = &pci_dev_ops_pci, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 794 | }; |
| 795 | |
Aaron Durbin | c1989c4 | 2012-12-11 17:13:17 -0600 | [diff] [blame] | 796 | /* IDs for LPC device of Intel 8 Series Chipset (Lynx Point) */ |
| 797 | static const unsigned short pci_device_ids[] = { |
| 798 | 0x8c41, /* Mobile Full Featured Engineering Sample. */ |
| 799 | 0x8c42, /* Desktop Full Featured Engineering Sample. */ |
| 800 | 0x8c44, /* Z87 SKU */ |
| 801 | 0x8c46, /* Z85 SKU */ |
| 802 | 0x8c49, /* HM86 SKU */ |
| 803 | 0x8c4a, /* H87 SKU */ |
| 804 | 0x8c4b, /* HM87 SKU */ |
| 805 | 0x8c4c, /* Q85 SKU */ |
| 806 | 0x8c4e, /* Q87 SKU */ |
| 807 | 0x8c4f, /* QM87 SKU */ |
Tristan Corrick | 9a08574 | 2018-10-31 02:20:28 +1300 | [diff] [blame] | 808 | 0x8c50, /* B85 SKU */ |
| 809 | 0x8c52, /* C222 SKU */ |
| 810 | 0x8c54, /* C224 SKU */ |
| 811 | 0x8c56, /* C226 SKU */ |
| 812 | 0x8c5c, /* H81 SKU */ |
Duncan Laurie | 74c0d05 | 2012-12-17 11:31:40 -0800 | [diff] [blame] | 813 | 0x9c41, /* LP Full Featured Engineering Sample */ |
| 814 | 0x9c43, /* LP Premium SKU */ |
| 815 | 0x9c45, /* LP Mainstream SKU */ |
| 816 | 0x9c47, /* LP Value SKU */ |
Aaron Durbin | c1989c4 | 2012-12-11 17:13:17 -0600 | [diff] [blame] | 817 | 0 }; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 818 | |
| 819 | static const struct pci_driver pch_lpc __pci_driver = { |
| 820 | .ops = &device_ops, |
| 821 | .vendor = PCI_VENDOR_ID_INTEL, |
| 822 | .devices = pci_device_ids, |
| 823 | }; |