blob: 13c975f3f8fea669d9a76502278c1c479d189d1b [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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
Patrick Georgib890a122015-03-26 15:17:45 +010018 * Foundation, Inc.
Duncan Lauriec88c54c2014-04-30 16:36:13 -070019 */
20
21#include <console/console.h>
22#include <delay.h>
23#include <device/device.h>
24#include <device/pci.h>
25#include <device/pci_ids.h>
26#include <pc80/mc146818rtc.h>
27#include <pc80/isa-dma.h>
28#include <pc80/i8259.h>
29#include <arch/io.h>
30#include <arch/ioapic.h>
31#include <arch/acpi.h>
32#include <cpu/cpu.h>
33#include <cpu/x86/smm.h>
34#include <cbmem.h>
35#include <reg_script.h>
36#include <string.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070037#include <soc/gpio.h>
38#include <soc/iobp.h>
39#include <soc/iomap.h>
40#include <soc/lpc.h>
41#include <soc/nvs.h>
42#include <soc/pch.h>
43#include <soc/pci_devs.h>
44#include <soc/pm.h>
45#include <soc/ramstage.h>
46#include <soc/rcba.h>
47#include <soc/intel/broadwell/chip.h>
Vladimir Serbinenkob219da82014-11-09 03:29:30 +010048#include <arch/acpi.h>
49#include <arch/acpigen.h>
50#include <cpu/cpu.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070051
Duncan Laurie35dc00f2015-01-18 14:06:42 -080052#if IS_ENABLED(CONFIG_CHROMEOS)
53#include <vendorcode/google/chromeos/chromeos.h>
54#endif
55
Duncan Lauriec88c54c2014-04-30 16:36:13 -070056static void pch_enable_ioapic(struct device *dev)
57{
58 u32 reg32;
59
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080060 set_ioapic_id(VIO_APIC_VADDR, 0x02);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070061
62 /* affirm full set of redirection table entries ("write once") */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080063 reg32 = io_apic_read(VIO_APIC_VADDR, 0x01);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070064
65 /* PCH-LP has 39 redirection entries */
66 reg32 &= ~0x00ff0000;
67 reg32 |= 0x00270000;
68
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080069 io_apic_write(VIO_APIC_VADDR, 0x01, reg32);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070070
71 /*
72 * Select Boot Configuration register (0x03) and
73 * use Processor System Bus (0x01) to deliver interrupts.
74 */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080075 io_apic_write(VIO_APIC_VADDR, 0x03, 0x01);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070076}
77
78/* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control
79 * 0x00 - 0000 = Reserved
80 * 0x01 - 0001 = Reserved
81 * 0x02 - 0010 = Reserved
82 * 0x03 - 0011 = IRQ3
83 * 0x04 - 0100 = IRQ4
84 * 0x05 - 0101 = IRQ5
85 * 0x06 - 0110 = IRQ6
86 * 0x07 - 0111 = IRQ7
87 * 0x08 - 1000 = Reserved
88 * 0x09 - 1001 = IRQ9
89 * 0x0A - 1010 = IRQ10
90 * 0x0B - 1011 = IRQ11
91 * 0x0C - 1100 = IRQ12
92 * 0x0D - 1101 = Reserved
93 * 0x0E - 1110 = IRQ14
94 * 0x0F - 1111 = IRQ15
95 * PIRQ[n]_ROUT[7] - PIRQ Routing Control
96 * 0x80 - The PIRQ is not routed.
97 */
98
99static void pch_pirq_init(device_t dev)
100{
101 device_t irq_dev;
102 config_t *config = dev->chip_info;
103
104 pci_write_config8(dev, PIRQA_ROUT, config->pirqa_routing);
105 pci_write_config8(dev, PIRQB_ROUT, config->pirqb_routing);
106 pci_write_config8(dev, PIRQC_ROUT, config->pirqc_routing);
107 pci_write_config8(dev, PIRQD_ROUT, config->pirqd_routing);
108
109 pci_write_config8(dev, PIRQE_ROUT, config->pirqe_routing);
110 pci_write_config8(dev, PIRQF_ROUT, config->pirqf_routing);
111 pci_write_config8(dev, PIRQG_ROUT, config->pirqg_routing);
112 pci_write_config8(dev, PIRQH_ROUT, config->pirqh_routing);
113
114 for(irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
115 u8 int_pin=0, int_line=0;
116
117 if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI)
118 continue;
119
120 int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
121
122 switch (int_pin) {
123 case 1: /* INTA# */ int_line = config->pirqa_routing; break;
124 case 2: /* INTB# */ int_line = config->pirqb_routing; break;
125 case 3: /* INTC# */ int_line = config->pirqc_routing; break;
126 case 4: /* INTD# */ int_line = config->pirqd_routing; break;
127 }
128
129 if (!int_line)
130 continue;
131
132 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line);
133 }
134}
135
136static void pch_power_options(device_t dev)
137{
138 u16 reg16;
139 const char *state;
140 /* Get the chip configuration */
141 config_t *config = dev->chip_info;
142 int pwr_on=CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL;
143
144 /* Which state do we want to goto after g3 (power restored)?
145 * 0 == S0 Full On
146 * 1 == S5 Soft Off
147 *
148 * If the option is not existent (Laptops), use Kconfig setting.
149 */
150 get_option(&pwr_on, "power_on_after_fail");
151
152 reg16 = pci_read_config16(dev, GEN_PMCON_3);
153 reg16 &= 0xfffe;
154 switch (pwr_on) {
155 case MAINBOARD_POWER_OFF:
156 reg16 |= 1;
157 state = "off";
158 break;
159 case MAINBOARD_POWER_ON:
160 reg16 &= ~1;
161 state = "on";
162 break;
163 case MAINBOARD_POWER_KEEP:
164 reg16 &= ~1;
165 state = "state keep";
166 break;
167 default:
168 state = "undefined";
169 }
170 pci_write_config16(dev, GEN_PMCON_3, reg16);
171 printk(BIOS_INFO, "Set power %s after power failure.\n", state);
172
173 /* GPE setup based on device tree configuration */
174 enable_all_gpe(config->gpe0_en_1, config->gpe0_en_2,
175 config->gpe0_en_3, config->gpe0_en_4);
176
177 /* SMI setup based on device tree configuration */
178 enable_alt_smi(config->alt_gp_smi_en);
179}
180
Patrick Georgi320ad822015-04-22 13:32:13 +0200181#if IS_ENABLED(CONFIG_CHROMEOS) && IS_ENABLED(CONFIG_CHROMEOS_VBNV_CMOS)
Duncan Laurie35dc00f2015-01-18 14:06:42 -0800182/*
183 * Preserve Vboot NV data when clearing CMOS as it will
184 * have been re-initialized already by Vboot firmware init.
185 */
186static void pch_cmos_init_preserve(int reset)
187{
188 uint8_t vbnv[CONFIG_VBNV_SIZE];
189
190 if (reset)
191 read_vbnv(vbnv);
192
193 cmos_init(reset);
194
195 if (reset)
196 save_vbnv(vbnv);
197}
198#endif
199
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700200static void pch_rtc_init(struct device *dev)
201{
202 u8 reg8;
203 int rtc_failed;
204
205 reg8 = pci_read_config8(dev, GEN_PMCON_3);
206 rtc_failed = reg8 & RTC_BATTERY_DEAD;
207 if (rtc_failed) {
208 reg8 &= ~RTC_BATTERY_DEAD;
209 pci_write_config8(dev, GEN_PMCON_3, reg8);
210 printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed);
211 }
212
Patrick Georgi320ad822015-04-22 13:32:13 +0200213#if IS_ENABLED(CONFIG_CHROMEOS) && IS_ENABLED(CONFIG_CHROMEOS_VBNV_CMOS)
Duncan Laurie35dc00f2015-01-18 14:06:42 -0800214 pch_cmos_init_preserve(rtc_failed);
215#else
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700216 cmos_init(rtc_failed);
Duncan Laurie35dc00f2015-01-18 14:06:42 -0800217#endif
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700218}
219
220static const struct reg_script pch_misc_init_script[] = {
221 /* Setup SLP signal assertion, SLP_S4=4s, SLP_S3=50ms */
222 REG_PCI_RMW16(GEN_PMCON_3, ~((3 << 4)|(1 << 10)),
223 (1 << 3)|(1 << 11)|(1 << 12)),
224 /* Prepare sleep mode */
225 REG_IO_RMW32(ACPI_BASE_ADDRESS + PM1_CNT, ~SLP_TYP, SCI_EN),
226 /* Setup NMI on errors, disable SERR */
227 REG_IO_RMW8(0x61, ~0xf0, (1 << 2)),
228 /* Disable NMI sources */
229 REG_IO_OR8(0x70, (1 << 7)),
230 /* Indicate DRAM init done for MRC */
231 REG_PCI_OR8(GEN_PMCON_2, (1 << 7)),
232 /* Enable BIOS updates outside of SMM */
233 REG_PCI_RMW8(0xdc, ~(1 << 5), 0),
234 /* Clear status bits to prevent unexpected wake */
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700235 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x3310, 0x0000002f),
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700236 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x3f02, ~0x0000000f, 0),
Kenji Chen074a0282014-09-20 01:39:20 +0800237 /* Enable PCIe Releaxed Order */
238 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2314, (1 << 31) | (1 << 7)),
239 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x1114, (1 << 15) | (1 << 14)),
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700240 /* Setup SERIRQ, enable continuous mode */
241 REG_PCI_OR8(SERIRQ_CNTL, (1 << 7) | (1 << 6)),
242#if !CONFIG_SERIRQ_CONTINUOUS_MODE
243 REG_PCI_RMW8(SERIRQ_CNTL, ~(1 << 6), 0),
244#endif
245 REG_SCRIPT_END
246};
247
248/* Magic register settings for power management */
249static const struct reg_script pch_pm_init_script[] = {
250 REG_PCI_WRITE8(0xa9, 0x46),
251 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x232c, ~1, 0),
252 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x1100, 0x0000c13f),
253 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x2320, ~0x60, 0x10),
254 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3314, 0x00012fff),
255 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x3318, ~0x000f0330, 0x0dcf0400),
256 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3324, 0x04000000),
257 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3368, 0x00041400),
258 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3388, 0x3f8ddbff),
259 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33ac, 0x00007001),
260 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33b0, 0x00181900),
261 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33c0, 0x00060A00),
262 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33d0, 0x06200840),
263 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a28, 0x01010101),
264 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a2c, 0x040c0404),
265 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a9c, 0x9000000a),
266 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b1c, 0x03808033),
267 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b34, 0x80000009),
268 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3348, 0x022ddfff),
269 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x334c, 0x00000001),
270 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3358, 0x0001c000),
271 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3380, 0x3f8ddbff),
272 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3384, 0x0001c7e1),
273 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x338c, 0x0001c7e1),
274 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3398, 0x0001c000),
275 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33a8, 0x00181900),
276 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33dc, 0x00080000),
277 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33e0, 0x00000001),
278 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a20, 0x0000040c),
279 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a24, 0x01010101),
280 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a30, 0x01010101),
281 REG_PCI_RMW32(0xac, ~0x00200000, 0),
282 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x0410, 0x00000003),
283 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2618, 0x08000000),
284 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2300, 0x00000002),
285 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2600, 0x00000008),
286 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33b4, 0x00007001),
287 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3350, 0x022ddfff),
288 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3354, 0x00000001),
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700289 /* Power Optimizer */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700290 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33d4, 0x08000000),
291 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33c8, 0x08000080),
292 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b10, 0x0000883c),
293 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b14, 0x1e0a4616),
294 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b24, 0x40000005),
295 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b20, 0x0005db01),
296 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a80, 0x05145005),
297 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a84, 0x00001005),
298 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33d4, 0x2fff2fb1),
299 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33c8, 0x00008000),
300 REG_SCRIPT_END
301};
302
303static void pch_enable_mphy(void)
304{
305 u32 gpio71_native = gpio_is_native(71);
306 u32 data_and = 0xffffffff;
307 u32 data_or = (1 << 14) | (1 << 13) | (1 << 12);
308
309 if (gpio71_native) {
310 data_or |= (1 << 0);
311 if (pch_is_wpt()) {
312 data_and &= ~((1 << 7) | (1 << 6) | (1 << 3));
313 data_or |= (1 << 5) | (1 << 4);
314
315 if (pch_is_wpt_ulx()) {
316 /* Check if SATA and USB3 MPHY are enabled */
317 u32 strap19 = pch_read_soft_strap(19);
318 strap19 &= ((1 << 31) | (1 << 30));
319 strap19 >>= 30;
320 if (strap19 == 3) {
321 data_or |= (1 << 3);
322 printk(BIOS_DEBUG, "Enable ULX MPHY PG "
323 "control in single domain\n");
324 } else if (strap19 == 0) {
325 printk(BIOS_DEBUG, "Enable ULX MPHY PG "
326 "control in split domains\n");
327 } else {
328 printk(BIOS_DEBUG, "Invalid PCH Soft "
329 "Strap 19 configuration\n");
330 }
331 } else {
332 data_or |= (1 << 3);
333 }
334 }
335 }
336
337 pch_iobp_update(0xCF000000, data_and, data_or);
338}
339
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700340static void pch_init_deep_sx(struct device *dev)
341{
342 config_t *config = dev->chip_info;
343
344 if (config->deep_sx_enable_ac) {
345 RCBA32_OR(DEEP_S3_POL, DEEP_S3_EN_AC);
346 RCBA32_OR(DEEP_S5_POL, DEEP_S5_EN_AC);
347 }
348
349 if (config->deep_sx_enable_dc) {
350 RCBA32_OR(DEEP_S3_POL, DEEP_S3_EN_DC);
351 RCBA32_OR(DEEP_S5_POL, DEEP_S5_EN_DC);
352 }
353
354 if (config->deep_sx_enable_ac || config->deep_sx_enable_dc)
355 RCBA32_OR(DEEP_SX_CONFIG,
356 DEEP_SX_WAKE_PIN_EN | DEEP_SX_GP27_PIN_EN);
357}
358
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700359/* Power Management init */
360static void pch_pm_init(struct device *dev)
361{
362 printk(BIOS_DEBUG, "PCH PM init\n");
363
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700364 pch_init_deep_sx(dev);
365
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700366 pch_enable_mphy();
367
368 reg_script_run_on_dev(dev, pch_pm_init_script);
369
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700370 if (pch_is_wpt()) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700371 RCBA32_OR(0x33e0, (1 << 4) | (1 << 1));
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700372 RCBA32_OR(0x2b1c, (1 << 22) | (1 << 14) | (1 << 13));
373 RCBA32(0x33e4) = 0x16bf0002;
374 RCBA32_OR(0x33e4, 0x1);
375 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700376
377 pch_iobp_update(0xCA000000, ~0UL, 0x00000009);
378
379 /* Set RCBA 0x2b1c[29]=1 if DSP disabled */
380 if (RCBA32(FD) & PCH_DISABLE_ADSPD)
381 RCBA32_OR(0x2b1c, (1 << 29));
382
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700383}
384
385static void pch_cg_init(device_t dev)
386{
387 u32 reg32;
388 u16 reg16;
389
390 /* DMI */
391 RCBA32_OR(0x2234, 0xf);
392
393 reg16 = pci_read_config16(dev, GEN_PMCON_1);
394 reg16 &= ~(1 << 10); /* Disable BIOS_PCI_EXP_EN for native PME */
395 if (pch_is_wpt())
396 reg16 &= ~(1 << 11);
397 else
398 reg16 |= (1 << 11);
399 reg16 |= (1 << 5) | (1 << 6) | (1 << 7) | (1 << 12);
400 reg16 |= (1 << 2); // PCI CLKRUN# Enable
401 pci_write_config16(dev, GEN_PMCON_1, reg16);
402
403 /*
404 * RCBA + 0x2614[27:25,14:13,10,8] = 101,11,1,1
405 * RCBA + 0x2614[23:16] = 0x20
406 * RCBA + 0x2614[30:28] = 0x0
407 * RCBA + 0x2614[26] = 1 (IF 0:2.0@0x08 >= 0x0b)
408 */
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700409 RCBA32_AND_OR(0x2614, ~0x64ff0000, 0x0a206500);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700410
411 /* Check for 0:2.0@0x08 >= 0x0b */
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700412 if (pch_is_wpt() || pci_read_config8(SA_DEV_IGD, 0x8) >= 0x0b)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700413 RCBA32_OR(0x2614, (1 << 26));
414
415 RCBA32_OR(0x900, 0x0000031f);
416
417 reg32 = RCBA32(CG);
418 if (RCBA32(0x3454) & (1 << 4))
419 reg32 &= ~(1 << 29); // LPC Dynamic
420 else
421 reg32 |= (1 << 29); // LPC Dynamic
422 reg32 |= (1 << 31); // LP LPC
423 reg32 |= (1 << 30); // LP BLA
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700424 if (RCBA32(0x3454) & (1 << 4))
425 reg32 &= ~(1 << 29);
426 else
427 reg32 |= (1 << 29);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700428 reg32 |= (1 << 28); // GPIO Dynamic
429 reg32 |= (1 << 27); // HPET Dynamic
430 reg32 |= (1 << 26); // Generic Platform Event Clock
431 if (RCBA32(BUC) & PCH_DISABLE_GBE)
432 reg32 |= (1 << 23); // GbE Static
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700433 if (RCBA32(FD) & PCH_DISABLE_HD_AUDIO)
434 reg32 |= (1 << 21); // HDA Static
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700435 reg32 |= (1 << 22); // HDA Dynamic
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700436 RCBA32(CG) = reg32;
437
438 /* PCH-LP LPC */
439 if (pch_is_wpt())
440 RCBA32_AND_OR(0x3434, ~0x1f, 0x17);
441 else
442 RCBA32_OR(0x3434, 0x7);
443
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700444 /* SPI */
445 RCBA32_OR(0x38c0, 0x3c07);
446
447 pch_iobp_update(0xCE00C000, ~1UL, 0x00000000);
448}
449
450static void pch_set_acpi_mode(void)
451{
452#if CONFIG_HAVE_SMI_HANDLER
Kyösti Mälkki9e94dbf2015-01-08 20:03:18 +0200453 if (!acpi_is_wakeup_s3()) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700454 printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n");
455 outb(APM_CNT_ACPI_DISABLE, APM_CNT);
456 printk(BIOS_DEBUG, "done.\n");
457 }
458#endif /* CONFIG_HAVE_SMI_HANDLER */
459}
460
461static void lpc_init(struct device *dev)
462{
463 /* Legacy initialization */
464 isa_dma_init();
465 pch_rtc_init(dev);
466 reg_script_run_on_dev(dev, pch_misc_init_script);
467
468 /* Interrupt configuration */
469 pch_enable_ioapic(dev);
470 pch_pirq_init(dev);
471 setup_i8259();
472 i8259_configure_irq_trigger(9, 1);
473
474 /* Initialize power management */
475 pch_power_options(dev);
476 pch_pm_init(dev);
477 pch_cg_init(dev);
478
479 pch_set_acpi_mode();
480}
481
482static void pch_lpc_add_mmio_resources(device_t dev)
483{
484 u32 reg;
485 struct resource *res;
486 const u32 default_decode_base = IO_APIC_ADDR;
487
488 /*
489 * Just report all resources from IO-APIC base to 4GiB. Don't mark
490 * them reserved as that may upset the OS if this range is marked
491 * as reserved in the e820.
492 */
493 res = new_resource(dev, OIC);
494 res->base = default_decode_base;
495 res->size = 0 - default_decode_base;
496 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
497
498 /* RCBA */
499 if (RCBA_BASE_ADDRESS < default_decode_base) {
500 res = new_resource(dev, RCBA);
501 res->base = RCBA_BASE_ADDRESS;
502 res->size = 16 * 1024;
503 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
504 IORESOURCE_FIXED | IORESOURCE_RESERVE;
505 }
506
507 /* Check LPC Memory Decode register. */
508 reg = pci_read_config32(dev, LGMR);
509 if (reg & 1) {
510 reg &= ~0xffff;
511 if (reg < default_decode_base) {
512 res = new_resource(dev, LGMR);
513 res->base = reg;
514 res->size = 16 * 1024;
515 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
516 IORESOURCE_FIXED | IORESOURCE_RESERVE;
517 }
518 }
519}
520
521/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
522#define LPC_DEFAULT_IO_RANGE_LOWER 0
523#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
524
525static inline int pch_io_range_in_default(u16 base, u16 size)
526{
527 /* Does it start above the range? */
528 if (base >= LPC_DEFAULT_IO_RANGE_UPPER)
529 return 0;
530
531 /* Is it entirely contained? */
532 if (base >= LPC_DEFAULT_IO_RANGE_LOWER &&
533 (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
534 return 1;
535
536 /* This will return not in range for partial overlaps. */
537 return 0;
538}
539
540/*
541 * Note: this function assumes there is no overlap with the default LPC device's
542 * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
543 */
544static void pch_lpc_add_io_resource(device_t dev, u16 base, u16 size, int index)
545{
546 struct resource *res;
547
548 if (pch_io_range_in_default(base, size))
549 return;
550
551 res = new_resource(dev, index);
552 res->base = base;
553 res->size = size;
554 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
555}
556
557static void pch_lpc_add_gen_io_resources(device_t dev, int reg_value, int index)
558{
559 /*
560 * Check if the register is enabled. If so and the base exceeds the
Martin Rothde7ed6f2014-12-07 14:58:18 -0700561 * device's default claim range add the resource.
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700562 */
563 if (reg_value & 1) {
564 u16 base = reg_value & 0xfffc;
565 u16 size = (0x3 | ((reg_value >> 16) & 0xfc)) + 1;
566 pch_lpc_add_io_resource(dev, base, size, index);
567 }
568}
569
570static void pch_lpc_add_io_resources(device_t dev)
571{
572 struct resource *res;
573 config_t *config = dev->chip_info;
574
575 /* Add the default claimed IO range for the LPC device. */
576 res = new_resource(dev, 0);
577 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
578 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
579 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
580
581 /* GPIOBASE */
582 pch_lpc_add_io_resource(dev, GPIO_BASE_ADDRESS,
583 GPIO_BASE_SIZE, GPIO_BASE);
584
585 /* PMBASE */
586 pch_lpc_add_io_resource(dev, ACPI_BASE_ADDRESS, ACPI_BASE_SIZE, PMBASE);
587
588 /* LPC Generic IO Decode range. */
589 pch_lpc_add_gen_io_resources(dev, config->gen1_dec, LPC_GEN1_DEC);
590 pch_lpc_add_gen_io_resources(dev, config->gen2_dec, LPC_GEN2_DEC);
591 pch_lpc_add_gen_io_resources(dev, config->gen3_dec, LPC_GEN3_DEC);
592 pch_lpc_add_gen_io_resources(dev, config->gen4_dec, LPC_GEN4_DEC);
593}
594
595static void pch_lpc_read_resources(device_t dev)
596{
597 global_nvs_t *gnvs;
598
599 /* Get the normal PCI resources of this device. */
600 pci_dev_read_resources(dev);
601
602 /* Add non-standard MMIO resources. */
603 pch_lpc_add_mmio_resources(dev);
604
605 /* Add IO resources. */
606 pch_lpc_add_io_resources(dev);
607
608 /* Allocate ACPI NVS in CBMEM */
609 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(global_nvs_t));
Kyösti Mälkki9e94dbf2015-01-08 20:03:18 +0200610 if (!acpi_is_wakeup_s3() && gnvs)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700611 memset(gnvs, 0, sizeof(global_nvs_t));
612}
613
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100614static void southcluster_inject_dsdt(void)
615{
616 global_nvs_t *gnvs;
617
618 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
619 if (!gnvs) {
620 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof (*gnvs));
621 if (gnvs)
622 memset(gnvs, 0, sizeof(*gnvs));
623 }
624
625 if (gnvs) {
626 memset(gnvs, 0, sizeof(*gnvs));
627 acpi_create_gnvs(gnvs);
628 acpi_save_gnvs((unsigned long)gnvs);
629 /* And tell SMI about it */
630 smm_setup_structures(gnvs, NULL, NULL);
631
632 /* Add it to DSDT. */
633 acpigen_write_scope("\\");
634 acpigen_write_name_dword("NVSA", (u32) gnvs);
635 acpigen_pop_len();
636 }
637}
638
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700639static struct device_operations device_ops = {
640 .read_resources = &pch_lpc_read_resources,
641 .set_resources = &pci_dev_set_resources,
642 .enable_resources = &pci_dev_enable_resources,
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100643 .acpi_inject_dsdt_generator = southcluster_inject_dsdt,
644 .write_acpi_tables = acpi_write_hpet,
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700645 .init = &lpc_init,
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200646 .scan_bus = &scan_lpc_bus,
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700647 .ops_pci = &broadwell_pci_ops,
648};
649
650static const unsigned short pci_device_ids[] = {
651 PCH_LPT_LP_SAMPLE,
652 PCH_LPT_LP_PREMIUM,
653 PCH_LPT_LP_MAINSTREAM,
654 PCH_LPT_LP_VALUE,
655 PCH_WPT_HSW_U_SAMPLE,
656 PCH_WPT_BDW_U_SAMPLE,
657 PCH_WPT_BDW_U_PREMIUM,
658 PCH_WPT_BDW_U_BASE,
659 PCH_WPT_BDW_Y_SAMPLE,
660 PCH_WPT_BDW_Y_PREMIUM,
661 PCH_WPT_BDW_Y_BASE,
662 PCH_WPT_BDW_H,
663 0
664};
665
666static const struct pci_driver pch_lpc __pci_driver = {
667 .ops = &device_ops,
668 .vendor = PCI_VENDOR_ID_INTEL,
669 .devices = pci_device_ids,
670};