blob: 287145380826928811094d7a2d7ae40939bf0df1 [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00002
Arthur Heymans98c92572022-11-07 11:39:58 +01003#include <cpu/intel/speedstep.h>
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00004#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>
Furquan Shaikh76cedd22020-05-02 10:24:23 -070015#include <acpi/acpi.h>
Sven Schnellef4dc1a72011-06-05 11:33:41 +020016#include <cpu/x86/smm.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -070017#include <acpi/acpigen.h>
Vladimir Serbinenkod5d94ea2014-10-18 02:13:11 +020018#include <arch/smp/mpspec.h>
Arthur Heymansa8a9f342017-12-24 08:11:13 +010019#include <southbridge/intel/common/acpi_pirq_gen.h>
Tim Wawrzynczakf62c4942021-02-26 10:30:52 -070020#include <southbridge/intel/common/rcba_pirq.h>
Angel Ponseef43432021-01-12 22:25:28 +010021#include <southbridge/intel/common/hpet.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"
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000027
Stefan Reinauer573f7d42009-07-21 21:50:34 +000028#define NMI_OFF 0
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000029
Paul Menzelddddf152013-04-23 14:40:23 +020030/**
Martin Roth2ed0aa22016-01-05 20:58:58 -070031 * Set miscellaneous static southbridge features.
Paul Menzelddddf152013-04-23 14:40:23 +020032 *
33 * @param dev PCI device with I/O APIC control registers
34 */
35static void i82801gx_enable_ioapic(struct device *dev)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000036{
Kyösti Mälkkid1653572021-06-08 11:31:19 +030037 register_new_ioapic_gsi0(VIO_APIC_VADDR);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000038}
39
40static void i82801gx_enable_serial_irqs(struct device *dev)
41{
42 /* Set packet length and toggle silent mode bit for one frame. */
Elyes HAOUAS92646ea2020-04-04 13:43:03 +020043 pci_write_config8(dev, SERIRQ_CNTL, (1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0));
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000044}
45
Stefan Reinauer573f7d42009-07-21 21:50:34 +000046/* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control
47 * 0x00 - 0000 = Reserved
48 * 0x01 - 0001 = Reserved
49 * 0x02 - 0010 = Reserved
50 * 0x03 - 0011 = IRQ3
51 * 0x04 - 0100 = IRQ4
52 * 0x05 - 0101 = IRQ5
53 * 0x06 - 0110 = IRQ6
54 * 0x07 - 0111 = IRQ7
55 * 0x08 - 1000 = Reserved
56 * 0x09 - 1001 = IRQ9
57 * 0x0A - 1010 = IRQ10
58 * 0x0B - 1011 = IRQ11
59 * 0x0C - 1100 = IRQ12
60 * 0x0D - 1101 = Reserved
61 * 0x0E - 1110 = IRQ14
62 * 0x0F - 1111 = IRQ15
63 * PIRQ[n]_ROUT[7] - PIRQ Routing Control
64 * 0x80 - The PIRQ is not routed.
65 */
66
Elyes HAOUAS99667032018-05-13 12:47:28 +020067static void i82801gx_pirq_init(struct device *dev)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000068{
Elyes HAOUAS99667032018-05-13 12:47:28 +020069 struct device *irq_dev;
Stefan Reinauer54309d62009-01-20 22:53:10 +000070 /* Get the chip configuration */
Elyes HAOUAS8d9a6f12020-04-28 04:57:27 +020071 const struct southbridge_intel_i82801gx_config *config = dev->chip_info;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000072
Stefan Reinauer54309d62009-01-20 22:53:10 +000073 pci_write_config8(dev, PIRQA_ROUT, config->pirqa_routing);
74 pci_write_config8(dev, PIRQB_ROUT, config->pirqb_routing);
75 pci_write_config8(dev, PIRQC_ROUT, config->pirqc_routing);
76 pci_write_config8(dev, PIRQD_ROUT, config->pirqd_routing);
77
78 pci_write_config8(dev, PIRQE_ROUT, config->pirqe_routing);
79 pci_write_config8(dev, PIRQF_ROUT, config->pirqf_routing);
80 pci_write_config8(dev, PIRQG_ROUT, config->pirqg_routing);
81 pci_write_config8(dev, PIRQH_ROUT, config->pirqh_routing);
82
83 /* Eric Biederman once said we should let the OS do this.
84 * I am not so sure anymore he was right.
85 */
86
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020087 for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
Arthur Heymans3f111b02017-03-09 12:02:52 +010088 u8 int_pin = 0, int_line = 0;
Stefan Reinauer54309d62009-01-20 22:53:10 +000089
Fabio Aiutod835da92022-09-30 11:25:28 +020090 if (!is_enabled_pci(irq_dev))
Stefan Reinauer54309d62009-01-20 22:53:10 +000091 continue;
92
93 int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
94
95 switch (int_pin) {
Arthur Heymans3f111b02017-03-09 12:02:52 +010096 case 1:
97 /* INTA# */ int_line = config->pirqa_routing; break;
98 case 2:
99 /* INTB# */ int_line = config->pirqb_routing; break;
100 case 3:
101 /* INTC# */ int_line = config->pirqc_routing; break;
102 case 4:
103 /* INTD# */ int_line = config->pirqd_routing; break;
Stefan Reinauer54309d62009-01-20 22:53:10 +0000104 }
105
106 if (!int_line)
107 continue;
108
109 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line);
110 }
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000111}
112
Elyes HAOUAS99667032018-05-13 12:47:28 +0200113static void i82801gx_gpi_routing(struct device *dev)
Stefan Reinauera8e11682009-03-11 14:54:18 +0000114{
115 /* Get the chip configuration */
Elyes HAOUAS8d9a6f12020-04-28 04:57:27 +0200116 const struct southbridge_intel_i82801gx_config *config = dev->chip_info;
Stefan Reinauera8e11682009-03-11 14:54:18 +0000117 u32 reg32 = 0;
118
Elyes HAOUAS92646ea2020-04-04 13:43:03 +0200119 /* An array would be much nicer here, or some other method of doing this. */
Stefan Reinauera8e11682009-03-11 14:54:18 +0000120 reg32 |= (config->gpi0_routing & 0x03) << 0;
121 reg32 |= (config->gpi1_routing & 0x03) << 2;
122 reg32 |= (config->gpi2_routing & 0x03) << 4;
123 reg32 |= (config->gpi3_routing & 0x03) << 6;
124 reg32 |= (config->gpi4_routing & 0x03) << 8;
125 reg32 |= (config->gpi5_routing & 0x03) << 10;
126 reg32 |= (config->gpi6_routing & 0x03) << 12;
127 reg32 |= (config->gpi7_routing & 0x03) << 14;
128 reg32 |= (config->gpi8_routing & 0x03) << 16;
129 reg32 |= (config->gpi9_routing & 0x03) << 18;
130 reg32 |= (config->gpi10_routing & 0x03) << 20;
131 reg32 |= (config->gpi11_routing & 0x03) << 22;
132 reg32 |= (config->gpi12_routing & 0x03) << 24;
133 reg32 |= (config->gpi13_routing & 0x03) << 26;
134 reg32 |= (config->gpi14_routing & 0x03) << 28;
135 reg32 |= (config->gpi15_routing & 0x03) << 30;
136
Kyösti Mälkkib85a87b2014-12-29 11:32:27 +0200137 pci_write_config32(dev, GPIO_ROUT, reg32);
Stefan Reinauera8e11682009-03-11 14:54:18 +0000138}
139
Elyes HAOUAS99667032018-05-13 12:47:28 +0200140static void i82801gx_power_options(struct device *dev)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000141{
142 u8 reg8;
Elyes HAOUAS71187012019-02-10 14:58:13 +0100143 u16 reg16;
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000144 u32 reg32;
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000145 const char *state;
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000146 /* Get the chip configuration */
Elyes HAOUAS8d9a6f12020-04-28 04:57:27 +0200147 const struct southbridge_intel_i82801gx_config *config = dev->chip_info;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000148
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000149 /* Which state do we want to goto after g3 (power restored)?
150 * 0 == S0 Full On
151 * 1 == S5 Soft Off
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000152 *
153 * If the option is not existent (Laptops), use MAINBOARD_POWER_ON.
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000154 */
Angel Pons88dcb312021-04-26 17:10:28 +0200155 const unsigned int pwr_on = get_uint_option("power_on_after_fail", MAINBOARD_POWER_ON);
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000156
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000157 reg8 = pci_read_config8(dev, GEN_PMCON_3);
158 reg8 &= 0xfe;
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000159 switch (pwr_on) {
160 case MAINBOARD_POWER_OFF:
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000161 reg8 |= 1;
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000162 state = "off";
163 break;
164 case MAINBOARD_POWER_ON:
165 reg8 &= ~1;
166 state = "on";
167 break;
168 case MAINBOARD_POWER_KEEP:
169 reg8 &= ~1;
170 state = "state keep";
171 break;
172 default:
173 state = "undefined";
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000174 }
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000175
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000176 reg8 |= (3 << 4); /* avoid #S4 assertions */
Martin Roth2ed0aa22016-01-05 20:58:58 -0700177 reg8 &= ~(1 << 3); /* minimum assertion is 1 to 2 RTCCLK */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000178
179 pci_write_config8(dev, GEN_PMCON_3, reg8);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000180 printk(BIOS_INFO, "Set power %s after power failure.\n", state);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000181
182 /* Set up NMI on errors. */
183 reg8 = inb(0x61);
184 reg8 &= 0x0f; /* Higher Nibble must be 0 */
185 reg8 &= ~(1 << 3); /* IOCHK# NMI Enable */
186 // reg8 &= ~(1 << 2); /* PCI SERR# Enable */
187 reg8 |= (1 << 2); /* PCI SERR# Disable for now */
188 outb(reg8, 0x61);
189
190 reg8 = inb(0x70);
Angel Pons88dcb312021-04-26 17:10:28 +0200191 const unsigned int nmi_option = get_uint_option("nmi", NMI_OFF);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000192 if (nmi_option) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000193 printk(BIOS_INFO, "NMI sources enabled.\n");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000194 reg8 &= ~(1 << 7); /* Set NMI. */
195 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000196 printk(BIOS_INFO, "NMI sources disabled.\n");
Arthur Heymans3f111b02017-03-09 12:02:52 +0100197 reg8 |= (1 << 7); /* Can't mask NMI from PCI-E and NMI_NOW */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000198 }
199 outb(reg8, 0x70);
200
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000201 /* Enable CPU_SLP# and Intel Speedstep, set SMI# rate down */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000202 reg16 = pci_read_config16(dev, GEN_PMCON_1);
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000203 reg16 &= ~(3 << 0); // SMI# rate 1 minute
204 reg16 |= (1 << 2); // CLKRUN_EN - Mobile/Ultra only
205 reg16 |= (1 << 3); // Speedstep Enable - Mobile/Ultra only
206 reg16 |= (1 << 5); // CPUSLP_EN Desktop only
Sven Schnelle906f9ae2011-10-23 16:35:01 +0200207
208 if (config->c4onc3_enable)
209 reg16 |= (1 << 7);
210
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000211 // another laptop wants this?
212 // reg16 &= ~(1 << 10); // BIOS_PCI_EXP_EN - Desktop/Mobile only
213 reg16 |= (1 << 10); // BIOS_PCI_EXP_EN - Desktop/Mobile only
Kyösti Mälkki94464472020-06-13 13:45:42 +0300214 if (CONFIG(DEBUG_PERIODIC_SMI))
215 reg16 |= (3 << 0); // Periodic SMI every 8s
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000216 pci_write_config16(dev, GEN_PMCON_1, reg16);
217
Stefan Reinauera8e11682009-03-11 14:54:18 +0000218 // Set the board's GPI routing.
219 i82801gx_gpi_routing(dev);
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000220
Elyes HAOUAS71187012019-02-10 14:58:13 +0100221 write_pmbase32(GPE0_EN, config->gpe0_en);
222 write_pmbase16(ALT_GP_SMI_EN, config->alt_gp_smi_en);
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000223
224 /* Set up power management block and determine sleep mode */
Elyes HAOUAS71187012019-02-10 14:58:13 +0100225 reg32 = read_pmbase32(PM1_CNT);
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000226
227 reg32 &= ~(7 << 10); // SLP_TYP
228 reg32 |= (1 << 1); // enable C3->C0 transition on bus master
229 reg32 |= (1 << 0); // SCI_EN
Elyes HAOUAS71187012019-02-10 14:58:13 +0100230 write_pmbase32(PM1_CNT, reg32);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000231}
232
Elyes HAOUAS99667032018-05-13 12:47:28 +0200233static void i82801gx_configure_cstates(struct device *dev)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000234{
Angel Ponsd19332c2020-06-08 12:32:54 +0200235 // Enable Popup & Popdown
236 pci_or_config8(dev, 0xa9, (1 << 4) | (1 << 3) | (1 << 2));
Stefan Reinauera8e11682009-03-11 14:54:18 +0000237
238 // Set Deeper Sleep configuration to recommended values
Angel Ponsd19332c2020-06-08 12:32:54 +0200239 // Deeper Sleep to Stop CPU: 34-40us
240 // Deeper Sleep to Sleep: 15us
241 pci_update_config8(dev, 0xaa, 0xf0, (2 << 2) | (2 << 0));
Stefan Reinauera8e11682009-03-11 14:54:18 +0000242}
243
244static void i82801gx_rtc_init(struct device *dev)
245{
246 u8 reg8;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000247 int rtc_failed;
248
249 reg8 = pci_read_config8(dev, GEN_PMCON_3);
250 rtc_failed = reg8 & RTC_BATTERY_DEAD;
251 if (rtc_failed) {
252 reg8 &= ~RTC_BATTERY_DEAD;
253 pci_write_config8(dev, GEN_PMCON_3, reg8);
254 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000255 printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000256
Gabe Blackb3f08c62014-04-30 17:12:25 -0700257 cmos_init(rtc_failed);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000258}
259
Stefan Reinauera8e11682009-03-11 14:54:18 +0000260static void enable_clock_gating(void)
261{
262 u32 reg32;
Stefan Reinauer109ab312009-08-12 16:08:05 +0000263
Stefan Reinauera8e11682009-03-11 14:54:18 +0000264 /* Enable Clock Gating for most devices */
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000265 reg32 = RCBA32(CG);
Stefan Reinauera8e11682009-03-11 14:54:18 +0000266 reg32 |= (1 << 31); // LPC clock gating
267 reg32 |= (1 << 30); // PATA clock gating
268 // SATA clock gating
269 reg32 |= (1 << 27) | (1 << 26) | (1 << 25) | (1 << 24);
270 reg32 |= (1 << 23); // AC97 clock gating
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000271 reg32 |= (1 << 19); // USB EHCI clock gating
Stefan Reinauera8e11682009-03-11 14:54:18 +0000272 reg32 |= (1 << 3) | (1 << 1); // DMI clock gating
273 reg32 |= (1 << 2); // PCIe clock gating;
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000274 reg32 &= ~(1 << 20); // No static clock gating for USB
Arthur Heymans3f111b02017-03-09 12:02:52 +0100275 reg32 &= ~((1 << 29) | (1 << 28)); // Disable UHCI clock gating
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000276 RCBA32(CG) = reg32;
Stefan Reinauera8e11682009-03-11 14:54:18 +0000277}
Stefan Reinauer269563a2009-01-19 21:20:22 +0000278
Kyösti Mälkki83d6a8a2019-07-12 08:16:53 +0300279static void i82801gx_set_acpi_mode(struct device *dev)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000280{
Kyösti Mälkkiad882c32020-06-02 05:05:30 +0300281 if (!acpi_is_wakeup_s3()) {
282 apm_control(APM_CNT_ACPI_DISABLE);
283 } else {
284 apm_control(APM_CNT_ACPI_ENABLE);
Sven Schnellee2618072011-06-05 11:39:12 +0200285 }
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000286}
287
Stefan Reinauera8e11682009-03-11 14:54:18 +0000288static void i82801gx_spi_init(void)
289{
290 u16 spicontrol;
291
292 spicontrol = RCBA16(SPIBASE + 2);
293 spicontrol &= ~(1 << 0); // SPI Access Request
294 RCBA16(SPIBASE + 2) = spicontrol;
295}
296
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000297static void i82801gx_fixups(struct device *dev)
Stefan Reinauera8e11682009-03-11 14:54:18 +0000298{
299 /* This needs to happen after PCI enumeration */
300 RCBA32(0x1d40) |= 1;
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000301
302 /* USB Transient Disconnect Detect:
303 * Prevent a SE0 condition on the USB ports from being
304 * interpreted by the UHCI controller as a disconnect
305 */
306 pci_write_config8(dev, 0xad, 0x3);
Stefan Reinauera8e11682009-03-11 14:54:18 +0000307}
308
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000309static void lpc_init(struct device *dev)
310{
Elyes HAOUASbfc255a2020-03-07 13:05:14 +0100311 printk(BIOS_DEBUG, "i82801gx: %s\n", __func__);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000312
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000313 /* IO APIC initialization. */
Paul Menzelddddf152013-04-23 14:40:23 +0200314 i82801gx_enable_ioapic(dev);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000315
316 i82801gx_enable_serial_irqs(dev);
317
318 /* Setup the PIRQ. */
319 i82801gx_pirq_init(dev);
320
321 /* Setup power options. */
322 i82801gx_power_options(dev);
323
Stefan Reinauera8e11682009-03-11 14:54:18 +0000324 /* Configure Cx state registers */
325 i82801gx_configure_cstates(dev);
326
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000327 /* Initialize the real time clock. */
328 i82801gx_rtc_init(dev);
329
330 /* Initialize ISA DMA. */
331 isa_dma_init();
332
333 /* Initialize the High Precision Event Timers, if present. */
Stefan Reinauera8e11682009-03-11 14:54:18 +0000334 enable_hpet();
335
336 /* Initialize Clock Gating */
337 enable_clock_gating();
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000338
339 setup_i8259();
340
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000341 /* The OS should do this? */
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000342 /* Interrupt 9 should be level triggered (SCI) */
343 i8259_configure_irq_trigger(9, 1);
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000344
Kyösti Mälkki44da9e72019-10-09 12:32:16 +0300345 i82801gx_set_acpi_mode(dev);
Stefan Reinauera8e11682009-03-11 14:54:18 +0000346
347 i82801gx_spi_init();
348
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000349 i82801gx_fixups(dev);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000350}
351
Vladimir Serbinenkod5d94ea2014-10-18 02:13:11 +0200352unsigned long acpi_fill_madt(unsigned long current)
353{
Vladimir Serbinenkod5d94ea2014-10-18 02:13:11 +0200354 /* IOAPIC */
Kyösti Mälkkic0457352021-06-08 06:12:25 +0300355 current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current, IO_APIC_ADDR);
Vladimir Serbinenkod5d94ea2014-10-18 02:13:11 +0200356
Vladimir Serbinenkod5d94ea2014-10-18 02:13:11 +0200357 /* INT_SRC_OVR */
358 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
359 current, 0, 0, 2, MP_IRQ_POLARITY_HIGH | MP_IRQ_TRIGGER_EDGE);
360 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
361 current, 0, 9, 9, MP_IRQ_POLARITY_HIGH | MP_IRQ_TRIGGER_LEVEL);
362
Vladimir Serbinenkod5d94ea2014-10-18 02:13:11 +0200363 return current;
364}
365
Elyes HAOUAS99667032018-05-13 12:47:28 +0200366static void i82801gx_lpc_read_resources(struct device *dev)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000367{
368 struct resource *res;
Vladimir Serbinenkof119f082014-11-24 21:05:56 +0100369 u8 io_index = 0;
370 int i;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000371
372 /* Get the normal PCI resources of this device. */
373 pci_dev_read_resources(dev);
374
375 /* Add an extra subtractive resource for both memory and I/O. */
Vladimir Serbinenkof119f082014-11-24 21:05:56 +0100376 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
Myles Watson29cc9ed2009-07-02 18:56:24 +0000377 res->base = 0;
378 res->size = 0x1000;
379 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
380 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000381
Vladimir Serbinenkof119f082014-11-24 21:05:56 +0100382 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
Myles Watson29cc9ed2009-07-02 18:56:24 +0000383 res->base = 0xff800000;
384 res->size = 0x00800000; /* 8 MB for flash */
385 res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE |
386 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
387
388 res = new_resource(dev, 3); /* IOAPIC */
Uwe Hermann74d1a6e2010-10-12 17:34:08 +0000389 res->base = IO_APIC_ADDR;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000390 res->size = 0x00001000;
391 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
Vladimir Serbinenkof119f082014-11-24 21:05:56 +0100392
393 /* Set IO decode ranges if required.*/
394 for (i = 0; i < 4; i++) {
395 u32 gen_dec;
396 gen_dec = pci_read_config32(dev, 0x84 + 4 * i);
397
398 if ((gen_dec & 0xFFFC) > 0x1000) {
399 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
400 res->base = gen_dec & 0xFFFC;
401 res->size = (gen_dec >> 16) & 0xFC;
402 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
403 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
404 }
405 }
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000406}
407
Arthur Heymans36646472018-01-22 14:42:18 +0100408static void lpc_final(struct device *dev)
409{
410 u16 tco1_cnt;
411
Julius Wernercd49cce2019-03-05 16:53:33 -0800412 if (!CONFIG(INTEL_CHIPSET_LOCKDOWN))
Arthur Heymans36646472018-01-22 14:42:18 +0100413 return;
414
Arthur Heymans767de0a2019-11-15 19:19:53 +0100415 if (CONFIG(BOOT_DEVICE_SPI_FLASH))
416 spi_finalize_ops();
Arthur Heymans36646472018-01-22 14:42:18 +0100417
418 /* Lock SPIBAR */
419 SPIBAR16(0) = SPIBAR16(0) | (1 << 15);
420
421 /* BIOS Interface Lockdown */
422 RCBA32(0x3410) |= 1 << 0;
423
424 /* Global SMI Lock */
425 pci_or_config16(dev, GEN_PMCON_1, 1 << 4);
426
427 /* TCO_Lock */
Kyösti Mälkkif38f30a2022-11-25 06:22:10 +0200428 tco1_cnt = inw(DEFAULT_PMBASE + 0x60 + TCO1_CNT);
Arthur Heymans36646472018-01-22 14:42:18 +0100429 tco1_cnt |= (1 << 12); /* TCO lock */
Kyösti Mälkkif38f30a2022-11-25 06:22:10 +0200430 outw(tco1_cnt, DEFAULT_PMBASE + 0x60 + TCO1_CNT);
Arthur Heymans36646472018-01-22 14:42:18 +0100431
432 /* Indicate finalize step with post code */
Elyes Haouas33477202022-11-22 15:15:21 +0100433 post_code(POST_OS_BOOT);
Arthur Heymans36646472018-01-22 14:42:18 +0100434}
435
Arthur Heymansa8a9f342017-12-24 08:11:13 +0100436static const char *lpc_acpi_name(const struct device *dev)
437{
438 return "LPCB";
439}
440
Furquan Shaikh7536a392020-04-24 21:59:21 -0700441static void southbridge_fill_ssdt(const struct device *device)
Arthur Heymansa8a9f342017-12-24 08:11:13 +0100442{
443 intel_acpi_gen_def_acpi_pirq(device);
444}
445
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000446static struct device_operations device_ops = {
447 .read_resources = i82801gx_lpc_read_resources,
448 .set_resources = pci_dev_set_resources,
Myles Watson7eac4452010-06-17 16:16:56 +0000449 .enable_resources = pci_dev_enable_resources,
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200450 .write_acpi_tables = acpi_write_hpet,
Nico Huber68680dd2020-03-31 17:34:52 +0200451 .acpi_fill_ssdt = southbridge_fill_ssdt,
Arthur Heymansa8a9f342017-12-24 08:11:13 +0100452 .acpi_name = lpc_acpi_name,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000453 .init = lpc_init,
Nico Huber51b75ae2019-03-14 16:02:05 +0100454 .scan_bus = scan_static_bus,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000455 .enable = i82801gx_enable,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200456 .ops_pci = &pci_dev_ops_pci,
Arthur Heymans36646472018-01-22 14:42:18 +0100457 .final = lpc_final,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000458};
459
Damien Zammitef33e032015-11-14 01:03:39 +1100460static const unsigned short pci_device_ids[] = {
Elyes HAOUAS92646ea2020-04-04 13:43:03 +0200461 0x27b0, /* 82801GH (ICH7 DH) */
462 0x27b8, /* 82801GB/GR (ICH7/ICH7R) */
463 0x27b9, /* 82801GBM/GU (ICH7-M/ICH7-U) */
464 0x27bc, /* 82NM10 (NM10) */
465 0x27bd, /* 82801GHM (ICH7-M DH) */
466 0
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000467};
468
Damien Zammitef33e032015-11-14 01:03:39 +1100469static const struct pci_driver ich7_lpc __pci_driver = {
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000470 .ops = &device_ops,
Felix Singer43b7f412022-03-07 04:34:52 +0100471 .vendor = PCI_VID_INTEL,
Damien Zammitef33e032015-11-14 01:03:39 +1100472 .devices = pci_device_ids,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000473};
Arthur Heymans98c92572022-11-07 11:39:58 +0100474
475bool southbridge_support_c5(void)
476{
477 return false;
478}
479
480bool southbridge_support_c6(void)
481{
482 return false;
483}