blob: 0330af0060ef02620411422c5831c64bac854b4b [file] [log] [blame]
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00001/*
2 * This file is part of the coreboot project.
3 *
Stefan Reinauer54309d62009-01-20 22:53:10 +00004 * Copyright (C) 2008-2009 coresystems GmbH
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00005 *
Stefan Reinauera8e11682009-03-11 14:54:18 +00006 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000010 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000015 */
16
17#include <console/console.h>
18#include <device/device.h>
19#include <device/pci.h>
20#include <device/pci_ids.h>
21#include <pc80/mc146818rtc.h>
22#include <pc80/isa-dma.h>
Stefan Reinauer54309d62009-01-20 22:53:10 +000023#include <pc80/i8259.h>
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000024#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020025#include <device/pci_ops.h>
Uwe Hermann74d1a6e2010-10-12 17:34:08 +000026#include <arch/ioapic.h>
Stefan Reinauerab872542011-10-14 15:18:29 -070027#include <arch/acpi.h>
Sven Schnellef4dc1a72011-06-05 11:33:41 +020028#include <cpu/x86/smm.h>
Vladimir Serbinenko0e646172014-08-31 00:27:05 +020029#include <arch/acpigen.h>
Vladimir Serbinenkod5d94ea2014-10-18 02:13:11 +020030#include <arch/smp/mpspec.h>
Vladimir Serbinenko0e646172014-08-31 00:27:05 +020031#include <cbmem.h>
32#include <string.h>
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +010033#include <drivers/intel/gma/i915.h>
Arthur Heymansa8a9f342017-12-24 08:11:13 +010034#include <southbridge/intel/common/acpi_pirq_gen.h>
Elyes HAOUAS71187012019-02-10 14:58:13 +010035#include <southbridge/intel/common/pmbase.h>
Arthur Heymansb429c5b2019-05-28 13:24:15 +020036#include <southbridge/intel/common/spi.h>
Elyes HAOUAS71187012019-02-10 14:58:13 +010037
Arthur Heymans742df5a2019-06-03 16:24:41 +020038#include "chip.h"
Elyes HAOUAS71187012019-02-10 14:58:13 +010039#include "i82801gx.h"
Vladimir Serbinenko0e646172014-08-31 00:27:05 +020040#include "nvs.h"
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000041
Stefan Reinauer573f7d42009-07-21 21:50:34 +000042#define NMI_OFF 0
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000043
Stefan Reinauer54309d62009-01-20 22:53:10 +000044typedef struct southbridge_intel_i82801gx_config config_t;
45
Paul Menzelddddf152013-04-23 14:40:23 +020046/**
Martin Roth2ed0aa22016-01-05 20:58:58 -070047 * Set miscellaneous static southbridge features.
Paul Menzelddddf152013-04-23 14:40:23 +020048 *
49 * @param dev PCI device with I/O APIC control registers
50 */
51static void i82801gx_enable_ioapic(struct device *dev)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000052{
Paul Menzelddddf152013-04-23 14:40:23 +020053 /* Enable ACPI I/O range decode */
Kyösti Mälkki1cca3402013-02-26 19:21:39 +020054 pci_write_config8(dev, ACPI_CNTL, ACPI_EN);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000055
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080056 set_ioapic_id(VIO_APIC_VADDR, 0x02);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000057
Paul Menzelddddf152013-04-23 14:40:23 +020058 /*
59 * Select Boot Configuration register (0x03) and
60 * use Processor System Bus (0x01) to deliver interrupts.
61 */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080062 io_apic_write(VIO_APIC_VADDR, 0x03, 0x01);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000063}
64
65static void i82801gx_enable_serial_irqs(struct device *dev)
66{
67 /* Set packet length and toggle silent mode bit for one frame. */
68 pci_write_config8(dev, SERIRQ_CNTL,
69 (1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0));
70}
71
Stefan Reinauer573f7d42009-07-21 21:50:34 +000072/* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control
73 * 0x00 - 0000 = Reserved
74 * 0x01 - 0001 = Reserved
75 * 0x02 - 0010 = Reserved
76 * 0x03 - 0011 = IRQ3
77 * 0x04 - 0100 = IRQ4
78 * 0x05 - 0101 = IRQ5
79 * 0x06 - 0110 = IRQ6
80 * 0x07 - 0111 = IRQ7
81 * 0x08 - 1000 = Reserved
82 * 0x09 - 1001 = IRQ9
83 * 0x0A - 1010 = IRQ10
84 * 0x0B - 1011 = IRQ11
85 * 0x0C - 1100 = IRQ12
86 * 0x0D - 1101 = Reserved
87 * 0x0E - 1110 = IRQ14
88 * 0x0F - 1111 = IRQ15
89 * PIRQ[n]_ROUT[7] - PIRQ Routing Control
90 * 0x80 - The PIRQ is not routed.
91 */
92
Elyes HAOUAS99667032018-05-13 12:47:28 +020093static void i82801gx_pirq_init(struct device *dev)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000094{
Elyes HAOUAS99667032018-05-13 12:47:28 +020095 struct device *irq_dev;
Stefan Reinauer54309d62009-01-20 22:53:10 +000096 /* Get the chip configuration */
97 config_t *config = dev->chip_info;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000098
Stefan Reinauer54309d62009-01-20 22:53:10 +000099 pci_write_config8(dev, PIRQA_ROUT, config->pirqa_routing);
100 pci_write_config8(dev, PIRQB_ROUT, config->pirqb_routing);
101 pci_write_config8(dev, PIRQC_ROUT, config->pirqc_routing);
102 pci_write_config8(dev, PIRQD_ROUT, config->pirqd_routing);
103
104 pci_write_config8(dev, PIRQE_ROUT, config->pirqe_routing);
105 pci_write_config8(dev, PIRQF_ROUT, config->pirqf_routing);
106 pci_write_config8(dev, PIRQG_ROUT, config->pirqg_routing);
107 pci_write_config8(dev, PIRQH_ROUT, config->pirqh_routing);
108
109 /* Eric Biederman once said we should let the OS do this.
110 * I am not so sure anymore he was right.
111 */
112
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200113 for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
Arthur Heymans3f111b02017-03-09 12:02:52 +0100114 u8 int_pin = 0, int_line = 0;
Stefan Reinauer54309d62009-01-20 22:53:10 +0000115
116 if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI)
117 continue;
118
119 int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
120
121 switch (int_pin) {
Arthur Heymans3f111b02017-03-09 12:02:52 +0100122 case 1:
123 /* INTA# */ int_line = config->pirqa_routing; break;
124 case 2:
125 /* INTB# */ int_line = config->pirqb_routing; break;
126 case 3:
127 /* INTC# */ int_line = config->pirqc_routing; break;
128 case 4:
129 /* INTD# */ int_line = config->pirqd_routing; break;
Stefan Reinauer54309d62009-01-20 22:53:10 +0000130 }
131
132 if (!int_line)
133 continue;
134
135 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line);
136 }
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000137}
138
Elyes HAOUAS99667032018-05-13 12:47:28 +0200139static void i82801gx_gpi_routing(struct device *dev)
Stefan Reinauera8e11682009-03-11 14:54:18 +0000140{
141 /* Get the chip configuration */
142 config_t *config = dev->chip_info;
143 u32 reg32 = 0;
144
145 /* An array would be much nicer here, or some
146 * other method of doing this.
147 */
148 reg32 |= (config->gpi0_routing & 0x03) << 0;
149 reg32 |= (config->gpi1_routing & 0x03) << 2;
150 reg32 |= (config->gpi2_routing & 0x03) << 4;
151 reg32 |= (config->gpi3_routing & 0x03) << 6;
152 reg32 |= (config->gpi4_routing & 0x03) << 8;
153 reg32 |= (config->gpi5_routing & 0x03) << 10;
154 reg32 |= (config->gpi6_routing & 0x03) << 12;
155 reg32 |= (config->gpi7_routing & 0x03) << 14;
156 reg32 |= (config->gpi8_routing & 0x03) << 16;
157 reg32 |= (config->gpi9_routing & 0x03) << 18;
158 reg32 |= (config->gpi10_routing & 0x03) << 20;
159 reg32 |= (config->gpi11_routing & 0x03) << 22;
160 reg32 |= (config->gpi12_routing & 0x03) << 24;
161 reg32 |= (config->gpi13_routing & 0x03) << 26;
162 reg32 |= (config->gpi14_routing & 0x03) << 28;
163 reg32 |= (config->gpi15_routing & 0x03) << 30;
164
Kyösti Mälkkib85a87b2014-12-29 11:32:27 +0200165 pci_write_config32(dev, GPIO_ROUT, reg32);
Stefan Reinauera8e11682009-03-11 14:54:18 +0000166}
167
Elyes HAOUAS99667032018-05-13 12:47:28 +0200168static void i82801gx_power_options(struct device *dev)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000169{
170 u8 reg8;
Elyes HAOUAS71187012019-02-10 14:58:13 +0100171 u16 reg16;
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000172 u32 reg32;
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000173 const char *state;
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000174 /* Get the chip configuration */
175 config_t *config = dev->chip_info;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000176
Nico Huber9faae2b2018-11-14 00:00:35 +0100177 int pwr_on = CONFIG_MAINBOARD_POWER_FAILURE_STATE;
Luc Verhaegena9c5ea02009-06-03 14:19:33 +0000178 int nmi_option;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000179
180 /* Which state do we want to goto after g3 (power restored)?
181 * 0 == S0 Full On
182 * 1 == S5 Soft Off
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000183 *
184 * If the option is not existent (Laptops), use MAINBOARD_POWER_ON.
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000185 */
Varad Gautam06ef0462015-03-11 09:54:41 +0530186 pwr_on = MAINBOARD_POWER_ON;
187 get_option(&pwr_on, "power_on_after_fail");
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000188
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000189 reg8 = pci_read_config8(dev, GEN_PMCON_3);
190 reg8 &= 0xfe;
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000191 switch (pwr_on) {
192 case MAINBOARD_POWER_OFF:
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000193 reg8 |= 1;
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000194 state = "off";
195 break;
196 case MAINBOARD_POWER_ON:
197 reg8 &= ~1;
198 state = "on";
199 break;
200 case MAINBOARD_POWER_KEEP:
201 reg8 &= ~1;
202 state = "state keep";
203 break;
204 default:
205 state = "undefined";
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000206 }
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000207
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000208 reg8 |= (3 << 4); /* avoid #S4 assertions */
Martin Roth2ed0aa22016-01-05 20:58:58 -0700209 reg8 &= ~(1 << 3); /* minimum assertion is 1 to 2 RTCCLK */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000210
211 pci_write_config8(dev, GEN_PMCON_3, reg8);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000212 printk(BIOS_INFO, "Set power %s after power failure.\n", state);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000213
214 /* Set up NMI on errors. */
215 reg8 = inb(0x61);
216 reg8 &= 0x0f; /* Higher Nibble must be 0 */
217 reg8 &= ~(1 << 3); /* IOCHK# NMI Enable */
218 // reg8 &= ~(1 << 2); /* PCI SERR# Enable */
219 reg8 |= (1 << 2); /* PCI SERR# Disable for now */
220 outb(reg8, 0x61);
221
222 reg8 = inb(0x70);
223 nmi_option = NMI_OFF;
Luc Verhaegena9c5ea02009-06-03 14:19:33 +0000224 get_option(&nmi_option, "nmi");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000225 if (nmi_option) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000226 printk(BIOS_INFO, "NMI sources enabled.\n");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000227 reg8 &= ~(1 << 7); /* Set NMI. */
228 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000229 printk(BIOS_INFO, "NMI sources disabled.\n");
Arthur Heymans3f111b02017-03-09 12:02:52 +0100230 reg8 |= (1 << 7); /* Can't mask NMI from PCI-E and NMI_NOW */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000231 }
232 outb(reg8, 0x70);
233
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000234 /* Enable CPU_SLP# and Intel Speedstep, set SMI# rate down */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000235 reg16 = pci_read_config16(dev, GEN_PMCON_1);
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000236 reg16 &= ~(3 << 0); // SMI# rate 1 minute
237 reg16 |= (1 << 2); // CLKRUN_EN - Mobile/Ultra only
238 reg16 |= (1 << 3); // Speedstep Enable - Mobile/Ultra only
239 reg16 |= (1 << 5); // CPUSLP_EN Desktop only
Sven Schnelle906f9ae2011-10-23 16:35:01 +0200240
241 if (config->c4onc3_enable)
242 reg16 |= (1 << 7);
243
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000244 // another laptop wants this?
245 // reg16 &= ~(1 << 10); // BIOS_PCI_EXP_EN - Desktop/Mobile only
246 reg16 |= (1 << 10); // BIOS_PCI_EXP_EN - Desktop/Mobile only
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000247#if DEBUG_PERIODIC_SMIS
248 /* Set DEBUG_PERIODIC_SMIS in i82801gx.h to debug using
249 * periodic SMIs.
250 */
251 reg16 |= (3 << 0); // Periodic SMI every 8s
252#endif
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000253 pci_write_config16(dev, GEN_PMCON_1, reg16);
254
Stefan Reinauera8e11682009-03-11 14:54:18 +0000255 // Set the board's GPI routing.
256 i82801gx_gpi_routing(dev);
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000257
Elyes HAOUAS71187012019-02-10 14:58:13 +0100258 write_pmbase32(GPE0_EN, config->gpe0_en);
259 write_pmbase16(ALT_GP_SMI_EN, config->alt_gp_smi_en);
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000260
261 /* Set up power management block and determine sleep mode */
Elyes HAOUAS71187012019-02-10 14:58:13 +0100262 reg32 = read_pmbase32(PM1_CNT);
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000263
264 reg32 &= ~(7 << 10); // SLP_TYP
265 reg32 |= (1 << 1); // enable C3->C0 transition on bus master
266 reg32 |= (1 << 0); // SCI_EN
Elyes HAOUAS71187012019-02-10 14:58:13 +0100267 write_pmbase32(PM1_CNT, reg32);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000268}
269
Elyes HAOUAS99667032018-05-13 12:47:28 +0200270static void i82801gx_configure_cstates(struct device *dev)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000271{
272 u8 reg8;
Stefan Reinauer109ab312009-08-12 16:08:05 +0000273
Stefan Reinauera8e11682009-03-11 14:54:18 +0000274 reg8 = pci_read_config8(dev, 0xa9); // Cx state configuration
275 reg8 |= (1 << 4) | (1 << 3) | (1 << 2); // Enable Popup & Popdown
276 pci_write_config8(dev, 0xa9, reg8);
277
278 // Set Deeper Sleep configuration to recommended values
279 reg8 = pci_read_config8(dev, 0xaa);
280 reg8 &= 0xf0;
281 reg8 |= (2 << 2); // Deeper Sleep to Stop CPU: 34-40us
282 reg8 |= (2 << 0); // Deeper Sleep to Sleep: 15us
283 pci_write_config8(dev, 0xaa, reg8);
284}
285
286static void i82801gx_rtc_init(struct device *dev)
287{
288 u8 reg8;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000289 int rtc_failed;
290
291 reg8 = pci_read_config8(dev, GEN_PMCON_3);
292 rtc_failed = reg8 & RTC_BATTERY_DEAD;
293 if (rtc_failed) {
294 reg8 &= ~RTC_BATTERY_DEAD;
295 pci_write_config8(dev, GEN_PMCON_3, reg8);
296 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000297 printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000298
Gabe Blackb3f08c62014-04-30 17:12:25 -0700299 cmos_init(rtc_failed);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000300}
301
Stefan Reinauera8e11682009-03-11 14:54:18 +0000302static void enable_hpet(void)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000303{
Stefan Reinauera8e11682009-03-11 14:54:18 +0000304 u32 reg32;
Stefan Reinauer109ab312009-08-12 16:08:05 +0000305
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000306 /* Move HPET to default address 0xfed00000 and enable it */
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000307 reg32 = RCBA32(HPTC);
Stefan Reinauera8e11682009-03-11 14:54:18 +0000308 reg32 |= (1 << 7); // HPET Address Enable
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000309 reg32 &= ~(3 << 0);
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000310 RCBA32(HPTC) = reg32;
Arthur Heymansc73c9232019-10-02 14:57:50 +0200311 /* On NM10 this only works if read back */
312 RCBA32(HPTC);
313
314 write32((u32 *)0xfed00010, read32((u32 *)0xfed00010) | 1);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000315}
316
Stefan Reinauera8e11682009-03-11 14:54:18 +0000317static void enable_clock_gating(void)
318{
319 u32 reg32;
Stefan Reinauer109ab312009-08-12 16:08:05 +0000320
Stefan Reinauera8e11682009-03-11 14:54:18 +0000321 /* Enable Clock Gating for most devices */
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000322 reg32 = RCBA32(CG);
Stefan Reinauera8e11682009-03-11 14:54:18 +0000323 reg32 |= (1 << 31); // LPC clock gating
324 reg32 |= (1 << 30); // PATA clock gating
325 // SATA clock gating
326 reg32 |= (1 << 27) | (1 << 26) | (1 << 25) | (1 << 24);
327 reg32 |= (1 << 23); // AC97 clock gating
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000328 reg32 |= (1 << 19); // USB EHCI clock gating
Stefan Reinauera8e11682009-03-11 14:54:18 +0000329 reg32 |= (1 << 3) | (1 << 1); // DMI clock gating
330 reg32 |= (1 << 2); // PCIe clock gating;
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000331 reg32 &= ~(1 << 20); // No static clock gating for USB
Arthur Heymans3f111b02017-03-09 12:02:52 +0100332 reg32 &= ~((1 << 29) | (1 << 28)); // Disable UHCI clock gating
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000333 RCBA32(CG) = reg32;
Stefan Reinauera8e11682009-03-11 14:54:18 +0000334}
Stefan Reinauer269563a2009-01-19 21:20:22 +0000335
Kyösti Mälkki83d6a8a2019-07-12 08:16:53 +0300336static void i82801gx_set_acpi_mode(struct device *dev)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000337{
Kyösti Mälkki44da9e72019-10-09 12:32:16 +0300338 if (CONFIG(HAVE_SMI_HANDLER)) {
339 if (!acpi_is_wakeup_s3()) {
340 printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n");
341 outb(APM_CNT_ACPI_DISABLE, APM_CNT); // Disable ACPI mode
342 printk(BIOS_DEBUG, "done.\n");
343 } else {
344 printk(BIOS_DEBUG, "S3 wakeup, enabling ACPI via APMC\n");
345 outb(APM_CNT_ACPI_ENABLE, APM_CNT);
346 }
Sven Schnellee2618072011-06-05 11:39:12 +0200347 }
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000348}
349
Stefan Reinauera8e11682009-03-11 14:54:18 +0000350#define SPIBASE 0x3020
351static void i82801gx_spi_init(void)
352{
353 u16 spicontrol;
354
355 spicontrol = RCBA16(SPIBASE + 2);
356 spicontrol &= ~(1 << 0); // SPI Access Request
357 RCBA16(SPIBASE + 2) = spicontrol;
358}
359
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000360static void i82801gx_fixups(struct device *dev)
Stefan Reinauera8e11682009-03-11 14:54:18 +0000361{
362 /* This needs to happen after PCI enumeration */
363 RCBA32(0x1d40) |= 1;
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000364
365 /* USB Transient Disconnect Detect:
366 * Prevent a SE0 condition on the USB ports from being
367 * interpreted by the UHCI controller as a disconnect
368 */
369 pci_write_config8(dev, 0xad, 0x3);
Stefan Reinauera8e11682009-03-11 14:54:18 +0000370}
371
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000372static void lpc_init(struct device *dev)
373{
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000374 printk(BIOS_DEBUG, "i82801gx: lpc_init\n");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000375
376 /* Set the value for PCI command register. */
377 pci_write_config16(dev, PCI_COMMAND, 0x000f);
378
379 /* IO APIC initialization. */
Paul Menzelddddf152013-04-23 14:40:23 +0200380 i82801gx_enable_ioapic(dev);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000381
382 i82801gx_enable_serial_irqs(dev);
383
384 /* Setup the PIRQ. */
385 i82801gx_pirq_init(dev);
386
387 /* Setup power options. */
388 i82801gx_power_options(dev);
389
Stefan Reinauera8e11682009-03-11 14:54:18 +0000390 /* Configure Cx state registers */
391 i82801gx_configure_cstates(dev);
392
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000393 /* Set the state of the GPIO lines. */
394 //gpio_init(dev);
395
396 /* Initialize the real time clock. */
397 i82801gx_rtc_init(dev);
398
399 /* Initialize ISA DMA. */
400 isa_dma_init();
401
402 /* Initialize the High Precision Event Timers, if present. */
Stefan Reinauera8e11682009-03-11 14:54:18 +0000403 enable_hpet();
404
405 /* Initialize Clock Gating */
406 enable_clock_gating();
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000407
408 setup_i8259();
409
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000410 /* The OS should do this? */
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000411 /* Interrupt 9 should be level triggered (SCI) */
412 i8259_configure_irq_trigger(9, 1);
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000413
Kyösti Mälkki44da9e72019-10-09 12:32:16 +0300414 i82801gx_set_acpi_mode(dev);
Stefan Reinauera8e11682009-03-11 14:54:18 +0000415
416 i82801gx_spi_init();
417
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000418 i82801gx_fixups(dev);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000419}
420
Vladimir Serbinenkod5d94ea2014-10-18 02:13:11 +0200421unsigned long acpi_fill_madt(unsigned long current)
422{
423 /* Local APICs */
424 current = acpi_create_madt_lapics(current);
425
426 /* IOAPIC */
427 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
428 2, IO_APIC_ADDR, 0);
429
430 /* LAPIC_NMI */
431 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)
432 current, 0,
433 MP_IRQ_POLARITY_HIGH |
434 MP_IRQ_TRIGGER_EDGE, 0x01);
435 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)
436 current, 1, MP_IRQ_POLARITY_HIGH |
437 MP_IRQ_TRIGGER_EDGE, 0x01);
438
439 /* INT_SRC_OVR */
440 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
441 current, 0, 0, 2, MP_IRQ_POLARITY_HIGH | MP_IRQ_TRIGGER_EDGE);
442 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
443 current, 0, 9, 9, MP_IRQ_POLARITY_HIGH | MP_IRQ_TRIGGER_LEVEL);
444
445
446 return current;
447}
448
Arthur Heymans3f111b02017-03-09 12:02:52 +0100449void acpi_fill_fadt(acpi_fadt_t *fadt)
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200450{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300451 struct device *dev = pcidev_on_root(0x1f, 0);
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200452 config_t *chip = dev->chip_info;
Elyes HAOUAS71187012019-02-10 14:58:13 +0100453 u16 pmbase = lpc_get_pmbase();
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200454
455 fadt->pm1a_evt_blk = pmbase;
456 fadt->pm1b_evt_blk = 0x0;
Elyes HAOUAS71187012019-02-10 14:58:13 +0100457 fadt->pm1a_cnt_blk = pmbase + PM1_CNT;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200458 fadt->pm1b_cnt_blk = 0x0;
Elyes HAOUAS71187012019-02-10 14:58:13 +0100459 fadt->pm2_cnt_blk = pmbase + PM2_CNT;
460 fadt->pm_tmr_blk = pmbase + PM1_TMR;
461 fadt->gpe0_blk = pmbase + GPE0_STS;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200462 fadt->gpe1_blk = 0;
463
464 fadt->pm1_evt_len = 4;
465 fadt->pm1_cnt_len = 2;
466 fadt->pm2_cnt_len = 1;
467 fadt->pm_tmr_len = 4;
468 fadt->gpe0_blk_len = 8;
469 fadt->gpe1_blk_len = 0;
470 fadt->gpe1_base = 0;
471
472 fadt->reset_reg.space_id = 1;
473 fadt->reset_reg.bit_width = 8;
474 fadt->reset_reg.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200475 fadt->reset_reg.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200476 fadt->reset_reg.addrl = 0xcf9;
477 fadt->reset_reg.addrh = 0;
478
479 fadt->reset_value = 6;
480
481 fadt->x_pm1a_evt_blk.space_id = 1;
482 fadt->x_pm1a_evt_blk.bit_width = 32;
483 fadt->x_pm1a_evt_blk.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200484 fadt->x_pm1a_evt_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200485 fadt->x_pm1a_evt_blk.addrl = pmbase;
486 fadt->x_pm1a_evt_blk.addrh = 0x0;
487
488 fadt->x_pm1b_evt_blk.space_id = 0;
489 fadt->x_pm1b_evt_blk.bit_width = 0;
490 fadt->x_pm1b_evt_blk.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200491 fadt->x_pm1b_evt_blk.access_size = 0;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200492 fadt->x_pm1b_evt_blk.addrl = 0x0;
493 fadt->x_pm1b_evt_blk.addrh = 0x0;
494
495 fadt->x_pm1a_cnt_blk.space_id = 1;
496 fadt->x_pm1a_cnt_blk.bit_width = 16;
497 fadt->x_pm1a_cnt_blk.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200498 fadt->x_pm1a_cnt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS;
Elyes HAOUAS71187012019-02-10 14:58:13 +0100499 fadt->x_pm1a_cnt_blk.addrl = pmbase + PM1_CNT;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200500 fadt->x_pm1a_cnt_blk.addrh = 0x0;
501
502 fadt->x_pm1b_cnt_blk.space_id = 0;
503 fadt->x_pm1b_cnt_blk.bit_width = 0;
504 fadt->x_pm1b_cnt_blk.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200505 fadt->x_pm1b_cnt_blk.access_size = 0;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200506 fadt->x_pm1b_cnt_blk.addrl = 0x0;
507 fadt->x_pm1b_cnt_blk.addrh = 0x0;
508
509 fadt->x_pm2_cnt_blk.space_id = 1;
510 fadt->x_pm2_cnt_blk.bit_width = 8;
511 fadt->x_pm2_cnt_blk.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200512 fadt->x_pm2_cnt_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
Elyes HAOUAS71187012019-02-10 14:58:13 +0100513 fadt->x_pm2_cnt_blk.addrl = pmbase + PM2_CNT;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200514 fadt->x_pm2_cnt_blk.addrh = 0x0;
515
516 fadt->x_pm_tmr_blk.space_id = 1;
517 fadt->x_pm_tmr_blk.bit_width = 32;
518 fadt->x_pm_tmr_blk.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200519 fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
Elyes HAOUAS71187012019-02-10 14:58:13 +0100520 fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200521 fadt->x_pm_tmr_blk.addrh = 0x0;
522
523 fadt->x_gpe0_blk.space_id = 1;
524 fadt->x_gpe0_blk.bit_width = 64;
525 fadt->x_gpe0_blk.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200526 fadt->x_gpe0_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
Elyes HAOUAS71187012019-02-10 14:58:13 +0100527 fadt->x_gpe0_blk.addrl = pmbase + GPE0_STS;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200528 fadt->x_gpe0_blk.addrh = 0x0;
529
530 fadt->x_gpe1_blk.space_id = 0;
531 fadt->x_gpe1_blk.bit_width = 0;
532 fadt->x_gpe1_blk.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200533 fadt->x_gpe1_blk.access_size = 0;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200534 fadt->x_gpe1_blk.addrl = 0x0;
535 fadt->x_gpe1_blk.addrh = 0x0;
536 fadt->day_alrm = 0xd;
537 fadt->mon_alrm = 0x00;
538 fadt->century = 0x32;
539
Elyes HAOUAS0d4de2a2019-02-28 13:04:29 +0100540 fadt->reserved = 0;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200541 fadt->sci_int = 0x9;
542 fadt->smi_cmd = APM_CNT;
543 fadt->acpi_enable = APM_CNT_ACPI_ENABLE;
544 fadt->acpi_disable = APM_CNT_ACPI_DISABLE;
545 fadt->s4bios_req = 0x0;
546 fadt->pstate_cnt = APM_CNT_PST_CONTROL;
547
548 fadt->cst_cnt = APM_CNT_CST_CONTROL;
549 fadt->p_lvl2_lat = 1;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200550 fadt->p_lvl3_lat = chip->c3_latency;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200551 fadt->flush_size = 0;
552 fadt->flush_stride = 0;
553 fadt->duty_offset = 1;
Arthur Heymans3f111b02017-03-09 12:02:52 +0100554 if (chip->p_cnt_throttling_supported)
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200555 fadt->duty_width = 3;
Arthur Heymans3f111b02017-03-09 12:02:52 +0100556 else
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200557 fadt->duty_width = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200558 fadt->iapc_boot_arch = 0x03;
559 fadt->flags = (ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED
560 | ACPI_FADT_SLEEP_BUTTON | ACPI_FADT_S4_RTC_WAKE
561 | ACPI_FADT_PLATFORM_CLOCK | ACPI_FADT_RESET_REGISTER
562 | ACPI_FADT_C2_MP_SUPPORTED);
Arthur Heymans3f111b02017-03-09 12:02:52 +0100563 if (chip->docking_supported)
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200564 fadt->flags |= ACPI_FADT_DOCKING_SUPPORTED;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200565}
566
Elyes HAOUAS99667032018-05-13 12:47:28 +0200567static void i82801gx_lpc_read_resources(struct device *dev)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000568{
569 struct resource *res;
Vladimir Serbinenkof119f082014-11-24 21:05:56 +0100570 u8 io_index = 0;
571 int i;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000572
573 /* Get the normal PCI resources of this device. */
574 pci_dev_read_resources(dev);
575
576 /* Add an extra subtractive resource for both memory and I/O. */
Vladimir Serbinenkof119f082014-11-24 21:05:56 +0100577 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
Myles Watson29cc9ed2009-07-02 18:56:24 +0000578 res->base = 0;
579 res->size = 0x1000;
580 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
581 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000582
Vladimir Serbinenkof119f082014-11-24 21:05:56 +0100583 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
Myles Watson29cc9ed2009-07-02 18:56:24 +0000584 res->base = 0xff800000;
585 res->size = 0x00800000; /* 8 MB for flash */
586 res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE |
587 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
588
589 res = new_resource(dev, 3); /* IOAPIC */
Uwe Hermann74d1a6e2010-10-12 17:34:08 +0000590 res->base = IO_APIC_ADDR;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000591 res->size = 0x00001000;
592 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
Vladimir Serbinenkof119f082014-11-24 21:05:56 +0100593
594 /* Set IO decode ranges if required.*/
595 for (i = 0; i < 4; i++) {
596 u32 gen_dec;
597 gen_dec = pci_read_config32(dev, 0x84 + 4 * i);
598
599 if ((gen_dec & 0xFFFC) > 0x1000) {
600 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
601 res->base = gen_dec & 0xFFFC;
602 res->size = (gen_dec >> 16) & 0xFC;
603 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
604 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
605 }
606 }
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000607}
608
Arthur Heymans36646472018-01-22 14:42:18 +0100609#define SPIBAR16(x) RCBA16(0x3020 + x)
610#define SPIBAR32(x) RCBA32(0x3020 + x)
611
612static void lpc_final(struct device *dev)
613{
614 u16 tco1_cnt;
615
Julius Wernercd49cce2019-03-05 16:53:33 -0800616 if (!CONFIG(INTEL_CHIPSET_LOCKDOWN))
Arthur Heymans36646472018-01-22 14:42:18 +0100617 return;
618
Arthur Heymans767de0a2019-11-15 19:19:53 +0100619 if (CONFIG(BOOT_DEVICE_SPI_FLASH))
620 spi_finalize_ops();
Arthur Heymans36646472018-01-22 14:42:18 +0100621
622 /* Lock SPIBAR */
623 SPIBAR16(0) = SPIBAR16(0) | (1 << 15);
624
625 /* BIOS Interface Lockdown */
626 RCBA32(0x3410) |= 1 << 0;
627
628 /* Global SMI Lock */
629 pci_or_config16(dev, GEN_PMCON_1, 1 << 4);
630
631 /* TCO_Lock */
632 tco1_cnt = inw(DEFAULT_PMBASE + 0x60 + TCO1_CNT);
633 tco1_cnt |= (1 << 12); /* TCO lock */
634 outw(tco1_cnt, DEFAULT_PMBASE + 0x60 + TCO1_CNT);
635
636 /* Indicate finalize step with post code */
637 outb(POST_OS_BOOT, 0x80);
638}
639
Elyes HAOUAS99667032018-05-13 12:47:28 +0200640static void southbridge_inject_dsdt(struct device *dev)
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200641{
Arthur Heymans3f111b02017-03-09 12:02:52 +0100642 global_nvs_t *gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(*gnvs));
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200643
644 if (gnvs) {
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100645 const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info();
646
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200647 memset(gnvs, 0, sizeof(*gnvs));
Vladimir Serbinenko385743a2014-10-18 02:26:21 +0200648
649 gnvs->apic = 1;
650 gnvs->mpen = 1; /* Enable Multi Processing */
651
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200652 acpi_create_gnvs(gnvs);
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100653
Nico Huber744d6bd2019-01-12 14:58:20 +0100654 if (gfx) {
655 gnvs->ndid = gfx->ndid;
656 memcpy(gnvs->did, gfx->did, sizeof(gnvs->did));
657 }
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100658
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200659 /* And tell SMI about it */
660 smm_setup_structures(gnvs, NULL, NULL);
661
662 /* Add it to SSDT. */
Vladimir Serbinenko1bad88e2014-11-04 21:20:56 +0100663 acpigen_write_scope("\\");
664 acpigen_write_name_dword("NVSA", (u32) gnvs);
665 acpigen_pop_len();
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200666 }
667}
668
Arthur Heymansa8a9f342017-12-24 08:11:13 +0100669static const char *lpc_acpi_name(const struct device *dev)
670{
671 return "LPCB";
672}
673
Elyes HAOUAS38f1d132018-09-17 08:44:18 +0200674static void southbridge_fill_ssdt(struct device *device)
Arthur Heymansa8a9f342017-12-24 08:11:13 +0100675{
676 intel_acpi_gen_def_acpi_pirq(device);
677}
678
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000679static struct pci_operations pci_ops = {
Subrata Banik4a0f0712019-03-20 14:29:47 +0530680 .set_subsystem = pci_dev_set_subsystem,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000681};
682
683static struct device_operations device_ops = {
684 .read_resources = i82801gx_lpc_read_resources,
685 .set_resources = pci_dev_set_resources,
Myles Watson7eac4452010-06-17 16:16:56 +0000686 .enable_resources = pci_dev_enable_resources,
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200687 .acpi_inject_dsdt_generator = southbridge_inject_dsdt,
688 .write_acpi_tables = acpi_write_hpet,
Arthur Heymansa8a9f342017-12-24 08:11:13 +0100689 .acpi_fill_ssdt_generator = southbridge_fill_ssdt,
690 .acpi_name = lpc_acpi_name,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000691 .init = lpc_init,
Nico Huber51b75ae2019-03-14 16:02:05 +0100692 .scan_bus = scan_static_bus,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000693 .enable = i82801gx_enable,
694 .ops_pci = &pci_ops,
Arthur Heymans36646472018-01-22 14:42:18 +0100695 .final = lpc_final,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000696};
697
Damien Zammitef33e032015-11-14 01:03:39 +1100698/* 27b0: 82801GH (ICH7 DH) */
699/* 27b8: 82801GB/GR (ICH7/ICH7R) */
700/* 27b9: 82801GBM/GU (ICH7-M/ICH7-U) */
701/* 27bc: 82NM10 (NM10) */
702/* 27bd: 82801GHM (ICH7-M DH) */
703
704static const unsigned short pci_device_ids[] = {
705 0x27b0, 0x27b8, 0x27b9, 0x27bc, 0x27bd, 0
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000706};
707
Damien Zammitef33e032015-11-14 01:03:39 +1100708static const struct pci_driver ich7_lpc __pci_driver = {
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000709 .ops = &device_ops,
710 .vendor = PCI_VENDOR_ID_INTEL,
Damien Zammitef33e032015-11-14 01:03:39 +1100711 .devices = pci_device_ids,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000712};