blob: c24460cd8146a97ddcd66d34c0be3298566ad074 [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00003
4#include <console/console.h>
5#include <device/device.h>
6#include <device/pci.h>
7#include <device/pci_ids.h>
Kyösti Mälkkicbf95712020-01-05 08:05:45 +02008#include <option.h>
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00009#include <pc80/mc146818rtc.h>
10#include <pc80/isa-dma.h>
Stefan Reinauer54309d62009-01-20 22:53:10 +000011#include <pc80/i8259.h>
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000012#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020013#include <device/pci_ops.h>
Uwe Hermann74d1a6e2010-10-12 17:34:08 +000014#include <arch/ioapic.h>
Stefan Reinauerab872542011-10-14 15:18:29 -070015#include <arch/acpi.h>
Sven Schnellef4dc1a72011-06-05 11:33:41 +020016#include <cpu/x86/smm.h>
Vladimir Serbinenko0e646172014-08-31 00:27:05 +020017#include <arch/acpigen.h>
Vladimir Serbinenkod5d94ea2014-10-18 02:13:11 +020018#include <arch/smp/mpspec.h>
Vladimir Serbinenko0e646172014-08-31 00:27:05 +020019#include <cbmem.h>
20#include <string.h>
Arthur Heymansa8a9f342017-12-24 08:11:13 +010021#include <southbridge/intel/common/acpi_pirq_gen.h>
Elyes HAOUAS71187012019-02-10 14:58:13 +010022#include <southbridge/intel/common/pmbase.h>
Arthur Heymansb429c5b2019-05-28 13:24:15 +020023#include <southbridge/intel/common/spi.h>
Elyes HAOUAS71187012019-02-10 14:58:13 +010024
Arthur Heymans742df5a2019-06-03 16:24:41 +020025#include "chip.h"
Elyes HAOUAS71187012019-02-10 14:58:13 +010026#include "i82801gx.h"
Vladimir Serbinenko0e646172014-08-31 00:27:05 +020027#include "nvs.h"
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000028
Stefan Reinauer573f7d42009-07-21 21:50:34 +000029#define NMI_OFF 0
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000030
Stefan Reinauer54309d62009-01-20 22:53:10 +000031typedef struct southbridge_intel_i82801gx_config config_t;
32
Paul Menzelddddf152013-04-23 14:40:23 +020033/**
Martin Roth2ed0aa22016-01-05 20:58:58 -070034 * Set miscellaneous static southbridge features.
Paul Menzelddddf152013-04-23 14:40:23 +020035 *
36 * @param dev PCI device with I/O APIC control registers
37 */
38static void i82801gx_enable_ioapic(struct device *dev)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000039{
Paul Menzelddddf152013-04-23 14:40:23 +020040 /* Enable ACPI I/O range decode */
Kyösti Mälkki1cca3402013-02-26 19:21:39 +020041 pci_write_config8(dev, ACPI_CNTL, ACPI_EN);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000042
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080043 set_ioapic_id(VIO_APIC_VADDR, 0x02);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000044
Paul Menzelddddf152013-04-23 14:40:23 +020045 /*
46 * Select Boot Configuration register (0x03) and
47 * use Processor System Bus (0x01) to deliver interrupts.
48 */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080049 io_apic_write(VIO_APIC_VADDR, 0x03, 0x01);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000050}
51
52static void i82801gx_enable_serial_irqs(struct device *dev)
53{
54 /* Set packet length and toggle silent mode bit for one frame. */
Elyes HAOUAS92646ea2020-04-04 13:43:03 +020055 pci_write_config8(dev, SERIRQ_CNTL, (1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0));
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000056}
57
Stefan Reinauer573f7d42009-07-21 21:50:34 +000058/* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control
59 * 0x00 - 0000 = Reserved
60 * 0x01 - 0001 = Reserved
61 * 0x02 - 0010 = Reserved
62 * 0x03 - 0011 = IRQ3
63 * 0x04 - 0100 = IRQ4
64 * 0x05 - 0101 = IRQ5
65 * 0x06 - 0110 = IRQ6
66 * 0x07 - 0111 = IRQ7
67 * 0x08 - 1000 = Reserved
68 * 0x09 - 1001 = IRQ9
69 * 0x0A - 1010 = IRQ10
70 * 0x0B - 1011 = IRQ11
71 * 0x0C - 1100 = IRQ12
72 * 0x0D - 1101 = Reserved
73 * 0x0E - 1110 = IRQ14
74 * 0x0F - 1111 = IRQ15
75 * PIRQ[n]_ROUT[7] - PIRQ Routing Control
76 * 0x80 - The PIRQ is not routed.
77 */
78
Elyes HAOUAS99667032018-05-13 12:47:28 +020079static void i82801gx_pirq_init(struct device *dev)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000080{
Elyes HAOUAS99667032018-05-13 12:47:28 +020081 struct device *irq_dev;
Stefan Reinauer54309d62009-01-20 22:53:10 +000082 /* Get the chip configuration */
83 config_t *config = dev->chip_info;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000084
Stefan Reinauer54309d62009-01-20 22:53:10 +000085 pci_write_config8(dev, PIRQA_ROUT, config->pirqa_routing);
86 pci_write_config8(dev, PIRQB_ROUT, config->pirqb_routing);
87 pci_write_config8(dev, PIRQC_ROUT, config->pirqc_routing);
88 pci_write_config8(dev, PIRQD_ROUT, config->pirqd_routing);
89
90 pci_write_config8(dev, PIRQE_ROUT, config->pirqe_routing);
91 pci_write_config8(dev, PIRQF_ROUT, config->pirqf_routing);
92 pci_write_config8(dev, PIRQG_ROUT, config->pirqg_routing);
93 pci_write_config8(dev, PIRQH_ROUT, config->pirqh_routing);
94
95 /* Eric Biederman once said we should let the OS do this.
96 * I am not so sure anymore he was right.
97 */
98
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020099 for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
Arthur Heymans3f111b02017-03-09 12:02:52 +0100100 u8 int_pin = 0, int_line = 0;
Stefan Reinauer54309d62009-01-20 22:53:10 +0000101
102 if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI)
103 continue;
104
105 int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
106
107 switch (int_pin) {
Arthur Heymans3f111b02017-03-09 12:02:52 +0100108 case 1:
109 /* INTA# */ int_line = config->pirqa_routing; break;
110 case 2:
111 /* INTB# */ int_line = config->pirqb_routing; break;
112 case 3:
113 /* INTC# */ int_line = config->pirqc_routing; break;
114 case 4:
115 /* INTD# */ int_line = config->pirqd_routing; break;
Stefan Reinauer54309d62009-01-20 22:53:10 +0000116 }
117
118 if (!int_line)
119 continue;
120
121 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line);
122 }
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000123}
124
Elyes HAOUAS99667032018-05-13 12:47:28 +0200125static void i82801gx_gpi_routing(struct device *dev)
Stefan Reinauera8e11682009-03-11 14:54:18 +0000126{
127 /* Get the chip configuration */
128 config_t *config = dev->chip_info;
129 u32 reg32 = 0;
130
Elyes HAOUAS92646ea2020-04-04 13:43:03 +0200131 /* An array would be much nicer here, or some other method of doing this. */
Stefan Reinauera8e11682009-03-11 14:54:18 +0000132 reg32 |= (config->gpi0_routing & 0x03) << 0;
133 reg32 |= (config->gpi1_routing & 0x03) << 2;
134 reg32 |= (config->gpi2_routing & 0x03) << 4;
135 reg32 |= (config->gpi3_routing & 0x03) << 6;
136 reg32 |= (config->gpi4_routing & 0x03) << 8;
137 reg32 |= (config->gpi5_routing & 0x03) << 10;
138 reg32 |= (config->gpi6_routing & 0x03) << 12;
139 reg32 |= (config->gpi7_routing & 0x03) << 14;
140 reg32 |= (config->gpi8_routing & 0x03) << 16;
141 reg32 |= (config->gpi9_routing & 0x03) << 18;
142 reg32 |= (config->gpi10_routing & 0x03) << 20;
143 reg32 |= (config->gpi11_routing & 0x03) << 22;
144 reg32 |= (config->gpi12_routing & 0x03) << 24;
145 reg32 |= (config->gpi13_routing & 0x03) << 26;
146 reg32 |= (config->gpi14_routing & 0x03) << 28;
147 reg32 |= (config->gpi15_routing & 0x03) << 30;
148
Kyösti Mälkkib85a87b2014-12-29 11:32:27 +0200149 pci_write_config32(dev, GPIO_ROUT, reg32);
Stefan Reinauera8e11682009-03-11 14:54:18 +0000150}
151
Elyes HAOUAS99667032018-05-13 12:47:28 +0200152static void i82801gx_power_options(struct device *dev)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000153{
154 u8 reg8;
Elyes HAOUAS71187012019-02-10 14:58:13 +0100155 u16 reg16;
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000156 u32 reg32;
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000157 const char *state;
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000158 /* Get the chip configuration */
159 config_t *config = dev->chip_info;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000160
Nico Huber9faae2b2018-11-14 00:00:35 +0100161 int pwr_on = CONFIG_MAINBOARD_POWER_FAILURE_STATE;
Luc Verhaegena9c5ea02009-06-03 14:19:33 +0000162 int nmi_option;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000163
164 /* Which state do we want to goto after g3 (power restored)?
165 * 0 == S0 Full On
166 * 1 == S5 Soft Off
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000167 *
168 * If the option is not existent (Laptops), use MAINBOARD_POWER_ON.
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000169 */
Varad Gautam06ef0462015-03-11 09:54:41 +0530170 pwr_on = MAINBOARD_POWER_ON;
171 get_option(&pwr_on, "power_on_after_fail");
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000172
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000173 reg8 = pci_read_config8(dev, GEN_PMCON_3);
174 reg8 &= 0xfe;
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000175 switch (pwr_on) {
176 case MAINBOARD_POWER_OFF:
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000177 reg8 |= 1;
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000178 state = "off";
179 break;
180 case MAINBOARD_POWER_ON:
181 reg8 &= ~1;
182 state = "on";
183 break;
184 case MAINBOARD_POWER_KEEP:
185 reg8 &= ~1;
186 state = "state keep";
187 break;
188 default:
189 state = "undefined";
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000190 }
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000191
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000192 reg8 |= (3 << 4); /* avoid #S4 assertions */
Martin Roth2ed0aa22016-01-05 20:58:58 -0700193 reg8 &= ~(1 << 3); /* minimum assertion is 1 to 2 RTCCLK */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000194
195 pci_write_config8(dev, GEN_PMCON_3, reg8);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000196 printk(BIOS_INFO, "Set power %s after power failure.\n", state);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000197
198 /* Set up NMI on errors. */
199 reg8 = inb(0x61);
200 reg8 &= 0x0f; /* Higher Nibble must be 0 */
201 reg8 &= ~(1 << 3); /* IOCHK# NMI Enable */
202 // reg8 &= ~(1 << 2); /* PCI SERR# Enable */
203 reg8 |= (1 << 2); /* PCI SERR# Disable for now */
204 outb(reg8, 0x61);
205
206 reg8 = inb(0x70);
207 nmi_option = NMI_OFF;
Luc Verhaegena9c5ea02009-06-03 14:19:33 +0000208 get_option(&nmi_option, "nmi");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000209 if (nmi_option) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000210 printk(BIOS_INFO, "NMI sources enabled.\n");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000211 reg8 &= ~(1 << 7); /* Set NMI. */
212 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000213 printk(BIOS_INFO, "NMI sources disabled.\n");
Arthur Heymans3f111b02017-03-09 12:02:52 +0100214 reg8 |= (1 << 7); /* Can't mask NMI from PCI-E and NMI_NOW */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000215 }
216 outb(reg8, 0x70);
217
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000218 /* Enable CPU_SLP# and Intel Speedstep, set SMI# rate down */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000219 reg16 = pci_read_config16(dev, GEN_PMCON_1);
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000220 reg16 &= ~(3 << 0); // SMI# rate 1 minute
221 reg16 |= (1 << 2); // CLKRUN_EN - Mobile/Ultra only
222 reg16 |= (1 << 3); // Speedstep Enable - Mobile/Ultra only
223 reg16 |= (1 << 5); // CPUSLP_EN Desktop only
Sven Schnelle906f9ae2011-10-23 16:35:01 +0200224
225 if (config->c4onc3_enable)
226 reg16 |= (1 << 7);
227
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000228 // another laptop wants this?
229 // reg16 &= ~(1 << 10); // BIOS_PCI_EXP_EN - Desktop/Mobile only
230 reg16 |= (1 << 10); // BIOS_PCI_EXP_EN - Desktop/Mobile only
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000231#if DEBUG_PERIODIC_SMIS
232 /* Set DEBUG_PERIODIC_SMIS in i82801gx.h to debug using
233 * periodic SMIs.
234 */
235 reg16 |= (3 << 0); // Periodic SMI every 8s
236#endif
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000237 pci_write_config16(dev, GEN_PMCON_1, reg16);
238
Stefan Reinauera8e11682009-03-11 14:54:18 +0000239 // Set the board's GPI routing.
240 i82801gx_gpi_routing(dev);
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000241
Elyes HAOUAS71187012019-02-10 14:58:13 +0100242 write_pmbase32(GPE0_EN, config->gpe0_en);
243 write_pmbase16(ALT_GP_SMI_EN, config->alt_gp_smi_en);
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000244
245 /* Set up power management block and determine sleep mode */
Elyes HAOUAS71187012019-02-10 14:58:13 +0100246 reg32 = read_pmbase32(PM1_CNT);
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000247
248 reg32 &= ~(7 << 10); // SLP_TYP
249 reg32 |= (1 << 1); // enable C3->C0 transition on bus master
250 reg32 |= (1 << 0); // SCI_EN
Elyes HAOUAS71187012019-02-10 14:58:13 +0100251 write_pmbase32(PM1_CNT, reg32);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000252}
253
Elyes HAOUAS99667032018-05-13 12:47:28 +0200254static void i82801gx_configure_cstates(struct device *dev)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000255{
256 u8 reg8;
Stefan Reinauer109ab312009-08-12 16:08:05 +0000257
Stefan Reinauera8e11682009-03-11 14:54:18 +0000258 reg8 = pci_read_config8(dev, 0xa9); // Cx state configuration
259 reg8 |= (1 << 4) | (1 << 3) | (1 << 2); // Enable Popup & Popdown
260 pci_write_config8(dev, 0xa9, reg8);
261
262 // Set Deeper Sleep configuration to recommended values
263 reg8 = pci_read_config8(dev, 0xaa);
264 reg8 &= 0xf0;
265 reg8 |= (2 << 2); // Deeper Sleep to Stop CPU: 34-40us
266 reg8 |= (2 << 0); // Deeper Sleep to Sleep: 15us
267 pci_write_config8(dev, 0xaa, reg8);
268}
269
270static void i82801gx_rtc_init(struct device *dev)
271{
272 u8 reg8;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000273 int rtc_failed;
274
275 reg8 = pci_read_config8(dev, GEN_PMCON_3);
276 rtc_failed = reg8 & RTC_BATTERY_DEAD;
277 if (rtc_failed) {
278 reg8 &= ~RTC_BATTERY_DEAD;
279 pci_write_config8(dev, GEN_PMCON_3, reg8);
280 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000281 printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000282
Gabe Blackb3f08c62014-04-30 17:12:25 -0700283 cmos_init(rtc_failed);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000284}
285
Stefan Reinauera8e11682009-03-11 14:54:18 +0000286static void enable_hpet(void)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000287{
Stefan Reinauera8e11682009-03-11 14:54:18 +0000288 u32 reg32;
Stefan Reinauer109ab312009-08-12 16:08:05 +0000289
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000290 /* Move HPET to default address 0xfed00000 and enable it */
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000291 reg32 = RCBA32(HPTC);
Stefan Reinauera8e11682009-03-11 14:54:18 +0000292 reg32 |= (1 << 7); // HPET Address Enable
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000293 reg32 &= ~(3 << 0);
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000294 RCBA32(HPTC) = reg32;
Arthur Heymansc73c9232019-10-02 14:57:50 +0200295 /* On NM10 this only works if read back */
296 RCBA32(HPTC);
297
298 write32((u32 *)0xfed00010, read32((u32 *)0xfed00010) | 1);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000299}
300
Stefan Reinauera8e11682009-03-11 14:54:18 +0000301static void enable_clock_gating(void)
302{
303 u32 reg32;
Stefan Reinauer109ab312009-08-12 16:08:05 +0000304
Stefan Reinauera8e11682009-03-11 14:54:18 +0000305 /* Enable Clock Gating for most devices */
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000306 reg32 = RCBA32(CG);
Stefan Reinauera8e11682009-03-11 14:54:18 +0000307 reg32 |= (1 << 31); // LPC clock gating
308 reg32 |= (1 << 30); // PATA clock gating
309 // SATA clock gating
310 reg32 |= (1 << 27) | (1 << 26) | (1 << 25) | (1 << 24);
311 reg32 |= (1 << 23); // AC97 clock gating
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000312 reg32 |= (1 << 19); // USB EHCI clock gating
Stefan Reinauera8e11682009-03-11 14:54:18 +0000313 reg32 |= (1 << 3) | (1 << 1); // DMI clock gating
314 reg32 |= (1 << 2); // PCIe clock gating;
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000315 reg32 &= ~(1 << 20); // No static clock gating for USB
Arthur Heymans3f111b02017-03-09 12:02:52 +0100316 reg32 &= ~((1 << 29) | (1 << 28)); // Disable UHCI clock gating
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000317 RCBA32(CG) = reg32;
Stefan Reinauera8e11682009-03-11 14:54:18 +0000318}
Stefan Reinauer269563a2009-01-19 21:20:22 +0000319
Kyösti Mälkki83d6a8a2019-07-12 08:16:53 +0300320static void i82801gx_set_acpi_mode(struct device *dev)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000321{
Kyösti Mälkki44da9e72019-10-09 12:32:16 +0300322 if (CONFIG(HAVE_SMI_HANDLER)) {
323 if (!acpi_is_wakeup_s3()) {
324 printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n");
325 outb(APM_CNT_ACPI_DISABLE, APM_CNT); // Disable ACPI mode
326 printk(BIOS_DEBUG, "done.\n");
327 } else {
328 printk(BIOS_DEBUG, "S3 wakeup, enabling ACPI via APMC\n");
329 outb(APM_CNT_ACPI_ENABLE, APM_CNT);
330 }
Sven Schnellee2618072011-06-05 11:39:12 +0200331 }
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000332}
333
Stefan Reinauera8e11682009-03-11 14:54:18 +0000334#define SPIBASE 0x3020
335static void i82801gx_spi_init(void)
336{
337 u16 spicontrol;
338
339 spicontrol = RCBA16(SPIBASE + 2);
340 spicontrol &= ~(1 << 0); // SPI Access Request
341 RCBA16(SPIBASE + 2) = spicontrol;
342}
343
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000344static void i82801gx_fixups(struct device *dev)
Stefan Reinauera8e11682009-03-11 14:54:18 +0000345{
346 /* This needs to happen after PCI enumeration */
347 RCBA32(0x1d40) |= 1;
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000348
349 /* USB Transient Disconnect Detect:
350 * Prevent a SE0 condition on the USB ports from being
351 * interpreted by the UHCI controller as a disconnect
352 */
353 pci_write_config8(dev, 0xad, 0x3);
Stefan Reinauera8e11682009-03-11 14:54:18 +0000354}
355
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000356static void lpc_init(struct device *dev)
357{
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000358 printk(BIOS_DEBUG, "i82801gx: lpc_init\n");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000359
360 /* Set the value for PCI command register. */
361 pci_write_config16(dev, PCI_COMMAND, 0x000f);
362
363 /* IO APIC initialization. */
Paul Menzelddddf152013-04-23 14:40:23 +0200364 i82801gx_enable_ioapic(dev);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000365
366 i82801gx_enable_serial_irqs(dev);
367
368 /* Setup the PIRQ. */
369 i82801gx_pirq_init(dev);
370
371 /* Setup power options. */
372 i82801gx_power_options(dev);
373
Stefan Reinauera8e11682009-03-11 14:54:18 +0000374 /* Configure Cx state registers */
375 i82801gx_configure_cstates(dev);
376
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000377 /* Set the state of the GPIO lines. */
378 //gpio_init(dev);
379
380 /* Initialize the real time clock. */
381 i82801gx_rtc_init(dev);
382
383 /* Initialize ISA DMA. */
384 isa_dma_init();
385
386 /* Initialize the High Precision Event Timers, if present. */
Stefan Reinauera8e11682009-03-11 14:54:18 +0000387 enable_hpet();
388
389 /* Initialize Clock Gating */
390 enable_clock_gating();
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000391
392 setup_i8259();
393
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000394 /* The OS should do this? */
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000395 /* Interrupt 9 should be level triggered (SCI) */
396 i8259_configure_irq_trigger(9, 1);
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000397
Kyösti Mälkki44da9e72019-10-09 12:32:16 +0300398 i82801gx_set_acpi_mode(dev);
Stefan Reinauera8e11682009-03-11 14:54:18 +0000399
400 i82801gx_spi_init();
401
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000402 i82801gx_fixups(dev);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000403}
404
Vladimir Serbinenkod5d94ea2014-10-18 02:13:11 +0200405unsigned long acpi_fill_madt(unsigned long current)
406{
407 /* Local APICs */
408 current = acpi_create_madt_lapics(current);
409
410 /* IOAPIC */
Elyes HAOUAS92646ea2020-04-04 13:43:03 +0200411 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, 2, IO_APIC_ADDR, 0);
Vladimir Serbinenkod5d94ea2014-10-18 02:13:11 +0200412
413 /* LAPIC_NMI */
414 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)
415 current, 0,
416 MP_IRQ_POLARITY_HIGH |
417 MP_IRQ_TRIGGER_EDGE, 0x01);
418 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)
419 current, 1, MP_IRQ_POLARITY_HIGH |
420 MP_IRQ_TRIGGER_EDGE, 0x01);
421
422 /* INT_SRC_OVR */
423 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
424 current, 0, 0, 2, MP_IRQ_POLARITY_HIGH | MP_IRQ_TRIGGER_EDGE);
425 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
426 current, 0, 9, 9, MP_IRQ_POLARITY_HIGH | MP_IRQ_TRIGGER_LEVEL);
427
428
429 return current;
430}
431
Arthur Heymans3f111b02017-03-09 12:02:52 +0100432void acpi_fill_fadt(acpi_fadt_t *fadt)
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200433{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300434 struct device *dev = pcidev_on_root(0x1f, 0);
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200435 config_t *chip = dev->chip_info;
Elyes HAOUAS71187012019-02-10 14:58:13 +0100436 u16 pmbase = lpc_get_pmbase();
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200437
438 fadt->pm1a_evt_blk = pmbase;
439 fadt->pm1b_evt_blk = 0x0;
Elyes HAOUAS71187012019-02-10 14:58:13 +0100440 fadt->pm1a_cnt_blk = pmbase + PM1_CNT;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200441 fadt->pm1b_cnt_blk = 0x0;
Elyes HAOUAS71187012019-02-10 14:58:13 +0100442 fadt->pm2_cnt_blk = pmbase + PM2_CNT;
443 fadt->pm_tmr_blk = pmbase + PM1_TMR;
444 fadt->gpe0_blk = pmbase + GPE0_STS;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200445 fadt->gpe1_blk = 0;
446
447 fadt->pm1_evt_len = 4;
448 fadt->pm1_cnt_len = 2;
449 fadt->pm2_cnt_len = 1;
450 fadt->pm_tmr_len = 4;
451 fadt->gpe0_blk_len = 8;
452 fadt->gpe1_blk_len = 0;
453 fadt->gpe1_base = 0;
454
455 fadt->reset_reg.space_id = 1;
456 fadt->reset_reg.bit_width = 8;
457 fadt->reset_reg.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200458 fadt->reset_reg.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200459 fadt->reset_reg.addrl = 0xcf9;
460 fadt->reset_reg.addrh = 0;
461
462 fadt->reset_value = 6;
463
464 fadt->x_pm1a_evt_blk.space_id = 1;
465 fadt->x_pm1a_evt_blk.bit_width = 32;
466 fadt->x_pm1a_evt_blk.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200467 fadt->x_pm1a_evt_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200468 fadt->x_pm1a_evt_blk.addrl = pmbase;
469 fadt->x_pm1a_evt_blk.addrh = 0x0;
470
471 fadt->x_pm1b_evt_blk.space_id = 0;
472 fadt->x_pm1b_evt_blk.bit_width = 0;
473 fadt->x_pm1b_evt_blk.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200474 fadt->x_pm1b_evt_blk.access_size = 0;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200475 fadt->x_pm1b_evt_blk.addrl = 0x0;
476 fadt->x_pm1b_evt_blk.addrh = 0x0;
477
478 fadt->x_pm1a_cnt_blk.space_id = 1;
479 fadt->x_pm1a_cnt_blk.bit_width = 16;
480 fadt->x_pm1a_cnt_blk.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200481 fadt->x_pm1a_cnt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS;
Elyes HAOUAS71187012019-02-10 14:58:13 +0100482 fadt->x_pm1a_cnt_blk.addrl = pmbase + PM1_CNT;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200483 fadt->x_pm1a_cnt_blk.addrh = 0x0;
484
485 fadt->x_pm1b_cnt_blk.space_id = 0;
486 fadt->x_pm1b_cnt_blk.bit_width = 0;
487 fadt->x_pm1b_cnt_blk.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200488 fadt->x_pm1b_cnt_blk.access_size = 0;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200489 fadt->x_pm1b_cnt_blk.addrl = 0x0;
490 fadt->x_pm1b_cnt_blk.addrh = 0x0;
491
492 fadt->x_pm2_cnt_blk.space_id = 1;
493 fadt->x_pm2_cnt_blk.bit_width = 8;
494 fadt->x_pm2_cnt_blk.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200495 fadt->x_pm2_cnt_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
Elyes HAOUAS71187012019-02-10 14:58:13 +0100496 fadt->x_pm2_cnt_blk.addrl = pmbase + PM2_CNT;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200497 fadt->x_pm2_cnt_blk.addrh = 0x0;
498
499 fadt->x_pm_tmr_blk.space_id = 1;
500 fadt->x_pm_tmr_blk.bit_width = 32;
501 fadt->x_pm_tmr_blk.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200502 fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
Elyes HAOUAS71187012019-02-10 14:58:13 +0100503 fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200504 fadt->x_pm_tmr_blk.addrh = 0x0;
505
506 fadt->x_gpe0_blk.space_id = 1;
507 fadt->x_gpe0_blk.bit_width = 64;
508 fadt->x_gpe0_blk.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200509 fadt->x_gpe0_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
Elyes HAOUAS71187012019-02-10 14:58:13 +0100510 fadt->x_gpe0_blk.addrl = pmbase + GPE0_STS;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200511 fadt->x_gpe0_blk.addrh = 0x0;
512
513 fadt->x_gpe1_blk.space_id = 0;
514 fadt->x_gpe1_blk.bit_width = 0;
515 fadt->x_gpe1_blk.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200516 fadt->x_gpe1_blk.access_size = 0;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200517 fadt->x_gpe1_blk.addrl = 0x0;
518 fadt->x_gpe1_blk.addrh = 0x0;
519 fadt->day_alrm = 0xd;
520 fadt->mon_alrm = 0x00;
521 fadt->century = 0x32;
522
Elyes HAOUAS0d4de2a2019-02-28 13:04:29 +0100523 fadt->reserved = 0;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200524 fadt->sci_int = 0x9;
525 fadt->smi_cmd = APM_CNT;
526 fadt->acpi_enable = APM_CNT_ACPI_ENABLE;
527 fadt->acpi_disable = APM_CNT_ACPI_DISABLE;
528 fadt->s4bios_req = 0x0;
529 fadt->pstate_cnt = APM_CNT_PST_CONTROL;
530
531 fadt->cst_cnt = APM_CNT_CST_CONTROL;
532 fadt->p_lvl2_lat = 1;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200533 fadt->p_lvl3_lat = chip->c3_latency;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200534 fadt->flush_size = 0;
535 fadt->flush_stride = 0;
536 fadt->duty_offset = 1;
Arthur Heymans3f111b02017-03-09 12:02:52 +0100537 if (chip->p_cnt_throttling_supported)
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200538 fadt->duty_width = 3;
Arthur Heymans3f111b02017-03-09 12:02:52 +0100539 else
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200540 fadt->duty_width = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200541 fadt->iapc_boot_arch = 0x03;
542 fadt->flags = (ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED
543 | ACPI_FADT_SLEEP_BUTTON | ACPI_FADT_S4_RTC_WAKE
544 | ACPI_FADT_PLATFORM_CLOCK | ACPI_FADT_RESET_REGISTER
545 | ACPI_FADT_C2_MP_SUPPORTED);
Arthur Heymans3f111b02017-03-09 12:02:52 +0100546 if (chip->docking_supported)
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200547 fadt->flags |= ACPI_FADT_DOCKING_SUPPORTED;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200548}
549
Elyes HAOUAS99667032018-05-13 12:47:28 +0200550static void i82801gx_lpc_read_resources(struct device *dev)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000551{
552 struct resource *res;
Vladimir Serbinenkof119f082014-11-24 21:05:56 +0100553 u8 io_index = 0;
554 int i;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000555
556 /* Get the normal PCI resources of this device. */
557 pci_dev_read_resources(dev);
558
559 /* Add an extra subtractive resource for both memory and I/O. */
Vladimir Serbinenkof119f082014-11-24 21:05:56 +0100560 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
Myles Watson29cc9ed2009-07-02 18:56:24 +0000561 res->base = 0;
562 res->size = 0x1000;
563 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
564 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000565
Vladimir Serbinenkof119f082014-11-24 21:05:56 +0100566 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
Myles Watson29cc9ed2009-07-02 18:56:24 +0000567 res->base = 0xff800000;
568 res->size = 0x00800000; /* 8 MB for flash */
569 res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE |
570 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
571
572 res = new_resource(dev, 3); /* IOAPIC */
Uwe Hermann74d1a6e2010-10-12 17:34:08 +0000573 res->base = IO_APIC_ADDR;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000574 res->size = 0x00001000;
575 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
Vladimir Serbinenkof119f082014-11-24 21:05:56 +0100576
577 /* Set IO decode ranges if required.*/
578 for (i = 0; i < 4; i++) {
579 u32 gen_dec;
580 gen_dec = pci_read_config32(dev, 0x84 + 4 * i);
581
582 if ((gen_dec & 0xFFFC) > 0x1000) {
583 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
584 res->base = gen_dec & 0xFFFC;
585 res->size = (gen_dec >> 16) & 0xFC;
586 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
587 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
588 }
589 }
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000590}
591
Arthur Heymans36646472018-01-22 14:42:18 +0100592#define SPIBAR16(x) RCBA16(0x3020 + x)
593#define SPIBAR32(x) RCBA32(0x3020 + x)
594
595static void lpc_final(struct device *dev)
596{
597 u16 tco1_cnt;
598
Julius Wernercd49cce2019-03-05 16:53:33 -0800599 if (!CONFIG(INTEL_CHIPSET_LOCKDOWN))
Arthur Heymans36646472018-01-22 14:42:18 +0100600 return;
601
Arthur Heymans767de0a2019-11-15 19:19:53 +0100602 if (CONFIG(BOOT_DEVICE_SPI_FLASH))
603 spi_finalize_ops();
Arthur Heymans36646472018-01-22 14:42:18 +0100604
605 /* Lock SPIBAR */
606 SPIBAR16(0) = SPIBAR16(0) | (1 << 15);
607
608 /* BIOS Interface Lockdown */
609 RCBA32(0x3410) |= 1 << 0;
610
611 /* Global SMI Lock */
612 pci_or_config16(dev, GEN_PMCON_1, 1 << 4);
613
614 /* TCO_Lock */
615 tco1_cnt = inw(DEFAULT_PMBASE + 0x60 + TCO1_CNT);
616 tco1_cnt |= (1 << 12); /* TCO lock */
617 outw(tco1_cnt, DEFAULT_PMBASE + 0x60 + TCO1_CNT);
618
619 /* Indicate finalize step with post code */
620 outb(POST_OS_BOOT, 0x80);
621}
622
Elyes HAOUAS99667032018-05-13 12:47:28 +0200623static void southbridge_inject_dsdt(struct device *dev)
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200624{
Arthur Heymans3f111b02017-03-09 12:02:52 +0100625 global_nvs_t *gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(*gnvs));
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200626
627 if (gnvs) {
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200628 memset(gnvs, 0, sizeof(*gnvs));
Vladimir Serbinenko385743a2014-10-18 02:26:21 +0200629
630 gnvs->apic = 1;
631 gnvs->mpen = 1; /* Enable Multi Processing */
632
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200633 acpi_create_gnvs(gnvs);
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100634
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200635 /* And tell SMI about it */
636 smm_setup_structures(gnvs, NULL, NULL);
637
638 /* Add it to SSDT. */
Vladimir Serbinenko1bad88e2014-11-04 21:20:56 +0100639 acpigen_write_scope("\\");
640 acpigen_write_name_dword("NVSA", (u32) gnvs);
641 acpigen_pop_len();
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200642 }
643}
644
Arthur Heymansa8a9f342017-12-24 08:11:13 +0100645static const char *lpc_acpi_name(const struct device *dev)
646{
647 return "LPCB";
648}
649
Elyes HAOUAS38f1d132018-09-17 08:44:18 +0200650static void southbridge_fill_ssdt(struct device *device)
Arthur Heymansa8a9f342017-12-24 08:11:13 +0100651{
652 intel_acpi_gen_def_acpi_pirq(device);
653}
654
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000655static struct pci_operations pci_ops = {
Subrata Banik4a0f0712019-03-20 14:29:47 +0530656 .set_subsystem = pci_dev_set_subsystem,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000657};
658
659static struct device_operations device_ops = {
660 .read_resources = i82801gx_lpc_read_resources,
661 .set_resources = pci_dev_set_resources,
Myles Watson7eac4452010-06-17 16:16:56 +0000662 .enable_resources = pci_dev_enable_resources,
Nico Huber68680dd2020-03-31 17:34:52 +0200663 .acpi_inject_dsdt = southbridge_inject_dsdt,
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200664 .write_acpi_tables = acpi_write_hpet,
Nico Huber68680dd2020-03-31 17:34:52 +0200665 .acpi_fill_ssdt = southbridge_fill_ssdt,
Arthur Heymansa8a9f342017-12-24 08:11:13 +0100666 .acpi_name = lpc_acpi_name,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000667 .init = lpc_init,
Nico Huber51b75ae2019-03-14 16:02:05 +0100668 .scan_bus = scan_static_bus,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000669 .enable = i82801gx_enable,
670 .ops_pci = &pci_ops,
Arthur Heymans36646472018-01-22 14:42:18 +0100671 .final = lpc_final,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000672};
673
Damien Zammitef33e032015-11-14 01:03:39 +1100674static const unsigned short pci_device_ids[] = {
Elyes HAOUAS92646ea2020-04-04 13:43:03 +0200675 0x27b0, /* 82801GH (ICH7 DH) */
676 0x27b8, /* 82801GB/GR (ICH7/ICH7R) */
677 0x27b9, /* 82801GBM/GU (ICH7-M/ICH7-U) */
678 0x27bc, /* 82NM10 (NM10) */
679 0x27bd, /* 82801GHM (ICH7-M DH) */
680 0
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000681};
682
Damien Zammitef33e032015-11-14 01:03:39 +1100683static const struct pci_driver ich7_lpc __pci_driver = {
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000684 .ops = &device_ops,
685 .vendor = PCI_VENDOR_ID_INTEL,
Damien Zammitef33e032015-11-14 01:03:39 +1100686 .devices = pci_device_ids,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000687};