blob: 0c7678117f34fbd289eedab779a37dc28dfd7900 [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
3#include <console/console.h>
4#include <device/device.h>
5#include <device/pci.h>
6#include <device/pci_ids.h>
Kyösti Mälkkicbf95712020-01-05 08:05:45 +02007#include <option.h>
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00008#include <pc80/mc146818rtc.h>
9#include <pc80/isa-dma.h>
Stefan Reinauer54309d62009-01-20 22:53:10 +000010#include <pc80/i8259.h>
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000011#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020012#include <device/pci_ops.h>
Uwe Hermann74d1a6e2010-10-12 17:34:08 +000013#include <arch/ioapic.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -070014#include <acpi/acpi.h>
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +030015#include <acpi/acpi_gnvs.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>
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
Paul Menzelddddf152013-04-23 14:40:23 +020031/**
Martin Roth2ed0aa22016-01-05 20:58:58 -070032 * Set miscellaneous static southbridge features.
Paul Menzelddddf152013-04-23 14:40:23 +020033 *
34 * @param dev PCI device with I/O APIC control registers
35 */
36static void i82801gx_enable_ioapic(struct device *dev)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000037{
Paul Menzelddddf152013-04-23 14:40:23 +020038 /* Enable ACPI I/O range decode */
Kyösti Mälkki1cca3402013-02-26 19:21:39 +020039 pci_write_config8(dev, ACPI_CNTL, ACPI_EN);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000040
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080041 set_ioapic_id(VIO_APIC_VADDR, 0x02);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000042
Paul Menzelddddf152013-04-23 14:40:23 +020043 /*
44 * Select Boot Configuration register (0x03) and
45 * use Processor System Bus (0x01) to deliver interrupts.
46 */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080047 io_apic_write(VIO_APIC_VADDR, 0x03, 0x01);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000048}
49
50static void i82801gx_enable_serial_irqs(struct device *dev)
51{
52 /* Set packet length and toggle silent mode bit for one frame. */
Elyes HAOUAS92646ea2020-04-04 13:43:03 +020053 pci_write_config8(dev, SERIRQ_CNTL, (1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0));
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000054}
55
Stefan Reinauer573f7d42009-07-21 21:50:34 +000056/* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control
57 * 0x00 - 0000 = Reserved
58 * 0x01 - 0001 = Reserved
59 * 0x02 - 0010 = Reserved
60 * 0x03 - 0011 = IRQ3
61 * 0x04 - 0100 = IRQ4
62 * 0x05 - 0101 = IRQ5
63 * 0x06 - 0110 = IRQ6
64 * 0x07 - 0111 = IRQ7
65 * 0x08 - 1000 = Reserved
66 * 0x09 - 1001 = IRQ9
67 * 0x0A - 1010 = IRQ10
68 * 0x0B - 1011 = IRQ11
69 * 0x0C - 1100 = IRQ12
70 * 0x0D - 1101 = Reserved
71 * 0x0E - 1110 = IRQ14
72 * 0x0F - 1111 = IRQ15
73 * PIRQ[n]_ROUT[7] - PIRQ Routing Control
74 * 0x80 - The PIRQ is not routed.
75 */
76
Elyes HAOUAS99667032018-05-13 12:47:28 +020077static void i82801gx_pirq_init(struct device *dev)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000078{
Elyes HAOUAS99667032018-05-13 12:47:28 +020079 struct device *irq_dev;
Stefan Reinauer54309d62009-01-20 22:53:10 +000080 /* Get the chip configuration */
Elyes HAOUAS8d9a6f12020-04-28 04:57:27 +020081 const struct southbridge_intel_i82801gx_config *config = dev->chip_info;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000082
Stefan Reinauer54309d62009-01-20 22:53:10 +000083 pci_write_config8(dev, PIRQA_ROUT, config->pirqa_routing);
84 pci_write_config8(dev, PIRQB_ROUT, config->pirqb_routing);
85 pci_write_config8(dev, PIRQC_ROUT, config->pirqc_routing);
86 pci_write_config8(dev, PIRQD_ROUT, config->pirqd_routing);
87
88 pci_write_config8(dev, PIRQE_ROUT, config->pirqe_routing);
89 pci_write_config8(dev, PIRQF_ROUT, config->pirqf_routing);
90 pci_write_config8(dev, PIRQG_ROUT, config->pirqg_routing);
91 pci_write_config8(dev, PIRQH_ROUT, config->pirqh_routing);
92
93 /* Eric Biederman once said we should let the OS do this.
94 * I am not so sure anymore he was right.
95 */
96
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020097 for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
Arthur Heymans3f111b02017-03-09 12:02:52 +010098 u8 int_pin = 0, int_line = 0;
Stefan Reinauer54309d62009-01-20 22:53:10 +000099
100 if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI)
101 continue;
102
103 int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
104
105 switch (int_pin) {
Arthur Heymans3f111b02017-03-09 12:02:52 +0100106 case 1:
107 /* INTA# */ int_line = config->pirqa_routing; break;
108 case 2:
109 /* INTB# */ int_line = config->pirqb_routing; break;
110 case 3:
111 /* INTC# */ int_line = config->pirqc_routing; break;
112 case 4:
113 /* INTD# */ int_line = config->pirqd_routing; break;
Stefan Reinauer54309d62009-01-20 22:53:10 +0000114 }
115
116 if (!int_line)
117 continue;
118
119 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line);
120 }
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000121}
122
Elyes HAOUAS99667032018-05-13 12:47:28 +0200123static void i82801gx_gpi_routing(struct device *dev)
Stefan Reinauera8e11682009-03-11 14:54:18 +0000124{
125 /* Get the chip configuration */
Elyes HAOUAS8d9a6f12020-04-28 04:57:27 +0200126 const struct southbridge_intel_i82801gx_config *config = dev->chip_info;
Stefan Reinauera8e11682009-03-11 14:54:18 +0000127 u32 reg32 = 0;
128
Elyes HAOUAS92646ea2020-04-04 13:43:03 +0200129 /* An array would be much nicer here, or some other method of doing this. */
Stefan Reinauera8e11682009-03-11 14:54:18 +0000130 reg32 |= (config->gpi0_routing & 0x03) << 0;
131 reg32 |= (config->gpi1_routing & 0x03) << 2;
132 reg32 |= (config->gpi2_routing & 0x03) << 4;
133 reg32 |= (config->gpi3_routing & 0x03) << 6;
134 reg32 |= (config->gpi4_routing & 0x03) << 8;
135 reg32 |= (config->gpi5_routing & 0x03) << 10;
136 reg32 |= (config->gpi6_routing & 0x03) << 12;
137 reg32 |= (config->gpi7_routing & 0x03) << 14;
138 reg32 |= (config->gpi8_routing & 0x03) << 16;
139 reg32 |= (config->gpi9_routing & 0x03) << 18;
140 reg32 |= (config->gpi10_routing & 0x03) << 20;
141 reg32 |= (config->gpi11_routing & 0x03) << 22;
142 reg32 |= (config->gpi12_routing & 0x03) << 24;
143 reg32 |= (config->gpi13_routing & 0x03) << 26;
144 reg32 |= (config->gpi14_routing & 0x03) << 28;
145 reg32 |= (config->gpi15_routing & 0x03) << 30;
146
Kyösti Mälkkib85a87b2014-12-29 11:32:27 +0200147 pci_write_config32(dev, GPIO_ROUT, reg32);
Stefan Reinauera8e11682009-03-11 14:54:18 +0000148}
149
Elyes HAOUAS99667032018-05-13 12:47:28 +0200150static void i82801gx_power_options(struct device *dev)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000151{
152 u8 reg8;
Elyes HAOUAS71187012019-02-10 14:58:13 +0100153 u16 reg16;
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000154 u32 reg32;
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000155 const char *state;
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000156 /* Get the chip configuration */
Elyes HAOUAS8d9a6f12020-04-28 04:57:27 +0200157 const struct southbridge_intel_i82801gx_config *config = dev->chip_info;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000158
Nico Huber9faae2b2018-11-14 00:00:35 +0100159 int pwr_on = CONFIG_MAINBOARD_POWER_FAILURE_STATE;
Luc Verhaegena9c5ea02009-06-03 14:19:33 +0000160 int nmi_option;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000161
162 /* Which state do we want to goto after g3 (power restored)?
163 * 0 == S0 Full On
164 * 1 == S5 Soft Off
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000165 *
166 * If the option is not existent (Laptops), use MAINBOARD_POWER_ON.
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000167 */
Varad Gautam06ef0462015-03-11 09:54:41 +0530168 pwr_on = MAINBOARD_POWER_ON;
169 get_option(&pwr_on, "power_on_after_fail");
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000170
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000171 reg8 = pci_read_config8(dev, GEN_PMCON_3);
172 reg8 &= 0xfe;
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000173 switch (pwr_on) {
174 case MAINBOARD_POWER_OFF:
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000175 reg8 |= 1;
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000176 state = "off";
177 break;
178 case MAINBOARD_POWER_ON:
179 reg8 &= ~1;
180 state = "on";
181 break;
182 case MAINBOARD_POWER_KEEP:
183 reg8 &= ~1;
184 state = "state keep";
185 break;
186 default:
187 state = "undefined";
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000188 }
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000189
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000190 reg8 |= (3 << 4); /* avoid #S4 assertions */
Martin Roth2ed0aa22016-01-05 20:58:58 -0700191 reg8 &= ~(1 << 3); /* minimum assertion is 1 to 2 RTCCLK */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000192
193 pci_write_config8(dev, GEN_PMCON_3, reg8);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000194 printk(BIOS_INFO, "Set power %s after power failure.\n", state);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000195
196 /* Set up NMI on errors. */
197 reg8 = inb(0x61);
198 reg8 &= 0x0f; /* Higher Nibble must be 0 */
199 reg8 &= ~(1 << 3); /* IOCHK# NMI Enable */
200 // reg8 &= ~(1 << 2); /* PCI SERR# Enable */
201 reg8 |= (1 << 2); /* PCI SERR# Disable for now */
202 outb(reg8, 0x61);
203
204 reg8 = inb(0x70);
205 nmi_option = NMI_OFF;
Luc Verhaegena9c5ea02009-06-03 14:19:33 +0000206 get_option(&nmi_option, "nmi");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000207 if (nmi_option) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000208 printk(BIOS_INFO, "NMI sources enabled.\n");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000209 reg8 &= ~(1 << 7); /* Set NMI. */
210 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000211 printk(BIOS_INFO, "NMI sources disabled.\n");
Arthur Heymans3f111b02017-03-09 12:02:52 +0100212 reg8 |= (1 << 7); /* Can't mask NMI from PCI-E and NMI_NOW */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000213 }
214 outb(reg8, 0x70);
215
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000216 /* Enable CPU_SLP# and Intel Speedstep, set SMI# rate down */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000217 reg16 = pci_read_config16(dev, GEN_PMCON_1);
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000218 reg16 &= ~(3 << 0); // SMI# rate 1 minute
219 reg16 |= (1 << 2); // CLKRUN_EN - Mobile/Ultra only
220 reg16 |= (1 << 3); // Speedstep Enable - Mobile/Ultra only
221 reg16 |= (1 << 5); // CPUSLP_EN Desktop only
Sven Schnelle906f9ae2011-10-23 16:35:01 +0200222
223 if (config->c4onc3_enable)
224 reg16 |= (1 << 7);
225
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000226 // another laptop wants this?
227 // reg16 &= ~(1 << 10); // BIOS_PCI_EXP_EN - Desktop/Mobile only
228 reg16 |= (1 << 10); // BIOS_PCI_EXP_EN - Desktop/Mobile only
Kyösti Mälkki94464472020-06-13 13:45:42 +0300229 if (CONFIG(DEBUG_PERIODIC_SMI))
230 reg16 |= (3 << 0); // Periodic SMI every 8s
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000231 pci_write_config16(dev, GEN_PMCON_1, reg16);
232
Stefan Reinauera8e11682009-03-11 14:54:18 +0000233 // Set the board's GPI routing.
234 i82801gx_gpi_routing(dev);
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000235
Elyes HAOUAS71187012019-02-10 14:58:13 +0100236 write_pmbase32(GPE0_EN, config->gpe0_en);
237 write_pmbase16(ALT_GP_SMI_EN, config->alt_gp_smi_en);
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000238
239 /* Set up power management block and determine sleep mode */
Elyes HAOUAS71187012019-02-10 14:58:13 +0100240 reg32 = read_pmbase32(PM1_CNT);
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000241
242 reg32 &= ~(7 << 10); // SLP_TYP
243 reg32 |= (1 << 1); // enable C3->C0 transition on bus master
244 reg32 |= (1 << 0); // SCI_EN
Elyes HAOUAS71187012019-02-10 14:58:13 +0100245 write_pmbase32(PM1_CNT, reg32);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000246}
247
Elyes HAOUAS99667032018-05-13 12:47:28 +0200248static void i82801gx_configure_cstates(struct device *dev)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000249{
250 u8 reg8;
Stefan Reinauer109ab312009-08-12 16:08:05 +0000251
Stefan Reinauera8e11682009-03-11 14:54:18 +0000252 reg8 = pci_read_config8(dev, 0xa9); // Cx state configuration
253 reg8 |= (1 << 4) | (1 << 3) | (1 << 2); // Enable Popup & Popdown
254 pci_write_config8(dev, 0xa9, reg8);
255
256 // Set Deeper Sleep configuration to recommended values
257 reg8 = pci_read_config8(dev, 0xaa);
258 reg8 &= 0xf0;
259 reg8 |= (2 << 2); // Deeper Sleep to Stop CPU: 34-40us
260 reg8 |= (2 << 0); // Deeper Sleep to Sleep: 15us
261 pci_write_config8(dev, 0xaa, reg8);
262}
263
264static void i82801gx_rtc_init(struct device *dev)
265{
266 u8 reg8;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000267 int rtc_failed;
268
269 reg8 = pci_read_config8(dev, GEN_PMCON_3);
270 rtc_failed = reg8 & RTC_BATTERY_DEAD;
271 if (rtc_failed) {
272 reg8 &= ~RTC_BATTERY_DEAD;
273 pci_write_config8(dev, GEN_PMCON_3, reg8);
274 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000275 printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000276
Gabe Blackb3f08c62014-04-30 17:12:25 -0700277 cmos_init(rtc_failed);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000278}
279
Stefan Reinauera8e11682009-03-11 14:54:18 +0000280static void enable_hpet(void)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000281{
Stefan Reinauera8e11682009-03-11 14:54:18 +0000282 u32 reg32;
Stefan Reinauer109ab312009-08-12 16:08:05 +0000283
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000284 /* Move HPET to default address 0xfed00000 and enable it */
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000285 reg32 = RCBA32(HPTC);
Stefan Reinauera8e11682009-03-11 14:54:18 +0000286 reg32 |= (1 << 7); // HPET Address Enable
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000287 reg32 &= ~(3 << 0);
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000288 RCBA32(HPTC) = reg32;
Arthur Heymansc73c9232019-10-02 14:57:50 +0200289 /* On NM10 this only works if read back */
290 RCBA32(HPTC);
291
292 write32((u32 *)0xfed00010, read32((u32 *)0xfed00010) | 1);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000293}
294
Stefan Reinauera8e11682009-03-11 14:54:18 +0000295static void enable_clock_gating(void)
296{
297 u32 reg32;
Stefan Reinauer109ab312009-08-12 16:08:05 +0000298
Stefan Reinauera8e11682009-03-11 14:54:18 +0000299 /* Enable Clock Gating for most devices */
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000300 reg32 = RCBA32(CG);
Stefan Reinauera8e11682009-03-11 14:54:18 +0000301 reg32 |= (1 << 31); // LPC clock gating
302 reg32 |= (1 << 30); // PATA clock gating
303 // SATA clock gating
304 reg32 |= (1 << 27) | (1 << 26) | (1 << 25) | (1 << 24);
305 reg32 |= (1 << 23); // AC97 clock gating
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000306 reg32 |= (1 << 19); // USB EHCI clock gating
Stefan Reinauera8e11682009-03-11 14:54:18 +0000307 reg32 |= (1 << 3) | (1 << 1); // DMI clock gating
308 reg32 |= (1 << 2); // PCIe clock gating;
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000309 reg32 &= ~(1 << 20); // No static clock gating for USB
Arthur Heymans3f111b02017-03-09 12:02:52 +0100310 reg32 &= ~((1 << 29) | (1 << 28)); // Disable UHCI clock gating
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000311 RCBA32(CG) = reg32;
Stefan Reinauera8e11682009-03-11 14:54:18 +0000312}
Stefan Reinauer269563a2009-01-19 21:20:22 +0000313
Kyösti Mälkki83d6a8a2019-07-12 08:16:53 +0300314static void i82801gx_set_acpi_mode(struct device *dev)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000315{
Kyösti Mälkkiad882c32020-06-02 05:05:30 +0300316 if (!acpi_is_wakeup_s3()) {
317 apm_control(APM_CNT_ACPI_DISABLE);
318 } else {
319 apm_control(APM_CNT_ACPI_ENABLE);
Sven Schnellee2618072011-06-05 11:39:12 +0200320 }
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000321}
322
Stefan Reinauera8e11682009-03-11 14:54:18 +0000323#define SPIBASE 0x3020
324static void i82801gx_spi_init(void)
325{
326 u16 spicontrol;
327
328 spicontrol = RCBA16(SPIBASE + 2);
329 spicontrol &= ~(1 << 0); // SPI Access Request
330 RCBA16(SPIBASE + 2) = spicontrol;
331}
332
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000333static void i82801gx_fixups(struct device *dev)
Stefan Reinauera8e11682009-03-11 14:54:18 +0000334{
335 /* This needs to happen after PCI enumeration */
336 RCBA32(0x1d40) |= 1;
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000337
338 /* USB Transient Disconnect Detect:
339 * Prevent a SE0 condition on the USB ports from being
340 * interpreted by the UHCI controller as a disconnect
341 */
342 pci_write_config8(dev, 0xad, 0x3);
Stefan Reinauera8e11682009-03-11 14:54:18 +0000343}
344
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000345static void lpc_init(struct device *dev)
346{
Elyes HAOUASbfc255a2020-03-07 13:05:14 +0100347 printk(BIOS_DEBUG, "i82801gx: %s\n", __func__);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000348
349 /* Set the value for PCI command register. */
Angel Pons89739ba2020-07-25 02:46:39 +0200350 pci_write_config16(dev, PCI_COMMAND,
351 PCI_COMMAND_MASTER | PCI_COMMAND_SPECIAL |
352 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000353
354 /* IO APIC initialization. */
Paul Menzelddddf152013-04-23 14:40:23 +0200355 i82801gx_enable_ioapic(dev);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000356
357 i82801gx_enable_serial_irqs(dev);
358
359 /* Setup the PIRQ. */
360 i82801gx_pirq_init(dev);
361
362 /* Setup power options. */
363 i82801gx_power_options(dev);
364
Stefan Reinauera8e11682009-03-11 14:54:18 +0000365 /* Configure Cx state registers */
366 i82801gx_configure_cstates(dev);
367
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000368 /* Set the state of the GPIO lines. */
369 //gpio_init(dev);
370
371 /* Initialize the real time clock. */
372 i82801gx_rtc_init(dev);
373
374 /* Initialize ISA DMA. */
375 isa_dma_init();
376
377 /* Initialize the High Precision Event Timers, if present. */
Stefan Reinauera8e11682009-03-11 14:54:18 +0000378 enable_hpet();
379
380 /* Initialize Clock Gating */
381 enable_clock_gating();
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000382
383 setup_i8259();
384
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000385 /* The OS should do this? */
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000386 /* Interrupt 9 should be level triggered (SCI) */
387 i8259_configure_irq_trigger(9, 1);
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000388
Kyösti Mälkki44da9e72019-10-09 12:32:16 +0300389 i82801gx_set_acpi_mode(dev);
Stefan Reinauera8e11682009-03-11 14:54:18 +0000390
391 i82801gx_spi_init();
392
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000393 i82801gx_fixups(dev);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000394}
395
Vladimir Serbinenkod5d94ea2014-10-18 02:13:11 +0200396unsigned long acpi_fill_madt(unsigned long current)
397{
398 /* Local APICs */
399 current = acpi_create_madt_lapics(current);
400
401 /* IOAPIC */
Elyes HAOUAS92646ea2020-04-04 13:43:03 +0200402 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, 2, IO_APIC_ADDR, 0);
Vladimir Serbinenkod5d94ea2014-10-18 02:13:11 +0200403
404 /* LAPIC_NMI */
405 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)
406 current, 0,
407 MP_IRQ_POLARITY_HIGH |
408 MP_IRQ_TRIGGER_EDGE, 0x01);
409 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)
410 current, 1, MP_IRQ_POLARITY_HIGH |
411 MP_IRQ_TRIGGER_EDGE, 0x01);
412
413 /* INT_SRC_OVR */
414 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
415 current, 0, 0, 2, MP_IRQ_POLARITY_HIGH | MP_IRQ_TRIGGER_EDGE);
416 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
417 current, 0, 9, 9, MP_IRQ_POLARITY_HIGH | MP_IRQ_TRIGGER_LEVEL);
418
419
420 return current;
421}
422
Elyes HAOUAS99667032018-05-13 12:47:28 +0200423static void i82801gx_lpc_read_resources(struct device *dev)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000424{
425 struct resource *res;
Vladimir Serbinenkof119f082014-11-24 21:05:56 +0100426 u8 io_index = 0;
427 int i;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000428
429 /* Get the normal PCI resources of this device. */
430 pci_dev_read_resources(dev);
431
432 /* Add an extra subtractive resource for both memory and I/O. */
Vladimir Serbinenkof119f082014-11-24 21:05:56 +0100433 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
Myles Watson29cc9ed2009-07-02 18:56:24 +0000434 res->base = 0;
435 res->size = 0x1000;
436 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
437 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000438
Vladimir Serbinenkof119f082014-11-24 21:05:56 +0100439 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
Myles Watson29cc9ed2009-07-02 18:56:24 +0000440 res->base = 0xff800000;
441 res->size = 0x00800000; /* 8 MB for flash */
442 res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE |
443 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
444
445 res = new_resource(dev, 3); /* IOAPIC */
Uwe Hermann74d1a6e2010-10-12 17:34:08 +0000446 res->base = IO_APIC_ADDR;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000447 res->size = 0x00001000;
448 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
Vladimir Serbinenkof119f082014-11-24 21:05:56 +0100449
450 /* Set IO decode ranges if required.*/
451 for (i = 0; i < 4; i++) {
452 u32 gen_dec;
453 gen_dec = pci_read_config32(dev, 0x84 + 4 * i);
454
455 if ((gen_dec & 0xFFFC) > 0x1000) {
456 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
457 res->base = gen_dec & 0xFFFC;
458 res->size = (gen_dec >> 16) & 0xFC;
459 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
460 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
461 }
462 }
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000463}
464
Arthur Heymans36646472018-01-22 14:42:18 +0100465#define SPIBAR16(x) RCBA16(0x3020 + x)
466#define SPIBAR32(x) RCBA32(0x3020 + x)
467
468static void lpc_final(struct device *dev)
469{
470 u16 tco1_cnt;
471
Julius Wernercd49cce2019-03-05 16:53:33 -0800472 if (!CONFIG(INTEL_CHIPSET_LOCKDOWN))
Arthur Heymans36646472018-01-22 14:42:18 +0100473 return;
474
Arthur Heymans767de0a2019-11-15 19:19:53 +0100475 if (CONFIG(BOOT_DEVICE_SPI_FLASH))
476 spi_finalize_ops();
Arthur Heymans36646472018-01-22 14:42:18 +0100477
478 /* Lock SPIBAR */
479 SPIBAR16(0) = SPIBAR16(0) | (1 << 15);
480
481 /* BIOS Interface Lockdown */
482 RCBA32(0x3410) |= 1 << 0;
483
484 /* Global SMI Lock */
485 pci_or_config16(dev, GEN_PMCON_1, 1 << 4);
486
487 /* TCO_Lock */
488 tco1_cnt = inw(DEFAULT_PMBASE + 0x60 + TCO1_CNT);
489 tco1_cnt |= (1 << 12); /* TCO lock */
490 outw(tco1_cnt, DEFAULT_PMBASE + 0x60 + TCO1_CNT);
491
492 /* Indicate finalize step with post code */
493 outb(POST_OS_BOOT, 0x80);
494}
495
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +0300496void southbridge_inject_dsdt(const struct device *dev)
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200497{
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +0300498 struct global_nvs *gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(*gnvs));
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200499
500 if (gnvs) {
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200501 memset(gnvs, 0, sizeof(*gnvs));
Vladimir Serbinenko385743a2014-10-18 02:26:21 +0200502
503 gnvs->apic = 1;
504 gnvs->mpen = 1; /* Enable Multi Processing */
505
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200506 acpi_create_gnvs(gnvs);
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100507
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200508 /* And tell SMI about it */
Kyösti Mälkkic3c55212020-06-17 10:34:26 +0300509 apm_control(APM_CNT_GNVS_UPDATE);
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200510
511 /* Add it to SSDT. */
Vladimir Serbinenko1bad88e2014-11-04 21:20:56 +0100512 acpigen_write_scope("\\");
513 acpigen_write_name_dword("NVSA", (u32) gnvs);
514 acpigen_pop_len();
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200515 }
516}
517
Arthur Heymansa8a9f342017-12-24 08:11:13 +0100518static const char *lpc_acpi_name(const struct device *dev)
519{
520 return "LPCB";
521}
522
Furquan Shaikh7536a392020-04-24 21:59:21 -0700523static void southbridge_fill_ssdt(const struct device *device)
Arthur Heymansa8a9f342017-12-24 08:11:13 +0100524{
525 intel_acpi_gen_def_acpi_pirq(device);
526}
527
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000528static struct device_operations device_ops = {
529 .read_resources = i82801gx_lpc_read_resources,
530 .set_resources = pci_dev_set_resources,
Myles Watson7eac4452010-06-17 16:16:56 +0000531 .enable_resources = pci_dev_enable_resources,
Nico Huber68680dd2020-03-31 17:34:52 +0200532 .acpi_inject_dsdt = southbridge_inject_dsdt,
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200533 .write_acpi_tables = acpi_write_hpet,
Nico Huber68680dd2020-03-31 17:34:52 +0200534 .acpi_fill_ssdt = southbridge_fill_ssdt,
Arthur Heymansa8a9f342017-12-24 08:11:13 +0100535 .acpi_name = lpc_acpi_name,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000536 .init = lpc_init,
Nico Huber51b75ae2019-03-14 16:02:05 +0100537 .scan_bus = scan_static_bus,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000538 .enable = i82801gx_enable,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200539 .ops_pci = &pci_dev_ops_pci,
Arthur Heymans36646472018-01-22 14:42:18 +0100540 .final = lpc_final,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000541};
542
Damien Zammitef33e032015-11-14 01:03:39 +1100543static const unsigned short pci_device_ids[] = {
Elyes HAOUAS92646ea2020-04-04 13:43:03 +0200544 0x27b0, /* 82801GH (ICH7 DH) */
545 0x27b8, /* 82801GB/GR (ICH7/ICH7R) */
546 0x27b9, /* 82801GBM/GU (ICH7-M/ICH7-U) */
547 0x27bc, /* 82NM10 (NM10) */
548 0x27bd, /* 82801GHM (ICH7-M DH) */
549 0
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000550};
551
Damien Zammitef33e032015-11-14 01:03:39 +1100552static const struct pci_driver ich7_lpc __pci_driver = {
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000553 .ops = &device_ops,
554 .vendor = PCI_VENDOR_ID_INTEL,
Damien Zammitef33e032015-11-14 01:03:39 +1100555 .devices = pci_device_ids,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000556};