blob: d1a720304159d0d2f53421329de363b1790f5337 [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
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
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>
Aaron Durbin76c37002012-10-30 09:03:43 -050041
42#define NMI_OFF 0
43
44#define ENABLE_ACPI_MODE_IN_COREBOOT 0
Aaron Durbin76c37002012-10-30 09:03:43 -050045
46typedef struct southbridge_intel_lynxpoint_config config_t;
47
Paul Menzel373a20c2013-05-03 12:17:02 +020048/**
49 * Set miscellanous static southbridge features.
50 *
51 * @param dev PCI device with I/O APIC control registers
52 */
53static void pch_enable_ioapic(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -050054{
Aaron Durbin76c37002012-10-30 09:03:43 -050055 u32 reg32;
Aaron Durbin76c37002012-10-30 09:03:43 -050056
Paul Menzel373a20c2013-05-03 12:17:02 +020057 /* Enable ACPI I/O range decode */
58 pci_write_config8(dev, ACPI_CNTL, ACPI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -050059
Paul Menzel373a20c2013-05-03 12:17:02 +020060 set_ioapic_id(IO_APIC_ADDR, 0x02);
Aaron Durbin76c37002012-10-30 09:03:43 -050061
62 /* affirm full set of redirection table entries ("write once") */
Paul Menzel373a20c2013-05-03 12:17:02 +020063 reg32 = io_apic_read(IO_APIC_ADDR, 0x01);
Duncan Lauriec5939992013-05-24 11:06:49 -070064 if (pch_is_lp()) {
65 /* PCH-LP has 39 redirection entries */
66 reg32 &= ~0x00ff0000;
67 reg32 |= 0x00270000;
68 }
Paul Menzel373a20c2013-05-03 12:17:02 +020069 io_apic_write(IO_APIC_ADDR, 0x01, reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -050070
Paul Menzel373a20c2013-05-03 12:17:02 +020071 /*
72 * Select Boot Configuration register (0x03) and
73 * use Processor System Bus (0x01) to deliver interrupts.
74 */
75 io_apic_write(IO_APIC_ADDR, 0x03, 0x01);
Aaron Durbin76c37002012-10-30 09:03:43 -050076}
77
78static void pch_enable_serial_irqs(struct device *dev)
79{
80 /* Set packet length and toggle silent mode bit for one frame. */
81 pci_write_config8(dev, SERIRQ_CNTL,
82 (1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0));
83#if !CONFIG_SERIRQ_CONTINUOUS_MODE
84 pci_write_config8(dev, SERIRQ_CNTL,
85 (1 << 7) | (0 << 6) | ((21 - 17) << 2) | (0 << 0));
86#endif
87}
88
89/* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control
90 * 0x00 - 0000 = Reserved
91 * 0x01 - 0001 = Reserved
92 * 0x02 - 0010 = Reserved
93 * 0x03 - 0011 = IRQ3
94 * 0x04 - 0100 = IRQ4
95 * 0x05 - 0101 = IRQ5
96 * 0x06 - 0110 = IRQ6
97 * 0x07 - 0111 = IRQ7
98 * 0x08 - 1000 = Reserved
99 * 0x09 - 1001 = IRQ9
100 * 0x0A - 1010 = IRQ10
101 * 0x0B - 1011 = IRQ11
102 * 0x0C - 1100 = IRQ12
103 * 0x0D - 1101 = Reserved
104 * 0x0E - 1110 = IRQ14
105 * 0x0F - 1111 = IRQ15
106 * PIRQ[n]_ROUT[7] - PIRQ Routing Control
107 * 0x80 - The PIRQ is not routed.
108 */
109
110static void pch_pirq_init(device_t dev)
111{
112 device_t irq_dev;
113 /* Get the chip configuration */
114 config_t *config = dev->chip_info;
115
116 pci_write_config8(dev, PIRQA_ROUT, config->pirqa_routing);
117 pci_write_config8(dev, PIRQB_ROUT, config->pirqb_routing);
118 pci_write_config8(dev, PIRQC_ROUT, config->pirqc_routing);
119 pci_write_config8(dev, PIRQD_ROUT, config->pirqd_routing);
120
121 pci_write_config8(dev, PIRQE_ROUT, config->pirqe_routing);
122 pci_write_config8(dev, PIRQF_ROUT, config->pirqf_routing);
123 pci_write_config8(dev, PIRQG_ROUT, config->pirqg_routing);
124 pci_write_config8(dev, PIRQH_ROUT, config->pirqh_routing);
125
126 /* Eric Biederman once said we should let the OS do this.
127 * I am not so sure anymore he was right.
128 */
129
130 for(irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
131 u8 int_pin=0, int_line=0;
132
133 if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI)
134 continue;
135
136 int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
137
138 switch (int_pin) {
139 case 1: /* INTA# */ int_line = config->pirqa_routing; break;
140 case 2: /* INTB# */ int_line = config->pirqb_routing; break;
141 case 3: /* INTC# */ int_line = config->pirqc_routing; break;
142 case 4: /* INTD# */ int_line = config->pirqd_routing; break;
143 }
144
145 if (!int_line)
146 continue;
147
148 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line);
149 }
150}
151
152static void pch_gpi_routing(device_t dev)
153{
154 /* Get the chip configuration */
155 config_t *config = dev->chip_info;
156 u32 reg32 = 0;
157
158 /* An array would be much nicer here, or some
159 * other method of doing this.
160 */
161 reg32 |= (config->gpi0_routing & 0x03) << 0;
162 reg32 |= (config->gpi1_routing & 0x03) << 2;
163 reg32 |= (config->gpi2_routing & 0x03) << 4;
164 reg32 |= (config->gpi3_routing & 0x03) << 6;
165 reg32 |= (config->gpi4_routing & 0x03) << 8;
166 reg32 |= (config->gpi5_routing & 0x03) << 10;
167 reg32 |= (config->gpi6_routing & 0x03) << 12;
168 reg32 |= (config->gpi7_routing & 0x03) << 14;
169 reg32 |= (config->gpi8_routing & 0x03) << 16;
170 reg32 |= (config->gpi9_routing & 0x03) << 18;
171 reg32 |= (config->gpi10_routing & 0x03) << 20;
172 reg32 |= (config->gpi11_routing & 0x03) << 22;
173 reg32 |= (config->gpi12_routing & 0x03) << 24;
174 reg32 |= (config->gpi13_routing & 0x03) << 26;
175 reg32 |= (config->gpi14_routing & 0x03) << 28;
176 reg32 |= (config->gpi15_routing & 0x03) << 30;
177
178 pci_write_config32(dev, 0xb8, reg32);
179}
180
181static void pch_power_options(device_t dev)
182{
183 u8 reg8;
Duncan Laurie467f31d2013-03-08 17:00:37 -0800184 u16 reg16;
Aaron Durbin76c37002012-10-30 09:03:43 -0500185 u32 reg32;
186 const char *state;
187 /* Get the chip configuration */
188 config_t *config = dev->chip_info;
Duncan Laurie467f31d2013-03-08 17:00:37 -0800189 u16 pmbase = get_pmbase();
Aaron Durbin76c37002012-10-30 09:03:43 -0500190 int pwr_on=CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL;
191 int nmi_option;
192
193 /* Which state do we want to goto after g3 (power restored)?
194 * 0 == S0 Full On
195 * 1 == S5 Soft Off
196 *
197 * If the option is not existent (Laptops), use Kconfig setting.
198 */
199 get_option(&pwr_on, "power_on_after_fail");
Luigi Semenzato562db3b2014-01-13 17:45:54 -0800200 pwr_on = MAINBOARD_POWER_KEEP;
Aaron Durbin76c37002012-10-30 09:03:43 -0500201
202 reg16 = pci_read_config16(dev, GEN_PMCON_3);
203 reg16 &= 0xfffe;
204 switch (pwr_on) {
205 case MAINBOARD_POWER_OFF:
206 reg16 |= 1;
207 state = "off";
208 break;
209 case MAINBOARD_POWER_ON:
210 reg16 &= ~1;
211 state = "on";
212 break;
213 case MAINBOARD_POWER_KEEP:
214 reg16 &= ~1;
215 state = "state keep";
216 break;
217 default:
218 state = "undefined";
219 }
220
221 reg16 &= ~(3 << 4); /* SLP_S4# Assertion Stretch 4s */
222 reg16 |= (1 << 3); /* SLP_S4# Assertion Stretch Enable */
223
224 reg16 &= ~(1 << 10);
225 reg16 |= (1 << 11); /* SLP_S3# Min Assertion Width 50ms */
226
227 reg16 |= (1 << 12); /* Disable SLP stretch after SUS well */
228
229 pci_write_config16(dev, GEN_PMCON_3, reg16);
230 printk(BIOS_INFO, "Set power %s after power failure.\n", state);
231
232 /* Set up NMI on errors. */
233 reg8 = inb(0x61);
234 reg8 &= 0x0f; /* Higher Nibble must be 0 */
235 reg8 &= ~(1 << 3); /* IOCHK# NMI Enable */
236 // reg8 &= ~(1 << 2); /* PCI SERR# Enable */
237 reg8 |= (1 << 2); /* PCI SERR# Disable for now */
238 outb(reg8, 0x61);
239
240 reg8 = inb(0x70);
241 nmi_option = NMI_OFF;
242 get_option(&nmi_option, "nmi");
243 if (nmi_option) {
244 printk(BIOS_INFO, "NMI sources enabled.\n");
245 reg8 &= ~(1 << 7); /* Set NMI. */
246 } else {
247 printk(BIOS_INFO, "NMI sources disabled.\n");
248 reg8 |= ( 1 << 7); /* Can't mask NMI from PCI-E and NMI_NOW */
249 }
250 outb(reg8, 0x70);
251
252 /* Enable CPU_SLP# and Intel Speedstep, set SMI# rate down */
253 reg16 = pci_read_config16(dev, GEN_PMCON_1);
254 reg16 &= ~(3 << 0); // SMI# rate 1 minute
255 reg16 &= ~(1 << 10); // Disable BIOS_PCI_EXP_EN for native PME
Aaron Durbin76c37002012-10-30 09:03:43 -0500256 pci_write_config16(dev, GEN_PMCON_1, reg16);
257
Duncan Laurie467f31d2013-03-08 17:00:37 -0800258 /*
259 * Set the board's GPI routing on LynxPoint-H.
260 * This is done as part of GPIO configuration on LynxPoint-LP.
261 */
262 if (pch_is_lp())
263 pch_gpi_routing(dev);
Aaron Durbin76c37002012-10-30 09:03:43 -0500264
Duncan Laurie467f31d2013-03-08 17:00:37 -0800265 /* GPE setup based on device tree configuration */
266 enable_all_gpe(config->gpe0_en_1, config->gpe0_en_2,
267 config->gpe0_en_3, config->gpe0_en_4);
Aaron Durbin76c37002012-10-30 09:03:43 -0500268
Duncan Laurie467f31d2013-03-08 17:00:37 -0800269 /* SMI setup based on device tree configuration */
270 enable_alt_smi(config->alt_gp_smi_en);
Aaron Durbin76c37002012-10-30 09:03:43 -0500271
272 /* Set up power management block and determine sleep mode */
273 reg32 = inl(pmbase + 0x04); // PM1_CNT
274 reg32 &= ~(7 << 10); // SLP_TYP
275 reg32 |= (1 << 0); // SCI_EN
276 outl(reg32, pmbase + 0x04);
277
278 /* Clear magic status bits to prevent unexpected wake */
279 reg32 = RCBA32(0x3310);
280 reg32 |= (1 << 4)|(1 << 5)|(1 << 0);
281 RCBA32(0x3310) = reg32;
282
283 reg32 = RCBA32(0x3f02);
284 reg32 &= ~0xf;
285 RCBA32(0x3f02) = reg32;
286}
287
288static void pch_rtc_init(struct device *dev)
289{
290 u8 reg8;
291 int rtc_failed;
292
293 reg8 = pci_read_config8(dev, GEN_PMCON_3);
294 rtc_failed = reg8 & RTC_BATTERY_DEAD;
295 if (rtc_failed) {
296 reg8 &= ~RTC_BATTERY_DEAD;
297 pci_write_config8(dev, GEN_PMCON_3, reg8);
298#if CONFIG_ELOG
299 elog_add_event(ELOG_TYPE_RTC_RESET);
300#endif
301 }
302 printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed);
303
304 rtc_init(rtc_failed);
305}
306
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800307/* LynxPoint PCH Power Management init */
308static void lpt_pm_init(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500309{
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800310 printk(BIOS_DEBUG, "LynxPoint PM init\n");
Aaron Durbin76c37002012-10-30 09:03:43 -0500311}
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800312
313const struct rcba_config_instruction lpt_lp_pm_rcba[] = {
Duncan Laurie4bc107b2013-06-24 13:14:44 -0700314 RCBA_RMW_REG_32(0x232c, ~1, 0x00000000),
315 RCBA_RMW_REG_32(0x1100, ~0xc000, 0xc000),
316 RCBA_RMW_REG_32(0x1100, ~0, 0x00000100),
317 RCBA_RMW_REG_32(0x1100, ~0, 0x0000003f),
318 RCBA_RMW_REG_32(0x2320, ~0x60, 0x10),
319 RCBA_RMW_REG_32(0x3314, 0, 0x00012fff),
320 RCBA_RMW_REG_32(0x3318, 0, 0x0dcf0400),
321 RCBA_RMW_REG_32(0x3324, 0, 0x04000000),
322 RCBA_RMW_REG_32(0x3368, 0, 0x00041400),
323 RCBA_RMW_REG_32(0x3388, 0, 0x3f8ddbff),
324 RCBA_RMW_REG_32(0x33ac, 0, 0x00007001),
325 RCBA_RMW_REG_32(0x33b0, 0, 0x00181900),
326 RCBA_RMW_REG_32(0x33c0, 0, 0x00060A00),
327 RCBA_RMW_REG_32(0x33d0, 0, 0x06200840),
328 RCBA_RMW_REG_32(0x3a28, 0, 0x01010101),
329 RCBA_RMW_REG_32(0x3a2c, 0, 0x04040404),
330 RCBA_RMW_REG_32(0x2b1c, 0, 0x03808033),
331 RCBA_RMW_REG_32(0x2b34, 0, 0x80000009),
332 RCBA_RMW_REG_32(0x3348, 0, 0x022ddfff),
333 RCBA_RMW_REG_32(0x334c, 0, 0x00000001),
334 RCBA_RMW_REG_32(0x3358, 0, 0x0001c000),
335 RCBA_RMW_REG_32(0x3380, 0, 0x3f8ddbff),
336 RCBA_RMW_REG_32(0x3384, 0, 0x0001c7e1),
337 RCBA_RMW_REG_32(0x338c, 0, 0x0001c7e1),
338 RCBA_RMW_REG_32(0x3398, 0, 0x0001c000),
339 RCBA_RMW_REG_32(0x33a8, 0, 0x00181900),
340 RCBA_RMW_REG_32(0x33dc, 0, 0x00080000),
341 RCBA_RMW_REG_32(0x33e0, 0, 0x00000001),
342 RCBA_RMW_REG_32(0x3a20, 0, 0x00000404),
343 RCBA_RMW_REG_32(0x3a24, 0, 0x01010101),
344 RCBA_RMW_REG_32(0x3a30, 0, 0x01010101),
345 RCBA_RMW_REG_32(0x0410, ~0, 0x00000003),
346 RCBA_RMW_REG_32(0x2618, ~0, 0x08000000),
347 RCBA_RMW_REG_32(0x2300, ~0, 0x00000002),
348 RCBA_RMW_REG_32(0x2600, ~0, 0x00000008),
349 RCBA_RMW_REG_32(0x33b4, 0, 0x00007001),
350 RCBA_RMW_REG_32(0x3350, 0, 0x022ddfff),
351 RCBA_RMW_REG_32(0x3354, 0, 0x00000001),
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800352 RCBA_RMW_REG_32(0x33d4, ~0, 0x08000000), /* Power Optimizer */
353 RCBA_RMW_REG_32(0x33c8, ~0, 0x08000080), /* Power Optimizer */
354 RCBA_RMW_REG_32(0x2b10, 0, 0x0000883c), /* Power Optimizer */
Duncan Laurie5cf34ce2013-04-26 10:41:33 -0700355 RCBA_RMW_REG_32(0x2b14, 0, 0x1e0a4616), /* Power Optimizer */
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800356 RCBA_RMW_REG_32(0x2b24, 0, 0x40000005), /* Power Optimizer */
357 RCBA_RMW_REG_32(0x2b20, 0, 0x0005db01), /* Power Optimizer */
Duncan Laurie4bc107b2013-06-24 13:14:44 -0700358 RCBA_RMW_REG_32(0x3a80, 0, 0x05145005),
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800359 RCBA_END_CONFIG
360};
361
362/* LynxPoint LP PCH Power Management init */
363static void lpt_lp_pm_init(struct device *dev)
364{
365 struct southbridge_intel_lynxpoint_config *config = dev->chip_info;
366 u32 data;
367
368 printk(BIOS_DEBUG, "LynxPoint LP PM init\n");
369
370 pci_write_config8(dev, 0xa9, 0x46);
371
372 pch_config_rcba(lpt_lp_pm_rcba);
373
374 pci_write_config32(dev, 0xac,
375 pci_read_config32(dev, 0xac) | (1 << 21));
376
Duncan Laurie4bc107b2013-06-24 13:14:44 -0700377 pch_iobp_update(0xED00015C, ~(1<<11), 0x00003700);
378 pch_iobp_update(0xED000118, ~0UL, 0x00c00000);
379 pch_iobp_update(0xED000120, ~0UL, 0x00240000);
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800380 pch_iobp_update(0xCA000000, ~0UL, 0x00000009);
381
382 /* Set RCBA CIR28 0x3A84 based on SATA port enables */
383 data = 0x00001005;
384 /* Port 3 and 2 disabled */
385 if ((config->sata_port_map & ((1 << 3)|(1 << 2))) == 0)
386 data |= (1 << 24) | (1 << 26);
387 /* Port 1 and 0 disabled */
388 if ((config->sata_port_map & ((1 << 1)|(1 << 0))) == 0)
389 data |= (1 << 20) | (1 << 18);
390 RCBA32(0x3a84) = data;
391
Duncan Laurie5cf34ce2013-04-26 10:41:33 -0700392 /* Set RCBA 0x2b1c[29]=1 if DSP disabled */
393 if (RCBA32(FD) & PCH_DISABLE_ADSPD)
394 RCBA32_OR(0x2b1c, (1 << 29));
395
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800396 /* Lock */
397 RCBA32_OR(0x3a6c, 0x00000001);
398
399 /* Set RCBA 0x33D4 after other setup */
400 RCBA32_OR(0x33d4, 0x2fff2fb1);
401
402 /* Set RCBA 0x33C8[15]=1 as last step */
403 RCBA32_OR(0x33c8, (1 << 15));
404}
Aaron Durbin76c37002012-10-30 09:03:43 -0500405
406static void enable_hpet(void)
407{
408 u32 reg32;
409
410 /* Move HPET to default address 0xfed00000 and enable it */
411 reg32 = RCBA32(HPTC);
412 reg32 |= (1 << 7); // HPET Address Enable
413 reg32 &= ~(3 << 0);
414 RCBA32(HPTC) = reg32;
415 /* Read it back to stick. It's affected by posted write syndrome. */
416 reg32 = RCBA32(HPTC);
417}
418
419static void enable_clock_gating(device_t dev)
420{
Duncan Laurie74c0d052012-12-17 11:31:40 -0800421 /* LynxPoint Mobile */
422 u32 reg32;
423 u16 reg16;
424
425 /* DMI */
426 RCBA32_AND_OR(0x2234, ~0UL, 0xf);
427 reg16 = pci_read_config16(dev, GEN_PMCON_1);
428 reg16 |= (1 << 11) | (1 << 12) | (1 << 14);
429 reg16 |= (1 << 2); // PCI CLKRUN# Enable
430 pci_write_config16(dev, GEN_PMCON_1, reg16);
431 RCBA32_OR(0x900, (1 << 14));
432
433 reg32 = RCBA32(CG);
434 reg32 |= (1 << 22); // HDA Dynamic
435 reg32 |= (1 << 31); // LPC Dynamic
436 reg32 |= (1 << 16); // PCIe Dynamic
437 reg32 |= (1 << 27); // HPET Dynamic
438 reg32 |= (1 << 28); // GPIO Dynamic
439 RCBA32(CG) = reg32;
440
441 RCBA32_OR(0x38c0, 0x7); // SPI Dynamic
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800442}
443
444static void enable_lp_clock_gating(device_t dev)
445{
446 /* LynxPoint LP */
447 u32 reg32;
448 u16 reg16;
449
450 /* DMI */
451 RCBA32_AND_OR(0x2234, ~0UL, 0xf);
452 reg16 = pci_read_config16(dev, GEN_PMCON_1);
453 reg16 &= ~((1 << 11) | (1 << 14));
454 reg16 |= (1 << 5) | (1 << 6) | (1 << 7) | (1 << 12) | (1 << 13);
455 reg16 |= (1 << 2); // PCI CLKRUN# Enable
456 pci_write_config16(dev, GEN_PMCON_1, reg16);
457
458 reg32 = pci_read_config32(dev, 0x64);
459 reg32 |= (1 << 6);
460 pci_write_config32(dev, 0x64, reg32);
461
Duncan Laurie4bc107b2013-06-24 13:14:44 -0700462 /*
463 * RCBA + 0x2614[27:25,14:13,10,8] = 101,11,1,1
464 * RCBA + 0x2614[23:16] = 0x20
465 * RCBA + 0x2614[30:28] = 0x0
Duncan Lauried8c7d732013-07-16 09:01:43 -0700466 * RCBA + 0x2614[26] = 1 (IF 0:2.0@0x08 >= 0x0b)
Duncan Laurie4bc107b2013-06-24 13:14:44 -0700467 */
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800468 RCBA32_AND_OR(0x2614, 0x8bffffff, 0x0a206500);
Duncan Laurie4bc107b2013-06-24 13:14:44 -0700469
470 /* Check for LPT-LP B2 stepping and 0:31.0@0xFA > 4 */
Duncan Lauried8c7d732013-07-16 09:01:43 -0700471 if (pci_read_config8(dev_find_slot(0, PCI_DEVFN(2, 0)), 0x8) >= 0x0b)
Duncan Laurie4bc107b2013-06-24 13:14:44 -0700472 RCBA32_OR(0x2614, (1<<26));
473
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800474 RCBA32_OR(0x900, 0x0000031f);
475
476 reg32 = RCBA32(CG);
Duncan Lauriea2d6a402013-03-22 11:24:45 -0700477 if (RCBA32(0x3454) & (1 << 4))
478 reg32 &= ~(1 << 29); // LPC Dynamic
479 else
480 reg32 |= (1 << 29); // LPC Dynamic
Duncan Laurie5cf34ce2013-04-26 10:41:33 -0700481 reg32 |= (1 << 31); // LP LPC
482 reg32 |= (1 << 30); // LP BLA
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800483 reg32 |= (1 << 28); // GPIO Dynamic
484 reg32 |= (1 << 27); // HPET Dynamic
Duncan Laurie5cf34ce2013-04-26 10:41:33 -0700485 reg32 |= (1 << 26); // Generic Platform Event Clock
486 if (RCBA32(BUC) & PCH_DISABLE_GBE)
487 reg32 |= (1 << 23); // GbE Static
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800488 reg32 |= (1 << 22); // HDA Dynamic
Duncan Laurie5cf34ce2013-04-26 10:41:33 -0700489 reg32 |= (1 << 16); // PCI Dynamic
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800490 RCBA32(CG) = reg32;
491
492 RCBA32_OR(0x3434, 0x7); // LP LPC
493
494 RCBA32_AND_OR(0x333c, 0xffcfffff, 0x00c00000); // SATA
495
496 RCBA32_OR(0x38c0, 0x3c07); // SPI Dynamic
497
498 pch_iobp_update(0xCF000000, ~0UL, 0x00007001);
Duncan Laurie5cf34ce2013-04-26 10:41:33 -0700499 pch_iobp_update(0xCE00C000, ~1UL, 0x00000000); // bit0=0 in BWG 1.4.0
Aaron Durbin76c37002012-10-30 09:03:43 -0500500}
501
Aaron Durbin29ffa542012-12-21 21:21:48 -0600502static void pch_set_acpi_mode(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500503{
Aaron Durbin29ffa542012-12-21 21:21:48 -0600504#if CONFIG_HAVE_SMI_HANDLER
Kyösti Mälkkic3ed8862014-06-19 19:50:51 +0300505 if (!acpi_is_wakeup_s3()) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500506#if ENABLE_ACPI_MODE_IN_COREBOOT
507 printk(BIOS_DEBUG, "Enabling ACPI via APMC:\n");
Aaron Durbin29ffa542012-12-21 21:21:48 -0600508 outb(APM_CNT_ACPI_ENABLE, APM_CNT);
Aaron Durbin76c37002012-10-30 09:03:43 -0500509 printk(BIOS_DEBUG, "done.\n");
510#else
511 printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n");
Aaron Durbin29ffa542012-12-21 21:21:48 -0600512 outb(APM_CNT_ACPI_DISABLE, APM_CNT);
Aaron Durbin76c37002012-10-30 09:03:43 -0500513 printk(BIOS_DEBUG, "done.\n");
514#endif
515 }
Aaron Durbin29ffa542012-12-21 21:21:48 -0600516#endif /* CONFIG_HAVE_SMI_HANDLER */
Aaron Durbin76c37002012-10-30 09:03:43 -0500517}
Aaron Durbin76c37002012-10-30 09:03:43 -0500518
519static void pch_disable_smm_only_flashing(struct device *dev)
520{
521 u8 reg8;
522
523 printk(BIOS_SPEW, "Enabling BIOS updates outside of SMM... ");
524 reg8 = pci_read_config8(dev, 0xdc); /* BIOS_CNTL */
525 reg8 &= ~(1 << 5);
526 pci_write_config8(dev, 0xdc, reg8);
527}
528
529static void pch_fixups(struct device *dev)
530{
531 u8 gen_pmcon_2;
532
533 /* Indicate DRAM init done for MRC S3 to know it can resume */
534 gen_pmcon_2 = pci_read_config8(dev, GEN_PMCON_2);
535 gen_pmcon_2 |= (1 << 7);
536 pci_write_config8(dev, GEN_PMCON_2, gen_pmcon_2);
537
538 /*
539 * Enable DMI ASPM in the PCH
540 */
541 RCBA32_AND_OR(0x2304, ~(1 << 10), 0);
542 RCBA32_OR(0x21a4, (1 << 11)|(1 << 10));
543 RCBA32_OR(0x21a8, 0x3);
544}
545
Aaron Durbin76c37002012-10-30 09:03:43 -0500546static void lpc_init(struct device *dev)
547{
548 printk(BIOS_DEBUG, "pch: lpc_init\n");
549
550 /* Set the value for PCI command register. */
551 pci_write_config16(dev, PCI_COMMAND, 0x000f);
552
553 /* IO APIC initialization. */
Paul Menzel373a20c2013-05-03 12:17:02 +0200554 pch_enable_ioapic(dev);
Aaron Durbin76c37002012-10-30 09:03:43 -0500555
556 pch_enable_serial_irqs(dev);
557
558 /* Setup the PIRQ. */
559 pch_pirq_init(dev);
560
561 /* Setup power options. */
562 pch_power_options(dev);
563
564 /* Initialize power management */
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800565 if (pch_is_lp()) {
566 lpt_lp_pm_init(dev);
567 enable_lp_clock_gating(dev);
568 } else {
569 lpt_pm_init(dev);
570 enable_clock_gating(dev);
Aaron Durbin76c37002012-10-30 09:03:43 -0500571 }
572
Aaron Durbin76c37002012-10-30 09:03:43 -0500573 /* Initialize the real time clock. */
574 pch_rtc_init(dev);
575
576 /* Initialize ISA DMA. */
577 isa_dma_init();
578
579 /* Initialize the High Precision Event Timers, if present. */
580 enable_hpet();
581
Aaron Durbin76c37002012-10-30 09:03:43 -0500582 setup_i8259();
583
Aaron Durbin76c37002012-10-30 09:03:43 -0500584 /* Interrupt 9 should be level triggered (SCI) */
585 i8259_configure_irq_trigger(9, 1);
586
587 pch_disable_smm_only_flashing(dev);
588
Aaron Durbin29ffa542012-12-21 21:21:48 -0600589 pch_set_acpi_mode();
Aaron Durbin76c37002012-10-30 09:03:43 -0500590
591 pch_fixups(dev);
592}
593
Aaron Durbin6f561af2012-12-19 14:38:01 -0600594static void pch_lpc_add_mmio_resources(device_t dev)
595{
596 u32 reg;
597 struct resource *res;
598 const u32 default_decode_base = IO_APIC_ADDR;
599
600 /*
601 * Just report all resources from IO-APIC base to 4GiB. Don't mark
602 * them reserved as that may upset the OS if this range is marked
603 * as reserved in the e820.
604 */
605 res = new_resource(dev, OIC);
606 res->base = default_decode_base;
607 res->size = 0 - default_decode_base;
608 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
609
610 /* RCBA */
611 if (DEFAULT_RCBA < default_decode_base) {
612 res = new_resource(dev, RCBA);
613 res->base = DEFAULT_RCBA;
614 res->size = 16 * 1024;
615 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
616 IORESOURCE_FIXED | IORESOURCE_RESERVE;
617 }
618
619 /* Check LPC Memory Decode register. */
620 reg = pci_read_config32(dev, LGMR);
621 if (reg & 1) {
622 reg &= ~0xffff;
623 if (reg < default_decode_base) {
624 res = new_resource(dev, LGMR);
625 res->base = reg;
626 res->size = 16 * 1024;
627 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
628 IORESOURCE_FIXED | IORESOURCE_RESERVE;
629 }
630 }
631}
632
633/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
634#define LPC_DEFAULT_IO_RANGE_LOWER 0
635#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
636
637static inline int pch_io_range_in_default(u16 base, u16 size)
638{
639 /* Does it start above the range? */
640 if (base >= LPC_DEFAULT_IO_RANGE_UPPER)
641 return 0;
642
643 /* Is it entirely contained? */
644 if (base >= LPC_DEFAULT_IO_RANGE_LOWER &&
645 (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
646 return 1;
647
648 /* This will return not in range for partial overlaps. */
649 return 0;
650}
651
652/*
653 * Note: this function assumes there is no overlap with the default LPC device's
654 * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
655 */
656static void pch_lpc_add_io_resource(device_t dev, u16 base, u16 size, int index)
657{
658 struct resource *res;
659
660 if (pch_io_range_in_default(base, size))
661 return;
662
663 res = new_resource(dev, index);
664 res->base = base;
665 res->size = size;
666 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
667}
668
669static void pch_lpc_add_gen_io_resources(device_t dev, int reg_value, int index)
670{
671 /*
672 * Check if the register is enabled. If so and the base exceeds the
673 * device's deafult claim range add the resoure.
674 */
675 if (reg_value & 1) {
676 u16 base = reg_value & 0xfffc;
677 u16 size = (0x3 | ((reg_value >> 16) & 0xfc)) + 1;
678 pch_lpc_add_io_resource(dev, base, size, index);
679 }
680}
681
682static void pch_lpc_add_io_resources(device_t dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500683{
684 struct resource *res;
685 config_t *config = dev->chip_info;
Aaron Durbin76c37002012-10-30 09:03:43 -0500686
Aaron Durbin6f561af2012-12-19 14:38:01 -0600687 /* Add the default claimed IO range for the LPC device. */
688 res = new_resource(dev, 0);
689 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
690 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
691 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
692
693 /* GPIOBASE */
Duncan Laurie7922b462013-03-08 16:34:33 -0800694 pch_lpc_add_io_resource(dev, get_gpiobase(), DEFAULT_GPIOSIZE,
Aaron Durbin6f561af2012-12-19 14:38:01 -0600695 GPIO_BASE);
696
697 /* PMBASE */
Duncan Laurie7922b462013-03-08 16:34:33 -0800698 pch_lpc_add_io_resource(dev, get_pmbase(), 256, PMBASE);
Aaron Durbin6f561af2012-12-19 14:38:01 -0600699
700 /* LPC Generic IO Decode range. */
701 pch_lpc_add_gen_io_resources(dev, config->gen1_dec, LPC_GEN1_DEC);
702 pch_lpc_add_gen_io_resources(dev, config->gen2_dec, LPC_GEN2_DEC);
703 pch_lpc_add_gen_io_resources(dev, config->gen3_dec, LPC_GEN3_DEC);
704 pch_lpc_add_gen_io_resources(dev, config->gen4_dec, LPC_GEN4_DEC);
705}
706
707static void pch_lpc_read_resources(device_t dev)
708{
Duncan Laurie9c07c8f2013-03-22 11:08:39 -0700709 global_nvs_t *gnvs;
710
Aaron Durbin76c37002012-10-30 09:03:43 -0500711 /* Get the normal PCI resources of this device. */
712 pci_dev_read_resources(dev);
713
Aaron Durbin6f561af2012-12-19 14:38:01 -0600714 /* Add non-standard MMIO resources. */
715 pch_lpc_add_mmio_resources(dev);
Aaron Durbin76c37002012-10-30 09:03:43 -0500716
Aaron Durbin6f561af2012-12-19 14:38:01 -0600717 /* Add IO resources. */
718 pch_lpc_add_io_resources(dev);
Duncan Laurie9c07c8f2013-03-22 11:08:39 -0700719
720 /* Allocate ACPI NVS in CBMEM */
721 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(global_nvs_t));
Kyösti Mälkkic3ed8862014-06-19 19:50:51 +0300722 if (!acpi_is_wakeup_s3() && gnvs)
Duncan Laurie9c07c8f2013-03-22 11:08:39 -0700723 memset(gnvs, 0, sizeof(global_nvs_t));
Aaron Durbin76c37002012-10-30 09:03:43 -0500724}
725
Aaron Durbin76c37002012-10-30 09:03:43 -0500726static void pch_lpc_enable(device_t dev)
727{
728 /* Enable PCH Display Port */
729 RCBA16(DISPBDF) = 0x0010;
730 RCBA32_OR(FD2, PCH_ENABLE_DBDF);
731
732 pch_enable(dev);
733}
734
735static void set_subsystem(device_t dev, unsigned vendor, unsigned device)
736{
737 if (!vendor || !device) {
738 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
739 pci_read_config32(dev, PCI_VENDOR_ID));
740 } else {
741 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
742 ((device & 0xffff) << 16) | (vendor & 0xffff));
743 }
744}
745
Vladimir Serbinenkoc6e566a2014-08-31 17:43:51 +0200746static unsigned long southbridge_fill_ssdt(unsigned long current, const char *oem_table_id)
747{
748 global_nvs_t *gnvs = cbmem_add (CBMEM_ID_ACPI_GNVS, sizeof (*gnvs));
749
750 if (gnvs) {
751 int scopelen;
752 acpi_create_gnvs(gnvs);
753 acpi_save_gnvs((unsigned long)gnvs);
754 /* And tell SMI about it */
755 smm_setup_structures(gnvs, NULL, NULL);
756
757 /* Add it to SSDT. */
758 scopelen = acpigen_write_scope("\\");
759 scopelen += acpigen_write_name_dword("NVSA", (u32) gnvs);
760 acpigen_patch_len(scopelen - 1);
761 }
762
763 return (unsigned long) (acpigen_get_current());
764}
765
766#define ALIGN_CURRENT current = (ALIGN(current, 16))
767static unsigned long southbridge_write_acpi_tables(unsigned long start, struct acpi_rsdp *rsdp)
768{
769 unsigned long current;
770 acpi_hpet_t *hpet;
771 acpi_header_t *ssdt;
772
773 current = start;
774
775 /* Align ACPI tables to 16byte */
776 ALIGN_CURRENT;
777
778 /*
779 * We explicitly add these tables later on:
780 */
781 printk(BIOS_DEBUG, "ACPI: * HPET\n");
782
783 hpet = (acpi_hpet_t *) current;
784 current += sizeof(acpi_hpet_t);
785 ALIGN_CURRENT;
786 acpi_create_intel_hpet(hpet);
787 acpi_add_table(rsdp, hpet);
788
789 ALIGN_CURRENT;
790
791 printk(BIOS_DEBUG, "ACPI: * SSDT2\n");
792 ssdt = (acpi_header_t *)current;
793 acpi_create_serialio_ssdt(ssdt);
794 current += ssdt->length;
795 acpi_add_table(rsdp, ssdt);
796 ALIGN_CURRENT;
797
798 printk(BIOS_DEBUG, "current = %lx\n", current);
799 return current;
800}
801
802
Aaron Durbin76c37002012-10-30 09:03:43 -0500803static struct pci_operations pci_ops = {
804 .set_subsystem = set_subsystem,
805};
806
807static struct device_operations device_ops = {
808 .read_resources = pch_lpc_read_resources,
809 .set_resources = pci_dev_set_resources,
Duncan Laurie8d783b82013-05-14 11:16:34 -0700810 .enable_resources = pci_dev_enable_resources,
Vladimir Serbinenkoc6e566a2014-08-31 17:43:51 +0200811 .acpi_fill_ssdt_generator = southbridge_fill_ssdt,
812 .write_acpi_tables = southbridge_write_acpi_tables,
Aaron Durbin76c37002012-10-30 09:03:43 -0500813 .init = lpc_init,
814 .enable = pch_lpc_enable,
815 .scan_bus = scan_static_bus,
816 .ops_pci = &pci_ops,
817};
818
819
Aaron Durbinc1989c42012-12-11 17:13:17 -0600820/* IDs for LPC device of Intel 8 Series Chipset (Lynx Point) */
821static const unsigned short pci_device_ids[] = {
822 0x8c41, /* Mobile Full Featured Engineering Sample. */
823 0x8c42, /* Desktop Full Featured Engineering Sample. */
824 0x8c44, /* Z87 SKU */
825 0x8c46, /* Z85 SKU */
826 0x8c49, /* HM86 SKU */
827 0x8c4a, /* H87 SKU */
828 0x8c4b, /* HM87 SKU */
829 0x8c4c, /* Q85 SKU */
830 0x8c4e, /* Q87 SKU */
831 0x8c4f, /* QM87 SKU */
Duncan Laurie74c0d052012-12-17 11:31:40 -0800832 0x9c41, /* LP Full Featured Engineering Sample */
833 0x9c43, /* LP Premium SKU */
834 0x9c45, /* LP Mainstream SKU */
835 0x9c47, /* LP Value SKU */
Aaron Durbinc1989c42012-12-11 17:13:17 -0600836 0 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500837
838static const struct pci_driver pch_lpc __pci_driver = {
839 .ops = &device_ops,
840 .vendor = PCI_VENDOR_ID_INTEL,
841 .devices = pci_device_ids,
842};