blob: 33926143037d8920a7c23001d0a125bfc02619bc [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>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070018#include <device/device.h>
19#include <device/pci.h>
20#include <device/pci_ids.h>
21#include <pc80/mc146818rtc.h>
22#include <pc80/isa-dma.h>
23#include <pc80/i8259.h>
Elyes HAOUASd2b9ec12018-10-27 09:41:02 +020024#include <arch/cpu.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070025#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020026#include <device/pci_ops.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070027#include <arch/ioapic.h>
28#include <arch/acpi.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070029#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/acpigen.h>
Arthur Heymans2abbe462019-06-04 14:12:01 +020045#include <southbridge/intel/common/rtc.h>
Duncan Laurie35dc00f2015-01-18 14:06:42 -080046
Duncan Lauriec88c54c2014-04-30 16:36:13 -070047static void pch_enable_ioapic(struct device *dev)
48{
49 u32 reg32;
50
Matt DeVillier81a6f102018-02-19 17:33:48 -060051 /* Assign unique bus/dev/fn for I/O APIC */
52 pci_write_config16(dev, LPC_IBDF,
53 PCH_IOAPIC_PCI_BUS << 8 | PCH_IOAPIC_PCI_SLOT << 3);
54
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080055 set_ioapic_id(VIO_APIC_VADDR, 0x02);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070056
57 /* affirm full set of redirection table entries ("write once") */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080058 reg32 = io_apic_read(VIO_APIC_VADDR, 0x01);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070059
60 /* PCH-LP has 39 redirection entries */
61 reg32 &= ~0x00ff0000;
62 reg32 |= 0x00270000;
63
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080064 io_apic_write(VIO_APIC_VADDR, 0x01, reg32);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070065
66 /*
67 * Select Boot Configuration register (0x03) and
68 * use Processor System Bus (0x01) to deliver interrupts.
69 */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080070 io_apic_write(VIO_APIC_VADDR, 0x03, 0x01);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070071}
72
Matt DeVillier81a6f102018-02-19 17:33:48 -060073static void enable_hpet(struct device *dev)
74{
75 size_t i;
76
77 /* Assign unique bus/dev/fn for each HPET */
78 for (i = 0; i < 8; ++i)
79 pci_write_config16(dev, LPC_HnBDF(i),
80 PCH_HPET_PCI_BUS << 8 | PCH_HPET_PCI_SLOT << 3 | i);
81}
82
Duncan Lauriec88c54c2014-04-30 16:36:13 -070083/* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control
84 * 0x00 - 0000 = Reserved
85 * 0x01 - 0001 = Reserved
86 * 0x02 - 0010 = Reserved
87 * 0x03 - 0011 = IRQ3
88 * 0x04 - 0100 = IRQ4
89 * 0x05 - 0101 = IRQ5
90 * 0x06 - 0110 = IRQ6
91 * 0x07 - 0111 = IRQ7
92 * 0x08 - 1000 = Reserved
93 * 0x09 - 1001 = IRQ9
94 * 0x0A - 1010 = IRQ10
95 * 0x0B - 1011 = IRQ11
96 * 0x0C - 1100 = IRQ12
97 * 0x0D - 1101 = Reserved
98 * 0x0E - 1110 = IRQ14
99 * 0x0F - 1111 = IRQ15
100 * PIRQ[n]_ROUT[7] - PIRQ Routing Control
101 * 0x80 - The PIRQ is not routed.
102 */
103
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200104static void pch_pirq_init(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700105{
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200106 struct device *irq_dev;
Kyösti Mälkki8950cfb2019-07-13 22:16:25 +0300107 config_t *config = config_of(dev);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700108
109 pci_write_config8(dev, PIRQA_ROUT, config->pirqa_routing);
110 pci_write_config8(dev, PIRQB_ROUT, config->pirqb_routing);
111 pci_write_config8(dev, PIRQC_ROUT, config->pirqc_routing);
112 pci_write_config8(dev, PIRQD_ROUT, config->pirqd_routing);
113
114 pci_write_config8(dev, PIRQE_ROUT, config->pirqe_routing);
115 pci_write_config8(dev, PIRQF_ROUT, config->pirqf_routing);
116 pci_write_config8(dev, PIRQG_ROUT, config->pirqg_routing);
117 pci_write_config8(dev, PIRQH_ROUT, config->pirqh_routing);
118
Elyes HAOUAS4a83f1c2016-08-25 21:07:59 +0200119 for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
Lee Leahy26b7cd02017-03-16 18:47:55 -0700120 u8 int_pin = 0, int_line = 0;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700121
122 if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI)
123 continue;
124
125 int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
126
127 switch (int_pin) {
Lee Leahy8a9c7dc2017-03-17 10:43:25 -0700128 case 1: /* INTA# */
129 int_line = config->pirqa_routing;
130 break;
131 case 2: /* INTB# */
132 int_line = config->pirqb_routing;
133 break;
134 case 3: /* INTC# */
135 int_line = config->pirqc_routing;
136 break;
137 case 4: /* INTD# */
138 int_line = config->pirqd_routing;
139 break;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700140 }
141
142 if (!int_line)
143 continue;
144
145 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line);
146 }
147}
148
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200149static void pch_power_options(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700150{
151 u16 reg16;
152 const char *state;
153 /* Get the chip configuration */
Kyösti Mälkki8950cfb2019-07-13 22:16:25 +0300154 config_t *config = config_of(dev);
Nico Huber9faae2b2018-11-14 00:00:35 +0100155 int pwr_on = CONFIG_MAINBOARD_POWER_FAILURE_STATE;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700156
157 /* Which state do we want to goto after g3 (power restored)?
158 * 0 == S0 Full On
159 * 1 == S5 Soft Off
160 *
161 * If the option is not existent (Laptops), use Kconfig setting.
162 */
163 get_option(&pwr_on, "power_on_after_fail");
164
165 reg16 = pci_read_config16(dev, GEN_PMCON_3);
166 reg16 &= 0xfffe;
167 switch (pwr_on) {
168 case MAINBOARD_POWER_OFF:
169 reg16 |= 1;
170 state = "off";
171 break;
172 case MAINBOARD_POWER_ON:
173 reg16 &= ~1;
174 state = "on";
175 break;
176 case MAINBOARD_POWER_KEEP:
177 reg16 &= ~1;
178 state = "state keep";
179 break;
180 default:
181 state = "undefined";
182 }
183 pci_write_config16(dev, GEN_PMCON_3, reg16);
184 printk(BIOS_INFO, "Set power %s after power failure.\n", state);
185
186 /* GPE setup based on device tree configuration */
187 enable_all_gpe(config->gpe0_en_1, config->gpe0_en_2,
188 config->gpe0_en_3, config->gpe0_en_4);
189
190 /* SMI setup based on device tree configuration */
191 enable_alt_smi(config->alt_gp_smi_en);
192}
193
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700194static const struct reg_script pch_misc_init_script[] = {
195 /* Setup SLP signal assertion, SLP_S4=4s, SLP_S3=50ms */
196 REG_PCI_RMW16(GEN_PMCON_3, ~((3 << 4)|(1 << 10)),
197 (1 << 3)|(1 << 11)|(1 << 12)),
198 /* Prepare sleep mode */
199 REG_IO_RMW32(ACPI_BASE_ADDRESS + PM1_CNT, ~SLP_TYP, SCI_EN),
200 /* Setup NMI on errors, disable SERR */
201 REG_IO_RMW8(0x61, ~0xf0, (1 << 2)),
202 /* Disable NMI sources */
203 REG_IO_OR8(0x70, (1 << 7)),
204 /* Indicate DRAM init done for MRC */
205 REG_PCI_OR8(GEN_PMCON_2, (1 << 7)),
206 /* Enable BIOS updates outside of SMM */
207 REG_PCI_RMW8(0xdc, ~(1 << 5), 0),
208 /* Clear status bits to prevent unexpected wake */
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700209 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x3310, 0x0000002f),
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700210 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x3f02, ~0x0000000f, 0),
Kenji Chen074a0282014-09-20 01:39:20 +0800211 /* Enable PCIe Releaxed Order */
212 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2314, (1 << 31) | (1 << 7)),
213 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x1114, (1 << 15) | (1 << 14)),
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700214 /* Setup SERIRQ, enable continuous mode */
215 REG_PCI_OR8(SERIRQ_CNTL, (1 << 7) | (1 << 6)),
Julius Wernercd49cce2019-03-05 16:53:33 -0800216#if !CONFIG(SERIRQ_CONTINUOUS_MODE)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700217 REG_PCI_RMW8(SERIRQ_CNTL, ~(1 << 6), 0),
218#endif
219 REG_SCRIPT_END
220};
221
222/* Magic register settings for power management */
223static const struct reg_script pch_pm_init_script[] = {
224 REG_PCI_WRITE8(0xa9, 0x46),
225 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x232c, ~1, 0),
226 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x1100, 0x0000c13f),
227 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x2320, ~0x60, 0x10),
228 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3314, 0x00012fff),
229 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x3318, ~0x000f0330, 0x0dcf0400),
230 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3324, 0x04000000),
231 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3368, 0x00041400),
232 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3388, 0x3f8ddbff),
233 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33ac, 0x00007001),
234 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33b0, 0x00181900),
235 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33c0, 0x00060A00),
236 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33d0, 0x06200840),
237 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a28, 0x01010101),
238 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a2c, 0x040c0404),
239 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a9c, 0x9000000a),
240 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b1c, 0x03808033),
241 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b34, 0x80000009),
242 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3348, 0x022ddfff),
243 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x334c, 0x00000001),
244 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3358, 0x0001c000),
245 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3380, 0x3f8ddbff),
246 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3384, 0x0001c7e1),
247 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x338c, 0x0001c7e1),
248 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3398, 0x0001c000),
249 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33a8, 0x00181900),
250 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33dc, 0x00080000),
251 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33e0, 0x00000001),
252 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a20, 0x0000040c),
253 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a24, 0x01010101),
254 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a30, 0x01010101),
255 REG_PCI_RMW32(0xac, ~0x00200000, 0),
256 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x0410, 0x00000003),
257 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2618, 0x08000000),
258 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2300, 0x00000002),
259 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2600, 0x00000008),
260 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33b4, 0x00007001),
261 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3350, 0x022ddfff),
262 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3354, 0x00000001),
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700263 /* Power Optimizer */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700264 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33d4, 0x08000000),
Matt DeVillierc97e0422017-02-16 11:36:16 -0600265 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33c8, 0x00000080),
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700266 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b10, 0x0000883c),
267 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b14, 0x1e0a4616),
268 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b24, 0x40000005),
269 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b20, 0x0005db01),
270 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a80, 0x05145005),
271 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a84, 0x00001005),
272 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33d4, 0x2fff2fb1),
273 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33c8, 0x00008000),
274 REG_SCRIPT_END
275};
276
277static void pch_enable_mphy(void)
278{
279 u32 gpio71_native = gpio_is_native(71);
280 u32 data_and = 0xffffffff;
281 u32 data_or = (1 << 14) | (1 << 13) | (1 << 12);
282
283 if (gpio71_native) {
284 data_or |= (1 << 0);
285 if (pch_is_wpt()) {
286 data_and &= ~((1 << 7) | (1 << 6) | (1 << 3));
287 data_or |= (1 << 5) | (1 << 4);
288
289 if (pch_is_wpt_ulx()) {
290 /* Check if SATA and USB3 MPHY are enabled */
291 u32 strap19 = pch_read_soft_strap(19);
292 strap19 &= ((1 << 31) | (1 << 30));
293 strap19 >>= 30;
294 if (strap19 == 3) {
295 data_or |= (1 << 3);
296 printk(BIOS_DEBUG, "Enable ULX MPHY PG "
297 "control in single domain\n");
298 } else if (strap19 == 0) {
299 printk(BIOS_DEBUG, "Enable ULX MPHY PG "
300 "control in split domains\n");
301 } else {
302 printk(BIOS_DEBUG, "Invalid PCH Soft "
303 "Strap 19 configuration\n");
304 }
305 } else {
306 data_or |= (1 << 3);
307 }
308 }
309 }
310
311 pch_iobp_update(0xCF000000, data_and, data_or);
312}
313
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700314static void pch_init_deep_sx(struct device *dev)
315{
Kyösti Mälkki8950cfb2019-07-13 22:16:25 +0300316 config_t *config = config_of(dev);
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700317
318 if (config->deep_sx_enable_ac) {
319 RCBA32_OR(DEEP_S3_POL, DEEP_S3_EN_AC);
320 RCBA32_OR(DEEP_S5_POL, DEEP_S5_EN_AC);
321 }
322
323 if (config->deep_sx_enable_dc) {
324 RCBA32_OR(DEEP_S3_POL, DEEP_S3_EN_DC);
325 RCBA32_OR(DEEP_S5_POL, DEEP_S5_EN_DC);
326 }
327
328 if (config->deep_sx_enable_ac || config->deep_sx_enable_dc)
329 RCBA32_OR(DEEP_SX_CONFIG,
330 DEEP_SX_WAKE_PIN_EN | DEEP_SX_GP27_PIN_EN);
331}
332
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700333/* Power Management init */
334static void pch_pm_init(struct device *dev)
335{
336 printk(BIOS_DEBUG, "PCH PM init\n");
337
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700338 pch_init_deep_sx(dev);
339
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700340 pch_enable_mphy();
341
342 reg_script_run_on_dev(dev, pch_pm_init_script);
343
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700344 if (pch_is_wpt()) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700345 RCBA32_OR(0x33e0, (1 << 4) | (1 << 1));
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700346 RCBA32_OR(0x2b1c, (1 << 22) | (1 << 14) | (1 << 13));
347 RCBA32(0x33e4) = 0x16bf0002;
348 RCBA32_OR(0x33e4, 0x1);
349 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700350
351 pch_iobp_update(0xCA000000, ~0UL, 0x00000009);
352
353 /* Set RCBA 0x2b1c[29]=1 if DSP disabled */
354 if (RCBA32(FD) & PCH_DISABLE_ADSPD)
355 RCBA32_OR(0x2b1c, (1 << 29));
356
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700357}
358
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200359static void pch_cg_init(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700360{
361 u32 reg32;
362 u16 reg16;
Kyösti Mälkki71756c212019-07-12 13:10:19 +0300363 struct device *igd_dev = pcidev_path_on_root(SA_DEVFN_IGD);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700364
365 /* DMI */
366 RCBA32_OR(0x2234, 0xf);
367
368 reg16 = pci_read_config16(dev, GEN_PMCON_1);
369 reg16 &= ~(1 << 10); /* Disable BIOS_PCI_EXP_EN for native PME */
370 if (pch_is_wpt())
371 reg16 &= ~(1 << 11);
372 else
373 reg16 |= (1 << 11);
374 reg16 |= (1 << 5) | (1 << 6) | (1 << 7) | (1 << 12);
375 reg16 |= (1 << 2); // PCI CLKRUN# Enable
376 pci_write_config16(dev, GEN_PMCON_1, reg16);
377
378 /*
379 * RCBA + 0x2614[27:25,14:13,10,8] = 101,11,1,1
380 * RCBA + 0x2614[23:16] = 0x20
381 * RCBA + 0x2614[30:28] = 0x0
382 * RCBA + 0x2614[26] = 1 (IF 0:2.0@0x08 >= 0x0b)
383 */
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700384 RCBA32_AND_OR(0x2614, ~0x64ff0000, 0x0a206500);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700385
386 /* Check for 0:2.0@0x08 >= 0x0b */
Kyösti Mälkki71756c212019-07-12 13:10:19 +0300387 if (pch_is_wpt() || pci_read_config8(igd_dev, 0x8) >= 0x0b)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700388 RCBA32_OR(0x2614, (1 << 26));
389
390 RCBA32_OR(0x900, 0x0000031f);
391
392 reg32 = RCBA32(CG);
393 if (RCBA32(0x3454) & (1 << 4))
394 reg32 &= ~(1 << 29); // LPC Dynamic
395 else
396 reg32 |= (1 << 29); // LPC Dynamic
397 reg32 |= (1 << 31); // LP LPC
398 reg32 |= (1 << 30); // LP BLA
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700399 if (RCBA32(0x3454) & (1 << 4))
400 reg32 &= ~(1 << 29);
401 else
402 reg32 |= (1 << 29);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700403 reg32 |= (1 << 28); // GPIO Dynamic
404 reg32 |= (1 << 27); // HPET Dynamic
405 reg32 |= (1 << 26); // Generic Platform Event Clock
406 if (RCBA32(BUC) & PCH_DISABLE_GBE)
407 reg32 |= (1 << 23); // GbE Static
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700408 if (RCBA32(FD) & PCH_DISABLE_HD_AUDIO)
409 reg32 |= (1 << 21); // HDA Static
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700410 reg32 |= (1 << 22); // HDA Dynamic
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700411 RCBA32(CG) = reg32;
412
413 /* PCH-LP LPC */
414 if (pch_is_wpt())
415 RCBA32_AND_OR(0x3434, ~0x1f, 0x17);
416 else
417 RCBA32_OR(0x3434, 0x7);
418
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700419 /* SPI */
420 RCBA32_OR(0x38c0, 0x3c07);
421
422 pch_iobp_update(0xCE00C000, ~1UL, 0x00000000);
423}
424
425static void pch_set_acpi_mode(void)
426{
Kyösti Mälkkib4905622019-07-12 08:02:35 +0300427 if (CONFIG(HAVE_SMI_HANDLER) && !acpi_is_wakeup_s3()) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700428 printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n");
429 outb(APM_CNT_ACPI_DISABLE, APM_CNT);
430 printk(BIOS_DEBUG, "done.\n");
431 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700432}
433
434static void lpc_init(struct device *dev)
435{
436 /* Legacy initialization */
437 isa_dma_init();
Arthur Heymans2abbe462019-06-04 14:12:01 +0200438 sb_rtc_init();
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700439 reg_script_run_on_dev(dev, pch_misc_init_script);
440
441 /* Interrupt configuration */
442 pch_enable_ioapic(dev);
443 pch_pirq_init(dev);
444 setup_i8259();
445 i8259_configure_irq_trigger(9, 1);
Matt DeVillier81a6f102018-02-19 17:33:48 -0600446 enable_hpet(dev);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700447
448 /* Initialize power management */
449 pch_power_options(dev);
450 pch_pm_init(dev);
451 pch_cg_init(dev);
452
453 pch_set_acpi_mode();
454}
455
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200456static void pch_lpc_add_mmio_resources(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700457{
458 u32 reg;
459 struct resource *res;
460 const u32 default_decode_base = IO_APIC_ADDR;
461
462 /*
463 * Just report all resources from IO-APIC base to 4GiB. Don't mark
464 * them reserved as that may upset the OS if this range is marked
465 * as reserved in the e820.
466 */
467 res = new_resource(dev, OIC);
468 res->base = default_decode_base;
469 res->size = 0 - default_decode_base;
470 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
471
472 /* RCBA */
Lee Leahy6ef51922017-03-17 10:56:08 -0700473 if (default_decode_base > RCBA_BASE_ADDRESS) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700474 res = new_resource(dev, RCBA);
475 res->base = RCBA_BASE_ADDRESS;
476 res->size = 16 * 1024;
477 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
Lee Leahy26b7cd02017-03-16 18:47:55 -0700478 IORESOURCE_FIXED | IORESOURCE_RESERVE;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700479 }
480
481 /* Check LPC Memory Decode register. */
482 reg = pci_read_config32(dev, LGMR);
483 if (reg & 1) {
484 reg &= ~0xffff;
485 if (reg < default_decode_base) {
486 res = new_resource(dev, LGMR);
487 res->base = reg;
488 res->size = 16 * 1024;
489 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
Lee Leahy26b7cd02017-03-16 18:47:55 -0700490 IORESOURCE_FIXED | IORESOURCE_RESERVE;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700491 }
492 }
493}
494
495/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
496#define LPC_DEFAULT_IO_RANGE_LOWER 0
497#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
498
Julius Werner7c712bb2019-05-01 16:51:20 -0700499static inline int pch_io_range_in_default(int base, int size)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700500{
501 /* Does it start above the range? */
502 if (base >= LPC_DEFAULT_IO_RANGE_UPPER)
503 return 0;
504
505 /* Is it entirely contained? */
506 if (base >= LPC_DEFAULT_IO_RANGE_LOWER &&
507 (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
508 return 1;
509
510 /* This will return not in range for partial overlaps. */
511 return 0;
512}
513
514/*
515 * Note: this function assumes there is no overlap with the default LPC device's
516 * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
517 */
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200518static void pch_lpc_add_io_resource(struct device *dev, u16 base, u16 size,
519 int index)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700520{
521 struct resource *res;
522
523 if (pch_io_range_in_default(base, size))
524 return;
525
526 res = new_resource(dev, index);
527 res->base = base;
528 res->size = size;
529 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
530}
531
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200532static void pch_lpc_add_gen_io_resources(struct device *dev, int reg_value,
533 int index)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700534{
535 /*
536 * Check if the register is enabled. If so and the base exceeds the
Martin Rothde7ed6f2014-12-07 14:58:18 -0700537 * device's default claim range add the resource.
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700538 */
539 if (reg_value & 1) {
540 u16 base = reg_value & 0xfffc;
541 u16 size = (0x3 | ((reg_value >> 16) & 0xfc)) + 1;
542 pch_lpc_add_io_resource(dev, base, size, index);
543 }
544}
545
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200546static void pch_lpc_add_io_resources(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700547{
548 struct resource *res;
Kyösti Mälkki8950cfb2019-07-13 22:16:25 +0300549 config_t *config = config_of(dev);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700550
551 /* Add the default claimed IO range for the LPC device. */
552 res = new_resource(dev, 0);
553 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
554 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
555 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
556
557 /* GPIOBASE */
558 pch_lpc_add_io_resource(dev, GPIO_BASE_ADDRESS,
559 GPIO_BASE_SIZE, GPIO_BASE);
560
561 /* PMBASE */
562 pch_lpc_add_io_resource(dev, ACPI_BASE_ADDRESS, ACPI_BASE_SIZE, PMBASE);
563
564 /* LPC Generic IO Decode range. */
565 pch_lpc_add_gen_io_resources(dev, config->gen1_dec, LPC_GEN1_DEC);
566 pch_lpc_add_gen_io_resources(dev, config->gen2_dec, LPC_GEN2_DEC);
567 pch_lpc_add_gen_io_resources(dev, config->gen3_dec, LPC_GEN3_DEC);
568 pch_lpc_add_gen_io_resources(dev, config->gen4_dec, LPC_GEN4_DEC);
569}
570
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200571static void pch_lpc_read_resources(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700572{
573 global_nvs_t *gnvs;
574
575 /* Get the normal PCI resources of this device. */
576 pci_dev_read_resources(dev);
577
578 /* Add non-standard MMIO resources. */
579 pch_lpc_add_mmio_resources(dev);
580
581 /* Add IO resources. */
582 pch_lpc_add_io_resources(dev);
583
584 /* Allocate ACPI NVS in CBMEM */
585 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(global_nvs_t));
Kyösti Mälkki9e94dbf2015-01-08 20:03:18 +0200586 if (!acpi_is_wakeup_s3() && gnvs)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700587 memset(gnvs, 0, sizeof(global_nvs_t));
588}
589
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200590static void southcluster_inject_dsdt(struct device *device)
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100591{
592 global_nvs_t *gnvs;
593
594 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
595 if (!gnvs) {
Lee Leahy26b7cd02017-03-16 18:47:55 -0700596 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(*gnvs));
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100597 if (gnvs)
598 memset(gnvs, 0, sizeof(*gnvs));
599 }
600
601 if (gnvs) {
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100602 acpi_create_gnvs(gnvs);
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100603 /* And tell SMI about it */
604 smm_setup_structures(gnvs, NULL, NULL);
605
606 /* Add it to DSDT. */
607 acpigen_write_scope("\\");
608 acpigen_write_name_dword("NVSA", (u32) gnvs);
609 acpigen_pop_len();
610 }
611}
612
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200613static unsigned long broadwell_write_acpi_tables(struct device *device,
Duncan Laurie93bbd412017-11-11 20:03:29 -0800614 unsigned long current,
615 struct acpi_rsdp *rsdp)
616{
Julius Wernercd49cce2019-03-05 16:53:33 -0800617 if (CONFIG(INTEL_PCH_UART_CONSOLE))
Duncan Laurie93bbd412017-11-11 20:03:29 -0800618 current = acpi_write_dbg2_pci_uart(rsdp, current,
619 (CONFIG_INTEL_PCH_UART_CONSOLE_NUMBER == 1) ?
620 PCH_DEV_UART1 : PCH_DEV_UART0,
621 ACPI_ACCESS_SIZE_BYTE_ACCESS);
622 return acpi_write_hpet(device, current, rsdp);
623}
624
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700625static struct device_operations device_ops = {
626 .read_resources = &pch_lpc_read_resources,
627 .set_resources = &pci_dev_set_resources,
628 .enable_resources = &pci_dev_enable_resources,
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100629 .acpi_inject_dsdt_generator = southcluster_inject_dsdt,
Duncan Laurie93bbd412017-11-11 20:03:29 -0800630 .write_acpi_tables = broadwell_write_acpi_tables,
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700631 .init = &lpc_init,
Nico Huber51b75ae2019-03-14 16:02:05 +0100632 .scan_bus = &scan_static_bus,
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700633 .ops_pci = &broadwell_pci_ops,
634};
635
636static const unsigned short pci_device_ids[] = {
637 PCH_LPT_LP_SAMPLE,
638 PCH_LPT_LP_PREMIUM,
639 PCH_LPT_LP_MAINSTREAM,
640 PCH_LPT_LP_VALUE,
641 PCH_WPT_HSW_U_SAMPLE,
642 PCH_WPT_BDW_U_SAMPLE,
643 PCH_WPT_BDW_U_PREMIUM,
644 PCH_WPT_BDW_U_BASE,
645 PCH_WPT_BDW_Y_SAMPLE,
646 PCH_WPT_BDW_Y_PREMIUM,
647 PCH_WPT_BDW_Y_BASE,
648 PCH_WPT_BDW_H,
649 0
650};
651
652static const struct pci_driver pch_lpc __pci_driver = {
653 .ops = &device_ops,
654 .vendor = PCI_VENDOR_ID_INTEL,
655 .devices = pci_device_ids,
656};