blob: ecd66fa62628ff11e4f906a974c2a33167e14098 [file] [log] [blame]
Angel Ponsf94ac9a2020-04-05 15:46:48 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Duncan Lauriec88c54c2014-04-30 16:36:13 -07002
3#include <console/console.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -07004#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>
Duncan Lauriec88c54c2014-04-30 16:36:13 -07008#include <pc80/isa-dma.h>
9#include <pc80/i8259.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020010#include <device/pci_ops.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070011#include <arch/ioapic.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -070012#include <acpi/acpi.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070013#include <cpu/x86/smm.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070014#include <soc/iomap.h>
15#include <soc/lpc.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070016#include <soc/pch.h>
17#include <soc/pci_devs.h>
18#include <soc/pm.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070019#include <soc/rcba.h>
Angel Pons3cc2c382020-10-23 20:38:23 +020020#include <soc/intel/broadwell/pch/chip.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -070021#include <acpi/acpigen.h>
Arthur Heymans2abbe462019-06-04 14:12:01 +020022#include <southbridge/intel/common/rtc.h>
Angel Ponsc423ce22021-04-19 16:13:31 +020023#include <southbridge/intel/lynxpoint/iobp.h>
Angel Pons733f03d2021-01-28 16:59:04 +010024#include <southbridge/intel/lynxpoint/lp_gpio.h>
Duncan Laurie35dc00f2015-01-18 14:06:42 -080025
Duncan Lauriec88c54c2014-04-30 16:36:13 -070026static void pch_enable_ioapic(struct device *dev)
27{
Matt DeVillier81a6f102018-02-19 17:33:48 -060028 /* Assign unique bus/dev/fn for I/O APIC */
29 pci_write_config16(dev, LPC_IBDF,
30 PCH_IOAPIC_PCI_BUS << 8 | PCH_IOAPIC_PCI_SLOT << 3);
31
Duncan Lauriec88c54c2014-04-30 16:36:13 -070032 /* affirm full set of redirection table entries ("write once") */
Kyösti Mälkki04a40372021-06-06 08:04:28 +030033 /* PCH-LP has 40 redirection entries */
Felix Held0d192892024-02-06 16:55:29 +010034 ioapic_set_max_vectors(IO_APIC_ADDR, 40);
Kyösti Mälkkiea6d12a2021-06-08 11:25:29 +030035
Felix Held0d192892024-02-06 16:55:29 +010036 register_new_ioapic_gsi0(IO_APIC_ADDR);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070037}
38
Kyösti Mälkkie742b682023-04-10 17:03:32 +030039#define ACPI_SCI_IRQ 9
40
41void ioapic_get_sci_pin(u8 *gsi, u8 *irq, u8 *flags)
42{
43 *gsi = ACPI_SCI_IRQ;
44 *irq = ACPI_SCI_IRQ;
45 *flags = MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_HIGH;
46}
47
Matt DeVillier81a6f102018-02-19 17:33:48 -060048static void enable_hpet(struct device *dev)
49{
50 size_t i;
51
52 /* Assign unique bus/dev/fn for each HPET */
53 for (i = 0; i < 8; ++i)
54 pci_write_config16(dev, LPC_HnBDF(i),
55 PCH_HPET_PCI_BUS << 8 | PCH_HPET_PCI_SLOT << 3 | i);
56}
57
Duncan Lauriec88c54c2014-04-30 16:36:13 -070058/* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control
59 * 0x00 - 0000 = Reserved
60 * 0x01 - 0001 = Reserved
61 * 0x02 - 0010 = Reserved
62 * 0x03 - 0011 = IRQ3
63 * 0x04 - 0100 = IRQ4
64 * 0x05 - 0101 = IRQ5
65 * 0x06 - 0110 = IRQ6
66 * 0x07 - 0111 = IRQ7
67 * 0x08 - 1000 = Reserved
68 * 0x09 - 1001 = IRQ9
69 * 0x0A - 1010 = IRQ10
70 * 0x0B - 1011 = IRQ11
71 * 0x0C - 1100 = IRQ12
72 * 0x0D - 1101 = Reserved
73 * 0x0E - 1110 = IRQ14
74 * 0x0F - 1111 = IRQ15
75 * PIRQ[n]_ROUT[7] - PIRQ Routing Control
76 * 0x80 - The PIRQ is not routed.
77 */
78
Elyes HAOUAS040aff22018-05-27 16:30:36 +020079static void pch_pirq_init(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -070080{
Elyes HAOUAS040aff22018-05-27 16:30:36 +020081 struct device *irq_dev;
Duncan Lauriec88c54c2014-04-30 16:36:13 -070082
Angel Pons4a6c0a32020-07-25 15:11:15 +020083 const uint8_t pirq = 0x80;
Duncan Lauriec88c54c2014-04-30 16:36:13 -070084
Angel Pons4a6c0a32020-07-25 15:11:15 +020085 pci_write_config8(dev, PIRQA_ROUT, pirq);
86 pci_write_config8(dev, PIRQB_ROUT, pirq);
87 pci_write_config8(dev, PIRQC_ROUT, pirq);
88 pci_write_config8(dev, PIRQD_ROUT, pirq);
89
90 pci_write_config8(dev, PIRQE_ROUT, pirq);
91 pci_write_config8(dev, PIRQF_ROUT, pirq);
92 pci_write_config8(dev, PIRQG_ROUT, pirq);
93 pci_write_config8(dev, PIRQH_ROUT, pirq);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070094
Elyes HAOUAS4a83f1c2016-08-25 21:07:59 +020095 for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
Lee Leahy26b7cd02017-03-16 18:47:55 -070096 u8 int_pin = 0, int_line = 0;
Duncan Lauriec88c54c2014-04-30 16:36:13 -070097
Fabio Aiutod835da92022-09-30 11:25:28 +020098 if (!is_enabled_pci(irq_dev))
Duncan Lauriec88c54c2014-04-30 16:36:13 -070099 continue;
100
101 int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
102
103 switch (int_pin) {
Lee Leahy8a9c7dc2017-03-17 10:43:25 -0700104 case 1: /* INTA# */
Lee Leahy8a9c7dc2017-03-17 10:43:25 -0700105 case 2: /* INTB# */
Lee Leahy8a9c7dc2017-03-17 10:43:25 -0700106 case 3: /* INTC# */
Lee Leahy8a9c7dc2017-03-17 10:43:25 -0700107 case 4: /* INTD# */
Angel Pons4a6c0a32020-07-25 15:11:15 +0200108 int_line = pirq;
Lee Leahy8a9c7dc2017-03-17 10:43:25 -0700109 break;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700110 }
111
112 if (!int_line)
113 continue;
114
115 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line);
116 }
117}
118
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200119static void pch_power_options(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700120{
121 u16 reg16;
122 const char *state;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700123
124 /* Which state do we want to goto after g3 (power restored)?
125 * 0 == S0 Full On
126 * 1 == S5 Soft Off
127 *
128 * If the option is not existent (Laptops), use Kconfig setting.
129 */
Angel Pons88dcb312021-04-26 17:10:28 +0200130 const unsigned int pwr_on = get_uint_option("power_on_after_fail",
Angel Pons62719a32021-04-19 13:15:28 +0200131 CONFIG_MAINBOARD_POWER_FAILURE_STATE);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700132
133 reg16 = pci_read_config16(dev, GEN_PMCON_3);
134 reg16 &= 0xfffe;
135 switch (pwr_on) {
136 case MAINBOARD_POWER_OFF:
137 reg16 |= 1;
138 state = "off";
139 break;
140 case MAINBOARD_POWER_ON:
141 reg16 &= ~1;
142 state = "on";
143 break;
144 case MAINBOARD_POWER_KEEP:
145 reg16 &= ~1;
146 state = "state keep";
147 break;
148 default:
149 state = "undefined";
150 }
Angel Pons6fb87c22020-10-30 20:40:48 +0100151
152 reg16 &= ~(3 << 4); /* SLP_S4# Assertion Stretch 4s */
153 reg16 |= (1 << 3); /* SLP_S4# Assertion Stretch Enable */
154
155 reg16 &= ~(1 << 10);
156 reg16 |= (1 << 11); /* SLP_S3# Min Assertion Width 50ms */
157
158 reg16 |= (1 << 12); /* Disable SLP stretch after SUS well */
159
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700160 pci_write_config16(dev, GEN_PMCON_3, reg16);
161 printk(BIOS_INFO, "Set power %s after power failure.\n", state);
162
Angel Pons02414f82020-10-28 13:50:38 +0100163 if (dev->chip_info) {
164 const struct soc_intel_broadwell_pch_config *config = dev->chip_info;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700165
Angel Pons02414f82020-10-28 13:50:38 +0100166 /* GPE setup based on device tree configuration */
167 enable_all_gpe(config->gpe0_en_1, config->gpe0_en_2,
168 config->gpe0_en_3, config->gpe0_en_4);
169
170 /* SMI setup based on device tree configuration */
171 enable_alt_smi(config->alt_gp_smi_en);
172 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700173}
174
Angel Ponsf2e2b962020-10-13 20:19:40 +0200175static void pch_misc_init(struct device *dev)
176{
177 u8 reg8;
Angel Ponsf2e2b962020-10-13 20:19:40 +0200178 u32 reg32;
179
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700180 /* Prepare sleep mode */
Angel Ponsf2e2b962020-10-13 20:19:40 +0200181 reg32 = inl(ACPI_BASE_ADDRESS + PM1_CNT);
182 reg32 &= ~SLP_TYP;
183 reg32 |= SCI_EN;
184 outl(reg32, ACPI_BASE_ADDRESS + PM1_CNT);
185
186 /* Set up NMI on errors */
187 reg8 = inb(0x61);
188 reg8 &= ~0xf0; /* Higher nibble must be 0 */
189 reg8 |= (1 << 2); /* PCI SERR# disable for now */
190 outb(reg8, 0x61);
191
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700192 /* Disable NMI sources */
Angel Ponsf2e2b962020-10-13 20:19:40 +0200193 reg8 = inb(0x70);
194 reg8 |= (1 << 7); /* Can't mask NMI from PCI-E and NMI_NOW */
195 outb(reg8, 0x70);
196
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700197 /* Indicate DRAM init done for MRC */
Angel Ponsf2e2b962020-10-13 20:19:40 +0200198 pci_or_config8(dev, GEN_PMCON_2, 1 << 7);
199
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700200 /* Enable BIOS updates outside of SMM */
Angel Ponsf2e2b962020-10-13 20:19:40 +0200201 pci_and_config8(dev, BIOS_CNTL, ~(1 << 5));
202
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700203 /* Clear status bits to prevent unexpected wake */
Angel Ponsf2e2b962020-10-13 20:19:40 +0200204 RCBA32_OR(0x3310, 0x2f);
205
206 RCBA32_AND_OR(0x3f02, ~0xf, 0);
207
Kenji Chen074a0282014-09-20 01:39:20 +0800208 /* Enable PCIe Releaxed Order */
Angel Ponsf2e2b962020-10-13 20:19:40 +0200209 RCBA32_OR(0x2314, (1 << 31) | (1 << 7)),
210 RCBA32_OR(0x1114, (1 << 15) | (1 << 14)),
211
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700212 /* Setup SERIRQ, enable continuous mode */
Angel Ponsf2e2b962020-10-13 20:19:40 +0200213 reg8 = pci_read_config8(dev, SERIRQ_CNTL);
214 reg8 |= 1 << 7;
215
216 if (CONFIG(SERIRQ_CONTINUOUS_MODE))
217 reg8 |= 1 << 6;
218
219 pci_write_config8(dev, SERIRQ_CNTL, reg8);
220}
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700221
222/* Magic register settings for power management */
Angel Pons2436ac02020-10-13 20:03:49 +0200223static void pch_pm_init_magic(struct device *dev)
224{
225 pci_write_config8(dev, 0xa9, 0x46);
226
227 RCBA32_AND_OR(0x232c, ~1, 0);
228
229 RCBA32_OR(0x1100, 0x0000c13f);
230
231 RCBA32_AND_OR(0x2320, ~0x60, 0x10);
232
233 RCBA32(0x3314) = 0x00012fff;
234
235 RCBA32_AND_OR(0x3318, ~0x000f0330, 0x0dcf0400);
236
237 RCBA32(0x3324) = 0x04000000;
238 RCBA32(0x3368) = 0x00041400;
239 RCBA32(0x3388) = 0x3f8ddbff;
240 RCBA32(0x33ac) = 0x00007001;
241 RCBA32(0x33b0) = 0x00181900;
242 RCBA32(0x33c0) = 0x00060A00;
243 RCBA32(0x33d0) = 0x06200840;
244 RCBA32(0x3a28) = 0x01010101;
245 RCBA32(0x3a2c) = 0x040c0404;
246 RCBA32(0x3a9c) = 0x9000000a;
247 RCBA32(0x2b1c) = 0x03808033;
248 RCBA32(0x2b34) = 0x80000009;
249 RCBA32(0x3348) = 0x022ddfff;
250 RCBA32(0x334c) = 0x00000001;
251 RCBA32(0x3358) = 0x0001c000;
252 RCBA32(0x3380) = 0x3f8ddbff;
253 RCBA32(0x3384) = 0x0001c7e1;
254 RCBA32(0x338c) = 0x0001c7e1;
255 RCBA32(0x3398) = 0x0001c000;
256 RCBA32(0x33a8) = 0x00181900;
257 RCBA32(0x33dc) = 0x00080000;
258 RCBA32(0x33e0) = 0x00000001;
259 RCBA32(0x3a20) = 0x0000040c;
260 RCBA32(0x3a24) = 0x01010101;
261 RCBA32(0x3a30) = 0x01010101;
262
263 pci_update_config32(dev, 0xac, ~0x00200000, 0);
264
265 RCBA32_OR(0x0410, 0x00000003);
266 RCBA32_OR(0x2618, 0x08000000);
267 RCBA32_OR(0x2300, 0x00000002);
268 RCBA32_OR(0x2600, 0x00000008);
269
270 RCBA32(0x33b4) = 0x00007001;
271 RCBA32(0x3350) = 0x022ddfff;
272 RCBA32(0x3354) = 0x00000001;
273
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700274 /* Power Optimizer */
Angel Pons2436ac02020-10-13 20:03:49 +0200275 RCBA32_OR(0x33d4, 0x08000000);
276 RCBA32_OR(0x33c8, 0x00000080);
277
278 RCBA32(0x2b10) = 0x0000883c;
279 RCBA32(0x2b14) = 0x1e0a4616;
280 RCBA32(0x2b24) = 0x40000005;
281 RCBA32(0x2b20) = 0x0005db01;
282 RCBA32(0x3a80) = 0x05145005;
283 RCBA32(0x3a84) = 0x00001005;
284
285 RCBA32_OR(0x33d4, 0x2fff2fb1);
286 RCBA32_OR(0x33c8, 0x00008000);
287}
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700288
289static void pch_enable_mphy(void)
290{
291 u32 gpio71_native = gpio_is_native(71);
292 u32 data_and = 0xffffffff;
293 u32 data_or = (1 << 14) | (1 << 13) | (1 << 12);
294
295 if (gpio71_native) {
296 data_or |= (1 << 0);
297 if (pch_is_wpt()) {
298 data_and &= ~((1 << 7) | (1 << 6) | (1 << 3));
299 data_or |= (1 << 5) | (1 << 4);
300
301 if (pch_is_wpt_ulx()) {
302 /* Check if SATA and USB3 MPHY are enabled */
303 u32 strap19 = pch_read_soft_strap(19);
304 strap19 &= ((1 << 31) | (1 << 30));
305 strap19 >>= 30;
306 if (strap19 == 3) {
307 data_or |= (1 << 3);
308 printk(BIOS_DEBUG, "Enable ULX MPHY PG "
309 "control in single domain\n");
310 } else if (strap19 == 0) {
311 printk(BIOS_DEBUG, "Enable ULX MPHY PG "
312 "control in split domains\n");
313 } else {
314 printk(BIOS_DEBUG, "Invalid PCH Soft "
315 "Strap 19 configuration\n");
316 }
317 } else {
318 data_or |= (1 << 3);
319 }
320 }
321 }
322
323 pch_iobp_update(0xCF000000, data_and, data_or);
324}
325
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700326static void pch_init_deep_sx(struct device *dev)
327{
Angel Pons02414f82020-10-28 13:50:38 +0100328 const struct soc_intel_broadwell_pch_config *config = dev->chip_info;
329
330 if (!config)
331 return;
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700332
333 if (config->deep_sx_enable_ac) {
334 RCBA32_OR(DEEP_S3_POL, DEEP_S3_EN_AC);
335 RCBA32_OR(DEEP_S5_POL, DEEP_S5_EN_AC);
336 }
337
338 if (config->deep_sx_enable_dc) {
339 RCBA32_OR(DEEP_S3_POL, DEEP_S3_EN_DC);
340 RCBA32_OR(DEEP_S5_POL, DEEP_S5_EN_DC);
341 }
342
343 if (config->deep_sx_enable_ac || config->deep_sx_enable_dc)
344 RCBA32_OR(DEEP_SX_CONFIG,
345 DEEP_SX_WAKE_PIN_EN | DEEP_SX_GP27_PIN_EN);
346}
347
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700348/* Power Management init */
349static void pch_pm_init(struct device *dev)
350{
351 printk(BIOS_DEBUG, "PCH PM init\n");
352
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700353 pch_init_deep_sx(dev);
354
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700355 pch_enable_mphy();
356
Angel Pons2436ac02020-10-13 20:03:49 +0200357 pch_pm_init_magic(dev);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700358
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700359 if (pch_is_wpt()) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700360 RCBA32_OR(0x33e0, (1 << 4) | (1 << 1));
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700361 RCBA32_OR(0x2b1c, (1 << 22) | (1 << 14) | (1 << 13));
362 RCBA32(0x33e4) = 0x16bf0002;
363 RCBA32_OR(0x33e4, 0x1);
364 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700365
366 pch_iobp_update(0xCA000000, ~0UL, 0x00000009);
367
368 /* Set RCBA 0x2b1c[29]=1 if DSP disabled */
369 if (RCBA32(FD) & PCH_DISABLE_ADSPD)
370 RCBA32_OR(0x2b1c, (1 << 29));
371
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700372}
373
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200374static void pch_cg_init(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700375{
376 u32 reg32;
377 u16 reg16;
Kyösti Mälkki71756c212019-07-12 13:10:19 +0300378 struct device *igd_dev = pcidev_path_on_root(SA_DEVFN_IGD);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700379
380 /* DMI */
381 RCBA32_OR(0x2234, 0xf);
382
383 reg16 = pci_read_config16(dev, GEN_PMCON_1);
384 reg16 &= ~(1 << 10); /* Disable BIOS_PCI_EXP_EN for native PME */
385 if (pch_is_wpt())
386 reg16 &= ~(1 << 11);
387 else
388 reg16 |= (1 << 11);
389 reg16 |= (1 << 5) | (1 << 6) | (1 << 7) | (1 << 12);
390 reg16 |= (1 << 2); // PCI CLKRUN# Enable
391 pci_write_config16(dev, GEN_PMCON_1, reg16);
392
393 /*
394 * RCBA + 0x2614[27:25,14:13,10,8] = 101,11,1,1
395 * RCBA + 0x2614[23:16] = 0x20
396 * RCBA + 0x2614[30:28] = 0x0
397 * RCBA + 0x2614[26] = 1 (IF 0:2.0@0x08 >= 0x0b)
398 */
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700399 RCBA32_AND_OR(0x2614, ~0x64ff0000, 0x0a206500);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700400
401 /* Check for 0:2.0@0x08 >= 0x0b */
Kyösti Mälkki71756c212019-07-12 13:10:19 +0300402 if (pch_is_wpt() || pci_read_config8(igd_dev, 0x8) >= 0x0b)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700403 RCBA32_OR(0x2614, (1 << 26));
404
405 RCBA32_OR(0x900, 0x0000031f);
406
407 reg32 = RCBA32(CG);
408 if (RCBA32(0x3454) & (1 << 4))
409 reg32 &= ~(1 << 29); // LPC Dynamic
410 else
411 reg32 |= (1 << 29); // LPC Dynamic
412 reg32 |= (1 << 31); // LP LPC
413 reg32 |= (1 << 30); // LP BLA
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700414 if (RCBA32(0x3454) & (1 << 4))
415 reg32 &= ~(1 << 29);
416 else
417 reg32 |= (1 << 29);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700418 reg32 |= (1 << 28); // GPIO Dynamic
419 reg32 |= (1 << 27); // HPET Dynamic
420 reg32 |= (1 << 26); // Generic Platform Event Clock
421 if (RCBA32(BUC) & PCH_DISABLE_GBE)
422 reg32 |= (1 << 23); // GbE Static
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700423 if (RCBA32(FD) & PCH_DISABLE_HD_AUDIO)
424 reg32 |= (1 << 21); // HDA Static
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700425 reg32 |= (1 << 22); // HDA Dynamic
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700426 RCBA32(CG) = reg32;
427
428 /* PCH-LP LPC */
429 if (pch_is_wpt())
430 RCBA32_AND_OR(0x3434, ~0x1f, 0x17);
431 else
432 RCBA32_OR(0x3434, 0x7);
433
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700434 /* SPI */
435 RCBA32_OR(0x38c0, 0x3c07);
436
437 pch_iobp_update(0xCE00C000, ~1UL, 0x00000000);
438}
439
440static void pch_set_acpi_mode(void)
441{
Kyösti Mälkkiad882c32020-06-02 05:05:30 +0300442 if (!acpi_is_wakeup_s3()) {
Kyösti Mälkkib6585482020-06-01 15:11:14 +0300443 apm_control(APM_CNT_ACPI_DISABLE);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700444 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700445}
446
447static void lpc_init(struct device *dev)
448{
449 /* Legacy initialization */
450 isa_dma_init();
Arthur Heymans2abbe462019-06-04 14:12:01 +0200451 sb_rtc_init();
Angel Ponsf2e2b962020-10-13 20:19:40 +0200452 pch_misc_init(dev);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700453
454 /* Interrupt configuration */
455 pch_enable_ioapic(dev);
456 pch_pirq_init(dev);
457 setup_i8259();
458 i8259_configure_irq_trigger(9, 1);
Matt DeVillier81a6f102018-02-19 17:33:48 -0600459 enable_hpet(dev);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700460
461 /* Initialize power management */
462 pch_power_options(dev);
463 pch_pm_init(dev);
464 pch_cg_init(dev);
465
466 pch_set_acpi_mode();
467}
468
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200469static void pch_lpc_add_mmio_resources(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700470{
471 u32 reg;
472 struct resource *res;
473 const u32 default_decode_base = IO_APIC_ADDR;
474
475 /*
476 * Just report all resources from IO-APIC base to 4GiB. Don't mark
477 * them reserved as that may upset the OS if this range is marked
478 * as reserved in the e820.
479 */
480 res = new_resource(dev, OIC);
481 res->base = default_decode_base;
Kyösti Mälkki37b161f2022-06-19 18:08:31 +0300482 res->size = 4ull * GiB - default_decode_base;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700483 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
484
485 /* RCBA */
Angel Pons64c6a742021-01-28 15:09:39 +0100486 if (default_decode_base > CONFIG_FIXED_RCBA_MMIO_BASE) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700487 res = new_resource(dev, RCBA);
Angel Pons64c6a742021-01-28 15:09:39 +0100488 res->base = CONFIG_FIXED_RCBA_MMIO_BASE;
489 res->size = CONFIG_RCBA_LENGTH;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700490 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
Lee Leahy26b7cd02017-03-16 18:47:55 -0700491 IORESOURCE_FIXED | IORESOURCE_RESERVE;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700492 }
493
494 /* Check LPC Memory Decode register. */
495 reg = pci_read_config32(dev, LGMR);
496 if (reg & 1) {
497 reg &= ~0xffff;
498 if (reg < default_decode_base) {
499 res = new_resource(dev, LGMR);
500 res->base = reg;
501 res->size = 16 * 1024;
502 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
Lee Leahy26b7cd02017-03-16 18:47:55 -0700503 IORESOURCE_FIXED | IORESOURCE_RESERVE;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700504 }
505 }
506}
507
508/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
509#define LPC_DEFAULT_IO_RANGE_LOWER 0
510#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
511
Julius Werner7c712bb2019-05-01 16:51:20 -0700512static inline int pch_io_range_in_default(int base, int size)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700513{
514 /* Does it start above the range? */
515 if (base >= LPC_DEFAULT_IO_RANGE_UPPER)
516 return 0;
517
518 /* Is it entirely contained? */
519 if (base >= LPC_DEFAULT_IO_RANGE_LOWER &&
520 (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
521 return 1;
522
523 /* This will return not in range for partial overlaps. */
524 return 0;
525}
526
527/*
528 * Note: this function assumes there is no overlap with the default LPC device's
529 * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
530 */
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200531static void pch_lpc_add_io_resource(struct device *dev, u16 base, u16 size,
532 int index)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700533{
534 struct resource *res;
535
536 if (pch_io_range_in_default(base, size))
537 return;
538
539 res = new_resource(dev, index);
540 res->base = base;
541 res->size = size;
542 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
543}
544
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200545static void pch_lpc_add_gen_io_resources(struct device *dev, int reg_value,
546 int index)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700547{
548 /*
549 * Check if the register is enabled. If so and the base exceeds the
Martin Rothde7ed6f2014-12-07 14:58:18 -0700550 * device's default claim range add the resource.
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700551 */
552 if (reg_value & 1) {
553 u16 base = reg_value & 0xfffc;
554 u16 size = (0x3 | ((reg_value >> 16) & 0xfc)) + 1;
555 pch_lpc_add_io_resource(dev, base, size, index);
556 }
557}
558
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200559static void pch_lpc_add_io_resources(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700560{
561 struct resource *res;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700562
563 /* Add the default claimed IO range for the LPC device. */
564 res = new_resource(dev, 0);
565 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
566 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
567 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
568
569 /* GPIOBASE */
570 pch_lpc_add_io_resource(dev, GPIO_BASE_ADDRESS,
571 GPIO_BASE_SIZE, GPIO_BASE);
572
573 /* PMBASE */
574 pch_lpc_add_io_resource(dev, ACPI_BASE_ADDRESS, ACPI_BASE_SIZE, PMBASE);
575
576 /* LPC Generic IO Decode range. */
Angel Pons02414f82020-10-28 13:50:38 +0100577 if (dev->chip_info) {
578 const struct soc_intel_broadwell_pch_config *config = dev->chip_info;
579 pch_lpc_add_gen_io_resources(dev, config->gen1_dec, LPC_GEN1_DEC);
580 pch_lpc_add_gen_io_resources(dev, config->gen2_dec, LPC_GEN2_DEC);
581 pch_lpc_add_gen_io_resources(dev, config->gen3_dec, LPC_GEN3_DEC);
582 pch_lpc_add_gen_io_resources(dev, config->gen4_dec, LPC_GEN4_DEC);
583 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700584}
585
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200586static void pch_lpc_read_resources(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700587{
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700588 /* Get the normal PCI resources of this device. */
589 pci_dev_read_resources(dev);
590
591 /* Add non-standard MMIO resources. */
592 pch_lpc_add_mmio_resources(dev);
593
594 /* Add IO resources. */
595 pch_lpc_add_io_resources(dev);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700596}
597
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700598static unsigned long broadwell_write_acpi_tables(const struct device *device,
Duncan Laurie93bbd412017-11-11 20:03:29 -0800599 unsigned long current,
600 struct acpi_rsdp *rsdp)
601{
Angel Pons07baa7a2021-04-19 17:12:42 +0200602 if (CONFIG(SERIALIO_UART_CONSOLE)) {
Duncan Laurie93bbd412017-11-11 20:03:29 -0800603 current = acpi_write_dbg2_pci_uart(rsdp, current,
Angel Pons07baa7a2021-04-19 17:12:42 +0200604 (CONFIG_UART_FOR_CONSOLE == 1) ?
Duncan Laurie93bbd412017-11-11 20:03:29 -0800605 PCH_DEV_UART1 : PCH_DEV_UART0,
Angel Pons07baa7a2021-04-19 17:12:42 +0200606 ACPI_ACCESS_SIZE_DWORD_ACCESS);
607 }
Furquan Shaikh27c51a02021-06-18 23:18:42 +0000608 return acpi_write_hpet(device, current, rsdp);
Duncan Laurie93bbd412017-11-11 20:03:29 -0800609}
610
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700611static struct device_operations device_ops = {
612 .read_resources = &pch_lpc_read_resources,
613 .set_resources = &pci_dev_set_resources,
614 .enable_resources = &pci_dev_enable_resources,
Duncan Laurie93bbd412017-11-11 20:03:29 -0800615 .write_acpi_tables = broadwell_write_acpi_tables,
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700616 .init = &lpc_init,
Nico Huber51b75ae2019-03-14 16:02:05 +0100617 .scan_bus = &scan_static_bus,
Angel Ponscb2080f2020-10-23 15:45:44 +0200618 .ops_pci = &pci_dev_ops_pci,
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700619};
620
621static const unsigned short pci_device_ids[] = {
622 PCH_LPT_LP_SAMPLE,
623 PCH_LPT_LP_PREMIUM,
624 PCH_LPT_LP_MAINSTREAM,
625 PCH_LPT_LP_VALUE,
626 PCH_WPT_HSW_U_SAMPLE,
627 PCH_WPT_BDW_U_SAMPLE,
628 PCH_WPT_BDW_U_PREMIUM,
629 PCH_WPT_BDW_U_BASE,
630 PCH_WPT_BDW_Y_SAMPLE,
631 PCH_WPT_BDW_Y_PREMIUM,
632 PCH_WPT_BDW_Y_BASE,
633 PCH_WPT_BDW_H,
634 0
635};
636
637static const struct pci_driver pch_lpc __pci_driver = {
638 .ops = &device_ops,
Felix Singer43b7f412022-03-07 04:34:52 +0100639 .vendor = PCI_VID_INTEL,
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700640 .devices = pci_device_ids,
641};