blob: b84129108654ce87314719767f3b294dc276c381 [file] [log] [blame]
Angel Ponsf94ac9a2020-04-05 15:46:48 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Duncan Lauriec88c54c2014-04-30 16:36:13 -07002
3#include <console/console.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -07004#include <device/device.h>
5#include <device/pci.h>
6#include <device/pci_ids.h>
Kyösti Mälkkicbf95712020-01-05 08:05:45 +02007#include <option.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -07008#include <pc80/isa-dma.h>
9#include <pc80/i8259.h>
10#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020011#include <device/pci_ops.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070012#include <arch/ioapic.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -070013#include <acpi/acpi.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070014#include <cpu/x86/smm.h>
15#include <cbmem.h>
16#include <reg_script.h>
17#include <string.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070018#include <soc/gpio.h>
19#include <soc/iobp.h>
20#include <soc/iomap.h>
21#include <soc/lpc.h>
22#include <soc/nvs.h>
23#include <soc/pch.h>
24#include <soc/pci_devs.h>
25#include <soc/pm.h>
26#include <soc/ramstage.h>
27#include <soc/rcba.h>
28#include <soc/intel/broadwell/chip.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -070029#include <acpi/acpigen.h>
Arthur Heymans2abbe462019-06-04 14:12:01 +020030#include <southbridge/intel/common/rtc.h>
Duncan Laurie35dc00f2015-01-18 14:06:42 -080031
Duncan Lauriec88c54c2014-04-30 16:36:13 -070032static void pch_enable_ioapic(struct device *dev)
33{
34 u32 reg32;
35
Matt DeVillier81a6f102018-02-19 17:33:48 -060036 /* Assign unique bus/dev/fn for I/O APIC */
37 pci_write_config16(dev, LPC_IBDF,
38 PCH_IOAPIC_PCI_BUS << 8 | PCH_IOAPIC_PCI_SLOT << 3);
39
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080040 set_ioapic_id(VIO_APIC_VADDR, 0x02);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070041
42 /* affirm full set of redirection table entries ("write once") */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080043 reg32 = io_apic_read(VIO_APIC_VADDR, 0x01);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070044
45 /* PCH-LP has 39 redirection entries */
46 reg32 &= ~0x00ff0000;
47 reg32 |= 0x00270000;
48
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080049 io_apic_write(VIO_APIC_VADDR, 0x01, reg32);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070050
51 /*
52 * Select Boot Configuration register (0x03) and
53 * use Processor System Bus (0x01) to deliver interrupts.
54 */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080055 io_apic_write(VIO_APIC_VADDR, 0x03, 0x01);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070056}
57
Matt DeVillier81a6f102018-02-19 17:33:48 -060058static void enable_hpet(struct device *dev)
59{
60 size_t i;
61
62 /* Assign unique bus/dev/fn for each HPET */
63 for (i = 0; i < 8; ++i)
64 pci_write_config16(dev, LPC_HnBDF(i),
65 PCH_HPET_PCI_BUS << 8 | PCH_HPET_PCI_SLOT << 3 | i);
66}
67
Duncan Lauriec88c54c2014-04-30 16:36:13 -070068/* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control
69 * 0x00 - 0000 = Reserved
70 * 0x01 - 0001 = Reserved
71 * 0x02 - 0010 = Reserved
72 * 0x03 - 0011 = IRQ3
73 * 0x04 - 0100 = IRQ4
74 * 0x05 - 0101 = IRQ5
75 * 0x06 - 0110 = IRQ6
76 * 0x07 - 0111 = IRQ7
77 * 0x08 - 1000 = Reserved
78 * 0x09 - 1001 = IRQ9
79 * 0x0A - 1010 = IRQ10
80 * 0x0B - 1011 = IRQ11
81 * 0x0C - 1100 = IRQ12
82 * 0x0D - 1101 = Reserved
83 * 0x0E - 1110 = IRQ14
84 * 0x0F - 1111 = IRQ15
85 * PIRQ[n]_ROUT[7] - PIRQ Routing Control
86 * 0x80 - The PIRQ is not routed.
87 */
88
Elyes HAOUAS040aff22018-05-27 16:30:36 +020089static void pch_pirq_init(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -070090{
Elyes HAOUAS040aff22018-05-27 16:30:36 +020091 struct device *irq_dev;
Kyösti Mälkki8950cfb2019-07-13 22:16:25 +030092 config_t *config = config_of(dev);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070093
94 pci_write_config8(dev, PIRQA_ROUT, config->pirqa_routing);
95 pci_write_config8(dev, PIRQB_ROUT, config->pirqb_routing);
96 pci_write_config8(dev, PIRQC_ROUT, config->pirqc_routing);
97 pci_write_config8(dev, PIRQD_ROUT, config->pirqd_routing);
98
99 pci_write_config8(dev, PIRQE_ROUT, config->pirqe_routing);
100 pci_write_config8(dev, PIRQF_ROUT, config->pirqf_routing);
101 pci_write_config8(dev, PIRQG_ROUT, config->pirqg_routing);
102 pci_write_config8(dev, PIRQH_ROUT, config->pirqh_routing);
103
Elyes HAOUAS4a83f1c2016-08-25 21:07:59 +0200104 for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
Lee Leahy26b7cd02017-03-16 18:47:55 -0700105 u8 int_pin = 0, int_line = 0;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700106
107 if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI)
108 continue;
109
110 int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
111
112 switch (int_pin) {
Lee Leahy8a9c7dc2017-03-17 10:43:25 -0700113 case 1: /* INTA# */
114 int_line = config->pirqa_routing;
115 break;
116 case 2: /* INTB# */
117 int_line = config->pirqb_routing;
118 break;
119 case 3: /* INTC# */
120 int_line = config->pirqc_routing;
121 break;
122 case 4: /* INTD# */
123 int_line = config->pirqd_routing;
124 break;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700125 }
126
127 if (!int_line)
128 continue;
129
130 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line);
131 }
132}
133
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200134static void pch_power_options(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700135{
136 u16 reg16;
137 const char *state;
138 /* Get the chip configuration */
Kyösti Mälkki8950cfb2019-07-13 22:16:25 +0300139 config_t *config = config_of(dev);
Nico Huber9faae2b2018-11-14 00:00:35 +0100140 int pwr_on = CONFIG_MAINBOARD_POWER_FAILURE_STATE;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700141
142 /* Which state do we want to goto after g3 (power restored)?
143 * 0 == S0 Full On
144 * 1 == S5 Soft Off
145 *
146 * If the option is not existent (Laptops), use Kconfig setting.
147 */
148 get_option(&pwr_on, "power_on_after_fail");
149
150 reg16 = pci_read_config16(dev, GEN_PMCON_3);
151 reg16 &= 0xfffe;
152 switch (pwr_on) {
153 case MAINBOARD_POWER_OFF:
154 reg16 |= 1;
155 state = "off";
156 break;
157 case MAINBOARD_POWER_ON:
158 reg16 &= ~1;
159 state = "on";
160 break;
161 case MAINBOARD_POWER_KEEP:
162 reg16 &= ~1;
163 state = "state keep";
164 break;
165 default:
166 state = "undefined";
167 }
168 pci_write_config16(dev, GEN_PMCON_3, reg16);
169 printk(BIOS_INFO, "Set power %s after power failure.\n", state);
170
171 /* GPE setup based on device tree configuration */
172 enable_all_gpe(config->gpe0_en_1, config->gpe0_en_2,
173 config->gpe0_en_3, config->gpe0_en_4);
174
175 /* SMI setup based on device tree configuration */
176 enable_alt_smi(config->alt_gp_smi_en);
177}
178
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700179static const struct reg_script pch_misc_init_script[] = {
180 /* Setup SLP signal assertion, SLP_S4=4s, SLP_S3=50ms */
181 REG_PCI_RMW16(GEN_PMCON_3, ~((3 << 4)|(1 << 10)),
182 (1 << 3)|(1 << 11)|(1 << 12)),
183 /* Prepare sleep mode */
184 REG_IO_RMW32(ACPI_BASE_ADDRESS + PM1_CNT, ~SLP_TYP, SCI_EN),
185 /* Setup NMI on errors, disable SERR */
186 REG_IO_RMW8(0x61, ~0xf0, (1 << 2)),
187 /* Disable NMI sources */
188 REG_IO_OR8(0x70, (1 << 7)),
189 /* Indicate DRAM init done for MRC */
190 REG_PCI_OR8(GEN_PMCON_2, (1 << 7)),
191 /* Enable BIOS updates outside of SMM */
192 REG_PCI_RMW8(0xdc, ~(1 << 5), 0),
193 /* Clear status bits to prevent unexpected wake */
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700194 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x3310, 0x0000002f),
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700195 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x3f02, ~0x0000000f, 0),
Kenji Chen074a0282014-09-20 01:39:20 +0800196 /* Enable PCIe Releaxed Order */
197 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2314, (1 << 31) | (1 << 7)),
198 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x1114, (1 << 15) | (1 << 14)),
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700199 /* Setup SERIRQ, enable continuous mode */
200 REG_PCI_OR8(SERIRQ_CNTL, (1 << 7) | (1 << 6)),
Julius Wernercd49cce2019-03-05 16:53:33 -0800201#if !CONFIG(SERIRQ_CONTINUOUS_MODE)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700202 REG_PCI_RMW8(SERIRQ_CNTL, ~(1 << 6), 0),
203#endif
204 REG_SCRIPT_END
205};
206
207/* Magic register settings for power management */
208static const struct reg_script pch_pm_init_script[] = {
209 REG_PCI_WRITE8(0xa9, 0x46),
210 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x232c, ~1, 0),
211 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x1100, 0x0000c13f),
212 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x2320, ~0x60, 0x10),
213 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3314, 0x00012fff),
214 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x3318, ~0x000f0330, 0x0dcf0400),
215 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3324, 0x04000000),
216 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3368, 0x00041400),
217 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3388, 0x3f8ddbff),
218 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33ac, 0x00007001),
219 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33b0, 0x00181900),
220 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33c0, 0x00060A00),
221 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33d0, 0x06200840),
222 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a28, 0x01010101),
223 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a2c, 0x040c0404),
224 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a9c, 0x9000000a),
225 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b1c, 0x03808033),
226 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b34, 0x80000009),
227 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3348, 0x022ddfff),
228 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x334c, 0x00000001),
229 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3358, 0x0001c000),
230 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3380, 0x3f8ddbff),
231 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3384, 0x0001c7e1),
232 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x338c, 0x0001c7e1),
233 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3398, 0x0001c000),
234 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33a8, 0x00181900),
235 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33dc, 0x00080000),
236 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33e0, 0x00000001),
237 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a20, 0x0000040c),
238 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a24, 0x01010101),
239 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a30, 0x01010101),
240 REG_PCI_RMW32(0xac, ~0x00200000, 0),
241 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x0410, 0x00000003),
242 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2618, 0x08000000),
243 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2300, 0x00000002),
244 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2600, 0x00000008),
245 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33b4, 0x00007001),
246 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3350, 0x022ddfff),
247 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3354, 0x00000001),
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700248 /* Power Optimizer */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700249 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33d4, 0x08000000),
Matt DeVillierc97e0422017-02-16 11:36:16 -0600250 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33c8, 0x00000080),
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700251 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b10, 0x0000883c),
252 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b14, 0x1e0a4616),
253 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b24, 0x40000005),
254 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b20, 0x0005db01),
255 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a80, 0x05145005),
256 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a84, 0x00001005),
257 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33d4, 0x2fff2fb1),
258 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33c8, 0x00008000),
259 REG_SCRIPT_END
260};
261
262static void pch_enable_mphy(void)
263{
264 u32 gpio71_native = gpio_is_native(71);
265 u32 data_and = 0xffffffff;
266 u32 data_or = (1 << 14) | (1 << 13) | (1 << 12);
267
268 if (gpio71_native) {
269 data_or |= (1 << 0);
270 if (pch_is_wpt()) {
271 data_and &= ~((1 << 7) | (1 << 6) | (1 << 3));
272 data_or |= (1 << 5) | (1 << 4);
273
274 if (pch_is_wpt_ulx()) {
275 /* Check if SATA and USB3 MPHY are enabled */
276 u32 strap19 = pch_read_soft_strap(19);
277 strap19 &= ((1 << 31) | (1 << 30));
278 strap19 >>= 30;
279 if (strap19 == 3) {
280 data_or |= (1 << 3);
281 printk(BIOS_DEBUG, "Enable ULX MPHY PG "
282 "control in single domain\n");
283 } else if (strap19 == 0) {
284 printk(BIOS_DEBUG, "Enable ULX MPHY PG "
285 "control in split domains\n");
286 } else {
287 printk(BIOS_DEBUG, "Invalid PCH Soft "
288 "Strap 19 configuration\n");
289 }
290 } else {
291 data_or |= (1 << 3);
292 }
293 }
294 }
295
296 pch_iobp_update(0xCF000000, data_and, data_or);
297}
298
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700299static void pch_init_deep_sx(struct device *dev)
300{
Kyösti Mälkki8950cfb2019-07-13 22:16:25 +0300301 config_t *config = config_of(dev);
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700302
303 if (config->deep_sx_enable_ac) {
304 RCBA32_OR(DEEP_S3_POL, DEEP_S3_EN_AC);
305 RCBA32_OR(DEEP_S5_POL, DEEP_S5_EN_AC);
306 }
307
308 if (config->deep_sx_enable_dc) {
309 RCBA32_OR(DEEP_S3_POL, DEEP_S3_EN_DC);
310 RCBA32_OR(DEEP_S5_POL, DEEP_S5_EN_DC);
311 }
312
313 if (config->deep_sx_enable_ac || config->deep_sx_enable_dc)
314 RCBA32_OR(DEEP_SX_CONFIG,
315 DEEP_SX_WAKE_PIN_EN | DEEP_SX_GP27_PIN_EN);
316}
317
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700318/* Power Management init */
319static void pch_pm_init(struct device *dev)
320{
321 printk(BIOS_DEBUG, "PCH PM init\n");
322
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700323 pch_init_deep_sx(dev);
324
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700325 pch_enable_mphy();
326
327 reg_script_run_on_dev(dev, pch_pm_init_script);
328
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700329 if (pch_is_wpt()) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700330 RCBA32_OR(0x33e0, (1 << 4) | (1 << 1));
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700331 RCBA32_OR(0x2b1c, (1 << 22) | (1 << 14) | (1 << 13));
332 RCBA32(0x33e4) = 0x16bf0002;
333 RCBA32_OR(0x33e4, 0x1);
334 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700335
336 pch_iobp_update(0xCA000000, ~0UL, 0x00000009);
337
338 /* Set RCBA 0x2b1c[29]=1 if DSP disabled */
339 if (RCBA32(FD) & PCH_DISABLE_ADSPD)
340 RCBA32_OR(0x2b1c, (1 << 29));
341
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700342}
343
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200344static void pch_cg_init(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700345{
346 u32 reg32;
347 u16 reg16;
Kyösti Mälkki71756c212019-07-12 13:10:19 +0300348 struct device *igd_dev = pcidev_path_on_root(SA_DEVFN_IGD);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700349
350 /* DMI */
351 RCBA32_OR(0x2234, 0xf);
352
353 reg16 = pci_read_config16(dev, GEN_PMCON_1);
354 reg16 &= ~(1 << 10); /* Disable BIOS_PCI_EXP_EN for native PME */
355 if (pch_is_wpt())
356 reg16 &= ~(1 << 11);
357 else
358 reg16 |= (1 << 11);
359 reg16 |= (1 << 5) | (1 << 6) | (1 << 7) | (1 << 12);
360 reg16 |= (1 << 2); // PCI CLKRUN# Enable
361 pci_write_config16(dev, GEN_PMCON_1, reg16);
362
363 /*
364 * RCBA + 0x2614[27:25,14:13,10,8] = 101,11,1,1
365 * RCBA + 0x2614[23:16] = 0x20
366 * RCBA + 0x2614[30:28] = 0x0
367 * RCBA + 0x2614[26] = 1 (IF 0:2.0@0x08 >= 0x0b)
368 */
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700369 RCBA32_AND_OR(0x2614, ~0x64ff0000, 0x0a206500);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700370
371 /* Check for 0:2.0@0x08 >= 0x0b */
Kyösti Mälkki71756c212019-07-12 13:10:19 +0300372 if (pch_is_wpt() || pci_read_config8(igd_dev, 0x8) >= 0x0b)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700373 RCBA32_OR(0x2614, (1 << 26));
374
375 RCBA32_OR(0x900, 0x0000031f);
376
377 reg32 = RCBA32(CG);
378 if (RCBA32(0x3454) & (1 << 4))
379 reg32 &= ~(1 << 29); // LPC Dynamic
380 else
381 reg32 |= (1 << 29); // LPC Dynamic
382 reg32 |= (1 << 31); // LP LPC
383 reg32 |= (1 << 30); // LP BLA
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700384 if (RCBA32(0x3454) & (1 << 4))
385 reg32 &= ~(1 << 29);
386 else
387 reg32 |= (1 << 29);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700388 reg32 |= (1 << 28); // GPIO Dynamic
389 reg32 |= (1 << 27); // HPET Dynamic
390 reg32 |= (1 << 26); // Generic Platform Event Clock
391 if (RCBA32(BUC) & PCH_DISABLE_GBE)
392 reg32 |= (1 << 23); // GbE Static
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700393 if (RCBA32(FD) & PCH_DISABLE_HD_AUDIO)
394 reg32 |= (1 << 21); // HDA Static
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700395 reg32 |= (1 << 22); // HDA Dynamic
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700396 RCBA32(CG) = reg32;
397
398 /* PCH-LP LPC */
399 if (pch_is_wpt())
400 RCBA32_AND_OR(0x3434, ~0x1f, 0x17);
401 else
402 RCBA32_OR(0x3434, 0x7);
403
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700404 /* SPI */
405 RCBA32_OR(0x38c0, 0x3c07);
406
407 pch_iobp_update(0xCE00C000, ~1UL, 0x00000000);
408}
409
410static void pch_set_acpi_mode(void)
411{
Kyösti Mälkkiad882c32020-06-02 05:05:30 +0300412 if (!acpi_is_wakeup_s3()) {
Kyösti Mälkkib6585482020-06-01 15:11:14 +0300413 apm_control(APM_CNT_ACPI_DISABLE);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700414 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700415}
416
417static void lpc_init(struct device *dev)
418{
419 /* Legacy initialization */
420 isa_dma_init();
Arthur Heymans2abbe462019-06-04 14:12:01 +0200421 sb_rtc_init();
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700422 reg_script_run_on_dev(dev, pch_misc_init_script);
423
424 /* Interrupt configuration */
425 pch_enable_ioapic(dev);
426 pch_pirq_init(dev);
427 setup_i8259();
428 i8259_configure_irq_trigger(9, 1);
Matt DeVillier81a6f102018-02-19 17:33:48 -0600429 enable_hpet(dev);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700430
431 /* Initialize power management */
432 pch_power_options(dev);
433 pch_pm_init(dev);
434 pch_cg_init(dev);
435
436 pch_set_acpi_mode();
437}
438
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200439static void pch_lpc_add_mmio_resources(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700440{
441 u32 reg;
442 struct resource *res;
443 const u32 default_decode_base = IO_APIC_ADDR;
444
445 /*
446 * Just report all resources from IO-APIC base to 4GiB. Don't mark
447 * them reserved as that may upset the OS if this range is marked
448 * as reserved in the e820.
449 */
450 res = new_resource(dev, OIC);
451 res->base = default_decode_base;
452 res->size = 0 - default_decode_base;
453 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
454
455 /* RCBA */
Lee Leahy6ef51922017-03-17 10:56:08 -0700456 if (default_decode_base > RCBA_BASE_ADDRESS) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700457 res = new_resource(dev, RCBA);
458 res->base = RCBA_BASE_ADDRESS;
459 res->size = 16 * 1024;
460 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
Lee Leahy26b7cd02017-03-16 18:47:55 -0700461 IORESOURCE_FIXED | IORESOURCE_RESERVE;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700462 }
463
464 /* Check LPC Memory Decode register. */
465 reg = pci_read_config32(dev, LGMR);
466 if (reg & 1) {
467 reg &= ~0xffff;
468 if (reg < default_decode_base) {
469 res = new_resource(dev, LGMR);
470 res->base = reg;
471 res->size = 16 * 1024;
472 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
Lee Leahy26b7cd02017-03-16 18:47:55 -0700473 IORESOURCE_FIXED | IORESOURCE_RESERVE;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700474 }
475 }
476}
477
478/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
479#define LPC_DEFAULT_IO_RANGE_LOWER 0
480#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
481
Julius Werner7c712bb2019-05-01 16:51:20 -0700482static inline int pch_io_range_in_default(int base, int size)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700483{
484 /* Does it start above the range? */
485 if (base >= LPC_DEFAULT_IO_RANGE_UPPER)
486 return 0;
487
488 /* Is it entirely contained? */
489 if (base >= LPC_DEFAULT_IO_RANGE_LOWER &&
490 (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
491 return 1;
492
493 /* This will return not in range for partial overlaps. */
494 return 0;
495}
496
497/*
498 * Note: this function assumes there is no overlap with the default LPC device's
499 * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
500 */
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200501static void pch_lpc_add_io_resource(struct device *dev, u16 base, u16 size,
502 int index)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700503{
504 struct resource *res;
505
506 if (pch_io_range_in_default(base, size))
507 return;
508
509 res = new_resource(dev, index);
510 res->base = base;
511 res->size = size;
512 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
513}
514
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200515static void pch_lpc_add_gen_io_resources(struct device *dev, int reg_value,
516 int index)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700517{
518 /*
519 * Check if the register is enabled. If so and the base exceeds the
Martin Rothde7ed6f2014-12-07 14:58:18 -0700520 * device's default claim range add the resource.
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700521 */
522 if (reg_value & 1) {
523 u16 base = reg_value & 0xfffc;
524 u16 size = (0x3 | ((reg_value >> 16) & 0xfc)) + 1;
525 pch_lpc_add_io_resource(dev, base, size, index);
526 }
527}
528
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200529static void pch_lpc_add_io_resources(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700530{
531 struct resource *res;
Kyösti Mälkki8950cfb2019-07-13 22:16:25 +0300532 config_t *config = config_of(dev);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700533
534 /* Add the default claimed IO range for the LPC device. */
535 res = new_resource(dev, 0);
536 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
537 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
538 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
539
540 /* GPIOBASE */
541 pch_lpc_add_io_resource(dev, GPIO_BASE_ADDRESS,
542 GPIO_BASE_SIZE, GPIO_BASE);
543
544 /* PMBASE */
545 pch_lpc_add_io_resource(dev, ACPI_BASE_ADDRESS, ACPI_BASE_SIZE, PMBASE);
546
547 /* LPC Generic IO Decode range. */
548 pch_lpc_add_gen_io_resources(dev, config->gen1_dec, LPC_GEN1_DEC);
549 pch_lpc_add_gen_io_resources(dev, config->gen2_dec, LPC_GEN2_DEC);
550 pch_lpc_add_gen_io_resources(dev, config->gen3_dec, LPC_GEN3_DEC);
551 pch_lpc_add_gen_io_resources(dev, config->gen4_dec, LPC_GEN4_DEC);
552}
553
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200554static void pch_lpc_read_resources(struct device *dev)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700555{
556 global_nvs_t *gnvs;
557
558 /* Get the normal PCI resources of this device. */
559 pci_dev_read_resources(dev);
560
561 /* Add non-standard MMIO resources. */
562 pch_lpc_add_mmio_resources(dev);
563
564 /* Add IO resources. */
565 pch_lpc_add_io_resources(dev);
566
567 /* Allocate ACPI NVS in CBMEM */
568 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(global_nvs_t));
Kyösti Mälkki9e94dbf2015-01-08 20:03:18 +0200569 if (!acpi_is_wakeup_s3() && gnvs)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700570 memset(gnvs, 0, sizeof(global_nvs_t));
571}
572
Furquan Shaikh338fd9a2020-04-24 22:57:05 -0700573static void southcluster_inject_dsdt(const struct device *device)
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100574{
575 global_nvs_t *gnvs;
576
577 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
578 if (!gnvs) {
Lee Leahy26b7cd02017-03-16 18:47:55 -0700579 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(*gnvs));
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100580 if (gnvs)
581 memset(gnvs, 0, sizeof(*gnvs));
582 }
583
584 if (gnvs) {
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100585 acpi_create_gnvs(gnvs);
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100586 /* And tell SMI about it */
587 smm_setup_structures(gnvs, NULL, NULL);
588
589 /* Add it to DSDT. */
590 acpigen_write_scope("\\");
591 acpigen_write_name_dword("NVSA", (u32) gnvs);
592 acpigen_pop_len();
593 }
594}
595
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700596static unsigned long broadwell_write_acpi_tables(const struct device *device,
Duncan Laurie93bbd412017-11-11 20:03:29 -0800597 unsigned long current,
598 struct acpi_rsdp *rsdp)
599{
Julius Wernercd49cce2019-03-05 16:53:33 -0800600 if (CONFIG(INTEL_PCH_UART_CONSOLE))
Duncan Laurie93bbd412017-11-11 20:03:29 -0800601 current = acpi_write_dbg2_pci_uart(rsdp, current,
602 (CONFIG_INTEL_PCH_UART_CONSOLE_NUMBER == 1) ?
603 PCH_DEV_UART1 : PCH_DEV_UART0,
604 ACPI_ACCESS_SIZE_BYTE_ACCESS);
605 return acpi_write_hpet(device, current, rsdp);
606}
607
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700608static struct device_operations device_ops = {
609 .read_resources = &pch_lpc_read_resources,
610 .set_resources = &pci_dev_set_resources,
611 .enable_resources = &pci_dev_enable_resources,
Nico Huber68680dd2020-03-31 17:34:52 +0200612 .acpi_inject_dsdt = southcluster_inject_dsdt,
Duncan Laurie93bbd412017-11-11 20:03:29 -0800613 .write_acpi_tables = broadwell_write_acpi_tables,
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700614 .init = &lpc_init,
Nico Huber51b75ae2019-03-14 16:02:05 +0100615 .scan_bus = &scan_static_bus,
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700616 .ops_pci = &broadwell_pci_ops,
617};
618
619static const unsigned short pci_device_ids[] = {
620 PCH_LPT_LP_SAMPLE,
621 PCH_LPT_LP_PREMIUM,
622 PCH_LPT_LP_MAINSTREAM,
623 PCH_LPT_LP_VALUE,
624 PCH_WPT_HSW_U_SAMPLE,
625 PCH_WPT_BDW_U_SAMPLE,
626 PCH_WPT_BDW_U_PREMIUM,
627 PCH_WPT_BDW_U_BASE,
628 PCH_WPT_BDW_Y_SAMPLE,
629 PCH_WPT_BDW_Y_PREMIUM,
630 PCH_WPT_BDW_Y_BASE,
631 PCH_WPT_BDW_H,
632 0
633};
634
635static const struct pci_driver pch_lpc __pci_driver = {
636 .ops = &device_ops,
637 .vendor = PCI_VENDOR_ID_INTEL,
638 .devices = pci_device_ids,
639};