Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 2 | |
| 3 | #include <console/console.h> |
| 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> |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 8 | #include <pc80/mc146818rtc.h> |
| 9 | #include <pc80/isa-dma.h> |
Stefan Reinauer | 54309d6 | 2009-01-20 22:53:10 +0000 | [diff] [blame] | 10 | #include <pc80/i8259.h> |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 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> |
Uwe Hermann | 74d1a6e | 2010-10-12 17:34:08 +0000 | [diff] [blame] | 13 | #include <arch/ioapic.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 14 | #include <acpi/acpi.h> |
Sven Schnelle | f4dc1a7 | 2011-06-05 11:33:41 +0200 | [diff] [blame] | 15 | #include <cpu/x86/smm.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 16 | #include <acpi/acpigen.h> |
Vladimir Serbinenko | d5d94ea | 2014-10-18 02:13:11 +0200 | [diff] [blame] | 17 | #include <arch/smp/mpspec.h> |
Vladimir Serbinenko | 0e64617 | 2014-08-31 00:27:05 +0200 | [diff] [blame] | 18 | #include <cbmem.h> |
| 19 | #include <string.h> |
Arthur Heymans | a8a9f34 | 2017-12-24 08:11:13 +0100 | [diff] [blame] | 20 | #include <southbridge/intel/common/acpi_pirq_gen.h> |
Elyes HAOUAS | 7118701 | 2019-02-10 14:58:13 +0100 | [diff] [blame] | 21 | #include <southbridge/intel/common/pmbase.h> |
Arthur Heymans | b429c5b | 2019-05-28 13:24:15 +0200 | [diff] [blame] | 22 | #include <southbridge/intel/common/spi.h> |
Elyes HAOUAS | 7118701 | 2019-02-10 14:58:13 +0100 | [diff] [blame] | 23 | |
Arthur Heymans | 742df5a | 2019-06-03 16:24:41 +0200 | [diff] [blame] | 24 | #include "chip.h" |
Elyes HAOUAS | 7118701 | 2019-02-10 14:58:13 +0100 | [diff] [blame] | 25 | #include "i82801gx.h" |
Vladimir Serbinenko | 0e64617 | 2014-08-31 00:27:05 +0200 | [diff] [blame] | 26 | #include "nvs.h" |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 27 | |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 28 | #define NMI_OFF 0 |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 29 | |
Stefan Reinauer | 54309d6 | 2009-01-20 22:53:10 +0000 | [diff] [blame] | 30 | typedef struct southbridge_intel_i82801gx_config config_t; |
| 31 | |
Paul Menzel | ddddf15 | 2013-04-23 14:40:23 +0200 | [diff] [blame] | 32 | /** |
Martin Roth | 2ed0aa2 | 2016-01-05 20:58:58 -0700 | [diff] [blame] | 33 | * Set miscellaneous static southbridge features. |
Paul Menzel | ddddf15 | 2013-04-23 14:40:23 +0200 | [diff] [blame] | 34 | * |
| 35 | * @param dev PCI device with I/O APIC control registers |
| 36 | */ |
| 37 | static void i82801gx_enable_ioapic(struct device *dev) |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 38 | { |
Paul Menzel | ddddf15 | 2013-04-23 14:40:23 +0200 | [diff] [blame] | 39 | /* Enable ACPI I/O range decode */ |
Kyösti Mälkki | 1cca340 | 2013-02-26 19:21:39 +0200 | [diff] [blame] | 40 | pci_write_config8(dev, ACPI_CNTL, ACPI_EN); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 41 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 42 | set_ioapic_id(VIO_APIC_VADDR, 0x02); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 43 | |
Paul Menzel | ddddf15 | 2013-04-23 14:40:23 +0200 | [diff] [blame] | 44 | /* |
| 45 | * Select Boot Configuration register (0x03) and |
| 46 | * use Processor System Bus (0x01) to deliver interrupts. |
| 47 | */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 48 | io_apic_write(VIO_APIC_VADDR, 0x03, 0x01); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | static void i82801gx_enable_serial_irqs(struct device *dev) |
| 52 | { |
| 53 | /* Set packet length and toggle silent mode bit for one frame. */ |
Elyes HAOUAS | 92646ea | 2020-04-04 13:43:03 +0200 | [diff] [blame] | 54 | pci_write_config8(dev, SERIRQ_CNTL, (1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0)); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 57 | /* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control |
| 58 | * 0x00 - 0000 = Reserved |
| 59 | * 0x01 - 0001 = Reserved |
| 60 | * 0x02 - 0010 = Reserved |
| 61 | * 0x03 - 0011 = IRQ3 |
| 62 | * 0x04 - 0100 = IRQ4 |
| 63 | * 0x05 - 0101 = IRQ5 |
| 64 | * 0x06 - 0110 = IRQ6 |
| 65 | * 0x07 - 0111 = IRQ7 |
| 66 | * 0x08 - 1000 = Reserved |
| 67 | * 0x09 - 1001 = IRQ9 |
| 68 | * 0x0A - 1010 = IRQ10 |
| 69 | * 0x0B - 1011 = IRQ11 |
| 70 | * 0x0C - 1100 = IRQ12 |
| 71 | * 0x0D - 1101 = Reserved |
| 72 | * 0x0E - 1110 = IRQ14 |
| 73 | * 0x0F - 1111 = IRQ15 |
| 74 | * PIRQ[n]_ROUT[7] - PIRQ Routing Control |
| 75 | * 0x80 - The PIRQ is not routed. |
| 76 | */ |
| 77 | |
Elyes HAOUAS | 9966703 | 2018-05-13 12:47:28 +0200 | [diff] [blame] | 78 | static void i82801gx_pirq_init(struct device *dev) |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 79 | { |
Elyes HAOUAS | 9966703 | 2018-05-13 12:47:28 +0200 | [diff] [blame] | 80 | struct device *irq_dev; |
Stefan Reinauer | 54309d6 | 2009-01-20 22:53:10 +0000 | [diff] [blame] | 81 | /* Get the chip configuration */ |
| 82 | config_t *config = dev->chip_info; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 83 | |
Stefan Reinauer | 54309d6 | 2009-01-20 22:53:10 +0000 | [diff] [blame] | 84 | pci_write_config8(dev, PIRQA_ROUT, config->pirqa_routing); |
| 85 | pci_write_config8(dev, PIRQB_ROUT, config->pirqb_routing); |
| 86 | pci_write_config8(dev, PIRQC_ROUT, config->pirqc_routing); |
| 87 | pci_write_config8(dev, PIRQD_ROUT, config->pirqd_routing); |
| 88 | |
| 89 | pci_write_config8(dev, PIRQE_ROUT, config->pirqe_routing); |
| 90 | pci_write_config8(dev, PIRQF_ROUT, config->pirqf_routing); |
| 91 | pci_write_config8(dev, PIRQG_ROUT, config->pirqg_routing); |
| 92 | pci_write_config8(dev, PIRQH_ROUT, config->pirqh_routing); |
| 93 | |
| 94 | /* Eric Biederman once said we should let the OS do this. |
| 95 | * I am not so sure anymore he was right. |
| 96 | */ |
| 97 | |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 98 | for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) { |
Arthur Heymans | 3f111b0 | 2017-03-09 12:02:52 +0100 | [diff] [blame] | 99 | u8 int_pin = 0, int_line = 0; |
Stefan Reinauer | 54309d6 | 2009-01-20 22:53:10 +0000 | [diff] [blame] | 100 | |
| 101 | if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI) |
| 102 | continue; |
| 103 | |
| 104 | int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN); |
| 105 | |
| 106 | switch (int_pin) { |
Arthur Heymans | 3f111b0 | 2017-03-09 12:02:52 +0100 | [diff] [blame] | 107 | case 1: |
| 108 | /* INTA# */ int_line = config->pirqa_routing; break; |
| 109 | case 2: |
| 110 | /* INTB# */ int_line = config->pirqb_routing; break; |
| 111 | case 3: |
| 112 | /* INTC# */ int_line = config->pirqc_routing; break; |
| 113 | case 4: |
| 114 | /* INTD# */ int_line = config->pirqd_routing; break; |
Stefan Reinauer | 54309d6 | 2009-01-20 22:53:10 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | if (!int_line) |
| 118 | continue; |
| 119 | |
| 120 | pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line); |
| 121 | } |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Elyes HAOUAS | 9966703 | 2018-05-13 12:47:28 +0200 | [diff] [blame] | 124 | static void i82801gx_gpi_routing(struct device *dev) |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 125 | { |
| 126 | /* Get the chip configuration */ |
| 127 | config_t *config = dev->chip_info; |
| 128 | u32 reg32 = 0; |
| 129 | |
Elyes HAOUAS | 92646ea | 2020-04-04 13:43:03 +0200 | [diff] [blame] | 130 | /* An array would be much nicer here, or some other method of doing this. */ |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 131 | reg32 |= (config->gpi0_routing & 0x03) << 0; |
| 132 | reg32 |= (config->gpi1_routing & 0x03) << 2; |
| 133 | reg32 |= (config->gpi2_routing & 0x03) << 4; |
| 134 | reg32 |= (config->gpi3_routing & 0x03) << 6; |
| 135 | reg32 |= (config->gpi4_routing & 0x03) << 8; |
| 136 | reg32 |= (config->gpi5_routing & 0x03) << 10; |
| 137 | reg32 |= (config->gpi6_routing & 0x03) << 12; |
| 138 | reg32 |= (config->gpi7_routing & 0x03) << 14; |
| 139 | reg32 |= (config->gpi8_routing & 0x03) << 16; |
| 140 | reg32 |= (config->gpi9_routing & 0x03) << 18; |
| 141 | reg32 |= (config->gpi10_routing & 0x03) << 20; |
| 142 | reg32 |= (config->gpi11_routing & 0x03) << 22; |
| 143 | reg32 |= (config->gpi12_routing & 0x03) << 24; |
| 144 | reg32 |= (config->gpi13_routing & 0x03) << 26; |
| 145 | reg32 |= (config->gpi14_routing & 0x03) << 28; |
| 146 | reg32 |= (config->gpi15_routing & 0x03) << 30; |
| 147 | |
Kyösti Mälkki | b85a87b | 2014-12-29 11:32:27 +0200 | [diff] [blame] | 148 | pci_write_config32(dev, GPIO_ROUT, reg32); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 149 | } |
| 150 | |
Elyes HAOUAS | 9966703 | 2018-05-13 12:47:28 +0200 | [diff] [blame] | 151 | static void i82801gx_power_options(struct device *dev) |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 152 | { |
| 153 | u8 reg8; |
Elyes HAOUAS | 7118701 | 2019-02-10 14:58:13 +0100 | [diff] [blame] | 154 | u16 reg16; |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 155 | u32 reg32; |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 156 | const char *state; |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 157 | /* Get the chip configuration */ |
| 158 | config_t *config = dev->chip_info; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 159 | |
Nico Huber | 9faae2b | 2018-11-14 00:00:35 +0100 | [diff] [blame] | 160 | int pwr_on = CONFIG_MAINBOARD_POWER_FAILURE_STATE; |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 161 | int nmi_option; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 162 | |
| 163 | /* Which state do we want to goto after g3 (power restored)? |
| 164 | * 0 == S0 Full On |
| 165 | * 1 == S5 Soft Off |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 166 | * |
| 167 | * If the option is not existent (Laptops), use MAINBOARD_POWER_ON. |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 168 | */ |
Varad Gautam | 06ef046 | 2015-03-11 09:54:41 +0530 | [diff] [blame] | 169 | pwr_on = MAINBOARD_POWER_ON; |
| 170 | get_option(&pwr_on, "power_on_after_fail"); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 171 | |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 172 | reg8 = pci_read_config8(dev, GEN_PMCON_3); |
| 173 | reg8 &= 0xfe; |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 174 | switch (pwr_on) { |
| 175 | case MAINBOARD_POWER_OFF: |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 176 | reg8 |= 1; |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 177 | state = "off"; |
| 178 | break; |
| 179 | case MAINBOARD_POWER_ON: |
| 180 | reg8 &= ~1; |
| 181 | state = "on"; |
| 182 | break; |
| 183 | case MAINBOARD_POWER_KEEP: |
| 184 | reg8 &= ~1; |
| 185 | state = "state keep"; |
| 186 | break; |
| 187 | default: |
| 188 | state = "undefined"; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 189 | } |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 190 | |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 191 | reg8 |= (3 << 4); /* avoid #S4 assertions */ |
Martin Roth | 2ed0aa2 | 2016-01-05 20:58:58 -0700 | [diff] [blame] | 192 | reg8 &= ~(1 << 3); /* minimum assertion is 1 to 2 RTCCLK */ |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 193 | |
| 194 | pci_write_config8(dev, GEN_PMCON_3, reg8); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 195 | printk(BIOS_INFO, "Set power %s after power failure.\n", state); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 196 | |
| 197 | /* Set up NMI on errors. */ |
| 198 | reg8 = inb(0x61); |
| 199 | reg8 &= 0x0f; /* Higher Nibble must be 0 */ |
| 200 | reg8 &= ~(1 << 3); /* IOCHK# NMI Enable */ |
| 201 | // reg8 &= ~(1 << 2); /* PCI SERR# Enable */ |
| 202 | reg8 |= (1 << 2); /* PCI SERR# Disable for now */ |
| 203 | outb(reg8, 0x61); |
| 204 | |
| 205 | reg8 = inb(0x70); |
| 206 | nmi_option = NMI_OFF; |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 207 | get_option(&nmi_option, "nmi"); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 208 | if (nmi_option) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 209 | printk(BIOS_INFO, "NMI sources enabled.\n"); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 210 | reg8 &= ~(1 << 7); /* Set NMI. */ |
| 211 | } else { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 212 | printk(BIOS_INFO, "NMI sources disabled.\n"); |
Arthur Heymans | 3f111b0 | 2017-03-09 12:02:52 +0100 | [diff] [blame] | 213 | reg8 |= (1 << 7); /* Can't mask NMI from PCI-E and NMI_NOW */ |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 214 | } |
| 215 | outb(reg8, 0x70); |
| 216 | |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 217 | /* Enable CPU_SLP# and Intel Speedstep, set SMI# rate down */ |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 218 | reg16 = pci_read_config16(dev, GEN_PMCON_1); |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 219 | reg16 &= ~(3 << 0); // SMI# rate 1 minute |
| 220 | reg16 |= (1 << 2); // CLKRUN_EN - Mobile/Ultra only |
| 221 | reg16 |= (1 << 3); // Speedstep Enable - Mobile/Ultra only |
| 222 | reg16 |= (1 << 5); // CPUSLP_EN Desktop only |
Sven Schnelle | 906f9ae | 2011-10-23 16:35:01 +0200 | [diff] [blame] | 223 | |
| 224 | if (config->c4onc3_enable) |
| 225 | reg16 |= (1 << 7); |
| 226 | |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 227 | // another laptop wants this? |
| 228 | // reg16 &= ~(1 << 10); // BIOS_PCI_EXP_EN - Desktop/Mobile only |
| 229 | reg16 |= (1 << 10); // BIOS_PCI_EXP_EN - Desktop/Mobile only |
Kyösti Mälkki | 9446447 | 2020-06-13 13:45:42 +0300 | [diff] [blame] | 230 | if (CONFIG(DEBUG_PERIODIC_SMI)) |
| 231 | reg16 |= (3 << 0); // Periodic SMI every 8s |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 232 | pci_write_config16(dev, GEN_PMCON_1, reg16); |
| 233 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 234 | // Set the board's GPI routing. |
| 235 | i82801gx_gpi_routing(dev); |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 236 | |
Elyes HAOUAS | 7118701 | 2019-02-10 14:58:13 +0100 | [diff] [blame] | 237 | write_pmbase32(GPE0_EN, config->gpe0_en); |
| 238 | write_pmbase16(ALT_GP_SMI_EN, config->alt_gp_smi_en); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 239 | |
| 240 | /* Set up power management block and determine sleep mode */ |
Elyes HAOUAS | 7118701 | 2019-02-10 14:58:13 +0100 | [diff] [blame] | 241 | reg32 = read_pmbase32(PM1_CNT); |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 242 | |
| 243 | reg32 &= ~(7 << 10); // SLP_TYP |
| 244 | reg32 |= (1 << 1); // enable C3->C0 transition on bus master |
| 245 | reg32 |= (1 << 0); // SCI_EN |
Elyes HAOUAS | 7118701 | 2019-02-10 14:58:13 +0100 | [diff] [blame] | 246 | write_pmbase32(PM1_CNT, reg32); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 247 | } |
| 248 | |
Elyes HAOUAS | 9966703 | 2018-05-13 12:47:28 +0200 | [diff] [blame] | 249 | static void i82801gx_configure_cstates(struct device *dev) |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 250 | { |
| 251 | u8 reg8; |
Stefan Reinauer | 109ab31 | 2009-08-12 16:08:05 +0000 | [diff] [blame] | 252 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 253 | reg8 = pci_read_config8(dev, 0xa9); // Cx state configuration |
| 254 | reg8 |= (1 << 4) | (1 << 3) | (1 << 2); // Enable Popup & Popdown |
| 255 | pci_write_config8(dev, 0xa9, reg8); |
| 256 | |
| 257 | // Set Deeper Sleep configuration to recommended values |
| 258 | reg8 = pci_read_config8(dev, 0xaa); |
| 259 | reg8 &= 0xf0; |
| 260 | reg8 |= (2 << 2); // Deeper Sleep to Stop CPU: 34-40us |
| 261 | reg8 |= (2 << 0); // Deeper Sleep to Sleep: 15us |
| 262 | pci_write_config8(dev, 0xaa, reg8); |
| 263 | } |
| 264 | |
| 265 | static void i82801gx_rtc_init(struct device *dev) |
| 266 | { |
| 267 | u8 reg8; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 268 | int rtc_failed; |
| 269 | |
| 270 | reg8 = pci_read_config8(dev, GEN_PMCON_3); |
| 271 | rtc_failed = reg8 & RTC_BATTERY_DEAD; |
| 272 | if (rtc_failed) { |
| 273 | reg8 &= ~RTC_BATTERY_DEAD; |
| 274 | pci_write_config8(dev, GEN_PMCON_3, reg8); |
| 275 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 276 | printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 277 | |
Gabe Black | b3f08c6 | 2014-04-30 17:12:25 -0700 | [diff] [blame] | 278 | cmos_init(rtc_failed); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 279 | } |
| 280 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 281 | static void enable_hpet(void) |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 282 | { |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 283 | u32 reg32; |
Stefan Reinauer | 109ab31 | 2009-08-12 16:08:05 +0000 | [diff] [blame] | 284 | |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 285 | /* Move HPET to default address 0xfed00000 and enable it */ |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 286 | reg32 = RCBA32(HPTC); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 287 | reg32 |= (1 << 7); // HPET Address Enable |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 288 | reg32 &= ~(3 << 0); |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 289 | RCBA32(HPTC) = reg32; |
Arthur Heymans | c73c923 | 2019-10-02 14:57:50 +0200 | [diff] [blame] | 290 | /* On NM10 this only works if read back */ |
| 291 | RCBA32(HPTC); |
| 292 | |
| 293 | write32((u32 *)0xfed00010, read32((u32 *)0xfed00010) | 1); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 294 | } |
| 295 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 296 | static void enable_clock_gating(void) |
| 297 | { |
| 298 | u32 reg32; |
Stefan Reinauer | 109ab31 | 2009-08-12 16:08:05 +0000 | [diff] [blame] | 299 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 300 | /* Enable Clock Gating for most devices */ |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 301 | reg32 = RCBA32(CG); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 302 | reg32 |= (1 << 31); // LPC clock gating |
| 303 | reg32 |= (1 << 30); // PATA clock gating |
| 304 | // SATA clock gating |
| 305 | reg32 |= (1 << 27) | (1 << 26) | (1 << 25) | (1 << 24); |
| 306 | reg32 |= (1 << 23); // AC97 clock gating |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 307 | reg32 |= (1 << 19); // USB EHCI clock gating |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 308 | reg32 |= (1 << 3) | (1 << 1); // DMI clock gating |
| 309 | reg32 |= (1 << 2); // PCIe clock gating; |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 310 | reg32 &= ~(1 << 20); // No static clock gating for USB |
Arthur Heymans | 3f111b0 | 2017-03-09 12:02:52 +0100 | [diff] [blame] | 311 | reg32 &= ~((1 << 29) | (1 << 28)); // Disable UHCI clock gating |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 312 | RCBA32(CG) = reg32; |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 313 | } |
Stefan Reinauer | 269563a | 2009-01-19 21:20:22 +0000 | [diff] [blame] | 314 | |
Kyösti Mälkki | 83d6a8a | 2019-07-12 08:16:53 +0300 | [diff] [blame] | 315 | static void i82801gx_set_acpi_mode(struct device *dev) |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 316 | { |
Kyösti Mälkki | 44da9e7 | 2019-10-09 12:32:16 +0300 | [diff] [blame] | 317 | if (CONFIG(HAVE_SMI_HANDLER)) { |
| 318 | if (!acpi_is_wakeup_s3()) { |
Kyösti Mälkki | b658548 | 2020-06-01 15:11:14 +0300 | [diff] [blame^] | 319 | apm_control(APM_CNT_ACPI_DISABLE); |
Kyösti Mälkki | 44da9e7 | 2019-10-09 12:32:16 +0300 | [diff] [blame] | 320 | } else { |
Kyösti Mälkki | b658548 | 2020-06-01 15:11:14 +0300 | [diff] [blame^] | 321 | apm_control(APM_CNT_ACPI_ENABLE); |
Kyösti Mälkki | 44da9e7 | 2019-10-09 12:32:16 +0300 | [diff] [blame] | 322 | } |
Sven Schnelle | e261807 | 2011-06-05 11:39:12 +0200 | [diff] [blame] | 323 | } |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 324 | } |
| 325 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 326 | #define SPIBASE 0x3020 |
| 327 | static void i82801gx_spi_init(void) |
| 328 | { |
| 329 | u16 spicontrol; |
| 330 | |
| 331 | spicontrol = RCBA16(SPIBASE + 2); |
| 332 | spicontrol &= ~(1 << 0); // SPI Access Request |
| 333 | RCBA16(SPIBASE + 2) = spicontrol; |
| 334 | } |
| 335 | |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 336 | static void i82801gx_fixups(struct device *dev) |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 337 | { |
| 338 | /* This needs to happen after PCI enumeration */ |
| 339 | RCBA32(0x1d40) |= 1; |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 340 | |
| 341 | /* USB Transient Disconnect Detect: |
| 342 | * Prevent a SE0 condition on the USB ports from being |
| 343 | * interpreted by the UHCI controller as a disconnect |
| 344 | */ |
| 345 | pci_write_config8(dev, 0xad, 0x3); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 346 | } |
| 347 | |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 348 | static void lpc_init(struct device *dev) |
| 349 | { |
Elyes HAOUAS | bfc255a | 2020-03-07 13:05:14 +0100 | [diff] [blame] | 350 | printk(BIOS_DEBUG, "i82801gx: %s\n", __func__); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 351 | |
| 352 | /* Set the value for PCI command register. */ |
| 353 | pci_write_config16(dev, PCI_COMMAND, 0x000f); |
| 354 | |
| 355 | /* IO APIC initialization. */ |
Paul Menzel | ddddf15 | 2013-04-23 14:40:23 +0200 | [diff] [blame] | 356 | i82801gx_enable_ioapic(dev); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 357 | |
| 358 | i82801gx_enable_serial_irqs(dev); |
| 359 | |
| 360 | /* Setup the PIRQ. */ |
| 361 | i82801gx_pirq_init(dev); |
| 362 | |
| 363 | /* Setup power options. */ |
| 364 | i82801gx_power_options(dev); |
| 365 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 366 | /* Configure Cx state registers */ |
| 367 | i82801gx_configure_cstates(dev); |
| 368 | |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 369 | /* Set the state of the GPIO lines. */ |
| 370 | //gpio_init(dev); |
| 371 | |
| 372 | /* Initialize the real time clock. */ |
| 373 | i82801gx_rtc_init(dev); |
| 374 | |
| 375 | /* Initialize ISA DMA. */ |
| 376 | isa_dma_init(); |
| 377 | |
| 378 | /* Initialize the High Precision Event Timers, if present. */ |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 379 | enable_hpet(); |
| 380 | |
| 381 | /* Initialize Clock Gating */ |
| 382 | enable_clock_gating(); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 383 | |
| 384 | setup_i8259(); |
| 385 | |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 386 | /* The OS should do this? */ |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 387 | /* Interrupt 9 should be level triggered (SCI) */ |
| 388 | i8259_configure_irq_trigger(9, 1); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 389 | |
Kyösti Mälkki | 44da9e7 | 2019-10-09 12:32:16 +0300 | [diff] [blame] | 390 | i82801gx_set_acpi_mode(dev); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 391 | |
| 392 | i82801gx_spi_init(); |
| 393 | |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 394 | i82801gx_fixups(dev); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 395 | } |
| 396 | |
Vladimir Serbinenko | d5d94ea | 2014-10-18 02:13:11 +0200 | [diff] [blame] | 397 | unsigned long acpi_fill_madt(unsigned long current) |
| 398 | { |
| 399 | /* Local APICs */ |
| 400 | current = acpi_create_madt_lapics(current); |
| 401 | |
| 402 | /* IOAPIC */ |
Elyes HAOUAS | 92646ea | 2020-04-04 13:43:03 +0200 | [diff] [blame] | 403 | current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, 2, IO_APIC_ADDR, 0); |
Vladimir Serbinenko | d5d94ea | 2014-10-18 02:13:11 +0200 | [diff] [blame] | 404 | |
| 405 | /* LAPIC_NMI */ |
| 406 | current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *) |
| 407 | current, 0, |
| 408 | MP_IRQ_POLARITY_HIGH | |
| 409 | MP_IRQ_TRIGGER_EDGE, 0x01); |
| 410 | current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *) |
| 411 | current, 1, MP_IRQ_POLARITY_HIGH | |
| 412 | MP_IRQ_TRIGGER_EDGE, 0x01); |
| 413 | |
| 414 | /* INT_SRC_OVR */ |
| 415 | current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) |
| 416 | current, 0, 0, 2, MP_IRQ_POLARITY_HIGH | MP_IRQ_TRIGGER_EDGE); |
| 417 | current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) |
| 418 | current, 0, 9, 9, MP_IRQ_POLARITY_HIGH | MP_IRQ_TRIGGER_LEVEL); |
| 419 | |
| 420 | |
| 421 | return current; |
| 422 | } |
| 423 | |
Arthur Heymans | 3f111b0 | 2017-03-09 12:02:52 +0100 | [diff] [blame] | 424 | void acpi_fill_fadt(acpi_fadt_t *fadt) |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 425 | { |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 426 | struct device *dev = pcidev_on_root(0x1f, 0); |
Vladimir Serbinenko | ab83ef0 | 2014-10-25 15:18:25 +0200 | [diff] [blame] | 427 | config_t *chip = dev->chip_info; |
Elyes HAOUAS | 7118701 | 2019-02-10 14:58:13 +0100 | [diff] [blame] | 428 | u16 pmbase = lpc_get_pmbase(); |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 429 | |
| 430 | fadt->pm1a_evt_blk = pmbase; |
| 431 | fadt->pm1b_evt_blk = 0x0; |
Elyes HAOUAS | 7118701 | 2019-02-10 14:58:13 +0100 | [diff] [blame] | 432 | fadt->pm1a_cnt_blk = pmbase + PM1_CNT; |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 433 | fadt->pm1b_cnt_blk = 0x0; |
Elyes HAOUAS | 7118701 | 2019-02-10 14:58:13 +0100 | [diff] [blame] | 434 | fadt->pm2_cnt_blk = pmbase + PM2_CNT; |
| 435 | fadt->pm_tmr_blk = pmbase + PM1_TMR; |
| 436 | fadt->gpe0_blk = pmbase + GPE0_STS; |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 437 | fadt->gpe1_blk = 0; |
| 438 | |
| 439 | fadt->pm1_evt_len = 4; |
| 440 | fadt->pm1_cnt_len = 2; |
| 441 | fadt->pm2_cnt_len = 1; |
| 442 | fadt->pm_tmr_len = 4; |
| 443 | fadt->gpe0_blk_len = 8; |
| 444 | fadt->gpe1_blk_len = 0; |
| 445 | fadt->gpe1_base = 0; |
| 446 | |
| 447 | fadt->reset_reg.space_id = 1; |
| 448 | fadt->reset_reg.bit_width = 8; |
| 449 | fadt->reset_reg.bit_offset = 0; |
Vladimir Serbinenko | ab83ef0 | 2014-10-25 15:18:25 +0200 | [diff] [blame] | 450 | fadt->reset_reg.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS; |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 451 | fadt->reset_reg.addrl = 0xcf9; |
| 452 | fadt->reset_reg.addrh = 0; |
| 453 | |
| 454 | fadt->reset_value = 6; |
| 455 | |
| 456 | fadt->x_pm1a_evt_blk.space_id = 1; |
| 457 | fadt->x_pm1a_evt_blk.bit_width = 32; |
| 458 | fadt->x_pm1a_evt_blk.bit_offset = 0; |
Vladimir Serbinenko | ab83ef0 | 2014-10-25 15:18:25 +0200 | [diff] [blame] | 459 | fadt->x_pm1a_evt_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS; |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 460 | fadt->x_pm1a_evt_blk.addrl = pmbase; |
| 461 | fadt->x_pm1a_evt_blk.addrh = 0x0; |
| 462 | |
| 463 | fadt->x_pm1b_evt_blk.space_id = 0; |
| 464 | fadt->x_pm1b_evt_blk.bit_width = 0; |
| 465 | fadt->x_pm1b_evt_blk.bit_offset = 0; |
Vladimir Serbinenko | ab83ef0 | 2014-10-25 15:18:25 +0200 | [diff] [blame] | 466 | fadt->x_pm1b_evt_blk.access_size = 0; |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 467 | fadt->x_pm1b_evt_blk.addrl = 0x0; |
| 468 | fadt->x_pm1b_evt_blk.addrh = 0x0; |
| 469 | |
| 470 | fadt->x_pm1a_cnt_blk.space_id = 1; |
| 471 | fadt->x_pm1a_cnt_blk.bit_width = 16; |
| 472 | fadt->x_pm1a_cnt_blk.bit_offset = 0; |
Vladimir Serbinenko | ab83ef0 | 2014-10-25 15:18:25 +0200 | [diff] [blame] | 473 | fadt->x_pm1a_cnt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS; |
Elyes HAOUAS | 7118701 | 2019-02-10 14:58:13 +0100 | [diff] [blame] | 474 | fadt->x_pm1a_cnt_blk.addrl = pmbase + PM1_CNT; |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 475 | fadt->x_pm1a_cnt_blk.addrh = 0x0; |
| 476 | |
| 477 | fadt->x_pm1b_cnt_blk.space_id = 0; |
| 478 | fadt->x_pm1b_cnt_blk.bit_width = 0; |
| 479 | fadt->x_pm1b_cnt_blk.bit_offset = 0; |
Vladimir Serbinenko | ab83ef0 | 2014-10-25 15:18:25 +0200 | [diff] [blame] | 480 | fadt->x_pm1b_cnt_blk.access_size = 0; |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 481 | fadt->x_pm1b_cnt_blk.addrl = 0x0; |
| 482 | fadt->x_pm1b_cnt_blk.addrh = 0x0; |
| 483 | |
| 484 | fadt->x_pm2_cnt_blk.space_id = 1; |
| 485 | fadt->x_pm2_cnt_blk.bit_width = 8; |
| 486 | fadt->x_pm2_cnt_blk.bit_offset = 0; |
Vladimir Serbinenko | ab83ef0 | 2014-10-25 15:18:25 +0200 | [diff] [blame] | 487 | fadt->x_pm2_cnt_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS; |
Elyes HAOUAS | 7118701 | 2019-02-10 14:58:13 +0100 | [diff] [blame] | 488 | fadt->x_pm2_cnt_blk.addrl = pmbase + PM2_CNT; |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 489 | fadt->x_pm2_cnt_blk.addrh = 0x0; |
| 490 | |
| 491 | fadt->x_pm_tmr_blk.space_id = 1; |
| 492 | fadt->x_pm_tmr_blk.bit_width = 32; |
| 493 | fadt->x_pm_tmr_blk.bit_offset = 0; |
Vladimir Serbinenko | ab83ef0 | 2014-10-25 15:18:25 +0200 | [diff] [blame] | 494 | fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS; |
Elyes HAOUAS | 7118701 | 2019-02-10 14:58:13 +0100 | [diff] [blame] | 495 | fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR; |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 496 | fadt->x_pm_tmr_blk.addrh = 0x0; |
| 497 | |
| 498 | fadt->x_gpe0_blk.space_id = 1; |
| 499 | fadt->x_gpe0_blk.bit_width = 64; |
| 500 | fadt->x_gpe0_blk.bit_offset = 0; |
Vladimir Serbinenko | ab83ef0 | 2014-10-25 15:18:25 +0200 | [diff] [blame] | 501 | fadt->x_gpe0_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS; |
Elyes HAOUAS | 7118701 | 2019-02-10 14:58:13 +0100 | [diff] [blame] | 502 | fadt->x_gpe0_blk.addrl = pmbase + GPE0_STS; |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 503 | fadt->x_gpe0_blk.addrh = 0x0; |
| 504 | |
| 505 | fadt->x_gpe1_blk.space_id = 0; |
| 506 | fadt->x_gpe1_blk.bit_width = 0; |
| 507 | fadt->x_gpe1_blk.bit_offset = 0; |
Vladimir Serbinenko | ab83ef0 | 2014-10-25 15:18:25 +0200 | [diff] [blame] | 508 | fadt->x_gpe1_blk.access_size = 0; |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 509 | fadt->x_gpe1_blk.addrl = 0x0; |
| 510 | fadt->x_gpe1_blk.addrh = 0x0; |
| 511 | fadt->day_alrm = 0xd; |
| 512 | fadt->mon_alrm = 0x00; |
| 513 | fadt->century = 0x32; |
| 514 | |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 515 | fadt->sci_int = 0x9; |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 516 | |
Kyösti Mälkki | 0a9e72e | 2019-08-11 01:22:28 +0300 | [diff] [blame] | 517 | if (permanent_smi_handler()) { |
Kyösti Mälkki | c328a68 | 2019-11-23 07:23:40 +0200 | [diff] [blame] | 518 | fadt->smi_cmd = APM_CNT; |
| 519 | fadt->acpi_enable = APM_CNT_ACPI_ENABLE; |
| 520 | fadt->acpi_disable = APM_CNT_ACPI_DISABLE; |
| 521 | fadt->pstate_cnt = APM_CNT_PST_CONTROL; |
| 522 | fadt->cst_cnt = APM_CNT_CST_CONTROL; |
| 523 | } |
| 524 | |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 525 | fadt->p_lvl2_lat = 1; |
Vladimir Serbinenko | ab83ef0 | 2014-10-25 15:18:25 +0200 | [diff] [blame] | 526 | fadt->p_lvl3_lat = chip->c3_latency; |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 527 | fadt->flush_size = 0; |
| 528 | fadt->flush_stride = 0; |
| 529 | fadt->duty_offset = 1; |
Arthur Heymans | 3f111b0 | 2017-03-09 12:02:52 +0100 | [diff] [blame] | 530 | if (chip->p_cnt_throttling_supported) |
Vladimir Serbinenko | ab83ef0 | 2014-10-25 15:18:25 +0200 | [diff] [blame] | 531 | fadt->duty_width = 3; |
Arthur Heymans | 3f111b0 | 2017-03-09 12:02:52 +0100 | [diff] [blame] | 532 | else |
Vladimir Serbinenko | ab83ef0 | 2014-10-25 15:18:25 +0200 | [diff] [blame] | 533 | fadt->duty_width = 0; |
Vladimir Serbinenko | ab83ef0 | 2014-10-25 15:18:25 +0200 | [diff] [blame] | 534 | fadt->iapc_boot_arch = 0x03; |
| 535 | fadt->flags = (ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED |
| 536 | | ACPI_FADT_SLEEP_BUTTON | ACPI_FADT_S4_RTC_WAKE |
| 537 | | ACPI_FADT_PLATFORM_CLOCK | ACPI_FADT_RESET_REGISTER |
| 538 | | ACPI_FADT_C2_MP_SUPPORTED); |
Arthur Heymans | 3f111b0 | 2017-03-09 12:02:52 +0100 | [diff] [blame] | 539 | if (chip->docking_supported) |
Vladimir Serbinenko | ab83ef0 | 2014-10-25 15:18:25 +0200 | [diff] [blame] | 540 | fadt->flags |= ACPI_FADT_DOCKING_SUPPORTED; |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 541 | } |
| 542 | |
Elyes HAOUAS | 9966703 | 2018-05-13 12:47:28 +0200 | [diff] [blame] | 543 | static void i82801gx_lpc_read_resources(struct device *dev) |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 544 | { |
| 545 | struct resource *res; |
Vladimir Serbinenko | f119f08 | 2014-11-24 21:05:56 +0100 | [diff] [blame] | 546 | u8 io_index = 0; |
| 547 | int i; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 548 | |
| 549 | /* Get the normal PCI resources of this device. */ |
| 550 | pci_dev_read_resources(dev); |
| 551 | |
| 552 | /* Add an extra subtractive resource for both memory and I/O. */ |
Vladimir Serbinenko | f119f08 | 2014-11-24 21:05:56 +0100 | [diff] [blame] | 553 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0)); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 554 | res->base = 0; |
| 555 | res->size = 0x1000; |
| 556 | res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | |
| 557 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 558 | |
Vladimir Serbinenko | f119f08 | 2014-11-24 21:05:56 +0100 | [diff] [blame] | 559 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0)); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 560 | res->base = 0xff800000; |
| 561 | res->size = 0x00800000; /* 8 MB for flash */ |
| 562 | res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | |
| 563 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 564 | |
| 565 | res = new_resource(dev, 3); /* IOAPIC */ |
Uwe Hermann | 74d1a6e | 2010-10-12 17:34:08 +0000 | [diff] [blame] | 566 | res->base = IO_APIC_ADDR; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 567 | res->size = 0x00001000; |
| 568 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
Vladimir Serbinenko | f119f08 | 2014-11-24 21:05:56 +0100 | [diff] [blame] | 569 | |
| 570 | /* Set IO decode ranges if required.*/ |
| 571 | for (i = 0; i < 4; i++) { |
| 572 | u32 gen_dec; |
| 573 | gen_dec = pci_read_config32(dev, 0x84 + 4 * i); |
| 574 | |
| 575 | if ((gen_dec & 0xFFFC) > 0x1000) { |
| 576 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0)); |
| 577 | res->base = gen_dec & 0xFFFC; |
| 578 | res->size = (gen_dec >> 16) & 0xFC; |
| 579 | res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | |
| 580 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 581 | } |
| 582 | } |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 583 | } |
| 584 | |
Arthur Heymans | 3664647 | 2018-01-22 14:42:18 +0100 | [diff] [blame] | 585 | #define SPIBAR16(x) RCBA16(0x3020 + x) |
| 586 | #define SPIBAR32(x) RCBA32(0x3020 + x) |
| 587 | |
| 588 | static void lpc_final(struct device *dev) |
| 589 | { |
| 590 | u16 tco1_cnt; |
| 591 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 592 | if (!CONFIG(INTEL_CHIPSET_LOCKDOWN)) |
Arthur Heymans | 3664647 | 2018-01-22 14:42:18 +0100 | [diff] [blame] | 593 | return; |
| 594 | |
Arthur Heymans | 767de0a | 2019-11-15 19:19:53 +0100 | [diff] [blame] | 595 | if (CONFIG(BOOT_DEVICE_SPI_FLASH)) |
| 596 | spi_finalize_ops(); |
Arthur Heymans | 3664647 | 2018-01-22 14:42:18 +0100 | [diff] [blame] | 597 | |
| 598 | /* Lock SPIBAR */ |
| 599 | SPIBAR16(0) = SPIBAR16(0) | (1 << 15); |
| 600 | |
| 601 | /* BIOS Interface Lockdown */ |
| 602 | RCBA32(0x3410) |= 1 << 0; |
| 603 | |
| 604 | /* Global SMI Lock */ |
| 605 | pci_or_config16(dev, GEN_PMCON_1, 1 << 4); |
| 606 | |
| 607 | /* TCO_Lock */ |
| 608 | tco1_cnt = inw(DEFAULT_PMBASE + 0x60 + TCO1_CNT); |
| 609 | tco1_cnt |= (1 << 12); /* TCO lock */ |
| 610 | outw(tco1_cnt, DEFAULT_PMBASE + 0x60 + TCO1_CNT); |
| 611 | |
| 612 | /* Indicate finalize step with post code */ |
| 613 | outb(POST_OS_BOOT, 0x80); |
| 614 | } |
| 615 | |
Furquan Shaikh | 338fd9a | 2020-04-24 22:57:05 -0700 | [diff] [blame] | 616 | static void southbridge_inject_dsdt(const struct device *dev) |
Vladimir Serbinenko | 0e64617 | 2014-08-31 00:27:05 +0200 | [diff] [blame] | 617 | { |
Arthur Heymans | 3f111b0 | 2017-03-09 12:02:52 +0100 | [diff] [blame] | 618 | global_nvs_t *gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(*gnvs)); |
Vladimir Serbinenko | 0e64617 | 2014-08-31 00:27:05 +0200 | [diff] [blame] | 619 | |
| 620 | if (gnvs) { |
Vladimir Serbinenko | 0e64617 | 2014-08-31 00:27:05 +0200 | [diff] [blame] | 621 | memset(gnvs, 0, sizeof(*gnvs)); |
Vladimir Serbinenko | 385743a | 2014-10-18 02:26:21 +0200 | [diff] [blame] | 622 | |
| 623 | gnvs->apic = 1; |
| 624 | gnvs->mpen = 1; /* Enable Multi Processing */ |
| 625 | |
Vladimir Serbinenko | 0e64617 | 2014-08-31 00:27:05 +0200 | [diff] [blame] | 626 | acpi_create_gnvs(gnvs); |
Vladimir Serbinenko | dd2bc3f | 2014-10-31 09:16:31 +0100 | [diff] [blame] | 627 | |
Vladimir Serbinenko | 0e64617 | 2014-08-31 00:27:05 +0200 | [diff] [blame] | 628 | /* And tell SMI about it */ |
| 629 | smm_setup_structures(gnvs, NULL, NULL); |
| 630 | |
| 631 | /* Add it to SSDT. */ |
Vladimir Serbinenko | 1bad88e | 2014-11-04 21:20:56 +0100 | [diff] [blame] | 632 | acpigen_write_scope("\\"); |
| 633 | acpigen_write_name_dword("NVSA", (u32) gnvs); |
| 634 | acpigen_pop_len(); |
Vladimir Serbinenko | 0e64617 | 2014-08-31 00:27:05 +0200 | [diff] [blame] | 635 | } |
| 636 | } |
| 637 | |
Arthur Heymans | a8a9f34 | 2017-12-24 08:11:13 +0100 | [diff] [blame] | 638 | static const char *lpc_acpi_name(const struct device *dev) |
| 639 | { |
| 640 | return "LPCB"; |
| 641 | } |
| 642 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 643 | static void southbridge_fill_ssdt(const struct device *device) |
Arthur Heymans | a8a9f34 | 2017-12-24 08:11:13 +0100 | [diff] [blame] | 644 | { |
| 645 | intel_acpi_gen_def_acpi_pirq(device); |
| 646 | } |
| 647 | |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 648 | static struct device_operations device_ops = { |
| 649 | .read_resources = i82801gx_lpc_read_resources, |
| 650 | .set_resources = pci_dev_set_resources, |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 651 | .enable_resources = pci_dev_enable_resources, |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 652 | .acpi_inject_dsdt = southbridge_inject_dsdt, |
Vladimir Serbinenko | 0e64617 | 2014-08-31 00:27:05 +0200 | [diff] [blame] | 653 | .write_acpi_tables = acpi_write_hpet, |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 654 | .acpi_fill_ssdt = southbridge_fill_ssdt, |
Arthur Heymans | a8a9f34 | 2017-12-24 08:11:13 +0100 | [diff] [blame] | 655 | .acpi_name = lpc_acpi_name, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 656 | .init = lpc_init, |
Nico Huber | 51b75ae | 2019-03-14 16:02:05 +0100 | [diff] [blame] | 657 | .scan_bus = scan_static_bus, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 658 | .enable = i82801gx_enable, |
Angel Pons | 1fc0edd | 2020-05-31 00:03:28 +0200 | [diff] [blame] | 659 | .ops_pci = &pci_dev_ops_pci, |
Arthur Heymans | 3664647 | 2018-01-22 14:42:18 +0100 | [diff] [blame] | 660 | .final = lpc_final, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 661 | }; |
| 662 | |
Damien Zammit | ef33e03 | 2015-11-14 01:03:39 +1100 | [diff] [blame] | 663 | static const unsigned short pci_device_ids[] = { |
Elyes HAOUAS | 92646ea | 2020-04-04 13:43:03 +0200 | [diff] [blame] | 664 | 0x27b0, /* 82801GH (ICH7 DH) */ |
| 665 | 0x27b8, /* 82801GB/GR (ICH7/ICH7R) */ |
| 666 | 0x27b9, /* 82801GBM/GU (ICH7-M/ICH7-U) */ |
| 667 | 0x27bc, /* 82NM10 (NM10) */ |
| 668 | 0x27bd, /* 82801GHM (ICH7-M DH) */ |
| 669 | 0 |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 670 | }; |
| 671 | |
Damien Zammit | ef33e03 | 2015-11-14 01:03:39 +1100 | [diff] [blame] | 672 | static const struct pci_driver ich7_lpc __pci_driver = { |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 673 | .ops = &device_ops, |
| 674 | .vendor = PCI_VENDOR_ID_INTEL, |
Damien Zammit | ef33e03 | 2015-11-14 01:03:39 +1100 | [diff] [blame] | 675 | .devices = pci_device_ids, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 676 | }; |