blob: 26bd30ffe69fc62056c8e847a2c3dc7996d521a8 [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Aaron Durbin76c37002012-10-30 09:03:43 -05002
3#include <console/console.h>
4#include <device/device.h>
5#include <device/pci.h>
6#include <device/pci_ids.h>
Patrick Rudolphe56189c2018-04-18 10:11:59 +02007#include <device/pci_ops.h>
Kyösti Mälkkicbf95712020-01-05 08:05:45 +02008#include <option.h>
Aaron Durbin76c37002012-10-30 09:03:43 -05009#include <pc80/isa-dma.h>
10#include <pc80/i8259.h>
11#include <arch/io.h>
12#include <arch/ioapic.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -070013#include <acpi/acpi.h>
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +030014#include <acpi/acpi_gnvs.h>
Aaron Durbin29ffa542012-12-21 21:21:48 -060015#include <cpu/x86/smm.h>
Duncan Laurie9c07c8f2013-03-22 11:08:39 -070016#include <cbmem.h>
17#include <string.h>
Kyösti Mälkki12b121c2019-08-18 16:33:39 +030018#include "chip.h"
Duncan Laurie9c07c8f2013-03-22 11:08:39 -070019#include "nvs.h"
Aaron Durbin76c37002012-10-30 09:03:43 -050020#include "pch.h"
Furquan Shaikh76cedd22020-05-02 10:24:23 -070021#include <acpi/acpigen.h>
Tristan Corrickf3127d42018-10-31 02:25:54 +130022#include <southbridge/intel/common/acpi_pirq_gen.h>
Patrick Rudolph6b931122018-11-01 17:48:37 +010023#include <southbridge/intel/common/rtc.h>
Arthur Heymansa3121b02019-05-28 13:46:49 +020024#include <southbridge/intel/common/spi.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050025
26#define NMI_OFF 0
27
Aaron Durbin76c37002012-10-30 09:03:43 -050028typedef struct southbridge_intel_lynxpoint_config config_t;
29
Paul Menzel373a20c2013-05-03 12:17:02 +020030/**
31 * Set miscellanous static southbridge features.
32 *
33 * @param dev PCI device with I/O APIC control registers
34 */
35static void pch_enable_ioapic(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -050036{
Aaron Durbin76c37002012-10-30 09:03:43 -050037 u32 reg32;
Aaron Durbin76c37002012-10-30 09:03:43 -050038
Matt DeVilliera51e3792018-03-04 01:44:15 -060039 /* Assign unique bus/dev/fn for I/O APIC */
40 pci_write_config16(dev, LPC_IBDF,
41 PCH_IOAPIC_PCI_BUS << 8 | PCH_IOAPIC_PCI_SLOT << 3);
42
Paul Menzel373a20c2013-05-03 12:17:02 +020043 /* Enable ACPI I/O range decode */
44 pci_write_config8(dev, ACPI_CNTL, ACPI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -050045
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080046 set_ioapic_id(VIO_APIC_VADDR, 0x02);
Aaron Durbin76c37002012-10-30 09:03:43 -050047
48 /* affirm full set of redirection table entries ("write once") */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080049 reg32 = io_apic_read(VIO_APIC_VADDR, 0x01);
Duncan Lauriec5939992013-05-24 11:06:49 -070050 if (pch_is_lp()) {
51 /* PCH-LP has 39 redirection entries */
52 reg32 &= ~0x00ff0000;
53 reg32 |= 0x00270000;
54 }
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080055 io_apic_write(VIO_APIC_VADDR, 0x01, reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -050056
Paul Menzel373a20c2013-05-03 12:17:02 +020057 /*
58 * Select Boot Configuration register (0x03) and
59 * use Processor System Bus (0x01) to deliver interrupts.
60 */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080061 io_apic_write(VIO_APIC_VADDR, 0x03, 0x01);
Aaron Durbin76c37002012-10-30 09:03:43 -050062}
63
64static void pch_enable_serial_irqs(struct device *dev)
65{
66 /* Set packet length and toggle silent mode bit for one frame. */
67 pci_write_config8(dev, SERIRQ_CNTL,
68 (1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0));
Julius Wernercd49cce2019-03-05 16:53:33 -080069#if !CONFIG(SERIRQ_CONTINUOUS_MODE)
Aaron Durbin76c37002012-10-30 09:03:43 -050070 pci_write_config8(dev, SERIRQ_CNTL,
71 (1 << 7) | (0 << 6) | ((21 - 17) << 2) | (0 << 0));
72#endif
73}
74
75/* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control
76 * 0x00 - 0000 = Reserved
77 * 0x01 - 0001 = Reserved
78 * 0x02 - 0010 = Reserved
79 * 0x03 - 0011 = IRQ3
80 * 0x04 - 0100 = IRQ4
81 * 0x05 - 0101 = IRQ5
82 * 0x06 - 0110 = IRQ6
83 * 0x07 - 0111 = IRQ7
84 * 0x08 - 1000 = Reserved
85 * 0x09 - 1001 = IRQ9
86 * 0x0A - 1010 = IRQ10
87 * 0x0B - 1011 = IRQ11
88 * 0x0C - 1100 = IRQ12
89 * 0x0D - 1101 = Reserved
90 * 0x0E - 1110 = IRQ14
91 * 0x0F - 1111 = IRQ15
92 * PIRQ[n]_ROUT[7] - PIRQ Routing Control
93 * 0x80 - The PIRQ is not routed.
94 */
95
Elyes HAOUAS7a5f7712018-06-08 17:20:38 +020096static void pch_pirq_init(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -050097{
Elyes HAOUAS7a5f7712018-06-08 17:20:38 +020098 struct device *irq_dev;
Aaron Durbin76c37002012-10-30 09:03:43 -050099 /* Get the chip configuration */
100 config_t *config = dev->chip_info;
101
102 pci_write_config8(dev, PIRQA_ROUT, config->pirqa_routing);
103 pci_write_config8(dev, PIRQB_ROUT, config->pirqb_routing);
104 pci_write_config8(dev, PIRQC_ROUT, config->pirqc_routing);
105 pci_write_config8(dev, PIRQD_ROUT, config->pirqd_routing);
106
107 pci_write_config8(dev, PIRQE_ROUT, config->pirqe_routing);
108 pci_write_config8(dev, PIRQF_ROUT, config->pirqf_routing);
109 pci_write_config8(dev, PIRQG_ROUT, config->pirqg_routing);
110 pci_write_config8(dev, PIRQH_ROUT, config->pirqh_routing);
111
112 /* Eric Biederman once said we should let the OS do this.
113 * I am not so sure anymore he was right.
114 */
115
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200116 for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500117 u8 int_pin=0, int_line=0;
118
119 if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI)
120 continue;
121
122 int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
123
124 switch (int_pin) {
125 case 1: /* INTA# */ int_line = config->pirqa_routing; break;
126 case 2: /* INTB# */ int_line = config->pirqb_routing; break;
127 case 3: /* INTC# */ int_line = config->pirqc_routing; break;
128 case 4: /* INTD# */ int_line = config->pirqd_routing; break;
129 }
130
131 if (!int_line)
132 continue;
133
134 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line);
135 }
136}
137
Elyes HAOUAS7a5f7712018-06-08 17:20:38 +0200138static void pch_gpi_routing(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500139{
140 /* Get the chip configuration */
141 config_t *config = dev->chip_info;
142 u32 reg32 = 0;
143
144 /* An array would be much nicer here, or some
145 * other method of doing this.
146 */
147 reg32 |= (config->gpi0_routing & 0x03) << 0;
148 reg32 |= (config->gpi1_routing & 0x03) << 2;
149 reg32 |= (config->gpi2_routing & 0x03) << 4;
150 reg32 |= (config->gpi3_routing & 0x03) << 6;
151 reg32 |= (config->gpi4_routing & 0x03) << 8;
152 reg32 |= (config->gpi5_routing & 0x03) << 10;
153 reg32 |= (config->gpi6_routing & 0x03) << 12;
154 reg32 |= (config->gpi7_routing & 0x03) << 14;
155 reg32 |= (config->gpi8_routing & 0x03) << 16;
156 reg32 |= (config->gpi9_routing & 0x03) << 18;
157 reg32 |= (config->gpi10_routing & 0x03) << 20;
158 reg32 |= (config->gpi11_routing & 0x03) << 22;
159 reg32 |= (config->gpi12_routing & 0x03) << 24;
160 reg32 |= (config->gpi13_routing & 0x03) << 26;
161 reg32 |= (config->gpi14_routing & 0x03) << 28;
162 reg32 |= (config->gpi15_routing & 0x03) << 30;
163
Kyösti Mälkkib85a87b2014-12-29 11:32:27 +0200164 pci_write_config32(dev, GPIO_ROUT, reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -0500165}
166
Elyes HAOUAS7a5f7712018-06-08 17:20:38 +0200167static void pch_power_options(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500168{
169 u8 reg8;
Duncan Laurie467f31d2013-03-08 17:00:37 -0800170 u16 reg16;
Aaron Durbin76c37002012-10-30 09:03:43 -0500171 u32 reg32;
172 const char *state;
173 /* Get the chip configuration */
174 config_t *config = dev->chip_info;
Duncan Laurie467f31d2013-03-08 17:00:37 -0800175 u16 pmbase = get_pmbase();
Nico Huber9faae2b2018-11-14 00:00:35 +0100176 int pwr_on = CONFIG_MAINBOARD_POWER_FAILURE_STATE;
Aaron Durbin76c37002012-10-30 09:03:43 -0500177 int nmi_option;
178
179 /* Which state do we want to goto after g3 (power restored)?
180 * 0 == S0 Full On
181 * 1 == S5 Soft Off
182 *
183 * If the option is not existent (Laptops), use Kconfig setting.
184 */
185 get_option(&pwr_on, "power_on_after_fail");
186
187 reg16 = pci_read_config16(dev, GEN_PMCON_3);
188 reg16 &= 0xfffe;
189 switch (pwr_on) {
190 case MAINBOARD_POWER_OFF:
191 reg16 |= 1;
192 state = "off";
193 break;
194 case MAINBOARD_POWER_ON:
195 reg16 &= ~1;
196 state = "on";
197 break;
198 case MAINBOARD_POWER_KEEP:
199 reg16 &= ~1;
200 state = "state keep";
201 break;
202 default:
203 state = "undefined";
204 }
205
206 reg16 &= ~(3 << 4); /* SLP_S4# Assertion Stretch 4s */
207 reg16 |= (1 << 3); /* SLP_S4# Assertion Stretch Enable */
208
209 reg16 &= ~(1 << 10);
210 reg16 |= (1 << 11); /* SLP_S3# Min Assertion Width 50ms */
211
212 reg16 |= (1 << 12); /* Disable SLP stretch after SUS well */
213
214 pci_write_config16(dev, GEN_PMCON_3, reg16);
215 printk(BIOS_INFO, "Set power %s after power failure.\n", state);
216
217 /* Set up NMI on errors. */
218 reg8 = inb(0x61);
219 reg8 &= 0x0f; /* Higher Nibble must be 0 */
220 reg8 &= ~(1 << 3); /* IOCHK# NMI Enable */
221 // reg8 &= ~(1 << 2); /* PCI SERR# Enable */
222 reg8 |= (1 << 2); /* PCI SERR# Disable for now */
223 outb(reg8, 0x61);
224
225 reg8 = inb(0x70);
226 nmi_option = NMI_OFF;
227 get_option(&nmi_option, "nmi");
228 if (nmi_option) {
229 printk(BIOS_INFO, "NMI sources enabled.\n");
230 reg8 &= ~(1 << 7); /* Set NMI. */
231 } else {
232 printk(BIOS_INFO, "NMI sources disabled.\n");
Elyes HAOUAS9c5d4632018-04-26 22:21:21 +0200233 reg8 |= (1 << 7); /* Can't mask NMI from PCI-E and NMI_NOW */
Aaron Durbin76c37002012-10-30 09:03:43 -0500234 }
235 outb(reg8, 0x70);
236
237 /* Enable CPU_SLP# and Intel Speedstep, set SMI# rate down */
238 reg16 = pci_read_config16(dev, GEN_PMCON_1);
239 reg16 &= ~(3 << 0); // SMI# rate 1 minute
240 reg16 &= ~(1 << 10); // Disable BIOS_PCI_EXP_EN for native PME
Aaron Durbin76c37002012-10-30 09:03:43 -0500241 pci_write_config16(dev, GEN_PMCON_1, reg16);
242
Duncan Laurie467f31d2013-03-08 17:00:37 -0800243 /*
244 * Set the board's GPI routing on LynxPoint-H.
245 * This is done as part of GPIO configuration on LynxPoint-LP.
246 */
247 if (pch_is_lp())
248 pch_gpi_routing(dev);
Aaron Durbin76c37002012-10-30 09:03:43 -0500249
Duncan Laurie467f31d2013-03-08 17:00:37 -0800250 /* GPE setup based on device tree configuration */
251 enable_all_gpe(config->gpe0_en_1, config->gpe0_en_2,
252 config->gpe0_en_3, config->gpe0_en_4);
Aaron Durbin76c37002012-10-30 09:03:43 -0500253
Duncan Laurie467f31d2013-03-08 17:00:37 -0800254 /* SMI setup based on device tree configuration */
255 enable_alt_smi(config->alt_gp_smi_en);
Aaron Durbin76c37002012-10-30 09:03:43 -0500256
257 /* Set up power management block and determine sleep mode */
258 reg32 = inl(pmbase + 0x04); // PM1_CNT
259 reg32 &= ~(7 << 10); // SLP_TYP
260 reg32 |= (1 << 0); // SCI_EN
261 outl(reg32, pmbase + 0x04);
262
263 /* Clear magic status bits to prevent unexpected wake */
264 reg32 = RCBA32(0x3310);
265 reg32 |= (1 << 4)|(1 << 5)|(1 << 0);
266 RCBA32(0x3310) = reg32;
267
Ryan Salsamendi889ce9c2017-06-30 17:45:14 -0700268 reg16 = RCBA16(0x3f02);
269 reg16 &= ~0xf;
270 RCBA16(0x3f02) = reg16;
Aaron Durbin76c37002012-10-30 09:03:43 -0500271}
272
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800273/* LynxPoint PCH Power Management init */
274static void lpt_pm_init(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500275{
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800276 printk(BIOS_DEBUG, "LynxPoint PM init\n");
Aaron Durbin76c37002012-10-30 09:03:43 -0500277}
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800278
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800279/* LynxPoint LP PCH Power Management init */
280static void lpt_lp_pm_init(struct device *dev)
281{
282 struct southbridge_intel_lynxpoint_config *config = dev->chip_info;
283 u32 data;
284
285 printk(BIOS_DEBUG, "LynxPoint LP PM init\n");
286
287 pci_write_config8(dev, 0xa9, 0x46);
288
Angel Pons725657a2020-07-03 13:15:00 +0200289 RCBA32_AND_OR(0x232c, ~1, 0x00000000);
290 RCBA32_AND_OR(0x1100, ~0xc000, 0xc000);
291 RCBA32_AND_OR(0x1100, ~0, 0x00000100);
292 RCBA32_AND_OR(0x1100, ~0, 0x0000003f);
293 RCBA32_AND_OR(0x2320, ~0x60, 0x10);
294 RCBA32_AND_OR(0x3314, 0, 0x00012fff);
295 RCBA32_AND_OR(0x3318, 0, 0x0dcf0400);
296 RCBA32_AND_OR(0x3324, 0, 0x04000000);
297 RCBA32_AND_OR(0x3368, 0, 0x00041400);
298 RCBA32_AND_OR(0x3388, 0, 0x3f8ddbff);
299 RCBA32_AND_OR(0x33ac, 0, 0x00007001);
300 RCBA32_AND_OR(0x33b0, 0, 0x00181900);
301 RCBA32_AND_OR(0x33c0, 0, 0x00060A00);
302 RCBA32_AND_OR(0x33d0, 0, 0x06200840);
303 RCBA32_AND_OR(0x3a28, 0, 0x01010101);
304 RCBA32_AND_OR(0x3a2c, 0, 0x04040404);
305 RCBA32_AND_OR(0x2b1c, 0, 0x03808033);
306 RCBA32_AND_OR(0x2b34, 0, 0x80000009);
307 RCBA32_AND_OR(0x3348, 0, 0x022ddfff);
308 RCBA32_AND_OR(0x334c, 0, 0x00000001);
309 RCBA32_AND_OR(0x3358, 0, 0x0001c000);
310 RCBA32_AND_OR(0x3380, 0, 0x3f8ddbff);
311 RCBA32_AND_OR(0x3384, 0, 0x0001c7e1);
312 RCBA32_AND_OR(0x338c, 0, 0x0001c7e1);
313 RCBA32_AND_OR(0x3398, 0, 0x0001c000);
314 RCBA32_AND_OR(0x33a8, 0, 0x00181900);
315 RCBA32_AND_OR(0x33dc, 0, 0x00080000);
316 RCBA32_AND_OR(0x33e0, 0, 0x00000001);
317 RCBA32_AND_OR(0x3a20, 0, 0x00000404);
318 RCBA32_AND_OR(0x3a24, 0, 0x01010101);
319 RCBA32_AND_OR(0x3a30, 0, 0x01010101);
320 RCBA32_AND_OR(0x0410, ~0, 0x00000003);
321 RCBA32_AND_OR(0x2618, ~0, 0x08000000);
322 RCBA32_AND_OR(0x2300, ~0, 0x00000002);
323 RCBA32_AND_OR(0x2600, ~0, 0x00000008);
324 RCBA32_AND_OR(0x33b4, 0, 0x00007001);
325 RCBA32_AND_OR(0x3350, 0, 0x022ddfff);
326 RCBA32_AND_OR(0x3354, 0, 0x00000001);
327 RCBA32_AND_OR(0x33d4, ~0, 0x08000000); /* Power Optimizer */
328 RCBA32_AND_OR(0x33c8, ~0, 0x00000080); /* Power Optimizer */
329 RCBA32_AND_OR(0x2b10, 0, 0x0000883c); /* Power Optimizer */
330 RCBA32_AND_OR(0x2b14, 0, 0x1e0a4616); /* Power Optimizer */
331 RCBA32_AND_OR(0x2b24, 0, 0x40000005); /* Power Optimizer */
332 RCBA32_AND_OR(0x2b20, 0, 0x0005db01); /* Power Optimizer */
333 RCBA32_AND_OR(0x3a80, 0, 0x05145005);
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800334
335 pci_write_config32(dev, 0xac,
336 pci_read_config32(dev, 0xac) | (1 << 21));
337
Elyes HAOUASa0aea562017-07-03 21:38:53 +0200338 pch_iobp_update(0xED00015C, ~(1 << 11), 0x00003700);
Duncan Laurie4bc107b2013-06-24 13:14:44 -0700339 pch_iobp_update(0xED000118, ~0UL, 0x00c00000);
340 pch_iobp_update(0xED000120, ~0UL, 0x00240000);
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800341 pch_iobp_update(0xCA000000, ~0UL, 0x00000009);
342
343 /* Set RCBA CIR28 0x3A84 based on SATA port enables */
344 data = 0x00001005;
345 /* Port 3 and 2 disabled */
346 if ((config->sata_port_map & ((1 << 3)|(1 << 2))) == 0)
347 data |= (1 << 24) | (1 << 26);
348 /* Port 1 and 0 disabled */
349 if ((config->sata_port_map & ((1 << 1)|(1 << 0))) == 0)
350 data |= (1 << 20) | (1 << 18);
351 RCBA32(0x3a84) = data;
352
Duncan Laurie5cf34ce2013-04-26 10:41:33 -0700353 /* Set RCBA 0x2b1c[29]=1 if DSP disabled */
354 if (RCBA32(FD) & PCH_DISABLE_ADSPD)
355 RCBA32_OR(0x2b1c, (1 << 29));
356
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800357 /* Lock */
358 RCBA32_OR(0x3a6c, 0x00000001);
359
360 /* Set RCBA 0x33D4 after other setup */
361 RCBA32_OR(0x33d4, 0x2fff2fb1);
362
363 /* Set RCBA 0x33C8[15]=1 as last step */
364 RCBA32_OR(0x33c8, (1 << 15));
365}
Aaron Durbin76c37002012-10-30 09:03:43 -0500366
Matt DeVilliera51e3792018-03-04 01:44:15 -0600367static void enable_hpet(struct device *const dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500368{
369 u32 reg32;
Matt DeVilliera51e3792018-03-04 01:44:15 -0600370 size_t i;
371
372 /* Assign unique bus/dev/fn for each HPET */
373 for (i = 0; i < 8; ++i)
374 pci_write_config16(dev, LPC_HnBDF(i),
375 PCH_HPET_PCI_BUS << 8 | PCH_HPET_PCI_SLOT << 3 | i);
Aaron Durbin76c37002012-10-30 09:03:43 -0500376
377 /* Move HPET to default address 0xfed00000 and enable it */
378 reg32 = RCBA32(HPTC);
379 reg32 |= (1 << 7); // HPET Address Enable
380 reg32 &= ~(3 << 0);
381 RCBA32(HPTC) = reg32;
382 /* Read it back to stick. It's affected by posted write syndrome. */
Elyes HAOUAS6de151e2019-10-18 16:43:30 +0200383 RCBA32(HPTC);
Aaron Durbin76c37002012-10-30 09:03:43 -0500384}
385
Elyes HAOUAS7a5f7712018-06-08 17:20:38 +0200386static void enable_clock_gating(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500387{
Duncan Laurie74c0d052012-12-17 11:31:40 -0800388 /* LynxPoint Mobile */
389 u32 reg32;
390 u16 reg16;
391
392 /* DMI */
393 RCBA32_AND_OR(0x2234, ~0UL, 0xf);
394 reg16 = pci_read_config16(dev, GEN_PMCON_1);
395 reg16 |= (1 << 11) | (1 << 12) | (1 << 14);
396 reg16 |= (1 << 2); // PCI CLKRUN# Enable
397 pci_write_config16(dev, GEN_PMCON_1, reg16);
398 RCBA32_OR(0x900, (1 << 14));
399
400 reg32 = RCBA32(CG);
401 reg32 |= (1 << 22); // HDA Dynamic
Ryan Salsamendi0d9b3602017-06-30 17:15:57 -0700402 reg32 |= (1UL << 31); // LPC Dynamic
Duncan Laurie74c0d052012-12-17 11:31:40 -0800403 reg32 |= (1 << 16); // PCIe Dynamic
404 reg32 |= (1 << 27); // HPET Dynamic
405 reg32 |= (1 << 28); // GPIO Dynamic
406 RCBA32(CG) = reg32;
407
408 RCBA32_OR(0x38c0, 0x7); // SPI Dynamic
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800409}
410
Elyes HAOUAS7a5f7712018-06-08 17:20:38 +0200411static void enable_lp_clock_gating(struct device *dev)
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800412{
413 /* LynxPoint LP */
414 u32 reg32;
415 u16 reg16;
416
417 /* DMI */
418 RCBA32_AND_OR(0x2234, ~0UL, 0xf);
419 reg16 = pci_read_config16(dev, GEN_PMCON_1);
420 reg16 &= ~((1 << 11) | (1 << 14));
421 reg16 |= (1 << 5) | (1 << 6) | (1 << 7) | (1 << 12) | (1 << 13);
422 reg16 |= (1 << 2); // PCI CLKRUN# Enable
423 pci_write_config16(dev, GEN_PMCON_1, reg16);
424
425 reg32 = pci_read_config32(dev, 0x64);
426 reg32 |= (1 << 6);
427 pci_write_config32(dev, 0x64, reg32);
428
Duncan Laurie4bc107b2013-06-24 13:14:44 -0700429 /*
430 * RCBA + 0x2614[27:25,14:13,10,8] = 101,11,1,1
431 * RCBA + 0x2614[23:16] = 0x20
432 * RCBA + 0x2614[30:28] = 0x0
Duncan Lauried8c7d732013-07-16 09:01:43 -0700433 * RCBA + 0x2614[26] = 1 (IF 0:2.0@0x08 >= 0x0b)
Duncan Laurie4bc107b2013-06-24 13:14:44 -0700434 */
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800435 RCBA32_AND_OR(0x2614, 0x8bffffff, 0x0a206500);
Duncan Laurie4bc107b2013-06-24 13:14:44 -0700436
437 /* Check for LPT-LP B2 stepping and 0:31.0@0xFA > 4 */
Nico Huber744d6bd2019-01-12 14:58:20 +0100438 struct device *const gma = pcidev_on_root(2, 0);
439 if (gma && pci_read_config8(gma, 0x8) >= 0x0b)
Elyes HAOUASa0aea562017-07-03 21:38:53 +0200440 RCBA32_OR(0x2614, (1 << 26));
Duncan Laurie4bc107b2013-06-24 13:14:44 -0700441
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800442 RCBA32_OR(0x900, 0x0000031f);
443
444 reg32 = RCBA32(CG);
Duncan Lauriea2d6a402013-03-22 11:24:45 -0700445 if (RCBA32(0x3454) & (1 << 4))
446 reg32 &= ~(1 << 29); // LPC Dynamic
447 else
448 reg32 |= (1 << 29); // LPC Dynamic
Ryan Salsamendi3f2fe182017-07-04 13:14:16 -0700449 reg32 |= (1UL << 31); // LP LPC
Duncan Laurie5cf34ce2013-04-26 10:41:33 -0700450 reg32 |= (1 << 30); // LP BLA
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800451 reg32 |= (1 << 28); // GPIO Dynamic
452 reg32 |= (1 << 27); // HPET Dynamic
Duncan Laurie5cf34ce2013-04-26 10:41:33 -0700453 reg32 |= (1 << 26); // Generic Platform Event Clock
454 if (RCBA32(BUC) & PCH_DISABLE_GBE)
455 reg32 |= (1 << 23); // GbE Static
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800456 reg32 |= (1 << 22); // HDA Dynamic
Duncan Laurie5cf34ce2013-04-26 10:41:33 -0700457 reg32 |= (1 << 16); // PCI Dynamic
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800458 RCBA32(CG) = reg32;
459
460 RCBA32_OR(0x3434, 0x7); // LP LPC
461
462 RCBA32_AND_OR(0x333c, 0xffcfffff, 0x00c00000); // SATA
463
464 RCBA32_OR(0x38c0, 0x3c07); // SPI Dynamic
465
466 pch_iobp_update(0xCF000000, ~0UL, 0x00007001);
Duncan Laurie5cf34ce2013-04-26 10:41:33 -0700467 pch_iobp_update(0xCE00C000, ~1UL, 0x00000000); // bit0=0 in BWG 1.4.0
Aaron Durbin76c37002012-10-30 09:03:43 -0500468}
469
Aaron Durbin29ffa542012-12-21 21:21:48 -0600470static void pch_set_acpi_mode(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500471{
Kyösti Mälkkiad882c32020-06-02 05:05:30 +0300472 if (!acpi_is_wakeup_s3())
Kyösti Mälkkib6585482020-06-01 15:11:14 +0300473 apm_control(APM_CNT_ACPI_DISABLE);
Aaron Durbin76c37002012-10-30 09:03:43 -0500474}
Aaron Durbin76c37002012-10-30 09:03:43 -0500475
476static void pch_disable_smm_only_flashing(struct device *dev)
477{
478 u8 reg8;
479
480 printk(BIOS_SPEW, "Enabling BIOS updates outside of SMM... ");
Elyes HAOUAS0c22d2f2018-12-01 12:19:52 +0100481 reg8 = pci_read_config8(dev, BIOS_CNTL);
Aaron Durbin76c37002012-10-30 09:03:43 -0500482 reg8 &= ~(1 << 5);
Elyes HAOUAS0c22d2f2018-12-01 12:19:52 +0100483 pci_write_config8(dev, BIOS_CNTL, reg8);
Aaron Durbin76c37002012-10-30 09:03:43 -0500484}
485
486static void pch_fixups(struct device *dev)
487{
488 u8 gen_pmcon_2;
489
490 /* Indicate DRAM init done for MRC S3 to know it can resume */
491 gen_pmcon_2 = pci_read_config8(dev, GEN_PMCON_2);
492 gen_pmcon_2 |= (1 << 7);
493 pci_write_config8(dev, GEN_PMCON_2, gen_pmcon_2);
494
495 /*
496 * Enable DMI ASPM in the PCH
497 */
498 RCBA32_AND_OR(0x2304, ~(1 << 10), 0);
499 RCBA32_OR(0x21a4, (1 << 11)|(1 << 10));
500 RCBA32_OR(0x21a8, 0x3);
501}
502
Aaron Durbin76c37002012-10-30 09:03:43 -0500503static void lpc_init(struct device *dev)
504{
Elyes HAOUASbfc255a2020-03-07 13:05:14 +0100505 printk(BIOS_DEBUG, "pch: %s\n", __func__);
Aaron Durbin76c37002012-10-30 09:03:43 -0500506
507 /* Set the value for PCI command register. */
508 pci_write_config16(dev, PCI_COMMAND, 0x000f);
509
510 /* IO APIC initialization. */
Paul Menzel373a20c2013-05-03 12:17:02 +0200511 pch_enable_ioapic(dev);
Aaron Durbin76c37002012-10-30 09:03:43 -0500512
513 pch_enable_serial_irqs(dev);
514
515 /* Setup the PIRQ. */
516 pch_pirq_init(dev);
517
518 /* Setup power options. */
519 pch_power_options(dev);
520
521 /* Initialize power management */
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800522 if (pch_is_lp()) {
523 lpt_lp_pm_init(dev);
524 enable_lp_clock_gating(dev);
525 } else {
526 lpt_pm_init(dev);
527 enable_clock_gating(dev);
Aaron Durbin76c37002012-10-30 09:03:43 -0500528 }
529
Aaron Durbin76c37002012-10-30 09:03:43 -0500530 /* Initialize the real time clock. */
Patrick Rudolph6b931122018-11-01 17:48:37 +0100531 sb_rtc_init();
Aaron Durbin76c37002012-10-30 09:03:43 -0500532
533 /* Initialize ISA DMA. */
534 isa_dma_init();
535
536 /* Initialize the High Precision Event Timers, if present. */
Matt DeVilliera51e3792018-03-04 01:44:15 -0600537 enable_hpet(dev);
Aaron Durbin76c37002012-10-30 09:03:43 -0500538
Aaron Durbin76c37002012-10-30 09:03:43 -0500539 setup_i8259();
540
Aaron Durbin76c37002012-10-30 09:03:43 -0500541 /* Interrupt 9 should be level triggered (SCI) */
542 i8259_configure_irq_trigger(9, 1);
543
544 pch_disable_smm_only_flashing(dev);
545
Aaron Durbin29ffa542012-12-21 21:21:48 -0600546 pch_set_acpi_mode();
Aaron Durbin76c37002012-10-30 09:03:43 -0500547
548 pch_fixups(dev);
549}
550
Elyes HAOUAS7a5f7712018-06-08 17:20:38 +0200551static void pch_lpc_add_mmio_resources(struct device *dev)
Aaron Durbin6f561af2012-12-19 14:38:01 -0600552{
553 u32 reg;
554 struct resource *res;
555 const u32 default_decode_base = IO_APIC_ADDR;
556
557 /*
558 * Just report all resources from IO-APIC base to 4GiB. Don't mark
559 * them reserved as that may upset the OS if this range is marked
560 * as reserved in the e820.
561 */
562 res = new_resource(dev, OIC);
563 res->base = default_decode_base;
564 res->size = 0 - default_decode_base;
565 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
566
567 /* RCBA */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800568 if ((uintptr_t)DEFAULT_RCBA < default_decode_base) {
Aaron Durbin6f561af2012-12-19 14:38:01 -0600569 res = new_resource(dev, RCBA);
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800570 res->base = (resource_t)(uintptr_t)DEFAULT_RCBA;
Aaron Durbin6f561af2012-12-19 14:38:01 -0600571 res->size = 16 * 1024;
572 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
573 IORESOURCE_FIXED | IORESOURCE_RESERVE;
574 }
575
576 /* Check LPC Memory Decode register. */
577 reg = pci_read_config32(dev, LGMR);
578 if (reg & 1) {
579 reg &= ~0xffff;
580 if (reg < default_decode_base) {
581 res = new_resource(dev, LGMR);
582 res->base = reg;
583 res->size = 16 * 1024;
584 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
585 IORESOURCE_FIXED | IORESOURCE_RESERVE;
586 }
587 }
588}
589
590/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
591#define LPC_DEFAULT_IO_RANGE_LOWER 0
592#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
593
Julius Werner7c712bb2019-05-01 16:51:20 -0700594static inline int pch_io_range_in_default(int base, int size)
Aaron Durbin6f561af2012-12-19 14:38:01 -0600595{
596 /* Does it start above the range? */
597 if (base >= LPC_DEFAULT_IO_RANGE_UPPER)
598 return 0;
599
600 /* Is it entirely contained? */
601 if (base >= LPC_DEFAULT_IO_RANGE_LOWER &&
602 (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
603 return 1;
604
605 /* This will return not in range for partial overlaps. */
606 return 0;
607}
608
609/*
610 * Note: this function assumes there is no overlap with the default LPC device's
611 * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
612 */
Elyes HAOUAS7a5f7712018-06-08 17:20:38 +0200613static void pch_lpc_add_io_resource(struct device *dev, u16 base, u16 size,
614 int index)
Aaron Durbin6f561af2012-12-19 14:38:01 -0600615{
616 struct resource *res;
617
618 if (pch_io_range_in_default(base, size))
619 return;
620
621 res = new_resource(dev, index);
622 res->base = base;
623 res->size = size;
624 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
625}
626
Elyes HAOUAS7a5f7712018-06-08 17:20:38 +0200627static void pch_lpc_add_gen_io_resources(struct device *dev, int reg_value,
628 int index)
Aaron Durbin6f561af2012-12-19 14:38:01 -0600629{
630 /*
631 * Check if the register is enabled. If so and the base exceeds the
Kyösti Mälkkib544c002019-01-06 10:41:41 +0200632 * device's default, claim range and add the resource.
Aaron Durbin6f561af2012-12-19 14:38:01 -0600633 */
634 if (reg_value & 1) {
635 u16 base = reg_value & 0xfffc;
636 u16 size = (0x3 | ((reg_value >> 16) & 0xfc)) + 1;
637 pch_lpc_add_io_resource(dev, base, size, index);
638 }
639}
640
Elyes HAOUAS7a5f7712018-06-08 17:20:38 +0200641static void pch_lpc_add_io_resources(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500642{
643 struct resource *res;
644 config_t *config = dev->chip_info;
Aaron Durbin76c37002012-10-30 09:03:43 -0500645
Aaron Durbin6f561af2012-12-19 14:38:01 -0600646 /* Add the default claimed IO range for the LPC device. */
647 res = new_resource(dev, 0);
648 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
649 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
650 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
651
652 /* GPIOBASE */
Duncan Laurie7922b462013-03-08 16:34:33 -0800653 pch_lpc_add_io_resource(dev, get_gpiobase(), DEFAULT_GPIOSIZE,
Aaron Durbin6f561af2012-12-19 14:38:01 -0600654 GPIO_BASE);
655
656 /* PMBASE */
Duncan Laurie7922b462013-03-08 16:34:33 -0800657 pch_lpc_add_io_resource(dev, get_pmbase(), 256, PMBASE);
Aaron Durbin6f561af2012-12-19 14:38:01 -0600658
659 /* LPC Generic IO Decode range. */
660 pch_lpc_add_gen_io_resources(dev, config->gen1_dec, LPC_GEN1_DEC);
661 pch_lpc_add_gen_io_resources(dev, config->gen2_dec, LPC_GEN2_DEC);
662 pch_lpc_add_gen_io_resources(dev, config->gen3_dec, LPC_GEN3_DEC);
663 pch_lpc_add_gen_io_resources(dev, config->gen4_dec, LPC_GEN4_DEC);
664}
665
Elyes HAOUAS7a5f7712018-06-08 17:20:38 +0200666static void pch_lpc_read_resources(struct device *dev)
Aaron Durbin6f561af2012-12-19 14:38:01 -0600667{
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +0300668 struct global_nvs *gnvs;
Duncan Laurie9c07c8f2013-03-22 11:08:39 -0700669
Aaron Durbin76c37002012-10-30 09:03:43 -0500670 /* Get the normal PCI resources of this device. */
671 pci_dev_read_resources(dev);
672
Aaron Durbin6f561af2012-12-19 14:38:01 -0600673 /* Add non-standard MMIO resources. */
674 pch_lpc_add_mmio_resources(dev);
Aaron Durbin76c37002012-10-30 09:03:43 -0500675
Aaron Durbin6f561af2012-12-19 14:38:01 -0600676 /* Add IO resources. */
677 pch_lpc_add_io_resources(dev);
Duncan Laurie9c07c8f2013-03-22 11:08:39 -0700678
679 /* Allocate ACPI NVS in CBMEM */
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +0300680 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(struct global_nvs));
Kyösti Mälkkic3ed8862014-06-19 19:50:51 +0300681 if (!acpi_is_wakeup_s3() && gnvs)
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +0300682 memset(gnvs, 0, sizeof(struct global_nvs));
Aaron Durbin76c37002012-10-30 09:03:43 -0500683}
684
Elyes HAOUAS7a5f7712018-06-08 17:20:38 +0200685static void pch_lpc_enable(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500686{
687 /* Enable PCH Display Port */
688 RCBA16(DISPBDF) = 0x0010;
689 RCBA32_OR(FD2, PCH_ENABLE_DBDF);
690
691 pch_enable(dev);
692}
693
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +0300694void southbridge_inject_dsdt(const struct device *dev)
Vladimir Serbinenkoc6e566a2014-08-31 17:43:51 +0200695{
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +0300696 struct global_nvs *gnvs;
Vladimir Serbinenko7309c642014-10-05 11:07:33 +0200697
698 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
699 if (!gnvs) {
Elyes HAOUAS035df002016-10-03 21:54:16 +0200700 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(*gnvs));
Vladimir Serbinenko7309c642014-10-05 11:07:33 +0200701 if (gnvs)
702 memset(gnvs, 0, sizeof(*gnvs));
703 }
Vladimir Serbinenkoc6e566a2014-08-31 17:43:51 +0200704
705 if (gnvs) {
Vladimir Serbinenkoc6e566a2014-08-31 17:43:51 +0200706 acpi_create_gnvs(gnvs);
Vladimir Serbinenko1b409fd2014-10-12 00:26:21 +0200707
708 gnvs->apic = 1;
709 gnvs->mpen = 1; /* Enable Multi Processing */
710 gnvs->pcnt = dev_count_cpu();
711
Julius Wernercd49cce2019-03-05 16:53:33 -0800712#if CONFIG(CHROMEOS)
Joel Kitching6fbd8742018-08-23 14:56:25 +0800713 chromeos_init_chromeos_acpi(&(gnvs->chromeos));
Vladimir Serbinenko1b409fd2014-10-12 00:26:21 +0200714#endif
715
716 /* Update the mem console pointer. */
717 gnvs->cbmc = (u32)cbmem_find(CBMEM_ID_CONSOLE);
718
Vladimir Serbinenkoc6e566a2014-08-31 17:43:51 +0200719 /* And tell SMI about it */
Kyösti Mälkkic3c55212020-06-17 10:34:26 +0300720 apm_control(APM_CNT_GNVS_UPDATE);
Vladimir Serbinenkoc6e566a2014-08-31 17:43:51 +0200721
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +0200722 /* Add it to DSDT. */
Vladimir Serbinenkobe0fd0a2014-11-04 21:10:59 +0100723 acpigen_write_scope("\\");
724 acpigen_write_name_dword("NVSA", (u32) gnvs);
725 acpigen_pop_len();
Vladimir Serbinenkoc6e566a2014-08-31 17:43:51 +0200726 }
Vladimir Serbinenkoc6e566a2014-08-31 17:43:51 +0200727}
728
Tristan Corrickb2632ce2018-10-31 02:28:13 +1300729void acpi_fill_fadt(acpi_fadt_t *fadt)
730{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300731 struct device *dev = pcidev_on_root(0x1f, 0);
Tristan Corrickb2632ce2018-10-31 02:28:13 +1300732 struct southbridge_intel_lynxpoint_config *cfg = dev->chip_info;
733 u16 pmbase = get_pmbase();
734
735 fadt->sci_int = 0x9;
Kyösti Mälkkic328a682019-11-23 07:23:40 +0200736
Kyösti Mälkki0a9e72e2019-08-11 01:22:28 +0300737 if (permanent_smi_handler()) {
Kyösti Mälkkic328a682019-11-23 07:23:40 +0200738 fadt->smi_cmd = APM_CNT;
739 fadt->acpi_enable = APM_CNT_ACPI_ENABLE;
740 fadt->acpi_disable = APM_CNT_ACPI_DISABLE;
741 }
Tristan Corrickb2632ce2018-10-31 02:28:13 +1300742
743 fadt->pm1a_evt_blk = pmbase + PM1_STS;
744 fadt->pm1b_evt_blk = 0x0;
745 fadt->pm1a_cnt_blk = pmbase + PM1_CNT;
746 fadt->pm1b_cnt_blk = 0x0;
747 fadt->pm2_cnt_blk = pmbase + PM2_CNT;
748 fadt->pm_tmr_blk = pmbase + PM1_TMR;
749 if (pch_is_lp())
750 fadt->gpe0_blk = pmbase + LP_GPE0_STS_1;
751 else
752 fadt->gpe0_blk = pmbase + GPE0_STS;
753 fadt->gpe1_blk = 0;
754
755 /*
756 * Some of the lengths here are doubled. This is because they describe
757 * blocks containing two registers, where the size of each register
758 * is found by halving the block length. See Table 5-34 and section
759 * 4.8.3 of the ACPI specification for details.
760 */
761 fadt->pm1_evt_len = 2 * 2;
762 fadt->pm1_cnt_len = 2;
763 fadt->pm2_cnt_len = 1;
764 fadt->pm_tmr_len = 4;
765 if (pch_is_lp())
766 fadt->gpe0_blk_len = 2 * 16;
767 else
768 fadt->gpe0_blk_len = 2 * 8;
769 fadt->gpe1_blk_len = 0;
770 fadt->gpe1_base = 0;
771
Tristan Corrickb2632ce2018-10-31 02:28:13 +1300772 fadt->p_lvl2_lat = 1;
773 fadt->p_lvl3_lat = 87;
774 fadt->flush_size = 0;
775 fadt->flush_stride = 0;
776 fadt->duty_offset = 0;
777 fadt->duty_width = 0;
778 fadt->day_alrm = 0xd;
779 fadt->mon_alrm = 0x00;
780 fadt->century = 0x00;
781 fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042;
782
783 fadt->flags = ACPI_FADT_WBINVD |
784 ACPI_FADT_C1_SUPPORTED |
785 ACPI_FADT_C2_MP_SUPPORTED |
786 ACPI_FADT_SLEEP_BUTTON |
787 ACPI_FADT_RESET_REGISTER |
788 ACPI_FADT_SEALED_CASE |
789 ACPI_FADT_S4_RTC_WAKE |
790 ACPI_FADT_PLATFORM_CLOCK;
791
792 if (cfg->docking_supported)
793 fadt->flags |= ACPI_FADT_DOCKING_SUPPORTED;
794
795 fadt->reset_reg.space_id = ACPI_ADDRESS_SPACE_IO;
796 fadt->reset_reg.bit_width = 8;
797 fadt->reset_reg.bit_offset = 0;
798 fadt->reset_reg.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
799 fadt->reset_reg.addrl = 0xcf9;
800 fadt->reset_reg.addrh = 0;
801
802 fadt->reset_value = 6;
803
804 fadt->x_pm1a_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
805 fadt->x_pm1a_evt_blk.bit_width = 2 * 16;
806 fadt->x_pm1a_evt_blk.bit_offset = 0;
807 fadt->x_pm1a_evt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS;
808 fadt->x_pm1a_evt_blk.addrl = pmbase + PM1_STS;
809 fadt->x_pm1a_evt_blk.addrh = 0x0;
810
811 fadt->x_pm1b_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
812 fadt->x_pm1b_evt_blk.bit_width = 0;
813 fadt->x_pm1b_evt_blk.bit_offset = 0;
814 fadt->x_pm1b_evt_blk.access_size = 0;
815 fadt->x_pm1b_evt_blk.addrl = 0x0;
816 fadt->x_pm1b_evt_blk.addrh = 0x0;
817
818 fadt->x_pm1a_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
819 fadt->x_pm1a_cnt_blk.bit_width = 16;
820 fadt->x_pm1a_cnt_blk.bit_offset = 0;
821 fadt->x_pm1a_cnt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS;
822 fadt->x_pm1a_cnt_blk.addrl = pmbase + PM1_CNT;
823 fadt->x_pm1a_cnt_blk.addrh = 0x0;
824
825 fadt->x_pm1b_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
826 fadt->x_pm1b_cnt_blk.bit_width = 0;
827 fadt->x_pm1b_cnt_blk.bit_offset = 0;
828 fadt->x_pm1b_cnt_blk.access_size = 0;
829 fadt->x_pm1b_cnt_blk.addrl = 0x0;
830 fadt->x_pm1b_cnt_blk.addrh = 0x0;
831
832 fadt->x_pm2_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
833 fadt->x_pm2_cnt_blk.bit_width = 8;
834 fadt->x_pm2_cnt_blk.bit_offset = 0;
835 fadt->x_pm2_cnt_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
836 fadt->x_pm2_cnt_blk.addrl = pmbase + PM2_CNT;
837 fadt->x_pm2_cnt_blk.addrh = 0x0;
838
839 fadt->x_pm_tmr_blk.space_id = ACPI_ADDRESS_SPACE_IO;
840 fadt->x_pm_tmr_blk.bit_width = 32;
841 fadt->x_pm_tmr_blk.bit_offset = 0;
842 fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
843 fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR;
844 fadt->x_pm_tmr_blk.addrh = 0x0;
845
846 /*
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100847 * Windows 10 requires x_gpe0_blk to be set starting with FADT revision 5.
848 * The bit_width field intentionally overflows here.
849 * The OSPM can instead use the values in `fadt->gpe0_blk{,_len}`, which
850 * seems to work fine on Linux 5.0 and Windows 10.
Tristan Corrickb2632ce2018-10-31 02:28:13 +1300851 */
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100852 fadt->x_gpe0_blk.space_id = ACPI_ADDRESS_SPACE_IO;
853 fadt->x_gpe0_blk.bit_width = fadt->gpe0_blk_len * 8;
854 fadt->x_gpe0_blk.bit_offset = 0;
Angel Ponsa23aff32020-06-21 20:47:54 +0200855 fadt->x_gpe0_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100856 fadt->x_gpe0_blk.addrl = fadt->gpe0_blk;
857 fadt->x_gpe0_blk.addrh = 0x0;
Tristan Corrickb2632ce2018-10-31 02:28:13 +1300858
859 fadt->x_gpe1_blk.space_id = ACPI_ADDRESS_SPACE_IO;
860 fadt->x_gpe1_blk.bit_width = 0;
861 fadt->x_gpe1_blk.bit_offset = 0;
862 fadt->x_gpe1_blk.access_size = 0;
863 fadt->x_gpe1_blk.addrl = 0x0;
864 fadt->x_gpe1_blk.addrh = 0x0;
865}
866
Tristan Corrickf3127d42018-10-31 02:25:54 +1300867static const char *lpc_acpi_name(const struct device *dev)
868{
869 return "LPCB";
870}
871
Furquan Shaikh7536a392020-04-24 21:59:21 -0700872static void southbridge_fill_ssdt(const struct device *dev)
Tristan Corrickf3127d42018-10-31 02:25:54 +1300873{
874 intel_acpi_gen_def_acpi_pirq(dev);
875}
876
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700877static unsigned long southbridge_write_acpi_tables(const struct device *device,
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200878 unsigned long start,
879 struct acpi_rsdp *rsdp)
Vladimir Serbinenkoc6e566a2014-08-31 17:43:51 +0200880{
881 unsigned long current;
882 acpi_hpet_t *hpet;
883 acpi_header_t *ssdt;
884
885 current = start;
886
887 /* Align ACPI tables to 16byte */
Aaron Durbin07a1b282015-12-10 17:07:38 -0600888 current = acpi_align_current(current);
Vladimir Serbinenkoc6e566a2014-08-31 17:43:51 +0200889
890 /*
891 * We explicitly add these tables later on:
892 */
893 printk(BIOS_DEBUG, "ACPI: * HPET\n");
894
895 hpet = (acpi_hpet_t *) current;
896 current += sizeof(acpi_hpet_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -0600897 current = acpi_align_current(current);
Vladimir Serbinenkoc6e566a2014-08-31 17:43:51 +0200898 acpi_create_intel_hpet(hpet);
899 acpi_add_table(rsdp, hpet);
900
Aaron Durbin07a1b282015-12-10 17:07:38 -0600901 current = acpi_align_current(current);
Vladimir Serbinenkoc6e566a2014-08-31 17:43:51 +0200902
903 printk(BIOS_DEBUG, "ACPI: * SSDT2\n");
904 ssdt = (acpi_header_t *)current;
905 acpi_create_serialio_ssdt(ssdt);
906 current += ssdt->length;
907 acpi_add_table(rsdp, ssdt);
Aaron Durbin07a1b282015-12-10 17:07:38 -0600908 current = acpi_align_current(current);
Vladimir Serbinenkoc6e566a2014-08-31 17:43:51 +0200909
910 printk(BIOS_DEBUG, "current = %lx\n", current);
911 return current;
912}
913
Tristan Corrick32ceed82018-11-30 22:53:27 +1300914static void lpc_final(struct device *dev)
915{
Arthur Heymansa3121b02019-05-28 13:46:49 +0200916 spi_finalize_ops();
Tristan Corrick63626b12018-11-30 22:53:50 +1300917
Julius Wernercd49cce2019-03-05 16:53:33 -0800918 if (acpi_is_wakeup_s3() || CONFIG(INTEL_CHIPSET_LOCKDOWN))
Kyösti Mälkkib6585482020-06-01 15:11:14 +0300919 apm_control(APM_CNT_FINALIZE);
Tristan Corrick32ceed82018-11-30 22:53:27 +1300920}
Vladimir Serbinenkoc6e566a2014-08-31 17:43:51 +0200921
Aaron Durbin76c37002012-10-30 09:03:43 -0500922static struct device_operations device_ops = {
923 .read_resources = pch_lpc_read_resources,
924 .set_resources = pci_dev_set_resources,
Duncan Laurie8d783b82013-05-14 11:16:34 -0700925 .enable_resources = pci_dev_enable_resources,
Nico Huber68680dd2020-03-31 17:34:52 +0200926 .acpi_fill_ssdt = southbridge_fill_ssdt,
927 .acpi_inject_dsdt = southbridge_inject_dsdt,
Tristan Corrickf3127d42018-10-31 02:25:54 +1300928 .acpi_name = lpc_acpi_name,
Vladimir Serbinenkoc6e566a2014-08-31 17:43:51 +0200929 .write_acpi_tables = southbridge_write_acpi_tables,
Aaron Durbin76c37002012-10-30 09:03:43 -0500930 .init = lpc_init,
Tristan Corrick32ceed82018-11-30 22:53:27 +1300931 .final = lpc_final,
Aaron Durbin76c37002012-10-30 09:03:43 -0500932 .enable = pch_lpc_enable,
Nico Huber51b75ae2019-03-14 16:02:05 +0100933 .scan_bus = scan_static_bus,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200934 .ops_pci = &pci_dev_ops_pci,
Aaron Durbin76c37002012-10-30 09:03:43 -0500935};
936
937
Aaron Durbinc1989c42012-12-11 17:13:17 -0600938/* IDs for LPC device of Intel 8 Series Chipset (Lynx Point) */
939static const unsigned short pci_device_ids[] = {
940 0x8c41, /* Mobile Full Featured Engineering Sample. */
941 0x8c42, /* Desktop Full Featured Engineering Sample. */
942 0x8c44, /* Z87 SKU */
943 0x8c46, /* Z85 SKU */
944 0x8c49, /* HM86 SKU */
945 0x8c4a, /* H87 SKU */
946 0x8c4b, /* HM87 SKU */
947 0x8c4c, /* Q85 SKU */
948 0x8c4e, /* Q87 SKU */
949 0x8c4f, /* QM87 SKU */
Tristan Corrick9a085742018-10-31 02:20:28 +1300950 0x8c50, /* B85 SKU */
951 0x8c52, /* C222 SKU */
952 0x8c54, /* C224 SKU */
953 0x8c56, /* C226 SKU */
954 0x8c5c, /* H81 SKU */
Duncan Laurie74c0d052012-12-17 11:31:40 -0800955 0x9c41, /* LP Full Featured Engineering Sample */
956 0x9c43, /* LP Premium SKU */
957 0x9c45, /* LP Mainstream SKU */
958 0x9c47, /* LP Value SKU */
Aaron Durbinc1989c42012-12-11 17:13:17 -0600959 0 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500960
961static const struct pci_driver pch_lpc __pci_driver = {
962 .ops = &device_ops,
963 .vendor = PCI_VENDOR_ID_INTEL,
964 .devices = pci_device_ids,
965};