blob: 8308f41618a894b5a8acac82aa23eb39174a1f46 [file] [log] [blame]
Aaron Durbin76c37002012-10-30 09:03:43 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
Duncan Laurie467f31d2013-03-08 17:00:37 -08005 * Copyright 2013 Google Inc.
Aaron Durbin76c37002012-10-30 09:03:43 -05006 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; version 2 of
10 * the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
Patrick Georgib890a122015-03-26 15:17:45 +010019 * Foundation, Inc.
Aaron Durbin76c37002012-10-30 09:03:43 -050020 */
21
22#include <console/console.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>
Aaron Durbin29ffa542012-12-21 21:21:48 -060033#include <cpu/x86/smm.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050034#include <elog.h>
Duncan Laurie9c07c8f2013-03-22 11:08:39 -070035#include <cbmem.h>
36#include <string.h>
37#include "nvs.h"
Aaron Durbin76c37002012-10-30 09:03:43 -050038#include "pch.h"
Vladimir Serbinenkoc6e566a2014-08-31 17:43:51 +020039#include <arch/acpigen.h>
40#include <cbmem.h>
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +010041#include <drivers/intel/gma/i915.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050042
43#define NMI_OFF 0
44
45#define ENABLE_ACPI_MODE_IN_COREBOOT 0
Aaron Durbin76c37002012-10-30 09:03:43 -050046
47typedef struct southbridge_intel_lynxpoint_config config_t;
48
Paul Menzel373a20c2013-05-03 12:17:02 +020049/**
50 * Set miscellanous static southbridge features.
51 *
52 * @param dev PCI device with I/O APIC control registers
53 */
54static void pch_enable_ioapic(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -050055{
Aaron Durbin76c37002012-10-30 09:03:43 -050056 u32 reg32;
Aaron Durbin76c37002012-10-30 09:03:43 -050057
Paul Menzel373a20c2013-05-03 12:17:02 +020058 /* Enable ACPI I/O range decode */
59 pci_write_config8(dev, ACPI_CNTL, ACPI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -050060
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080061 set_ioapic_id(VIO_APIC_VADDR, 0x02);
Aaron Durbin76c37002012-10-30 09:03:43 -050062
63 /* affirm full set of redirection table entries ("write once") */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080064 reg32 = io_apic_read(VIO_APIC_VADDR, 0x01);
Duncan Lauriec5939992013-05-24 11:06:49 -070065 if (pch_is_lp()) {
66 /* PCH-LP has 39 redirection entries */
67 reg32 &= ~0x00ff0000;
68 reg32 |= 0x00270000;
69 }
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080070 io_apic_write(VIO_APIC_VADDR, 0x01, reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -050071
Paul Menzel373a20c2013-05-03 12:17:02 +020072 /*
73 * Select Boot Configuration register (0x03) and
74 * use Processor System Bus (0x01) to deliver interrupts.
75 */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080076 io_apic_write(VIO_APIC_VADDR, 0x03, 0x01);
Aaron Durbin76c37002012-10-30 09:03:43 -050077}
78
79static void pch_enable_serial_irqs(struct device *dev)
80{
81 /* Set packet length and toggle silent mode bit for one frame. */
82 pci_write_config8(dev, SERIRQ_CNTL,
83 (1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0));
84#if !CONFIG_SERIRQ_CONTINUOUS_MODE
85 pci_write_config8(dev, SERIRQ_CNTL,
86 (1 << 7) | (0 << 6) | ((21 - 17) << 2) | (0 << 0));
87#endif
88}
89
90/* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control
91 * 0x00 - 0000 = Reserved
92 * 0x01 - 0001 = Reserved
93 * 0x02 - 0010 = Reserved
94 * 0x03 - 0011 = IRQ3
95 * 0x04 - 0100 = IRQ4
96 * 0x05 - 0101 = IRQ5
97 * 0x06 - 0110 = IRQ6
98 * 0x07 - 0111 = IRQ7
99 * 0x08 - 1000 = Reserved
100 * 0x09 - 1001 = IRQ9
101 * 0x0A - 1010 = IRQ10
102 * 0x0B - 1011 = IRQ11
103 * 0x0C - 1100 = IRQ12
104 * 0x0D - 1101 = Reserved
105 * 0x0E - 1110 = IRQ14
106 * 0x0F - 1111 = IRQ15
107 * PIRQ[n]_ROUT[7] - PIRQ Routing Control
108 * 0x80 - The PIRQ is not routed.
109 */
110
111static void pch_pirq_init(device_t dev)
112{
113 device_t irq_dev;
114 /* Get the chip configuration */
115 config_t *config = dev->chip_info;
116
117 pci_write_config8(dev, PIRQA_ROUT, config->pirqa_routing);
118 pci_write_config8(dev, PIRQB_ROUT, config->pirqb_routing);
119 pci_write_config8(dev, PIRQC_ROUT, config->pirqc_routing);
120 pci_write_config8(dev, PIRQD_ROUT, config->pirqd_routing);
121
122 pci_write_config8(dev, PIRQE_ROUT, config->pirqe_routing);
123 pci_write_config8(dev, PIRQF_ROUT, config->pirqf_routing);
124 pci_write_config8(dev, PIRQG_ROUT, config->pirqg_routing);
125 pci_write_config8(dev, PIRQH_ROUT, config->pirqh_routing);
126
127 /* Eric Biederman once said we should let the OS do this.
128 * I am not so sure anymore he was right.
129 */
130
131 for(irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
132 u8 int_pin=0, int_line=0;
133
134 if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI)
135 continue;
136
137 int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
138
139 switch (int_pin) {
140 case 1: /* INTA# */ int_line = config->pirqa_routing; break;
141 case 2: /* INTB# */ int_line = config->pirqb_routing; break;
142 case 3: /* INTC# */ int_line = config->pirqc_routing; break;
143 case 4: /* INTD# */ int_line = config->pirqd_routing; break;
144 }
145
146 if (!int_line)
147 continue;
148
149 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line);
150 }
151}
152
153static void pch_gpi_routing(device_t dev)
154{
155 /* Get the chip configuration */
156 config_t *config = dev->chip_info;
157 u32 reg32 = 0;
158
159 /* An array would be much nicer here, or some
160 * other method of doing this.
161 */
162 reg32 |= (config->gpi0_routing & 0x03) << 0;
163 reg32 |= (config->gpi1_routing & 0x03) << 2;
164 reg32 |= (config->gpi2_routing & 0x03) << 4;
165 reg32 |= (config->gpi3_routing & 0x03) << 6;
166 reg32 |= (config->gpi4_routing & 0x03) << 8;
167 reg32 |= (config->gpi5_routing & 0x03) << 10;
168 reg32 |= (config->gpi6_routing & 0x03) << 12;
169 reg32 |= (config->gpi7_routing & 0x03) << 14;
170 reg32 |= (config->gpi8_routing & 0x03) << 16;
171 reg32 |= (config->gpi9_routing & 0x03) << 18;
172 reg32 |= (config->gpi10_routing & 0x03) << 20;
173 reg32 |= (config->gpi11_routing & 0x03) << 22;
174 reg32 |= (config->gpi12_routing & 0x03) << 24;
175 reg32 |= (config->gpi13_routing & 0x03) << 26;
176 reg32 |= (config->gpi14_routing & 0x03) << 28;
177 reg32 |= (config->gpi15_routing & 0x03) << 30;
178
Kyösti Mälkkib85a87b2014-12-29 11:32:27 +0200179 pci_write_config32(dev, GPIO_ROUT, reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -0500180}
181
182static void pch_power_options(device_t dev)
183{
184 u8 reg8;
Duncan Laurie467f31d2013-03-08 17:00:37 -0800185 u16 reg16;
Aaron Durbin76c37002012-10-30 09:03:43 -0500186 u32 reg32;
187 const char *state;
188 /* Get the chip configuration */
189 config_t *config = dev->chip_info;
Duncan Laurie467f31d2013-03-08 17:00:37 -0800190 u16 pmbase = get_pmbase();
Aaron Durbin76c37002012-10-30 09:03:43 -0500191 int pwr_on=CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL;
192 int nmi_option;
193
194 /* Which state do we want to goto after g3 (power restored)?
195 * 0 == S0 Full On
196 * 1 == S5 Soft Off
197 *
198 * If the option is not existent (Laptops), use Kconfig setting.
199 */
200 get_option(&pwr_on, "power_on_after_fail");
Luigi Semenzato562db3b2014-01-13 17:45:54 -0800201 pwr_on = MAINBOARD_POWER_KEEP;
Aaron Durbin76c37002012-10-30 09:03:43 -0500202
203 reg16 = pci_read_config16(dev, GEN_PMCON_3);
204 reg16 &= 0xfffe;
205 switch (pwr_on) {
206 case MAINBOARD_POWER_OFF:
207 reg16 |= 1;
208 state = "off";
209 break;
210 case MAINBOARD_POWER_ON:
211 reg16 &= ~1;
212 state = "on";
213 break;
214 case MAINBOARD_POWER_KEEP:
215 reg16 &= ~1;
216 state = "state keep";
217 break;
218 default:
219 state = "undefined";
220 }
221
222 reg16 &= ~(3 << 4); /* SLP_S4# Assertion Stretch 4s */
223 reg16 |= (1 << 3); /* SLP_S4# Assertion Stretch Enable */
224
225 reg16 &= ~(1 << 10);
226 reg16 |= (1 << 11); /* SLP_S3# Min Assertion Width 50ms */
227
228 reg16 |= (1 << 12); /* Disable SLP stretch after SUS well */
229
230 pci_write_config16(dev, GEN_PMCON_3, reg16);
231 printk(BIOS_INFO, "Set power %s after power failure.\n", state);
232
233 /* Set up NMI on errors. */
234 reg8 = inb(0x61);
235 reg8 &= 0x0f; /* Higher Nibble must be 0 */
236 reg8 &= ~(1 << 3); /* IOCHK# NMI Enable */
237 // reg8 &= ~(1 << 2); /* PCI SERR# Enable */
238 reg8 |= (1 << 2); /* PCI SERR# Disable for now */
239 outb(reg8, 0x61);
240
241 reg8 = inb(0x70);
242 nmi_option = NMI_OFF;
243 get_option(&nmi_option, "nmi");
244 if (nmi_option) {
245 printk(BIOS_INFO, "NMI sources enabled.\n");
246 reg8 &= ~(1 << 7); /* Set NMI. */
247 } else {
248 printk(BIOS_INFO, "NMI sources disabled.\n");
249 reg8 |= ( 1 << 7); /* Can't mask NMI from PCI-E and NMI_NOW */
250 }
251 outb(reg8, 0x70);
252
253 /* Enable CPU_SLP# and Intel Speedstep, set SMI# rate down */
254 reg16 = pci_read_config16(dev, GEN_PMCON_1);
255 reg16 &= ~(3 << 0); // SMI# rate 1 minute
256 reg16 &= ~(1 << 10); // Disable BIOS_PCI_EXP_EN for native PME
Aaron Durbin76c37002012-10-30 09:03:43 -0500257 pci_write_config16(dev, GEN_PMCON_1, reg16);
258
Duncan Laurie467f31d2013-03-08 17:00:37 -0800259 /*
260 * Set the board's GPI routing on LynxPoint-H.
261 * This is done as part of GPIO configuration on LynxPoint-LP.
262 */
263 if (pch_is_lp())
264 pch_gpi_routing(dev);
Aaron Durbin76c37002012-10-30 09:03:43 -0500265
Duncan Laurie467f31d2013-03-08 17:00:37 -0800266 /* GPE setup based on device tree configuration */
267 enable_all_gpe(config->gpe0_en_1, config->gpe0_en_2,
268 config->gpe0_en_3, config->gpe0_en_4);
Aaron Durbin76c37002012-10-30 09:03:43 -0500269
Duncan Laurie467f31d2013-03-08 17:00:37 -0800270 /* SMI setup based on device tree configuration */
271 enable_alt_smi(config->alt_gp_smi_en);
Aaron Durbin76c37002012-10-30 09:03:43 -0500272
273 /* Set up power management block and determine sleep mode */
274 reg32 = inl(pmbase + 0x04); // PM1_CNT
275 reg32 &= ~(7 << 10); // SLP_TYP
276 reg32 |= (1 << 0); // SCI_EN
277 outl(reg32, pmbase + 0x04);
278
279 /* Clear magic status bits to prevent unexpected wake */
280 reg32 = RCBA32(0x3310);
281 reg32 |= (1 << 4)|(1 << 5)|(1 << 0);
282 RCBA32(0x3310) = reg32;
283
284 reg32 = RCBA32(0x3f02);
285 reg32 &= ~0xf;
286 RCBA32(0x3f02) = reg32;
287}
288
289static void pch_rtc_init(struct device *dev)
290{
291 u8 reg8;
292 int rtc_failed;
293
294 reg8 = pci_read_config8(dev, GEN_PMCON_3);
295 rtc_failed = reg8 & RTC_BATTERY_DEAD;
296 if (rtc_failed) {
297 reg8 &= ~RTC_BATTERY_DEAD;
298 pci_write_config8(dev, GEN_PMCON_3, reg8);
299#if CONFIG_ELOG
300 elog_add_event(ELOG_TYPE_RTC_RESET);
301#endif
302 }
303 printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed);
304
Gabe Blackb3f08c62014-04-30 17:12:25 -0700305 cmos_init(rtc_failed);
Aaron Durbin76c37002012-10-30 09:03:43 -0500306}
307
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800308/* LynxPoint PCH Power Management init */
309static void lpt_pm_init(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500310{
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800311 printk(BIOS_DEBUG, "LynxPoint PM init\n");
Aaron Durbin76c37002012-10-30 09:03:43 -0500312}
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800313
314const struct rcba_config_instruction lpt_lp_pm_rcba[] = {
Duncan Laurie4bc107b2013-06-24 13:14:44 -0700315 RCBA_RMW_REG_32(0x232c, ~1, 0x00000000),
316 RCBA_RMW_REG_32(0x1100, ~0xc000, 0xc000),
317 RCBA_RMW_REG_32(0x1100, ~0, 0x00000100),
318 RCBA_RMW_REG_32(0x1100, ~0, 0x0000003f),
319 RCBA_RMW_REG_32(0x2320, ~0x60, 0x10),
320 RCBA_RMW_REG_32(0x3314, 0, 0x00012fff),
321 RCBA_RMW_REG_32(0x3318, 0, 0x0dcf0400),
322 RCBA_RMW_REG_32(0x3324, 0, 0x04000000),
323 RCBA_RMW_REG_32(0x3368, 0, 0x00041400),
324 RCBA_RMW_REG_32(0x3388, 0, 0x3f8ddbff),
325 RCBA_RMW_REG_32(0x33ac, 0, 0x00007001),
326 RCBA_RMW_REG_32(0x33b0, 0, 0x00181900),
327 RCBA_RMW_REG_32(0x33c0, 0, 0x00060A00),
328 RCBA_RMW_REG_32(0x33d0, 0, 0x06200840),
329 RCBA_RMW_REG_32(0x3a28, 0, 0x01010101),
330 RCBA_RMW_REG_32(0x3a2c, 0, 0x04040404),
331 RCBA_RMW_REG_32(0x2b1c, 0, 0x03808033),
332 RCBA_RMW_REG_32(0x2b34, 0, 0x80000009),
333 RCBA_RMW_REG_32(0x3348, 0, 0x022ddfff),
334 RCBA_RMW_REG_32(0x334c, 0, 0x00000001),
335 RCBA_RMW_REG_32(0x3358, 0, 0x0001c000),
336 RCBA_RMW_REG_32(0x3380, 0, 0x3f8ddbff),
337 RCBA_RMW_REG_32(0x3384, 0, 0x0001c7e1),
338 RCBA_RMW_REG_32(0x338c, 0, 0x0001c7e1),
339 RCBA_RMW_REG_32(0x3398, 0, 0x0001c000),
340 RCBA_RMW_REG_32(0x33a8, 0, 0x00181900),
341 RCBA_RMW_REG_32(0x33dc, 0, 0x00080000),
342 RCBA_RMW_REG_32(0x33e0, 0, 0x00000001),
343 RCBA_RMW_REG_32(0x3a20, 0, 0x00000404),
344 RCBA_RMW_REG_32(0x3a24, 0, 0x01010101),
345 RCBA_RMW_REG_32(0x3a30, 0, 0x01010101),
346 RCBA_RMW_REG_32(0x0410, ~0, 0x00000003),
347 RCBA_RMW_REG_32(0x2618, ~0, 0x08000000),
348 RCBA_RMW_REG_32(0x2300, ~0, 0x00000002),
349 RCBA_RMW_REG_32(0x2600, ~0, 0x00000008),
350 RCBA_RMW_REG_32(0x33b4, 0, 0x00007001),
351 RCBA_RMW_REG_32(0x3350, 0, 0x022ddfff),
352 RCBA_RMW_REG_32(0x3354, 0, 0x00000001),
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800353 RCBA_RMW_REG_32(0x33d4, ~0, 0x08000000), /* Power Optimizer */
354 RCBA_RMW_REG_32(0x33c8, ~0, 0x08000080), /* Power Optimizer */
355 RCBA_RMW_REG_32(0x2b10, 0, 0x0000883c), /* Power Optimizer */
Duncan Laurie5cf34ce2013-04-26 10:41:33 -0700356 RCBA_RMW_REG_32(0x2b14, 0, 0x1e0a4616), /* Power Optimizer */
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800357 RCBA_RMW_REG_32(0x2b24, 0, 0x40000005), /* Power Optimizer */
358 RCBA_RMW_REG_32(0x2b20, 0, 0x0005db01), /* Power Optimizer */
Duncan Laurie4bc107b2013-06-24 13:14:44 -0700359 RCBA_RMW_REG_32(0x3a80, 0, 0x05145005),
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800360 RCBA_END_CONFIG
361};
362
363/* LynxPoint LP PCH Power Management init */
364static void lpt_lp_pm_init(struct device *dev)
365{
366 struct southbridge_intel_lynxpoint_config *config = dev->chip_info;
367 u32 data;
368
369 printk(BIOS_DEBUG, "LynxPoint LP PM init\n");
370
371 pci_write_config8(dev, 0xa9, 0x46);
372
373 pch_config_rcba(lpt_lp_pm_rcba);
374
375 pci_write_config32(dev, 0xac,
376 pci_read_config32(dev, 0xac) | (1 << 21));
377
Duncan Laurie4bc107b2013-06-24 13:14:44 -0700378 pch_iobp_update(0xED00015C, ~(1<<11), 0x00003700);
379 pch_iobp_update(0xED000118, ~0UL, 0x00c00000);
380 pch_iobp_update(0xED000120, ~0UL, 0x00240000);
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800381 pch_iobp_update(0xCA000000, ~0UL, 0x00000009);
382
383 /* Set RCBA CIR28 0x3A84 based on SATA port enables */
384 data = 0x00001005;
385 /* Port 3 and 2 disabled */
386 if ((config->sata_port_map & ((1 << 3)|(1 << 2))) == 0)
387 data |= (1 << 24) | (1 << 26);
388 /* Port 1 and 0 disabled */
389 if ((config->sata_port_map & ((1 << 1)|(1 << 0))) == 0)
390 data |= (1 << 20) | (1 << 18);
391 RCBA32(0x3a84) = data;
392
Duncan Laurie5cf34ce2013-04-26 10:41:33 -0700393 /* Set RCBA 0x2b1c[29]=1 if DSP disabled */
394 if (RCBA32(FD) & PCH_DISABLE_ADSPD)
395 RCBA32_OR(0x2b1c, (1 << 29));
396
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800397 /* Lock */
398 RCBA32_OR(0x3a6c, 0x00000001);
399
400 /* Set RCBA 0x33D4 after other setup */
401 RCBA32_OR(0x33d4, 0x2fff2fb1);
402
403 /* Set RCBA 0x33C8[15]=1 as last step */
404 RCBA32_OR(0x33c8, (1 << 15));
405}
Aaron Durbin76c37002012-10-30 09:03:43 -0500406
407static void enable_hpet(void)
408{
409 u32 reg32;
410
411 /* Move HPET to default address 0xfed00000 and enable it */
412 reg32 = RCBA32(HPTC);
413 reg32 |= (1 << 7); // HPET Address Enable
414 reg32 &= ~(3 << 0);
415 RCBA32(HPTC) = reg32;
416 /* Read it back to stick. It's affected by posted write syndrome. */
417 reg32 = RCBA32(HPTC);
418}
419
420static void enable_clock_gating(device_t dev)
421{
Duncan Laurie74c0d052012-12-17 11:31:40 -0800422 /* LynxPoint Mobile */
423 u32 reg32;
424 u16 reg16;
425
426 /* DMI */
427 RCBA32_AND_OR(0x2234, ~0UL, 0xf);
428 reg16 = pci_read_config16(dev, GEN_PMCON_1);
429 reg16 |= (1 << 11) | (1 << 12) | (1 << 14);
430 reg16 |= (1 << 2); // PCI CLKRUN# Enable
431 pci_write_config16(dev, GEN_PMCON_1, reg16);
432 RCBA32_OR(0x900, (1 << 14));
433
434 reg32 = RCBA32(CG);
435 reg32 |= (1 << 22); // HDA Dynamic
436 reg32 |= (1 << 31); // LPC Dynamic
437 reg32 |= (1 << 16); // PCIe Dynamic
438 reg32 |= (1 << 27); // HPET Dynamic
439 reg32 |= (1 << 28); // GPIO Dynamic
440 RCBA32(CG) = reg32;
441
442 RCBA32_OR(0x38c0, 0x7); // SPI Dynamic
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800443}
444
445static void enable_lp_clock_gating(device_t dev)
446{
447 /* LynxPoint LP */
448 u32 reg32;
449 u16 reg16;
450
451 /* DMI */
452 RCBA32_AND_OR(0x2234, ~0UL, 0xf);
453 reg16 = pci_read_config16(dev, GEN_PMCON_1);
454 reg16 &= ~((1 << 11) | (1 << 14));
455 reg16 |= (1 << 5) | (1 << 6) | (1 << 7) | (1 << 12) | (1 << 13);
456 reg16 |= (1 << 2); // PCI CLKRUN# Enable
457 pci_write_config16(dev, GEN_PMCON_1, reg16);
458
459 reg32 = pci_read_config32(dev, 0x64);
460 reg32 |= (1 << 6);
461 pci_write_config32(dev, 0x64, reg32);
462
Duncan Laurie4bc107b2013-06-24 13:14:44 -0700463 /*
464 * RCBA + 0x2614[27:25,14:13,10,8] = 101,11,1,1
465 * RCBA + 0x2614[23:16] = 0x20
466 * RCBA + 0x2614[30:28] = 0x0
Duncan Lauried8c7d732013-07-16 09:01:43 -0700467 * RCBA + 0x2614[26] = 1 (IF 0:2.0@0x08 >= 0x0b)
Duncan Laurie4bc107b2013-06-24 13:14:44 -0700468 */
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800469 RCBA32_AND_OR(0x2614, 0x8bffffff, 0x0a206500);
Duncan Laurie4bc107b2013-06-24 13:14:44 -0700470
471 /* Check for LPT-LP B2 stepping and 0:31.0@0xFA > 4 */
Duncan Lauried8c7d732013-07-16 09:01:43 -0700472 if (pci_read_config8(dev_find_slot(0, PCI_DEVFN(2, 0)), 0x8) >= 0x0b)
Duncan Laurie4bc107b2013-06-24 13:14:44 -0700473 RCBA32_OR(0x2614, (1<<26));
474
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800475 RCBA32_OR(0x900, 0x0000031f);
476
477 reg32 = RCBA32(CG);
Duncan Lauriea2d6a402013-03-22 11:24:45 -0700478 if (RCBA32(0x3454) & (1 << 4))
479 reg32 &= ~(1 << 29); // LPC Dynamic
480 else
481 reg32 |= (1 << 29); // LPC Dynamic
Duncan Laurie5cf34ce2013-04-26 10:41:33 -0700482 reg32 |= (1 << 31); // LP LPC
483 reg32 |= (1 << 30); // LP BLA
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800484 reg32 |= (1 << 28); // GPIO Dynamic
485 reg32 |= (1 << 27); // HPET Dynamic
Duncan Laurie5cf34ce2013-04-26 10:41:33 -0700486 reg32 |= (1 << 26); // Generic Platform Event Clock
487 if (RCBA32(BUC) & PCH_DISABLE_GBE)
488 reg32 |= (1 << 23); // GbE Static
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800489 reg32 |= (1 << 22); // HDA Dynamic
Duncan Laurie5cf34ce2013-04-26 10:41:33 -0700490 reg32 |= (1 << 16); // PCI Dynamic
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800491 RCBA32(CG) = reg32;
492
493 RCBA32_OR(0x3434, 0x7); // LP LPC
494
495 RCBA32_AND_OR(0x333c, 0xffcfffff, 0x00c00000); // SATA
496
497 RCBA32_OR(0x38c0, 0x3c07); // SPI Dynamic
498
499 pch_iobp_update(0xCF000000, ~0UL, 0x00007001);
Duncan Laurie5cf34ce2013-04-26 10:41:33 -0700500 pch_iobp_update(0xCE00C000, ~1UL, 0x00000000); // bit0=0 in BWG 1.4.0
Aaron Durbin76c37002012-10-30 09:03:43 -0500501}
502
Aaron Durbin29ffa542012-12-21 21:21:48 -0600503static void pch_set_acpi_mode(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500504{
Aaron Durbin29ffa542012-12-21 21:21:48 -0600505#if CONFIG_HAVE_SMI_HANDLER
Kyösti Mälkkic3ed8862014-06-19 19:50:51 +0300506 if (!acpi_is_wakeup_s3()) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500507#if ENABLE_ACPI_MODE_IN_COREBOOT
508 printk(BIOS_DEBUG, "Enabling ACPI via APMC:\n");
Aaron Durbin29ffa542012-12-21 21:21:48 -0600509 outb(APM_CNT_ACPI_ENABLE, APM_CNT);
Aaron Durbin76c37002012-10-30 09:03:43 -0500510 printk(BIOS_DEBUG, "done.\n");
511#else
512 printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n");
Aaron Durbin29ffa542012-12-21 21:21:48 -0600513 outb(APM_CNT_ACPI_DISABLE, APM_CNT);
Aaron Durbin76c37002012-10-30 09:03:43 -0500514 printk(BIOS_DEBUG, "done.\n");
515#endif
516 }
Aaron Durbin29ffa542012-12-21 21:21:48 -0600517#endif /* CONFIG_HAVE_SMI_HANDLER */
Aaron Durbin76c37002012-10-30 09:03:43 -0500518}
Aaron Durbin76c37002012-10-30 09:03:43 -0500519
520static void pch_disable_smm_only_flashing(struct device *dev)
521{
522 u8 reg8;
523
524 printk(BIOS_SPEW, "Enabling BIOS updates outside of SMM... ");
525 reg8 = pci_read_config8(dev, 0xdc); /* BIOS_CNTL */
526 reg8 &= ~(1 << 5);
527 pci_write_config8(dev, 0xdc, reg8);
528}
529
530static void pch_fixups(struct device *dev)
531{
532 u8 gen_pmcon_2;
533
534 /* Indicate DRAM init done for MRC S3 to know it can resume */
535 gen_pmcon_2 = pci_read_config8(dev, GEN_PMCON_2);
536 gen_pmcon_2 |= (1 << 7);
537 pci_write_config8(dev, GEN_PMCON_2, gen_pmcon_2);
538
539 /*
540 * Enable DMI ASPM in the PCH
541 */
542 RCBA32_AND_OR(0x2304, ~(1 << 10), 0);
543 RCBA32_OR(0x21a4, (1 << 11)|(1 << 10));
544 RCBA32_OR(0x21a8, 0x3);
545}
546
Aaron Durbin76c37002012-10-30 09:03:43 -0500547static void lpc_init(struct device *dev)
548{
549 printk(BIOS_DEBUG, "pch: lpc_init\n");
550
551 /* Set the value for PCI command register. */
552 pci_write_config16(dev, PCI_COMMAND, 0x000f);
553
554 /* IO APIC initialization. */
Paul Menzel373a20c2013-05-03 12:17:02 +0200555 pch_enable_ioapic(dev);
Aaron Durbin76c37002012-10-30 09:03:43 -0500556
557 pch_enable_serial_irqs(dev);
558
559 /* Setup the PIRQ. */
560 pch_pirq_init(dev);
561
562 /* Setup power options. */
563 pch_power_options(dev);
564
565 /* Initialize power management */
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800566 if (pch_is_lp()) {
567 lpt_lp_pm_init(dev);
568 enable_lp_clock_gating(dev);
569 } else {
570 lpt_pm_init(dev);
571 enable_clock_gating(dev);
Aaron Durbin76c37002012-10-30 09:03:43 -0500572 }
573
Aaron Durbin76c37002012-10-30 09:03:43 -0500574 /* Initialize the real time clock. */
575 pch_rtc_init(dev);
576
577 /* Initialize ISA DMA. */
578 isa_dma_init();
579
580 /* Initialize the High Precision Event Timers, if present. */
581 enable_hpet();
582
Aaron Durbin76c37002012-10-30 09:03:43 -0500583 setup_i8259();
584
Aaron Durbin76c37002012-10-30 09:03:43 -0500585 /* Interrupt 9 should be level triggered (SCI) */
586 i8259_configure_irq_trigger(9, 1);
587
588 pch_disable_smm_only_flashing(dev);
589
Aaron Durbin29ffa542012-12-21 21:21:48 -0600590 pch_set_acpi_mode();
Aaron Durbin76c37002012-10-30 09:03:43 -0500591
592 pch_fixups(dev);
593}
594
Aaron Durbin6f561af2012-12-19 14:38:01 -0600595static void pch_lpc_add_mmio_resources(device_t dev)
596{
597 u32 reg;
598 struct resource *res;
599 const u32 default_decode_base = IO_APIC_ADDR;
600
601 /*
602 * Just report all resources from IO-APIC base to 4GiB. Don't mark
603 * them reserved as that may upset the OS if this range is marked
604 * as reserved in the e820.
605 */
606 res = new_resource(dev, OIC);
607 res->base = default_decode_base;
608 res->size = 0 - default_decode_base;
609 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
610
611 /* RCBA */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800612 if ((uintptr_t)DEFAULT_RCBA < default_decode_base) {
Aaron Durbin6f561af2012-12-19 14:38:01 -0600613 res = new_resource(dev, RCBA);
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800614 res->base = (resource_t)(uintptr_t)DEFAULT_RCBA;
Aaron Durbin6f561af2012-12-19 14:38:01 -0600615 res->size = 16 * 1024;
616 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
617 IORESOURCE_FIXED | IORESOURCE_RESERVE;
618 }
619
620 /* Check LPC Memory Decode register. */
621 reg = pci_read_config32(dev, LGMR);
622 if (reg & 1) {
623 reg &= ~0xffff;
624 if (reg < default_decode_base) {
625 res = new_resource(dev, LGMR);
626 res->base = reg;
627 res->size = 16 * 1024;
628 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
629 IORESOURCE_FIXED | IORESOURCE_RESERVE;
630 }
631 }
632}
633
634/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
635#define LPC_DEFAULT_IO_RANGE_LOWER 0
636#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
637
638static inline int pch_io_range_in_default(u16 base, u16 size)
639{
640 /* Does it start above the range? */
641 if (base >= LPC_DEFAULT_IO_RANGE_UPPER)
642 return 0;
643
644 /* Is it entirely contained? */
645 if (base >= LPC_DEFAULT_IO_RANGE_LOWER &&
646 (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
647 return 1;
648
649 /* This will return not in range for partial overlaps. */
650 return 0;
651}
652
653/*
654 * Note: this function assumes there is no overlap with the default LPC device's
655 * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
656 */
657static void pch_lpc_add_io_resource(device_t dev, u16 base, u16 size, int index)
658{
659 struct resource *res;
660
661 if (pch_io_range_in_default(base, size))
662 return;
663
664 res = new_resource(dev, index);
665 res->base = base;
666 res->size = size;
667 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
668}
669
670static void pch_lpc_add_gen_io_resources(device_t dev, int reg_value, int index)
671{
672 /*
673 * Check if the register is enabled. If so and the base exceeds the
674 * device's deafult claim range add the resoure.
675 */
676 if (reg_value & 1) {
677 u16 base = reg_value & 0xfffc;
678 u16 size = (0x3 | ((reg_value >> 16) & 0xfc)) + 1;
679 pch_lpc_add_io_resource(dev, base, size, index);
680 }
681}
682
683static void pch_lpc_add_io_resources(device_t dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500684{
685 struct resource *res;
686 config_t *config = dev->chip_info;
Aaron Durbin76c37002012-10-30 09:03:43 -0500687
Aaron Durbin6f561af2012-12-19 14:38:01 -0600688 /* Add the default claimed IO range for the LPC device. */
689 res = new_resource(dev, 0);
690 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
691 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
692 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
693
694 /* GPIOBASE */
Duncan Laurie7922b462013-03-08 16:34:33 -0800695 pch_lpc_add_io_resource(dev, get_gpiobase(), DEFAULT_GPIOSIZE,
Aaron Durbin6f561af2012-12-19 14:38:01 -0600696 GPIO_BASE);
697
698 /* PMBASE */
Duncan Laurie7922b462013-03-08 16:34:33 -0800699 pch_lpc_add_io_resource(dev, get_pmbase(), 256, PMBASE);
Aaron Durbin6f561af2012-12-19 14:38:01 -0600700
701 /* LPC Generic IO Decode range. */
702 pch_lpc_add_gen_io_resources(dev, config->gen1_dec, LPC_GEN1_DEC);
703 pch_lpc_add_gen_io_resources(dev, config->gen2_dec, LPC_GEN2_DEC);
704 pch_lpc_add_gen_io_resources(dev, config->gen3_dec, LPC_GEN3_DEC);
705 pch_lpc_add_gen_io_resources(dev, config->gen4_dec, LPC_GEN4_DEC);
706}
707
708static void pch_lpc_read_resources(device_t dev)
709{
Duncan Laurie9c07c8f2013-03-22 11:08:39 -0700710 global_nvs_t *gnvs;
711
Aaron Durbin76c37002012-10-30 09:03:43 -0500712 /* Get the normal PCI resources of this device. */
713 pci_dev_read_resources(dev);
714
Aaron Durbin6f561af2012-12-19 14:38:01 -0600715 /* Add non-standard MMIO resources. */
716 pch_lpc_add_mmio_resources(dev);
Aaron Durbin76c37002012-10-30 09:03:43 -0500717
Aaron Durbin6f561af2012-12-19 14:38:01 -0600718 /* Add IO resources. */
719 pch_lpc_add_io_resources(dev);
Duncan Laurie9c07c8f2013-03-22 11:08:39 -0700720
721 /* Allocate ACPI NVS in CBMEM */
722 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(global_nvs_t));
Kyösti Mälkkic3ed8862014-06-19 19:50:51 +0300723 if (!acpi_is_wakeup_s3() && gnvs)
Duncan Laurie9c07c8f2013-03-22 11:08:39 -0700724 memset(gnvs, 0, sizeof(global_nvs_t));
Aaron Durbin76c37002012-10-30 09:03:43 -0500725}
726
Aaron Durbin76c37002012-10-30 09:03:43 -0500727static void pch_lpc_enable(device_t dev)
728{
729 /* Enable PCH Display Port */
730 RCBA16(DISPBDF) = 0x0010;
731 RCBA32_OR(FD2, PCH_ENABLE_DBDF);
732
733 pch_enable(dev);
734}
735
736static void set_subsystem(device_t dev, unsigned vendor, unsigned device)
737{
738 if (!vendor || !device) {
739 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
740 pci_read_config32(dev, PCI_VENDOR_ID));
741 } else {
742 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
743 ((device & 0xffff) << 16) | (vendor & 0xffff));
744 }
745}
746
Alexander Couzensa90dad12015-04-12 21:49:46 +0200747static void southbridge_inject_dsdt(device_t dev)
Vladimir Serbinenkoc6e566a2014-08-31 17:43:51 +0200748{
Vladimir Serbinenko7309c642014-10-05 11:07:33 +0200749 global_nvs_t *gnvs;
750
751 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
752 if (!gnvs) {
753 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof (*gnvs));
754 if (gnvs)
755 memset(gnvs, 0, sizeof(*gnvs));
756 }
Vladimir Serbinenkoc6e566a2014-08-31 17:43:51 +0200757
758 if (gnvs) {
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100759 const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info();
760
Vladimir Serbinenkoc6e566a2014-08-31 17:43:51 +0200761 acpi_create_gnvs(gnvs);
Vladimir Serbinenko1b409fd2014-10-12 00:26:21 +0200762
763 gnvs->apic = 1;
764 gnvs->mpen = 1; /* Enable Multi Processing */
765 gnvs->pcnt = dev_count_cpu();
766
767#if CONFIG_CHROMEOS
768 chromeos_init_vboot(&(gnvs->chromeos));
769#endif
770
771 /* Update the mem console pointer. */
772 gnvs->cbmc = (u32)cbmem_find(CBMEM_ID_CONSOLE);
773
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100774 gnvs->ndid = gfx->ndid;
775 memcpy(gnvs->did, gfx->did, sizeof(gnvs->did));
776
Vladimir Serbinenkoc6e566a2014-08-31 17:43:51 +0200777 acpi_save_gnvs((unsigned long)gnvs);
778 /* And tell SMI about it */
779 smm_setup_structures(gnvs, NULL, NULL);
780
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +0200781 /* Add it to DSDT. */
Vladimir Serbinenkobe0fd0a2014-11-04 21:10:59 +0100782 acpigen_write_scope("\\");
783 acpigen_write_name_dword("NVSA", (u32) gnvs);
784 acpigen_pop_len();
Vladimir Serbinenkoc6e566a2014-08-31 17:43:51 +0200785 }
Vladimir Serbinenkoc6e566a2014-08-31 17:43:51 +0200786}
787
788#define ALIGN_CURRENT current = (ALIGN(current, 16))
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200789static unsigned long southbridge_write_acpi_tables(device_t device,
790 unsigned long start,
791 struct acpi_rsdp *rsdp)
Vladimir Serbinenkoc6e566a2014-08-31 17:43:51 +0200792{
793 unsigned long current;
794 acpi_hpet_t *hpet;
795 acpi_header_t *ssdt;
796
797 current = start;
798
799 /* Align ACPI tables to 16byte */
800 ALIGN_CURRENT;
801
802 /*
803 * We explicitly add these tables later on:
804 */
805 printk(BIOS_DEBUG, "ACPI: * HPET\n");
806
807 hpet = (acpi_hpet_t *) current;
808 current += sizeof(acpi_hpet_t);
809 ALIGN_CURRENT;
810 acpi_create_intel_hpet(hpet);
811 acpi_add_table(rsdp, hpet);
812
813 ALIGN_CURRENT;
814
815 printk(BIOS_DEBUG, "ACPI: * SSDT2\n");
816 ssdt = (acpi_header_t *)current;
817 acpi_create_serialio_ssdt(ssdt);
818 current += ssdt->length;
819 acpi_add_table(rsdp, ssdt);
820 ALIGN_CURRENT;
821
822 printk(BIOS_DEBUG, "current = %lx\n", current);
823 return current;
824}
825
826
Aaron Durbin76c37002012-10-30 09:03:43 -0500827static struct pci_operations pci_ops = {
828 .set_subsystem = set_subsystem,
829};
830
831static struct device_operations device_ops = {
832 .read_resources = pch_lpc_read_resources,
833 .set_resources = pci_dev_set_resources,
Duncan Laurie8d783b82013-05-14 11:16:34 -0700834 .enable_resources = pci_dev_enable_resources,
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +0200835 .acpi_inject_dsdt_generator = southbridge_inject_dsdt,
Vladimir Serbinenkoc6e566a2014-08-31 17:43:51 +0200836 .write_acpi_tables = southbridge_write_acpi_tables,
Aaron Durbin76c37002012-10-30 09:03:43 -0500837 .init = lpc_init,
838 .enable = pch_lpc_enable,
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200839 .scan_bus = scan_lpc_bus,
Aaron Durbin76c37002012-10-30 09:03:43 -0500840 .ops_pci = &pci_ops,
841};
842
843
Aaron Durbinc1989c42012-12-11 17:13:17 -0600844/* IDs for LPC device of Intel 8 Series Chipset (Lynx Point) */
845static const unsigned short pci_device_ids[] = {
846 0x8c41, /* Mobile Full Featured Engineering Sample. */
847 0x8c42, /* Desktop Full Featured Engineering Sample. */
848 0x8c44, /* Z87 SKU */
849 0x8c46, /* Z85 SKU */
850 0x8c49, /* HM86 SKU */
851 0x8c4a, /* H87 SKU */
852 0x8c4b, /* HM87 SKU */
853 0x8c4c, /* Q85 SKU */
854 0x8c4e, /* Q87 SKU */
855 0x8c4f, /* QM87 SKU */
Duncan Laurie74c0d052012-12-17 11:31:40 -0800856 0x9c41, /* LP Full Featured Engineering Sample */
857 0x9c43, /* LP Premium SKU */
858 0x9c45, /* LP Mainstream SKU */
859 0x9c47, /* LP Value SKU */
Aaron Durbinc1989c42012-12-11 17:13:17 -0600860 0 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500861
862static const struct pci_driver pch_lpc __pci_driver = {
863 .ops = &device_ops,
864 .vendor = PCI_VENDOR_ID_INTEL,
865 .devices = pci_device_ids,
866};