blob: 45669b398733814387a7b1ffd0c5e78a03163712 [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 */
34 ioapic_set_max_vectors(VIO_APIC_VADDR, 40);
Kyösti Mälkkiea6d12a2021-06-08 11:25:29 +030035
Kyösti Mälkki682613f2021-06-08 11:31:19 +030036 setup_ioapic(VIO_APIC_VADDR, 0x02);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070037}
38
Matt DeVillier81a6f102018-02-19 17:33:48 -060039static void enable_hpet(struct device *dev)
40{
41 size_t i;
42
43 /* Assign unique bus/dev/fn for each HPET */
44 for (i = 0; i < 8; ++i)
45 pci_write_config16(dev, LPC_HnBDF(i),
46 PCH_HPET_PCI_BUS << 8 | PCH_HPET_PCI_SLOT << 3 | i);
47}
48
Duncan Lauriec88c54c2014-04-30 16:36:13 -070049/* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control
50 * 0x00 - 0000 = Reserved
51 * 0x01 - 0001 = Reserved
52 * 0x02 - 0010 = Reserved
53 * 0x03 - 0011 = IRQ3
54 * 0x04 - 0100 = IRQ4
55 * 0x05 - 0101 = IRQ5
56 * 0x06 - 0110 = IRQ6
57 * 0x07 - 0111 = IRQ7
58 * 0x08 - 1000 = Reserved
59 * 0x09 - 1001 = IRQ9
60 * 0x0A - 1010 = IRQ10
61 * 0x0B - 1011 = IRQ11
62 * 0x0C - 1100 = IRQ12
63 * 0x0D - 1101 = Reserved
64 * 0x0E - 1110 = IRQ14
65 * 0x0F - 1111 = IRQ15
66 * PIRQ[n]_ROUT[7] - PIRQ Routing Control
67 * 0x80 - The PIRQ is not routed.
68 */
69
Elyes HAOUAS040aff22018-05-27 16:30:36 +020070static void pch_pirq_init(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -070071{
Elyes HAOUAS040aff22018-05-27 16:30:36 +020072 struct device *irq_dev;
Duncan Lauriec88c54c2014-04-30 16:36:13 -070073
Angel Pons4a6c0a32020-07-25 15:11:15 +020074 const uint8_t pirq = 0x80;
Duncan Lauriec88c54c2014-04-30 16:36:13 -070075
Angel Pons4a6c0a32020-07-25 15:11:15 +020076 pci_write_config8(dev, PIRQA_ROUT, pirq);
77 pci_write_config8(dev, PIRQB_ROUT, pirq);
78 pci_write_config8(dev, PIRQC_ROUT, pirq);
79 pci_write_config8(dev, PIRQD_ROUT, pirq);
80
81 pci_write_config8(dev, PIRQE_ROUT, pirq);
82 pci_write_config8(dev, PIRQF_ROUT, pirq);
83 pci_write_config8(dev, PIRQG_ROUT, pirq);
84 pci_write_config8(dev, PIRQH_ROUT, pirq);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070085
Elyes HAOUAS4a83f1c2016-08-25 21:07:59 +020086 for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
Lee Leahy26b7cd02017-03-16 18:47:55 -070087 u8 int_pin = 0, int_line = 0;
Duncan Lauriec88c54c2014-04-30 16:36:13 -070088
89 if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI)
90 continue;
91
92 int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
93
94 switch (int_pin) {
Lee Leahy8a9c7dc2017-03-17 10:43:25 -070095 case 1: /* INTA# */
Lee Leahy8a9c7dc2017-03-17 10:43:25 -070096 case 2: /* INTB# */
Lee Leahy8a9c7dc2017-03-17 10:43:25 -070097 case 3: /* INTC# */
Lee Leahy8a9c7dc2017-03-17 10:43:25 -070098 case 4: /* INTD# */
Angel Pons4a6c0a32020-07-25 15:11:15 +020099 int_line = pirq;
Lee Leahy8a9c7dc2017-03-17 10:43:25 -0700100 break;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700101 }
102
103 if (!int_line)
104 continue;
105
106 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line);
107 }
108}
109
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200110static void pch_power_options(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700111{
112 u16 reg16;
113 const char *state;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700114
115 /* Which state do we want to goto after g3 (power restored)?
116 * 0 == S0 Full On
117 * 1 == S5 Soft Off
118 *
119 * If the option is not existent (Laptops), use Kconfig setting.
120 */
Angel Pons88dcb312021-04-26 17:10:28 +0200121 const unsigned int pwr_on = get_uint_option("power_on_after_fail",
Angel Pons62719a32021-04-19 13:15:28 +0200122 CONFIG_MAINBOARD_POWER_FAILURE_STATE);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700123
124 reg16 = pci_read_config16(dev, GEN_PMCON_3);
125 reg16 &= 0xfffe;
126 switch (pwr_on) {
127 case MAINBOARD_POWER_OFF:
128 reg16 |= 1;
129 state = "off";
130 break;
131 case MAINBOARD_POWER_ON:
132 reg16 &= ~1;
133 state = "on";
134 break;
135 case MAINBOARD_POWER_KEEP:
136 reg16 &= ~1;
137 state = "state keep";
138 break;
139 default:
140 state = "undefined";
141 }
Angel Pons6fb87c22020-10-30 20:40:48 +0100142
143 reg16 &= ~(3 << 4); /* SLP_S4# Assertion Stretch 4s */
144 reg16 |= (1 << 3); /* SLP_S4# Assertion Stretch Enable */
145
146 reg16 &= ~(1 << 10);
147 reg16 |= (1 << 11); /* SLP_S3# Min Assertion Width 50ms */
148
149 reg16 |= (1 << 12); /* Disable SLP stretch after SUS well */
150
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700151 pci_write_config16(dev, GEN_PMCON_3, reg16);
152 printk(BIOS_INFO, "Set power %s after power failure.\n", state);
153
Angel Pons02414f82020-10-28 13:50:38 +0100154 if (dev->chip_info) {
155 const struct soc_intel_broadwell_pch_config *config = dev->chip_info;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700156
Angel Pons02414f82020-10-28 13:50:38 +0100157 /* GPE setup based on device tree configuration */
158 enable_all_gpe(config->gpe0_en_1, config->gpe0_en_2,
159 config->gpe0_en_3, config->gpe0_en_4);
160
161 /* SMI setup based on device tree configuration */
162 enable_alt_smi(config->alt_gp_smi_en);
163 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700164}
165
Angel Ponsf2e2b962020-10-13 20:19:40 +0200166static void pch_misc_init(struct device *dev)
167{
168 u8 reg8;
Angel Ponsf2e2b962020-10-13 20:19:40 +0200169 u32 reg32;
170
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700171 /* Prepare sleep mode */
Angel Ponsf2e2b962020-10-13 20:19:40 +0200172 reg32 = inl(ACPI_BASE_ADDRESS + PM1_CNT);
173 reg32 &= ~SLP_TYP;
174 reg32 |= SCI_EN;
175 outl(reg32, ACPI_BASE_ADDRESS + PM1_CNT);
176
177 /* Set up NMI on errors */
178 reg8 = inb(0x61);
179 reg8 &= ~0xf0; /* Higher nibble must be 0 */
180 reg8 |= (1 << 2); /* PCI SERR# disable for now */
181 outb(reg8, 0x61);
182
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700183 /* Disable NMI sources */
Angel Ponsf2e2b962020-10-13 20:19:40 +0200184 reg8 = inb(0x70);
185 reg8 |= (1 << 7); /* Can't mask NMI from PCI-E and NMI_NOW */
186 outb(reg8, 0x70);
187
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700188 /* Indicate DRAM init done for MRC */
Angel Ponsf2e2b962020-10-13 20:19:40 +0200189 pci_or_config8(dev, GEN_PMCON_2, 1 << 7);
190
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700191 /* Enable BIOS updates outside of SMM */
Angel Ponsf2e2b962020-10-13 20:19:40 +0200192 pci_and_config8(dev, BIOS_CNTL, ~(1 << 5));
193
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700194 /* Clear status bits to prevent unexpected wake */
Angel Ponsf2e2b962020-10-13 20:19:40 +0200195 RCBA32_OR(0x3310, 0x2f);
196
197 RCBA32_AND_OR(0x3f02, ~0xf, 0);
198
Kenji Chen074a0282014-09-20 01:39:20 +0800199 /* Enable PCIe Releaxed Order */
Angel Ponsf2e2b962020-10-13 20:19:40 +0200200 RCBA32_OR(0x2314, (1 << 31) | (1 << 7)),
201 RCBA32_OR(0x1114, (1 << 15) | (1 << 14)),
202
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700203 /* Setup SERIRQ, enable continuous mode */
Angel Ponsf2e2b962020-10-13 20:19:40 +0200204 reg8 = pci_read_config8(dev, SERIRQ_CNTL);
205 reg8 |= 1 << 7;
206
207 if (CONFIG(SERIRQ_CONTINUOUS_MODE))
208 reg8 |= 1 << 6;
209
210 pci_write_config8(dev, SERIRQ_CNTL, reg8);
211}
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700212
213/* Magic register settings for power management */
Angel Pons2436ac02020-10-13 20:03:49 +0200214static void pch_pm_init_magic(struct device *dev)
215{
216 pci_write_config8(dev, 0xa9, 0x46);
217
218 RCBA32_AND_OR(0x232c, ~1, 0);
219
220 RCBA32_OR(0x1100, 0x0000c13f);
221
222 RCBA32_AND_OR(0x2320, ~0x60, 0x10);
223
224 RCBA32(0x3314) = 0x00012fff;
225
226 RCBA32_AND_OR(0x3318, ~0x000f0330, 0x0dcf0400);
227
228 RCBA32(0x3324) = 0x04000000;
229 RCBA32(0x3368) = 0x00041400;
230 RCBA32(0x3388) = 0x3f8ddbff;
231 RCBA32(0x33ac) = 0x00007001;
232 RCBA32(0x33b0) = 0x00181900;
233 RCBA32(0x33c0) = 0x00060A00;
234 RCBA32(0x33d0) = 0x06200840;
235 RCBA32(0x3a28) = 0x01010101;
236 RCBA32(0x3a2c) = 0x040c0404;
237 RCBA32(0x3a9c) = 0x9000000a;
238 RCBA32(0x2b1c) = 0x03808033;
239 RCBA32(0x2b34) = 0x80000009;
240 RCBA32(0x3348) = 0x022ddfff;
241 RCBA32(0x334c) = 0x00000001;
242 RCBA32(0x3358) = 0x0001c000;
243 RCBA32(0x3380) = 0x3f8ddbff;
244 RCBA32(0x3384) = 0x0001c7e1;
245 RCBA32(0x338c) = 0x0001c7e1;
246 RCBA32(0x3398) = 0x0001c000;
247 RCBA32(0x33a8) = 0x00181900;
248 RCBA32(0x33dc) = 0x00080000;
249 RCBA32(0x33e0) = 0x00000001;
250 RCBA32(0x3a20) = 0x0000040c;
251 RCBA32(0x3a24) = 0x01010101;
252 RCBA32(0x3a30) = 0x01010101;
253
254 pci_update_config32(dev, 0xac, ~0x00200000, 0);
255
256 RCBA32_OR(0x0410, 0x00000003);
257 RCBA32_OR(0x2618, 0x08000000);
258 RCBA32_OR(0x2300, 0x00000002);
259 RCBA32_OR(0x2600, 0x00000008);
260
261 RCBA32(0x33b4) = 0x00007001;
262 RCBA32(0x3350) = 0x022ddfff;
263 RCBA32(0x3354) = 0x00000001;
264
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700265 /* Power Optimizer */
Angel Pons2436ac02020-10-13 20:03:49 +0200266 RCBA32_OR(0x33d4, 0x08000000);
267 RCBA32_OR(0x33c8, 0x00000080);
268
269 RCBA32(0x2b10) = 0x0000883c;
270 RCBA32(0x2b14) = 0x1e0a4616;
271 RCBA32(0x2b24) = 0x40000005;
272 RCBA32(0x2b20) = 0x0005db01;
273 RCBA32(0x3a80) = 0x05145005;
274 RCBA32(0x3a84) = 0x00001005;
275
276 RCBA32_OR(0x33d4, 0x2fff2fb1);
277 RCBA32_OR(0x33c8, 0x00008000);
278}
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700279
280static void pch_enable_mphy(void)
281{
282 u32 gpio71_native = gpio_is_native(71);
283 u32 data_and = 0xffffffff;
284 u32 data_or = (1 << 14) | (1 << 13) | (1 << 12);
285
286 if (gpio71_native) {
287 data_or |= (1 << 0);
288 if (pch_is_wpt()) {
289 data_and &= ~((1 << 7) | (1 << 6) | (1 << 3));
290 data_or |= (1 << 5) | (1 << 4);
291
292 if (pch_is_wpt_ulx()) {
293 /* Check if SATA and USB3 MPHY are enabled */
294 u32 strap19 = pch_read_soft_strap(19);
295 strap19 &= ((1 << 31) | (1 << 30));
296 strap19 >>= 30;
297 if (strap19 == 3) {
298 data_or |= (1 << 3);
299 printk(BIOS_DEBUG, "Enable ULX MPHY PG "
300 "control in single domain\n");
301 } else if (strap19 == 0) {
302 printk(BIOS_DEBUG, "Enable ULX MPHY PG "
303 "control in split domains\n");
304 } else {
305 printk(BIOS_DEBUG, "Invalid PCH Soft "
306 "Strap 19 configuration\n");
307 }
308 } else {
309 data_or |= (1 << 3);
310 }
311 }
312 }
313
314 pch_iobp_update(0xCF000000, data_and, data_or);
315}
316
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700317static void pch_init_deep_sx(struct device *dev)
318{
Angel Pons02414f82020-10-28 13:50:38 +0100319 const struct soc_intel_broadwell_pch_config *config = dev->chip_info;
320
321 if (!config)
322 return;
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700323
324 if (config->deep_sx_enable_ac) {
325 RCBA32_OR(DEEP_S3_POL, DEEP_S3_EN_AC);
326 RCBA32_OR(DEEP_S5_POL, DEEP_S5_EN_AC);
327 }
328
329 if (config->deep_sx_enable_dc) {
330 RCBA32_OR(DEEP_S3_POL, DEEP_S3_EN_DC);
331 RCBA32_OR(DEEP_S5_POL, DEEP_S5_EN_DC);
332 }
333
334 if (config->deep_sx_enable_ac || config->deep_sx_enable_dc)
335 RCBA32_OR(DEEP_SX_CONFIG,
336 DEEP_SX_WAKE_PIN_EN | DEEP_SX_GP27_PIN_EN);
337}
338
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700339/* Power Management init */
340static void pch_pm_init(struct device *dev)
341{
342 printk(BIOS_DEBUG, "PCH PM init\n");
343
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700344 pch_init_deep_sx(dev);
345
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700346 pch_enable_mphy();
347
Angel Pons2436ac02020-10-13 20:03:49 +0200348 pch_pm_init_magic(dev);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700349
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700350 if (pch_is_wpt()) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700351 RCBA32_OR(0x33e0, (1 << 4) | (1 << 1));
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700352 RCBA32_OR(0x2b1c, (1 << 22) | (1 << 14) | (1 << 13));
353 RCBA32(0x33e4) = 0x16bf0002;
354 RCBA32_OR(0x33e4, 0x1);
355 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700356
357 pch_iobp_update(0xCA000000, ~0UL, 0x00000009);
358
359 /* Set RCBA 0x2b1c[29]=1 if DSP disabled */
360 if (RCBA32(FD) & PCH_DISABLE_ADSPD)
361 RCBA32_OR(0x2b1c, (1 << 29));
362
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700363}
364
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200365static void pch_cg_init(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700366{
367 u32 reg32;
368 u16 reg16;
Kyösti Mälkki71756c212019-07-12 13:10:19 +0300369 struct device *igd_dev = pcidev_path_on_root(SA_DEVFN_IGD);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700370
371 /* DMI */
372 RCBA32_OR(0x2234, 0xf);
373
374 reg16 = pci_read_config16(dev, GEN_PMCON_1);
375 reg16 &= ~(1 << 10); /* Disable BIOS_PCI_EXP_EN for native PME */
376 if (pch_is_wpt())
377 reg16 &= ~(1 << 11);
378 else
379 reg16 |= (1 << 11);
380 reg16 |= (1 << 5) | (1 << 6) | (1 << 7) | (1 << 12);
381 reg16 |= (1 << 2); // PCI CLKRUN# Enable
382 pci_write_config16(dev, GEN_PMCON_1, reg16);
383
384 /*
385 * RCBA + 0x2614[27:25,14:13,10,8] = 101,11,1,1
386 * RCBA + 0x2614[23:16] = 0x20
387 * RCBA + 0x2614[30:28] = 0x0
388 * RCBA + 0x2614[26] = 1 (IF 0:2.0@0x08 >= 0x0b)
389 */
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700390 RCBA32_AND_OR(0x2614, ~0x64ff0000, 0x0a206500);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700391
392 /* Check for 0:2.0@0x08 >= 0x0b */
Kyösti Mälkki71756c212019-07-12 13:10:19 +0300393 if (pch_is_wpt() || pci_read_config8(igd_dev, 0x8) >= 0x0b)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700394 RCBA32_OR(0x2614, (1 << 26));
395
396 RCBA32_OR(0x900, 0x0000031f);
397
398 reg32 = RCBA32(CG);
399 if (RCBA32(0x3454) & (1 << 4))
400 reg32 &= ~(1 << 29); // LPC Dynamic
401 else
402 reg32 |= (1 << 29); // LPC Dynamic
403 reg32 |= (1 << 31); // LP LPC
404 reg32 |= (1 << 30); // LP BLA
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700405 if (RCBA32(0x3454) & (1 << 4))
406 reg32 &= ~(1 << 29);
407 else
408 reg32 |= (1 << 29);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700409 reg32 |= (1 << 28); // GPIO Dynamic
410 reg32 |= (1 << 27); // HPET Dynamic
411 reg32 |= (1 << 26); // Generic Platform Event Clock
412 if (RCBA32(BUC) & PCH_DISABLE_GBE)
413 reg32 |= (1 << 23); // GbE Static
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700414 if (RCBA32(FD) & PCH_DISABLE_HD_AUDIO)
415 reg32 |= (1 << 21); // HDA Static
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700416 reg32 |= (1 << 22); // HDA Dynamic
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700417 RCBA32(CG) = reg32;
418
419 /* PCH-LP LPC */
420 if (pch_is_wpt())
421 RCBA32_AND_OR(0x3434, ~0x1f, 0x17);
422 else
423 RCBA32_OR(0x3434, 0x7);
424
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700425 /* SPI */
426 RCBA32_OR(0x38c0, 0x3c07);
427
428 pch_iobp_update(0xCE00C000, ~1UL, 0x00000000);
429}
430
431static void pch_set_acpi_mode(void)
432{
Kyösti Mälkkiad882c32020-06-02 05:05:30 +0300433 if (!acpi_is_wakeup_s3()) {
Kyösti Mälkkib6585482020-06-01 15:11:14 +0300434 apm_control(APM_CNT_ACPI_DISABLE);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700435 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700436}
437
438static void lpc_init(struct device *dev)
439{
440 /* Legacy initialization */
441 isa_dma_init();
Arthur Heymans2abbe462019-06-04 14:12:01 +0200442 sb_rtc_init();
Angel Ponsf2e2b962020-10-13 20:19:40 +0200443 pch_misc_init(dev);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700444
445 /* Interrupt configuration */
446 pch_enable_ioapic(dev);
447 pch_pirq_init(dev);
448 setup_i8259();
449 i8259_configure_irq_trigger(9, 1);
Matt DeVillier81a6f102018-02-19 17:33:48 -0600450 enable_hpet(dev);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700451
452 /* Initialize power management */
453 pch_power_options(dev);
454 pch_pm_init(dev);
455 pch_cg_init(dev);
456
457 pch_set_acpi_mode();
458}
459
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200460static void pch_lpc_add_mmio_resources(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700461{
462 u32 reg;
463 struct resource *res;
464 const u32 default_decode_base = IO_APIC_ADDR;
465
466 /*
467 * Just report all resources from IO-APIC base to 4GiB. Don't mark
468 * them reserved as that may upset the OS if this range is marked
469 * as reserved in the e820.
470 */
471 res = new_resource(dev, OIC);
472 res->base = default_decode_base;
473 res->size = 0 - default_decode_base;
474 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
475
476 /* RCBA */
Angel Pons64c6a742021-01-28 15:09:39 +0100477 if (default_decode_base > CONFIG_FIXED_RCBA_MMIO_BASE) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700478 res = new_resource(dev, RCBA);
Angel Pons64c6a742021-01-28 15:09:39 +0100479 res->base = CONFIG_FIXED_RCBA_MMIO_BASE;
480 res->size = CONFIG_RCBA_LENGTH;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700481 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
Lee Leahy26b7cd02017-03-16 18:47:55 -0700482 IORESOURCE_FIXED | IORESOURCE_RESERVE;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700483 }
484
485 /* Check LPC Memory Decode register. */
486 reg = pci_read_config32(dev, LGMR);
487 if (reg & 1) {
488 reg &= ~0xffff;
489 if (reg < default_decode_base) {
490 res = new_resource(dev, LGMR);
491 res->base = reg;
492 res->size = 16 * 1024;
493 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
Lee Leahy26b7cd02017-03-16 18:47:55 -0700494 IORESOURCE_FIXED | IORESOURCE_RESERVE;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700495 }
496 }
497}
498
499/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
500#define LPC_DEFAULT_IO_RANGE_LOWER 0
501#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
502
Julius Werner7c712bb2019-05-01 16:51:20 -0700503static inline int pch_io_range_in_default(int base, int size)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700504{
505 /* Does it start above the range? */
506 if (base >= LPC_DEFAULT_IO_RANGE_UPPER)
507 return 0;
508
509 /* Is it entirely contained? */
510 if (base >= LPC_DEFAULT_IO_RANGE_LOWER &&
511 (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
512 return 1;
513
514 /* This will return not in range for partial overlaps. */
515 return 0;
516}
517
518/*
519 * Note: this function assumes there is no overlap with the default LPC device's
520 * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
521 */
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200522static void pch_lpc_add_io_resource(struct device *dev, u16 base, u16 size,
523 int index)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700524{
525 struct resource *res;
526
527 if (pch_io_range_in_default(base, size))
528 return;
529
530 res = new_resource(dev, index);
531 res->base = base;
532 res->size = size;
533 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
534}
535
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200536static void pch_lpc_add_gen_io_resources(struct device *dev, int reg_value,
537 int index)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700538{
539 /*
540 * Check if the register is enabled. If so and the base exceeds the
Martin Rothde7ed6f2014-12-07 14:58:18 -0700541 * device's default claim range add the resource.
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700542 */
543 if (reg_value & 1) {
544 u16 base = reg_value & 0xfffc;
545 u16 size = (0x3 | ((reg_value >> 16) & 0xfc)) + 1;
546 pch_lpc_add_io_resource(dev, base, size, index);
547 }
548}
549
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200550static void pch_lpc_add_io_resources(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700551{
552 struct resource *res;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700553
554 /* Add the default claimed IO range for the LPC device. */
555 res = new_resource(dev, 0);
556 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
557 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
558 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
559
560 /* GPIOBASE */
561 pch_lpc_add_io_resource(dev, GPIO_BASE_ADDRESS,
562 GPIO_BASE_SIZE, GPIO_BASE);
563
564 /* PMBASE */
565 pch_lpc_add_io_resource(dev, ACPI_BASE_ADDRESS, ACPI_BASE_SIZE, PMBASE);
566
567 /* LPC Generic IO Decode range. */
Angel Pons02414f82020-10-28 13:50:38 +0100568 if (dev->chip_info) {
569 const struct soc_intel_broadwell_pch_config *config = dev->chip_info;
570 pch_lpc_add_gen_io_resources(dev, config->gen1_dec, LPC_GEN1_DEC);
571 pch_lpc_add_gen_io_resources(dev, config->gen2_dec, LPC_GEN2_DEC);
572 pch_lpc_add_gen_io_resources(dev, config->gen3_dec, LPC_GEN3_DEC);
573 pch_lpc_add_gen_io_resources(dev, config->gen4_dec, LPC_GEN4_DEC);
574 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700575}
576
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200577static void pch_lpc_read_resources(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700578{
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700579 /* Get the normal PCI resources of this device. */
580 pci_dev_read_resources(dev);
581
582 /* Add non-standard MMIO resources. */
583 pch_lpc_add_mmio_resources(dev);
584
585 /* Add IO resources. */
586 pch_lpc_add_io_resources(dev);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700587}
588
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700589static unsigned long broadwell_write_acpi_tables(const struct device *device,
Duncan Laurie93bbd412017-11-11 20:03:29 -0800590 unsigned long current,
591 struct acpi_rsdp *rsdp)
592{
Angel Pons07baa7a2021-04-19 17:12:42 +0200593 if (CONFIG(SERIALIO_UART_CONSOLE)) {
Duncan Laurie93bbd412017-11-11 20:03:29 -0800594 current = acpi_write_dbg2_pci_uart(rsdp, current,
Angel Pons07baa7a2021-04-19 17:12:42 +0200595 (CONFIG_UART_FOR_CONSOLE == 1) ?
Duncan Laurie93bbd412017-11-11 20:03:29 -0800596 PCH_DEV_UART1 : PCH_DEV_UART0,
Angel Pons07baa7a2021-04-19 17:12:42 +0200597 ACPI_ACCESS_SIZE_DWORD_ACCESS);
598 }
Furquan Shaikh27c51a02021-06-18 23:18:42 +0000599 return acpi_write_hpet(device, current, rsdp);
Duncan Laurie93bbd412017-11-11 20:03:29 -0800600}
601
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700602static struct device_operations device_ops = {
603 .read_resources = &pch_lpc_read_resources,
604 .set_resources = &pci_dev_set_resources,
605 .enable_resources = &pci_dev_enable_resources,
Duncan Laurie93bbd412017-11-11 20:03:29 -0800606 .write_acpi_tables = broadwell_write_acpi_tables,
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700607 .init = &lpc_init,
Nico Huber51b75ae2019-03-14 16:02:05 +0100608 .scan_bus = &scan_static_bus,
Angel Ponscb2080f2020-10-23 15:45:44 +0200609 .ops_pci = &pci_dev_ops_pci,
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700610};
611
612static const unsigned short pci_device_ids[] = {
613 PCH_LPT_LP_SAMPLE,
614 PCH_LPT_LP_PREMIUM,
615 PCH_LPT_LP_MAINSTREAM,
616 PCH_LPT_LP_VALUE,
617 PCH_WPT_HSW_U_SAMPLE,
618 PCH_WPT_BDW_U_SAMPLE,
619 PCH_WPT_BDW_U_PREMIUM,
620 PCH_WPT_BDW_U_BASE,
621 PCH_WPT_BDW_Y_SAMPLE,
622 PCH_WPT_BDW_Y_PREMIUM,
623 PCH_WPT_BDW_Y_BASE,
624 PCH_WPT_BDW_H,
625 0
626};
627
628static const struct pci_driver pch_lpc __pci_driver = {
629 .ops = &device_ops,
Felix Singer43b7f412022-03-07 04:34:52 +0100630 .vendor = PCI_VID_INTEL,
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700631 .devices = pci_device_ids,
632};