blob: c13c92a742c9c47dfbd6c3adf57c1536a71a2029 [file] [log] [blame]
Duncan Lauriec88c54c2014-04-30 16:36:13 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 * Copyright (C) 2014 Google Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Duncan Lauriec88c54c2014-04-30 16:36:13 -070015 */
16
17#include <console/console.h>
18#include <delay.h>
19#include <device/device.h>
20#include <device/pci.h>
21#include <device/pci_ids.h>
22#include <pc80/mc146818rtc.h>
23#include <pc80/isa-dma.h>
24#include <pc80/i8259.h>
25#include <arch/io.h>
26#include <arch/ioapic.h>
27#include <arch/acpi.h>
28#include <cpu/cpu.h>
29#include <cpu/x86/smm.h>
30#include <cbmem.h>
31#include <reg_script.h>
32#include <string.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070033#include <soc/gpio.h>
34#include <soc/iobp.h>
35#include <soc/iomap.h>
36#include <soc/lpc.h>
37#include <soc/nvs.h>
38#include <soc/pch.h>
39#include <soc/pci_devs.h>
40#include <soc/pm.h>
41#include <soc/ramstage.h>
42#include <soc/rcba.h>
43#include <soc/intel/broadwell/chip.h>
Vladimir Serbinenkob219da82014-11-09 03:29:30 +010044#include <arch/acpi.h>
45#include <arch/acpigen.h>
46#include <cpu/cpu.h>
Duncan Laurie35dc00f2015-01-18 14:06:42 -080047
Duncan Lauriec88c54c2014-04-30 16:36:13 -070048static void pch_enable_ioapic(struct device *dev)
49{
50 u32 reg32;
51
Matt DeVillier81a6f102018-02-19 17:33:48 -060052 /* Assign unique bus/dev/fn for I/O APIC */
53 pci_write_config16(dev, LPC_IBDF,
54 PCH_IOAPIC_PCI_BUS << 8 | PCH_IOAPIC_PCI_SLOT << 3);
55
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080056 set_ioapic_id(VIO_APIC_VADDR, 0x02);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070057
58 /* affirm full set of redirection table entries ("write once") */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080059 reg32 = io_apic_read(VIO_APIC_VADDR, 0x01);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070060
61 /* PCH-LP has 39 redirection entries */
62 reg32 &= ~0x00ff0000;
63 reg32 |= 0x00270000;
64
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080065 io_apic_write(VIO_APIC_VADDR, 0x01, reg32);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070066
67 /*
68 * Select Boot Configuration register (0x03) and
69 * use Processor System Bus (0x01) to deliver interrupts.
70 */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080071 io_apic_write(VIO_APIC_VADDR, 0x03, 0x01);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070072}
73
Matt DeVillier81a6f102018-02-19 17:33:48 -060074static void enable_hpet(struct device *dev)
75{
76 size_t i;
77
78 /* Assign unique bus/dev/fn for each HPET */
79 for (i = 0; i < 8; ++i)
80 pci_write_config16(dev, LPC_HnBDF(i),
81 PCH_HPET_PCI_BUS << 8 | PCH_HPET_PCI_SLOT << 3 | i);
82}
83
Duncan Lauriec88c54c2014-04-30 16:36:13 -070084/* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control
85 * 0x00 - 0000 = Reserved
86 * 0x01 - 0001 = Reserved
87 * 0x02 - 0010 = Reserved
88 * 0x03 - 0011 = IRQ3
89 * 0x04 - 0100 = IRQ4
90 * 0x05 - 0101 = IRQ5
91 * 0x06 - 0110 = IRQ6
92 * 0x07 - 0111 = IRQ7
93 * 0x08 - 1000 = Reserved
94 * 0x09 - 1001 = IRQ9
95 * 0x0A - 1010 = IRQ10
96 * 0x0B - 1011 = IRQ11
97 * 0x0C - 1100 = IRQ12
98 * 0x0D - 1101 = Reserved
99 * 0x0E - 1110 = IRQ14
100 * 0x0F - 1111 = IRQ15
101 * PIRQ[n]_ROUT[7] - PIRQ Routing Control
102 * 0x80 - The PIRQ is not routed.
103 */
104
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200105static void pch_pirq_init(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700106{
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200107 struct device *irq_dev;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700108 config_t *config = dev->chip_info;
109
110 pci_write_config8(dev, PIRQA_ROUT, config->pirqa_routing);
111 pci_write_config8(dev, PIRQB_ROUT, config->pirqb_routing);
112 pci_write_config8(dev, PIRQC_ROUT, config->pirqc_routing);
113 pci_write_config8(dev, PIRQD_ROUT, config->pirqd_routing);
114
115 pci_write_config8(dev, PIRQE_ROUT, config->pirqe_routing);
116 pci_write_config8(dev, PIRQF_ROUT, config->pirqf_routing);
117 pci_write_config8(dev, PIRQG_ROUT, config->pirqg_routing);
118 pci_write_config8(dev, PIRQH_ROUT, config->pirqh_routing);
119
Elyes HAOUAS4a83f1c2016-08-25 21:07:59 +0200120 for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
Lee Leahy26b7cd02017-03-16 18:47:55 -0700121 u8 int_pin = 0, int_line = 0;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700122
123 if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI)
124 continue;
125
126 int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
127
128 switch (int_pin) {
Lee Leahy8a9c7dc2017-03-17 10:43:25 -0700129 case 1: /* INTA# */
130 int_line = config->pirqa_routing;
131 break;
132 case 2: /* INTB# */
133 int_line = config->pirqb_routing;
134 break;
135 case 3: /* INTC# */
136 int_line = config->pirqc_routing;
137 break;
138 case 4: /* INTD# */
139 int_line = config->pirqd_routing;
140 break;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700141 }
142
143 if (!int_line)
144 continue;
145
146 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line);
147 }
148}
149
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200150static void pch_power_options(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700151{
152 u16 reg16;
153 const char *state;
154 /* Get the chip configuration */
155 config_t *config = dev->chip_info;
Lee Leahy26b7cd02017-03-16 18:47:55 -0700156 int pwr_on = CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700157
158 /* Which state do we want to goto after g3 (power restored)?
159 * 0 == S0 Full On
160 * 1 == S5 Soft Off
161 *
162 * If the option is not existent (Laptops), use Kconfig setting.
163 */
164 get_option(&pwr_on, "power_on_after_fail");
165
166 reg16 = pci_read_config16(dev, GEN_PMCON_3);
167 reg16 &= 0xfffe;
168 switch (pwr_on) {
169 case MAINBOARD_POWER_OFF:
170 reg16 |= 1;
171 state = "off";
172 break;
173 case MAINBOARD_POWER_ON:
174 reg16 &= ~1;
175 state = "on";
176 break;
177 case MAINBOARD_POWER_KEEP:
178 reg16 &= ~1;
179 state = "state keep";
180 break;
181 default:
182 state = "undefined";
183 }
184 pci_write_config16(dev, GEN_PMCON_3, reg16);
185 printk(BIOS_INFO, "Set power %s after power failure.\n", state);
186
187 /* GPE setup based on device tree configuration */
188 enable_all_gpe(config->gpe0_en_1, config->gpe0_en_2,
189 config->gpe0_en_3, config->gpe0_en_4);
190
191 /* SMI setup based on device tree configuration */
192 enable_alt_smi(config->alt_gp_smi_en);
193}
194
195static void pch_rtc_init(struct device *dev)
196{
Aaron Durbinb9d9b792017-09-15 11:51:58 -0600197 cmos_init(rtc_failure());
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700198}
199
200static const struct reg_script pch_misc_init_script[] = {
201 /* Setup SLP signal assertion, SLP_S4=4s, SLP_S3=50ms */
202 REG_PCI_RMW16(GEN_PMCON_3, ~((3 << 4)|(1 << 10)),
203 (1 << 3)|(1 << 11)|(1 << 12)),
204 /* Prepare sleep mode */
205 REG_IO_RMW32(ACPI_BASE_ADDRESS + PM1_CNT, ~SLP_TYP, SCI_EN),
206 /* Setup NMI on errors, disable SERR */
207 REG_IO_RMW8(0x61, ~0xf0, (1 << 2)),
208 /* Disable NMI sources */
209 REG_IO_OR8(0x70, (1 << 7)),
210 /* Indicate DRAM init done for MRC */
211 REG_PCI_OR8(GEN_PMCON_2, (1 << 7)),
212 /* Enable BIOS updates outside of SMM */
213 REG_PCI_RMW8(0xdc, ~(1 << 5), 0),
214 /* Clear status bits to prevent unexpected wake */
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700215 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x3310, 0x0000002f),
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700216 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x3f02, ~0x0000000f, 0),
Kenji Chen074a0282014-09-20 01:39:20 +0800217 /* Enable PCIe Releaxed Order */
218 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2314, (1 << 31) | (1 << 7)),
219 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x1114, (1 << 15) | (1 << 14)),
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700220 /* Setup SERIRQ, enable continuous mode */
221 REG_PCI_OR8(SERIRQ_CNTL, (1 << 7) | (1 << 6)),
Martin Rothe6ff1592017-06-24 21:34:29 -0600222#if !IS_ENABLED(CONFIG_SERIRQ_CONTINUOUS_MODE)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700223 REG_PCI_RMW8(SERIRQ_CNTL, ~(1 << 6), 0),
224#endif
225 REG_SCRIPT_END
226};
227
228/* Magic register settings for power management */
229static const struct reg_script pch_pm_init_script[] = {
230 REG_PCI_WRITE8(0xa9, 0x46),
231 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x232c, ~1, 0),
232 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x1100, 0x0000c13f),
233 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x2320, ~0x60, 0x10),
234 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3314, 0x00012fff),
235 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x3318, ~0x000f0330, 0x0dcf0400),
236 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3324, 0x04000000),
237 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3368, 0x00041400),
238 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3388, 0x3f8ddbff),
239 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33ac, 0x00007001),
240 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33b0, 0x00181900),
241 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33c0, 0x00060A00),
242 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33d0, 0x06200840),
243 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a28, 0x01010101),
244 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a2c, 0x040c0404),
245 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a9c, 0x9000000a),
246 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b1c, 0x03808033),
247 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b34, 0x80000009),
248 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3348, 0x022ddfff),
249 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x334c, 0x00000001),
250 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3358, 0x0001c000),
251 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3380, 0x3f8ddbff),
252 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3384, 0x0001c7e1),
253 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x338c, 0x0001c7e1),
254 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3398, 0x0001c000),
255 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33a8, 0x00181900),
256 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33dc, 0x00080000),
257 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33e0, 0x00000001),
258 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a20, 0x0000040c),
259 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a24, 0x01010101),
260 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a30, 0x01010101),
261 REG_PCI_RMW32(0xac, ~0x00200000, 0),
262 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x0410, 0x00000003),
263 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2618, 0x08000000),
264 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2300, 0x00000002),
265 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2600, 0x00000008),
266 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33b4, 0x00007001),
267 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3350, 0x022ddfff),
268 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3354, 0x00000001),
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700269 /* Power Optimizer */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700270 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33d4, 0x08000000),
Matt DeVillierc97e0422017-02-16 11:36:16 -0600271 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33c8, 0x00000080),
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700272 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b10, 0x0000883c),
273 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b14, 0x1e0a4616),
274 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b24, 0x40000005),
275 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b20, 0x0005db01),
276 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a80, 0x05145005),
277 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a84, 0x00001005),
278 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33d4, 0x2fff2fb1),
279 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33c8, 0x00008000),
280 REG_SCRIPT_END
281};
282
283static void pch_enable_mphy(void)
284{
285 u32 gpio71_native = gpio_is_native(71);
286 u32 data_and = 0xffffffff;
287 u32 data_or = (1 << 14) | (1 << 13) | (1 << 12);
288
289 if (gpio71_native) {
290 data_or |= (1 << 0);
291 if (pch_is_wpt()) {
292 data_and &= ~((1 << 7) | (1 << 6) | (1 << 3));
293 data_or |= (1 << 5) | (1 << 4);
294
295 if (pch_is_wpt_ulx()) {
296 /* Check if SATA and USB3 MPHY are enabled */
297 u32 strap19 = pch_read_soft_strap(19);
298 strap19 &= ((1 << 31) | (1 << 30));
299 strap19 >>= 30;
300 if (strap19 == 3) {
301 data_or |= (1 << 3);
302 printk(BIOS_DEBUG, "Enable ULX MPHY PG "
303 "control in single domain\n");
304 } else if (strap19 == 0) {
305 printk(BIOS_DEBUG, "Enable ULX MPHY PG "
306 "control in split domains\n");
307 } else {
308 printk(BIOS_DEBUG, "Invalid PCH Soft "
309 "Strap 19 configuration\n");
310 }
311 } else {
312 data_or |= (1 << 3);
313 }
314 }
315 }
316
317 pch_iobp_update(0xCF000000, data_and, data_or);
318}
319
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700320static void pch_init_deep_sx(struct device *dev)
321{
322 config_t *config = dev->chip_info;
323
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
348 reg_script_run_on_dev(dev, pch_pm_init_script);
349
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;
369
370 /* DMI */
371 RCBA32_OR(0x2234, 0xf);
372
373 reg16 = pci_read_config16(dev, GEN_PMCON_1);
374 reg16 &= ~(1 << 10); /* Disable BIOS_PCI_EXP_EN for native PME */
375 if (pch_is_wpt())
376 reg16 &= ~(1 << 11);
377 else
378 reg16 |= (1 << 11);
379 reg16 |= (1 << 5) | (1 << 6) | (1 << 7) | (1 << 12);
380 reg16 |= (1 << 2); // PCI CLKRUN# Enable
381 pci_write_config16(dev, GEN_PMCON_1, reg16);
382
383 /*
384 * RCBA + 0x2614[27:25,14:13,10,8] = 101,11,1,1
385 * RCBA + 0x2614[23:16] = 0x20
386 * RCBA + 0x2614[30:28] = 0x0
387 * RCBA + 0x2614[26] = 1 (IF 0:2.0@0x08 >= 0x0b)
388 */
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700389 RCBA32_AND_OR(0x2614, ~0x64ff0000, 0x0a206500);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700390
391 /* Check for 0:2.0@0x08 >= 0x0b */
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700392 if (pch_is_wpt() || pci_read_config8(SA_DEV_IGD, 0x8) >= 0x0b)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700393 RCBA32_OR(0x2614, (1 << 26));
394
395 RCBA32_OR(0x900, 0x0000031f);
396
397 reg32 = RCBA32(CG);
398 if (RCBA32(0x3454) & (1 << 4))
399 reg32 &= ~(1 << 29); // LPC Dynamic
400 else
401 reg32 |= (1 << 29); // LPC Dynamic
402 reg32 |= (1 << 31); // LP LPC
403 reg32 |= (1 << 30); // LP BLA
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700404 if (RCBA32(0x3454) & (1 << 4))
405 reg32 &= ~(1 << 29);
406 else
407 reg32 |= (1 << 29);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700408 reg32 |= (1 << 28); // GPIO Dynamic
409 reg32 |= (1 << 27); // HPET Dynamic
410 reg32 |= (1 << 26); // Generic Platform Event Clock
411 if (RCBA32(BUC) & PCH_DISABLE_GBE)
412 reg32 |= (1 << 23); // GbE Static
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700413 if (RCBA32(FD) & PCH_DISABLE_HD_AUDIO)
414 reg32 |= (1 << 21); // HDA Static
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700415 reg32 |= (1 << 22); // HDA Dynamic
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700416 RCBA32(CG) = reg32;
417
418 /* PCH-LP LPC */
419 if (pch_is_wpt())
420 RCBA32_AND_OR(0x3434, ~0x1f, 0x17);
421 else
422 RCBA32_OR(0x3434, 0x7);
423
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700424 /* SPI */
425 RCBA32_OR(0x38c0, 0x3c07);
426
427 pch_iobp_update(0xCE00C000, ~1UL, 0x00000000);
428}
429
430static void pch_set_acpi_mode(void)
431{
Martin Rothe6ff1592017-06-24 21:34:29 -0600432#if IS_ENABLED(CONFIG_HAVE_SMI_HANDLER)
Kyösti Mälkki9e94dbf2015-01-08 20:03:18 +0200433 if (!acpi_is_wakeup_s3()) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700434 printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n");
435 outb(APM_CNT_ACPI_DISABLE, APM_CNT);
436 printk(BIOS_DEBUG, "done.\n");
437 }
438#endif /* CONFIG_HAVE_SMI_HANDLER */
439}
440
441static void lpc_init(struct device *dev)
442{
443 /* Legacy initialization */
444 isa_dma_init();
445 pch_rtc_init(dev);
446 reg_script_run_on_dev(dev, pch_misc_init_script);
447
448 /* Interrupt configuration */
449 pch_enable_ioapic(dev);
450 pch_pirq_init(dev);
451 setup_i8259();
452 i8259_configure_irq_trigger(9, 1);
Matt DeVillier81a6f102018-02-19 17:33:48 -0600453 enable_hpet(dev);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700454
455 /* Initialize power management */
456 pch_power_options(dev);
457 pch_pm_init(dev);
458 pch_cg_init(dev);
459
460 pch_set_acpi_mode();
461}
462
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200463static void pch_lpc_add_mmio_resources(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700464{
465 u32 reg;
466 struct resource *res;
467 const u32 default_decode_base = IO_APIC_ADDR;
468
469 /*
470 * Just report all resources from IO-APIC base to 4GiB. Don't mark
471 * them reserved as that may upset the OS if this range is marked
472 * as reserved in the e820.
473 */
474 res = new_resource(dev, OIC);
475 res->base = default_decode_base;
476 res->size = 0 - default_decode_base;
477 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
478
479 /* RCBA */
Lee Leahy6ef51922017-03-17 10:56:08 -0700480 if (default_decode_base > RCBA_BASE_ADDRESS) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700481 res = new_resource(dev, RCBA);
482 res->base = RCBA_BASE_ADDRESS;
483 res->size = 16 * 1024;
484 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
Lee Leahy26b7cd02017-03-16 18:47:55 -0700485 IORESOURCE_FIXED | IORESOURCE_RESERVE;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700486 }
487
488 /* Check LPC Memory Decode register. */
489 reg = pci_read_config32(dev, LGMR);
490 if (reg & 1) {
491 reg &= ~0xffff;
492 if (reg < default_decode_base) {
493 res = new_resource(dev, LGMR);
494 res->base = reg;
495 res->size = 16 * 1024;
496 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
Lee Leahy26b7cd02017-03-16 18:47:55 -0700497 IORESOURCE_FIXED | IORESOURCE_RESERVE;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700498 }
499 }
500}
501
502/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
503#define LPC_DEFAULT_IO_RANGE_LOWER 0
504#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
505
506static inline int pch_io_range_in_default(u16 base, u16 size)
507{
508 /* Does it start above the range? */
509 if (base >= LPC_DEFAULT_IO_RANGE_UPPER)
510 return 0;
511
512 /* Is it entirely contained? */
513 if (base >= LPC_DEFAULT_IO_RANGE_LOWER &&
514 (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
515 return 1;
516
517 /* This will return not in range for partial overlaps. */
518 return 0;
519}
520
521/*
522 * Note: this function assumes there is no overlap with the default LPC device's
523 * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
524 */
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200525static void pch_lpc_add_io_resource(struct device *dev, u16 base, u16 size,
526 int index)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700527{
528 struct resource *res;
529
530 if (pch_io_range_in_default(base, size))
531 return;
532
533 res = new_resource(dev, index);
534 res->base = base;
535 res->size = size;
536 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
537}
538
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200539static void pch_lpc_add_gen_io_resources(struct device *dev, int reg_value,
540 int index)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700541{
542 /*
543 * Check if the register is enabled. If so and the base exceeds the
Martin Rothde7ed6f2014-12-07 14:58:18 -0700544 * device's default claim range add the resource.
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700545 */
546 if (reg_value & 1) {
547 u16 base = reg_value & 0xfffc;
548 u16 size = (0x3 | ((reg_value >> 16) & 0xfc)) + 1;
549 pch_lpc_add_io_resource(dev, base, size, index);
550 }
551}
552
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200553static void pch_lpc_add_io_resources(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700554{
555 struct resource *res;
556 config_t *config = dev->chip_info;
557
558 /* Add the default claimed IO range for the LPC device. */
559 res = new_resource(dev, 0);
560 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
561 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
562 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
563
564 /* GPIOBASE */
565 pch_lpc_add_io_resource(dev, GPIO_BASE_ADDRESS,
566 GPIO_BASE_SIZE, GPIO_BASE);
567
568 /* PMBASE */
569 pch_lpc_add_io_resource(dev, ACPI_BASE_ADDRESS, ACPI_BASE_SIZE, PMBASE);
570
571 /* LPC Generic IO Decode range. */
572 pch_lpc_add_gen_io_resources(dev, config->gen1_dec, LPC_GEN1_DEC);
573 pch_lpc_add_gen_io_resources(dev, config->gen2_dec, LPC_GEN2_DEC);
574 pch_lpc_add_gen_io_resources(dev, config->gen3_dec, LPC_GEN3_DEC);
575 pch_lpc_add_gen_io_resources(dev, config->gen4_dec, LPC_GEN4_DEC);
576}
577
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200578static void pch_lpc_read_resources(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700579{
580 global_nvs_t *gnvs;
581
582 /* Get the normal PCI resources of this device. */
583 pci_dev_read_resources(dev);
584
585 /* Add non-standard MMIO resources. */
586 pch_lpc_add_mmio_resources(dev);
587
588 /* Add IO resources. */
589 pch_lpc_add_io_resources(dev);
590
591 /* Allocate ACPI NVS in CBMEM */
592 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(global_nvs_t));
Kyösti Mälkki9e94dbf2015-01-08 20:03:18 +0200593 if (!acpi_is_wakeup_s3() && gnvs)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700594 memset(gnvs, 0, sizeof(global_nvs_t));
595}
596
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200597static void southcluster_inject_dsdt(struct device *device)
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100598{
599 global_nvs_t *gnvs;
600
601 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
602 if (!gnvs) {
Lee Leahy26b7cd02017-03-16 18:47:55 -0700603 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(*gnvs));
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100604 if (gnvs)
605 memset(gnvs, 0, sizeof(*gnvs));
606 }
607
608 if (gnvs) {
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100609 acpi_create_gnvs(gnvs);
610 acpi_save_gnvs((unsigned long)gnvs);
611 /* And tell SMI about it */
612 smm_setup_structures(gnvs, NULL, NULL);
613
614 /* Add it to DSDT. */
615 acpigen_write_scope("\\");
616 acpigen_write_name_dword("NVSA", (u32) gnvs);
617 acpigen_pop_len();
618 }
619}
620
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200621static unsigned long broadwell_write_acpi_tables(struct device *device,
Duncan Laurie93bbd412017-11-11 20:03:29 -0800622 unsigned long current,
623 struct acpi_rsdp *rsdp)
624{
625 if (IS_ENABLED(CONFIG_INTEL_PCH_UART_CONSOLE))
626 current = acpi_write_dbg2_pci_uart(rsdp, current,
627 (CONFIG_INTEL_PCH_UART_CONSOLE_NUMBER == 1) ?
628 PCH_DEV_UART1 : PCH_DEV_UART0,
629 ACPI_ACCESS_SIZE_BYTE_ACCESS);
630 return acpi_write_hpet(device, current, rsdp);
631}
632
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700633static struct device_operations device_ops = {
634 .read_resources = &pch_lpc_read_resources,
635 .set_resources = &pci_dev_set_resources,
636 .enable_resources = &pci_dev_enable_resources,
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100637 .acpi_inject_dsdt_generator = southcluster_inject_dsdt,
Duncan Laurie93bbd412017-11-11 20:03:29 -0800638 .write_acpi_tables = broadwell_write_acpi_tables,
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700639 .init = &lpc_init,
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200640 .scan_bus = &scan_lpc_bus,
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700641 .ops_pci = &broadwell_pci_ops,
642};
643
644static const unsigned short pci_device_ids[] = {
645 PCH_LPT_LP_SAMPLE,
646 PCH_LPT_LP_PREMIUM,
647 PCH_LPT_LP_MAINSTREAM,
648 PCH_LPT_LP_VALUE,
649 PCH_WPT_HSW_U_SAMPLE,
650 PCH_WPT_BDW_U_SAMPLE,
651 PCH_WPT_BDW_U_PREMIUM,
652 PCH_WPT_BDW_U_BASE,
653 PCH_WPT_BDW_Y_SAMPLE,
654 PCH_WPT_BDW_Y_PREMIUM,
655 PCH_WPT_BDW_Y_BASE,
656 PCH_WPT_BDW_H,
657 0
658};
659
660static const struct pci_driver pch_lpc __pci_driver = {
661 .ops = &device_ops,
662 .vendor = PCI_VENDOR_ID_INTEL,
663 .devices = pci_device_ids,
664};