blob: 20fa345676a1b2b9bb2b52868f3a19dc08de5179 [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>
Furquan Shaikh2a12e2e2016-07-25 11:48:03 -070047#include <vboot/vbnv.h>
48#include <vboot/vbnv_layout.h>
Duncan Laurie35dc00f2015-01-18 14:06:42 -080049
Duncan Lauriec88c54c2014-04-30 16:36:13 -070050static void pch_enable_ioapic(struct device *dev)
51{
52 u32 reg32;
53
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080054 set_ioapic_id(VIO_APIC_VADDR, 0x02);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070055
56 /* affirm full set of redirection table entries ("write once") */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080057 reg32 = io_apic_read(VIO_APIC_VADDR, 0x01);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070058
59 /* PCH-LP has 39 redirection entries */
60 reg32 &= ~0x00ff0000;
61 reg32 |= 0x00270000;
62
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080063 io_apic_write(VIO_APIC_VADDR, 0x01, reg32);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070064
65 /*
66 * Select Boot Configuration register (0x03) and
67 * use Processor System Bus (0x01) to deliver interrupts.
68 */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080069 io_apic_write(VIO_APIC_VADDR, 0x03, 0x01);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070070}
71
72/* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control
73 * 0x00 - 0000 = Reserved
74 * 0x01 - 0001 = Reserved
75 * 0x02 - 0010 = Reserved
76 * 0x03 - 0011 = IRQ3
77 * 0x04 - 0100 = IRQ4
78 * 0x05 - 0101 = IRQ5
79 * 0x06 - 0110 = IRQ6
80 * 0x07 - 0111 = IRQ7
81 * 0x08 - 1000 = Reserved
82 * 0x09 - 1001 = IRQ9
83 * 0x0A - 1010 = IRQ10
84 * 0x0B - 1011 = IRQ11
85 * 0x0C - 1100 = IRQ12
86 * 0x0D - 1101 = Reserved
87 * 0x0E - 1110 = IRQ14
88 * 0x0F - 1111 = IRQ15
89 * PIRQ[n]_ROUT[7] - PIRQ Routing Control
90 * 0x80 - The PIRQ is not routed.
91 */
92
93static void pch_pirq_init(device_t dev)
94{
95 device_t irq_dev;
96 config_t *config = dev->chip_info;
97
98 pci_write_config8(dev, PIRQA_ROUT, config->pirqa_routing);
99 pci_write_config8(dev, PIRQB_ROUT, config->pirqb_routing);
100 pci_write_config8(dev, PIRQC_ROUT, config->pirqc_routing);
101 pci_write_config8(dev, PIRQD_ROUT, config->pirqd_routing);
102
103 pci_write_config8(dev, PIRQE_ROUT, config->pirqe_routing);
104 pci_write_config8(dev, PIRQF_ROUT, config->pirqf_routing);
105 pci_write_config8(dev, PIRQG_ROUT, config->pirqg_routing);
106 pci_write_config8(dev, PIRQH_ROUT, config->pirqh_routing);
107
108 for(irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
109 u8 int_pin=0, int_line=0;
110
111 if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI)
112 continue;
113
114 int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
115
116 switch (int_pin) {
117 case 1: /* INTA# */ int_line = config->pirqa_routing; break;
118 case 2: /* INTB# */ int_line = config->pirqb_routing; break;
119 case 3: /* INTC# */ int_line = config->pirqc_routing; break;
120 case 4: /* INTD# */ int_line = config->pirqd_routing; break;
121 }
122
123 if (!int_line)
124 continue;
125
126 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line);
127 }
128}
129
130static void pch_power_options(device_t dev)
131{
132 u16 reg16;
133 const char *state;
134 /* Get the chip configuration */
135 config_t *config = dev->chip_info;
136 int pwr_on=CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL;
137
138 /* Which state do we want to goto after g3 (power restored)?
139 * 0 == S0 Full On
140 * 1 == S5 Soft Off
141 *
142 * If the option is not existent (Laptops), use Kconfig setting.
143 */
144 get_option(&pwr_on, "power_on_after_fail");
145
146 reg16 = pci_read_config16(dev, GEN_PMCON_3);
147 reg16 &= 0xfffe;
148 switch (pwr_on) {
149 case MAINBOARD_POWER_OFF:
150 reg16 |= 1;
151 state = "off";
152 break;
153 case MAINBOARD_POWER_ON:
154 reg16 &= ~1;
155 state = "on";
156 break;
157 case MAINBOARD_POWER_KEEP:
158 reg16 &= ~1;
159 state = "state keep";
160 break;
161 default:
162 state = "undefined";
163 }
164 pci_write_config16(dev, GEN_PMCON_3, reg16);
165 printk(BIOS_INFO, "Set power %s after power failure.\n", state);
166
167 /* GPE setup based on device tree configuration */
168 enable_all_gpe(config->gpe0_en_1, config->gpe0_en_2,
169 config->gpe0_en_3, config->gpe0_en_4);
170
171 /* SMI setup based on device tree configuration */
172 enable_alt_smi(config->alt_gp_smi_en);
173}
174
Furquan Shaikh2a12e2e2016-07-25 11:48:03 -0700175#if IS_ENABLED(CONFIG_CHROMEOS) && IS_ENABLED(CONFIG_VBOOT_VBNV_CMOS)
Duncan Laurie35dc00f2015-01-18 14:06:42 -0800176/*
177 * Preserve Vboot NV data when clearing CMOS as it will
178 * have been re-initialized already by Vboot firmware init.
179 */
180static void pch_cmos_init_preserve(int reset)
181{
Furquan Shaikh2a12e2e2016-07-25 11:48:03 -0700182 uint8_t vbnv[VBOOT_VBNV_BLOCK_SIZE];
Duncan Laurie35dc00f2015-01-18 14:06:42 -0800183
184 if (reset)
185 read_vbnv(vbnv);
186
187 cmos_init(reset);
188
189 if (reset)
190 save_vbnv(vbnv);
191}
192#endif
193
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700194static void pch_rtc_init(struct device *dev)
195{
196 u8 reg8;
197 int rtc_failed;
198
199 reg8 = pci_read_config8(dev, GEN_PMCON_3);
200 rtc_failed = reg8 & RTC_BATTERY_DEAD;
201 if (rtc_failed) {
202 reg8 &= ~RTC_BATTERY_DEAD;
203 pci_write_config8(dev, GEN_PMCON_3, reg8);
204 printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed);
205 }
206
Furquan Shaikh2a12e2e2016-07-25 11:48:03 -0700207#if IS_ENABLED(CONFIG_CHROMEOS) && IS_ENABLED(CONFIG_VBOOT_VBNV_CMOS)
Duncan Laurie35dc00f2015-01-18 14:06:42 -0800208 pch_cmos_init_preserve(rtc_failed);
209#else
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700210 cmos_init(rtc_failed);
Duncan Laurie35dc00f2015-01-18 14:06:42 -0800211#endif
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700212}
213
214static const struct reg_script pch_misc_init_script[] = {
215 /* Setup SLP signal assertion, SLP_S4=4s, SLP_S3=50ms */
216 REG_PCI_RMW16(GEN_PMCON_3, ~((3 << 4)|(1 << 10)),
217 (1 << 3)|(1 << 11)|(1 << 12)),
218 /* Prepare sleep mode */
219 REG_IO_RMW32(ACPI_BASE_ADDRESS + PM1_CNT, ~SLP_TYP, SCI_EN),
220 /* Setup NMI on errors, disable SERR */
221 REG_IO_RMW8(0x61, ~0xf0, (1 << 2)),
222 /* Disable NMI sources */
223 REG_IO_OR8(0x70, (1 << 7)),
224 /* Indicate DRAM init done for MRC */
225 REG_PCI_OR8(GEN_PMCON_2, (1 << 7)),
226 /* Enable BIOS updates outside of SMM */
227 REG_PCI_RMW8(0xdc, ~(1 << 5), 0),
228 /* Clear status bits to prevent unexpected wake */
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700229 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x3310, 0x0000002f),
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700230 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x3f02, ~0x0000000f, 0),
Kenji Chen074a0282014-09-20 01:39:20 +0800231 /* Enable PCIe Releaxed Order */
232 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2314, (1 << 31) | (1 << 7)),
233 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x1114, (1 << 15) | (1 << 14)),
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700234 /* Setup SERIRQ, enable continuous mode */
235 REG_PCI_OR8(SERIRQ_CNTL, (1 << 7) | (1 << 6)),
236#if !CONFIG_SERIRQ_CONTINUOUS_MODE
237 REG_PCI_RMW8(SERIRQ_CNTL, ~(1 << 6), 0),
238#endif
239 REG_SCRIPT_END
240};
241
242/* Magic register settings for power management */
243static const struct reg_script pch_pm_init_script[] = {
244 REG_PCI_WRITE8(0xa9, 0x46),
245 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x232c, ~1, 0),
246 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x1100, 0x0000c13f),
247 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x2320, ~0x60, 0x10),
248 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3314, 0x00012fff),
249 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x3318, ~0x000f0330, 0x0dcf0400),
250 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3324, 0x04000000),
251 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3368, 0x00041400),
252 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3388, 0x3f8ddbff),
253 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33ac, 0x00007001),
254 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33b0, 0x00181900),
255 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33c0, 0x00060A00),
256 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33d0, 0x06200840),
257 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a28, 0x01010101),
258 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a2c, 0x040c0404),
259 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a9c, 0x9000000a),
260 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b1c, 0x03808033),
261 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b34, 0x80000009),
262 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3348, 0x022ddfff),
263 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x334c, 0x00000001),
264 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3358, 0x0001c000),
265 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3380, 0x3f8ddbff),
266 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3384, 0x0001c7e1),
267 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x338c, 0x0001c7e1),
268 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3398, 0x0001c000),
269 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33a8, 0x00181900),
270 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33dc, 0x00080000),
271 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33e0, 0x00000001),
272 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a20, 0x0000040c),
273 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a24, 0x01010101),
274 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a30, 0x01010101),
275 REG_PCI_RMW32(0xac, ~0x00200000, 0),
276 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x0410, 0x00000003),
277 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2618, 0x08000000),
278 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2300, 0x00000002),
279 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2600, 0x00000008),
280 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33b4, 0x00007001),
281 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3350, 0x022ddfff),
282 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3354, 0x00000001),
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700283 /* Power Optimizer */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700284 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33d4, 0x08000000),
285 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33c8, 0x08000080),
286 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b10, 0x0000883c),
287 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b14, 0x1e0a4616),
288 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b24, 0x40000005),
289 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b20, 0x0005db01),
290 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a80, 0x05145005),
291 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a84, 0x00001005),
292 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33d4, 0x2fff2fb1),
293 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33c8, 0x00008000),
294 REG_SCRIPT_END
295};
296
297static void pch_enable_mphy(void)
298{
299 u32 gpio71_native = gpio_is_native(71);
300 u32 data_and = 0xffffffff;
301 u32 data_or = (1 << 14) | (1 << 13) | (1 << 12);
302
303 if (gpio71_native) {
304 data_or |= (1 << 0);
305 if (pch_is_wpt()) {
306 data_and &= ~((1 << 7) | (1 << 6) | (1 << 3));
307 data_or |= (1 << 5) | (1 << 4);
308
309 if (pch_is_wpt_ulx()) {
310 /* Check if SATA and USB3 MPHY are enabled */
311 u32 strap19 = pch_read_soft_strap(19);
312 strap19 &= ((1 << 31) | (1 << 30));
313 strap19 >>= 30;
314 if (strap19 == 3) {
315 data_or |= (1 << 3);
316 printk(BIOS_DEBUG, "Enable ULX MPHY PG "
317 "control in single domain\n");
318 } else if (strap19 == 0) {
319 printk(BIOS_DEBUG, "Enable ULX MPHY PG "
320 "control in split domains\n");
321 } else {
322 printk(BIOS_DEBUG, "Invalid PCH Soft "
323 "Strap 19 configuration\n");
324 }
325 } else {
326 data_or |= (1 << 3);
327 }
328 }
329 }
330
331 pch_iobp_update(0xCF000000, data_and, data_or);
332}
333
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700334static void pch_init_deep_sx(struct device *dev)
335{
336 config_t *config = dev->chip_info;
337
338 if (config->deep_sx_enable_ac) {
339 RCBA32_OR(DEEP_S3_POL, DEEP_S3_EN_AC);
340 RCBA32_OR(DEEP_S5_POL, DEEP_S5_EN_AC);
341 }
342
343 if (config->deep_sx_enable_dc) {
344 RCBA32_OR(DEEP_S3_POL, DEEP_S3_EN_DC);
345 RCBA32_OR(DEEP_S5_POL, DEEP_S5_EN_DC);
346 }
347
348 if (config->deep_sx_enable_ac || config->deep_sx_enable_dc)
349 RCBA32_OR(DEEP_SX_CONFIG,
350 DEEP_SX_WAKE_PIN_EN | DEEP_SX_GP27_PIN_EN);
351}
352
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700353/* Power Management init */
354static void pch_pm_init(struct device *dev)
355{
356 printk(BIOS_DEBUG, "PCH PM init\n");
357
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700358 pch_init_deep_sx(dev);
359
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700360 pch_enable_mphy();
361
362 reg_script_run_on_dev(dev, pch_pm_init_script);
363
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700364 if (pch_is_wpt()) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700365 RCBA32_OR(0x33e0, (1 << 4) | (1 << 1));
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700366 RCBA32_OR(0x2b1c, (1 << 22) | (1 << 14) | (1 << 13));
367 RCBA32(0x33e4) = 0x16bf0002;
368 RCBA32_OR(0x33e4, 0x1);
369 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700370
371 pch_iobp_update(0xCA000000, ~0UL, 0x00000009);
372
373 /* Set RCBA 0x2b1c[29]=1 if DSP disabled */
374 if (RCBA32(FD) & PCH_DISABLE_ADSPD)
375 RCBA32_OR(0x2b1c, (1 << 29));
376
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700377}
378
379static void pch_cg_init(device_t dev)
380{
381 u32 reg32;
382 u16 reg16;
383
384 /* DMI */
385 RCBA32_OR(0x2234, 0xf);
386
387 reg16 = pci_read_config16(dev, GEN_PMCON_1);
388 reg16 &= ~(1 << 10); /* Disable BIOS_PCI_EXP_EN for native PME */
389 if (pch_is_wpt())
390 reg16 &= ~(1 << 11);
391 else
392 reg16 |= (1 << 11);
393 reg16 |= (1 << 5) | (1 << 6) | (1 << 7) | (1 << 12);
394 reg16 |= (1 << 2); // PCI CLKRUN# Enable
395 pci_write_config16(dev, GEN_PMCON_1, reg16);
396
397 /*
398 * RCBA + 0x2614[27:25,14:13,10,8] = 101,11,1,1
399 * RCBA + 0x2614[23:16] = 0x20
400 * RCBA + 0x2614[30:28] = 0x0
401 * RCBA + 0x2614[26] = 1 (IF 0:2.0@0x08 >= 0x0b)
402 */
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700403 RCBA32_AND_OR(0x2614, ~0x64ff0000, 0x0a206500);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700404
405 /* Check for 0:2.0@0x08 >= 0x0b */
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700406 if (pch_is_wpt() || pci_read_config8(SA_DEV_IGD, 0x8) >= 0x0b)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700407 RCBA32_OR(0x2614, (1 << 26));
408
409 RCBA32_OR(0x900, 0x0000031f);
410
411 reg32 = RCBA32(CG);
412 if (RCBA32(0x3454) & (1 << 4))
413 reg32 &= ~(1 << 29); // LPC Dynamic
414 else
415 reg32 |= (1 << 29); // LPC Dynamic
416 reg32 |= (1 << 31); // LP LPC
417 reg32 |= (1 << 30); // LP BLA
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700418 if (RCBA32(0x3454) & (1 << 4))
419 reg32 &= ~(1 << 29);
420 else
421 reg32 |= (1 << 29);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700422 reg32 |= (1 << 28); // GPIO Dynamic
423 reg32 |= (1 << 27); // HPET Dynamic
424 reg32 |= (1 << 26); // Generic Platform Event Clock
425 if (RCBA32(BUC) & PCH_DISABLE_GBE)
426 reg32 |= (1 << 23); // GbE Static
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700427 if (RCBA32(FD) & PCH_DISABLE_HD_AUDIO)
428 reg32 |= (1 << 21); // HDA Static
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700429 reg32 |= (1 << 22); // HDA Dynamic
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700430 RCBA32(CG) = reg32;
431
432 /* PCH-LP LPC */
433 if (pch_is_wpt())
434 RCBA32_AND_OR(0x3434, ~0x1f, 0x17);
435 else
436 RCBA32_OR(0x3434, 0x7);
437
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700438 /* SPI */
439 RCBA32_OR(0x38c0, 0x3c07);
440
441 pch_iobp_update(0xCE00C000, ~1UL, 0x00000000);
442}
443
444static void pch_set_acpi_mode(void)
445{
446#if CONFIG_HAVE_SMI_HANDLER
Kyösti Mälkki9e94dbf2015-01-08 20:03:18 +0200447 if (!acpi_is_wakeup_s3()) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700448 printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n");
449 outb(APM_CNT_ACPI_DISABLE, APM_CNT);
450 printk(BIOS_DEBUG, "done.\n");
451 }
452#endif /* CONFIG_HAVE_SMI_HANDLER */
453}
454
455static void lpc_init(struct device *dev)
456{
457 /* Legacy initialization */
458 isa_dma_init();
459 pch_rtc_init(dev);
460 reg_script_run_on_dev(dev, pch_misc_init_script);
461
462 /* Interrupt configuration */
463 pch_enable_ioapic(dev);
464 pch_pirq_init(dev);
465 setup_i8259();
466 i8259_configure_irq_trigger(9, 1);
467
468 /* Initialize power management */
469 pch_power_options(dev);
470 pch_pm_init(dev);
471 pch_cg_init(dev);
472
473 pch_set_acpi_mode();
474}
475
476static void pch_lpc_add_mmio_resources(device_t dev)
477{
478 u32 reg;
479 struct resource *res;
480 const u32 default_decode_base = IO_APIC_ADDR;
481
482 /*
483 * Just report all resources from IO-APIC base to 4GiB. Don't mark
484 * them reserved as that may upset the OS if this range is marked
485 * as reserved in the e820.
486 */
487 res = new_resource(dev, OIC);
488 res->base = default_decode_base;
489 res->size = 0 - default_decode_base;
490 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
491
492 /* RCBA */
493 if (RCBA_BASE_ADDRESS < default_decode_base) {
494 res = new_resource(dev, RCBA);
495 res->base = RCBA_BASE_ADDRESS;
496 res->size = 16 * 1024;
497 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
498 IORESOURCE_FIXED | IORESOURCE_RESERVE;
499 }
500
501 /* Check LPC Memory Decode register. */
502 reg = pci_read_config32(dev, LGMR);
503 if (reg & 1) {
504 reg &= ~0xffff;
505 if (reg < default_decode_base) {
506 res = new_resource(dev, LGMR);
507 res->base = reg;
508 res->size = 16 * 1024;
509 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
510 IORESOURCE_FIXED | IORESOURCE_RESERVE;
511 }
512 }
513}
514
515/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
516#define LPC_DEFAULT_IO_RANGE_LOWER 0
517#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
518
519static inline int pch_io_range_in_default(u16 base, u16 size)
520{
521 /* Does it start above the range? */
522 if (base >= LPC_DEFAULT_IO_RANGE_UPPER)
523 return 0;
524
525 /* Is it entirely contained? */
526 if (base >= LPC_DEFAULT_IO_RANGE_LOWER &&
527 (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
528 return 1;
529
530 /* This will return not in range for partial overlaps. */
531 return 0;
532}
533
534/*
535 * Note: this function assumes there is no overlap with the default LPC device's
536 * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
537 */
538static void pch_lpc_add_io_resource(device_t dev, u16 base, u16 size, int index)
539{
540 struct resource *res;
541
542 if (pch_io_range_in_default(base, size))
543 return;
544
545 res = new_resource(dev, index);
546 res->base = base;
547 res->size = size;
548 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
549}
550
551static void pch_lpc_add_gen_io_resources(device_t dev, int reg_value, int index)
552{
553 /*
554 * Check if the register is enabled. If so and the base exceeds the
Martin Rothde7ed6f2014-12-07 14:58:18 -0700555 * device's default claim range add the resource.
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700556 */
557 if (reg_value & 1) {
558 u16 base = reg_value & 0xfffc;
559 u16 size = (0x3 | ((reg_value >> 16) & 0xfc)) + 1;
560 pch_lpc_add_io_resource(dev, base, size, index);
561 }
562}
563
564static void pch_lpc_add_io_resources(device_t dev)
565{
566 struct resource *res;
567 config_t *config = dev->chip_info;
568
569 /* Add the default claimed IO range for the LPC device. */
570 res = new_resource(dev, 0);
571 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
572 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
573 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
574
575 /* GPIOBASE */
576 pch_lpc_add_io_resource(dev, GPIO_BASE_ADDRESS,
577 GPIO_BASE_SIZE, GPIO_BASE);
578
579 /* PMBASE */
580 pch_lpc_add_io_resource(dev, ACPI_BASE_ADDRESS, ACPI_BASE_SIZE, PMBASE);
581
582 /* LPC Generic IO Decode range. */
583 pch_lpc_add_gen_io_resources(dev, config->gen1_dec, LPC_GEN1_DEC);
584 pch_lpc_add_gen_io_resources(dev, config->gen2_dec, LPC_GEN2_DEC);
585 pch_lpc_add_gen_io_resources(dev, config->gen3_dec, LPC_GEN3_DEC);
586 pch_lpc_add_gen_io_resources(dev, config->gen4_dec, LPC_GEN4_DEC);
587}
588
589static void pch_lpc_read_resources(device_t dev)
590{
591 global_nvs_t *gnvs;
592
593 /* Get the normal PCI resources of this device. */
594 pci_dev_read_resources(dev);
595
596 /* Add non-standard MMIO resources. */
597 pch_lpc_add_mmio_resources(dev);
598
599 /* Add IO resources. */
600 pch_lpc_add_io_resources(dev);
601
602 /* Allocate ACPI NVS in CBMEM */
603 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(global_nvs_t));
Kyösti Mälkki9e94dbf2015-01-08 20:03:18 +0200604 if (!acpi_is_wakeup_s3() && gnvs)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700605 memset(gnvs, 0, sizeof(global_nvs_t));
606}
607
Alexander Couzensa90dad12015-04-12 21:49:46 +0200608static void southcluster_inject_dsdt(device_t device)
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100609{
610 global_nvs_t *gnvs;
611
612 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
613 if (!gnvs) {
614 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof (*gnvs));
615 if (gnvs)
616 memset(gnvs, 0, sizeof(*gnvs));
617 }
618
619 if (gnvs) {
620 memset(gnvs, 0, sizeof(*gnvs));
621 acpi_create_gnvs(gnvs);
622 acpi_save_gnvs((unsigned long)gnvs);
623 /* And tell SMI about it */
624 smm_setup_structures(gnvs, NULL, NULL);
625
626 /* Add it to DSDT. */
627 acpigen_write_scope("\\");
628 acpigen_write_name_dword("NVSA", (u32) gnvs);
629 acpigen_pop_len();
630 }
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,
638 .write_acpi_tables = acpi_write_hpet,
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};