blob: c3b53221900c041ed48f0fa38eefbf7e1bb48c25 [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"
39
40#define NMI_OFF 0
41
42#define ENABLE_ACPI_MODE_IN_COREBOOT 0
Aaron Durbin76c37002012-10-30 09:03:43 -050043
44typedef struct southbridge_intel_lynxpoint_config config_t;
45
Paul Menzel373a20c2013-05-03 12:17:02 +020046/**
47 * Set miscellanous static southbridge features.
48 *
49 * @param dev PCI device with I/O APIC control registers
50 */
51static void pch_enable_ioapic(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -050052{
Aaron Durbin76c37002012-10-30 09:03:43 -050053 u32 reg32;
Aaron Durbin76c37002012-10-30 09:03:43 -050054
Paul Menzel373a20c2013-05-03 12:17:02 +020055 /* Enable ACPI I/O range decode */
56 pci_write_config8(dev, ACPI_CNTL, ACPI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -050057
Paul Menzel373a20c2013-05-03 12:17:02 +020058 set_ioapic_id(IO_APIC_ADDR, 0x02);
Aaron Durbin76c37002012-10-30 09:03:43 -050059
60 /* affirm full set of redirection table entries ("write once") */
Paul Menzel373a20c2013-05-03 12:17:02 +020061 reg32 = io_apic_read(IO_APIC_ADDR, 0x01);
62 io_apic_write(IO_APIC_ADDR, 0x01, reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -050063
Paul Menzel373a20c2013-05-03 12:17:02 +020064 /*
65 * Select Boot Configuration register (0x03) and
66 * use Processor System Bus (0x01) to deliver interrupts.
67 */
68 io_apic_write(IO_APIC_ADDR, 0x03, 0x01);
Aaron Durbin76c37002012-10-30 09:03:43 -050069}
70
71static void pch_enable_serial_irqs(struct device *dev)
72{
73 /* Set packet length and toggle silent mode bit for one frame. */
74 pci_write_config8(dev, SERIRQ_CNTL,
75 (1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0));
76#if !CONFIG_SERIRQ_CONTINUOUS_MODE
77 pci_write_config8(dev, SERIRQ_CNTL,
78 (1 << 7) | (0 << 6) | ((21 - 17) << 2) | (0 << 0));
79#endif
80}
81
82/* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control
83 * 0x00 - 0000 = Reserved
84 * 0x01 - 0001 = Reserved
85 * 0x02 - 0010 = Reserved
86 * 0x03 - 0011 = IRQ3
87 * 0x04 - 0100 = IRQ4
88 * 0x05 - 0101 = IRQ5
89 * 0x06 - 0110 = IRQ6
90 * 0x07 - 0111 = IRQ7
91 * 0x08 - 1000 = Reserved
92 * 0x09 - 1001 = IRQ9
93 * 0x0A - 1010 = IRQ10
94 * 0x0B - 1011 = IRQ11
95 * 0x0C - 1100 = IRQ12
96 * 0x0D - 1101 = Reserved
97 * 0x0E - 1110 = IRQ14
98 * 0x0F - 1111 = IRQ15
99 * PIRQ[n]_ROUT[7] - PIRQ Routing Control
100 * 0x80 - The PIRQ is not routed.
101 */
102
103static void pch_pirq_init(device_t dev)
104{
105 device_t irq_dev;
106 /* Get the chip configuration */
107 config_t *config = dev->chip_info;
108
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
119 /* Eric Biederman once said we should let the OS do this.
120 * I am not so sure anymore he was right.
121 */
122
123 for(irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
124 u8 int_pin=0, int_line=0;
125
126 if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI)
127 continue;
128
129 int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
130
131 switch (int_pin) {
132 case 1: /* INTA# */ int_line = config->pirqa_routing; break;
133 case 2: /* INTB# */ int_line = config->pirqb_routing; break;
134 case 3: /* INTC# */ int_line = config->pirqc_routing; break;
135 case 4: /* INTD# */ int_line = config->pirqd_routing; break;
136 }
137
138 if (!int_line)
139 continue;
140
141 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line);
142 }
143}
144
145static void pch_gpi_routing(device_t dev)
146{
147 /* Get the chip configuration */
148 config_t *config = dev->chip_info;
149 u32 reg32 = 0;
150
151 /* An array would be much nicer here, or some
152 * other method of doing this.
153 */
154 reg32 |= (config->gpi0_routing & 0x03) << 0;
155 reg32 |= (config->gpi1_routing & 0x03) << 2;
156 reg32 |= (config->gpi2_routing & 0x03) << 4;
157 reg32 |= (config->gpi3_routing & 0x03) << 6;
158 reg32 |= (config->gpi4_routing & 0x03) << 8;
159 reg32 |= (config->gpi5_routing & 0x03) << 10;
160 reg32 |= (config->gpi6_routing & 0x03) << 12;
161 reg32 |= (config->gpi7_routing & 0x03) << 14;
162 reg32 |= (config->gpi8_routing & 0x03) << 16;
163 reg32 |= (config->gpi9_routing & 0x03) << 18;
164 reg32 |= (config->gpi10_routing & 0x03) << 20;
165 reg32 |= (config->gpi11_routing & 0x03) << 22;
166 reg32 |= (config->gpi12_routing & 0x03) << 24;
167 reg32 |= (config->gpi13_routing & 0x03) << 26;
168 reg32 |= (config->gpi14_routing & 0x03) << 28;
169 reg32 |= (config->gpi15_routing & 0x03) << 30;
170
171 pci_write_config32(dev, 0xb8, reg32);
172}
173
174static void pch_power_options(device_t dev)
175{
176 u8 reg8;
Duncan Laurie467f31d2013-03-08 17:00:37 -0800177 u16 reg16;
Aaron Durbin76c37002012-10-30 09:03:43 -0500178 u32 reg32;
179 const char *state;
180 /* Get the chip configuration */
181 config_t *config = dev->chip_info;
Duncan Laurie467f31d2013-03-08 17:00:37 -0800182 u16 pmbase = get_pmbase();
Aaron Durbin76c37002012-10-30 09:03:43 -0500183 int pwr_on=CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL;
184 int nmi_option;
185
186 /* Which state do we want to goto after g3 (power restored)?
187 * 0 == S0 Full On
188 * 1 == S5 Soft Off
189 *
190 * If the option is not existent (Laptops), use Kconfig setting.
191 */
192 get_option(&pwr_on, "power_on_after_fail");
193
194 reg16 = pci_read_config16(dev, GEN_PMCON_3);
195 reg16 &= 0xfffe;
196 switch (pwr_on) {
197 case MAINBOARD_POWER_OFF:
198 reg16 |= 1;
199 state = "off";
200 break;
201 case MAINBOARD_POWER_ON:
202 reg16 &= ~1;
203 state = "on";
204 break;
205 case MAINBOARD_POWER_KEEP:
206 reg16 &= ~1;
207 state = "state keep";
208 break;
209 default:
210 state = "undefined";
211 }
212
213 reg16 &= ~(3 << 4); /* SLP_S4# Assertion Stretch 4s */
214 reg16 |= (1 << 3); /* SLP_S4# Assertion Stretch Enable */
215
216 reg16 &= ~(1 << 10);
217 reg16 |= (1 << 11); /* SLP_S3# Min Assertion Width 50ms */
218
219 reg16 |= (1 << 12); /* Disable SLP stretch after SUS well */
220
221 pci_write_config16(dev, GEN_PMCON_3, reg16);
222 printk(BIOS_INFO, "Set power %s after power failure.\n", state);
223
224 /* Set up NMI on errors. */
225 reg8 = inb(0x61);
226 reg8 &= 0x0f; /* Higher Nibble must be 0 */
227 reg8 &= ~(1 << 3); /* IOCHK# NMI Enable */
228 // reg8 &= ~(1 << 2); /* PCI SERR# Enable */
229 reg8 |= (1 << 2); /* PCI SERR# Disable for now */
230 outb(reg8, 0x61);
231
232 reg8 = inb(0x70);
233 nmi_option = NMI_OFF;
234 get_option(&nmi_option, "nmi");
235 if (nmi_option) {
236 printk(BIOS_INFO, "NMI sources enabled.\n");
237 reg8 &= ~(1 << 7); /* Set NMI. */
238 } else {
239 printk(BIOS_INFO, "NMI sources disabled.\n");
240 reg8 |= ( 1 << 7); /* Can't mask NMI from PCI-E and NMI_NOW */
241 }
242 outb(reg8, 0x70);
243
244 /* Enable CPU_SLP# and Intel Speedstep, set SMI# rate down */
245 reg16 = pci_read_config16(dev, GEN_PMCON_1);
246 reg16 &= ~(3 << 0); // SMI# rate 1 minute
247 reg16 &= ~(1 << 10); // Disable BIOS_PCI_EXP_EN for native PME
Aaron Durbin76c37002012-10-30 09:03:43 -0500248 pci_write_config16(dev, GEN_PMCON_1, reg16);
249
Duncan Laurie467f31d2013-03-08 17:00:37 -0800250 /*
251 * Set the board's GPI routing on LynxPoint-H.
252 * This is done as part of GPIO configuration on LynxPoint-LP.
253 */
254 if (pch_is_lp())
255 pch_gpi_routing(dev);
Aaron Durbin76c37002012-10-30 09:03:43 -0500256
Duncan Laurie467f31d2013-03-08 17:00:37 -0800257 /* GPE setup based on device tree configuration */
258 enable_all_gpe(config->gpe0_en_1, config->gpe0_en_2,
259 config->gpe0_en_3, config->gpe0_en_4);
Aaron Durbin76c37002012-10-30 09:03:43 -0500260
Duncan Laurie467f31d2013-03-08 17:00:37 -0800261 /* SMI setup based on device tree configuration */
262 enable_alt_smi(config->alt_gp_smi_en);
Aaron Durbin76c37002012-10-30 09:03:43 -0500263
264 /* Set up power management block and determine sleep mode */
265 reg32 = inl(pmbase + 0x04); // PM1_CNT
266 reg32 &= ~(7 << 10); // SLP_TYP
267 reg32 |= (1 << 0); // SCI_EN
268 outl(reg32, pmbase + 0x04);
269
270 /* Clear magic status bits to prevent unexpected wake */
271 reg32 = RCBA32(0x3310);
272 reg32 |= (1 << 4)|(1 << 5)|(1 << 0);
273 RCBA32(0x3310) = reg32;
274
275 reg32 = RCBA32(0x3f02);
276 reg32 &= ~0xf;
277 RCBA32(0x3f02) = reg32;
278}
279
280static void pch_rtc_init(struct device *dev)
281{
282 u8 reg8;
283 int rtc_failed;
284
285 reg8 = pci_read_config8(dev, GEN_PMCON_3);
286 rtc_failed = reg8 & RTC_BATTERY_DEAD;
287 if (rtc_failed) {
288 reg8 &= ~RTC_BATTERY_DEAD;
289 pci_write_config8(dev, GEN_PMCON_3, reg8);
290#if CONFIG_ELOG
291 elog_add_event(ELOG_TYPE_RTC_RESET);
292#endif
293 }
294 printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed);
295
296 rtc_init(rtc_failed);
297}
298
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800299/* LynxPoint PCH Power Management init */
300static void lpt_pm_init(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500301{
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800302 printk(BIOS_DEBUG, "LynxPoint PM init\n");
Aaron Durbin76c37002012-10-30 09:03:43 -0500303}
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800304
305const struct rcba_config_instruction lpt_lp_pm_rcba[] = {
306 RCBA_RMW_REG_32(0x232c, ~1, 0x00000000), /* 4 */
Duncan Laurie5cf34ce2013-04-26 10:41:33 -0700307 RCBA_RMW_REG_32(0x1100, ~0xc000, 0xc000), /* 5 */
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800308 RCBA_RMW_REG_32(0x1100, ~0, 0x00000100), /* 6 */
309 RCBA_RMW_REG_32(0x1100, ~0, 0x0000003f), /* 7 */
310 RCBA_RMW_REG_32(0x2320, ~0x60, 0x10), /* 8? */
311 RCBA_RMW_REG_32(0x3314, 0, 0x00012fff), /* 9? */
312 RCBA_RMW_REG_32(0x3318, 0, 0x0dcf0400), /* 10? */
313 RCBA_RMW_REG_32(0x3324, 0, 0x04000000), /* 11 */
314 RCBA_RMW_REG_32(0x3368, 0, 0x00041400), /* 12? */
315 RCBA_RMW_REG_32(0x3388, 0, 0x3f8ddbff), /* 13? */
316 RCBA_RMW_REG_32(0x33ac, 0, 0x00007001), /* 14? */
317 RCBA_RMW_REG_32(0x33b0, 0, 0x00181900), /* 15? */
318 RCBA_RMW_REG_32(0x33c0, 0, 0x00060A00), /* 16? */
319 RCBA_RMW_REG_32(0x33d0, 0, 0x06200840), /* 17? */
320 RCBA_RMW_REG_32(0x3a28, 0, 0x01010101), /* 19 */
321 RCBA_RMW_REG_32(0x3a2c, 0, 0x04040404), /* 20 */
322 RCBA_RMW_REG_32(0x2b1c, 0, 0x03808033), /* 23? */
323 RCBA_RMW_REG_32(0x2b34, 0, 0x80000008), /* 24 */
324 RCBA_RMW_REG_32(0x3348, 0, 0x022ddfff), /* 25? */
325 RCBA_RMW_REG_32(0x334c, 0, 0x00000001), /* 26 */
326 RCBA_RMW_REG_32(0x3358, 0, 0x0001c000), /* 27 */
327 RCBA_RMW_REG_32(0x3380, 0, 0x3f8ddbff), /* 28 */
328 RCBA_RMW_REG_32(0x3384, 0, 0x0001c7e1), /* 29 */
329 RCBA_RMW_REG_32(0x338c, 0, 0x0001c7e1), /* ? */
330 RCBA_RMW_REG_32(0x3398, 0, 0x0001c000), /* 30 */
331 RCBA_RMW_REG_32(0x33a8, 0, 0x00181900), /* 31? */
332 RCBA_RMW_REG_32(0x33dc, 0, 0x00080000), /* 32 */
333 RCBA_RMW_REG_32(0x33e0, 0, 0x00000001), /* 33 */
334 RCBA_RMW_REG_32(0x3a20, 0, 0x00000404), /* 34 */
335 RCBA_RMW_REG_32(0x3a24, 0, 0x01010101), /* 35 */
336 RCBA_RMW_REG_32(0x3a30, 0, 0x01010101), /* 36 */
337 RCBA_RMW_REG_32(0x0410, ~0, 0x00000003), /* 42 */
338 RCBA_RMW_REG_32(0x2618, ~0, 0x08000000), /* 43 */
339 RCBA_RMW_REG_32(0x2600, ~0, 0x00000008), /* 44 */
340 RCBA_RMW_REG_32(0x33b4, 0, 0x00007001), /* 46? */
341 RCBA_RMW_REG_32(0x3350, 0, 0x022ddfff), /* 47? */
342 RCBA_RMW_REG_32(0x3354, 0, 0x00000001), /* ? */
343 RCBA_RMW_REG_32(0x33d4, ~0, 0x08000000), /* Power Optimizer */
344 RCBA_RMW_REG_32(0x33c8, ~0, 0x08000080), /* Power Optimizer */
345 RCBA_RMW_REG_32(0x2b10, 0, 0x0000883c), /* Power Optimizer */
Duncan Laurie5cf34ce2013-04-26 10:41:33 -0700346 RCBA_RMW_REG_32(0x2b14, 0, 0x1e0a4616), /* Power Optimizer */
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800347 RCBA_RMW_REG_32(0x2b24, 0, 0x40000005), /* Power Optimizer */
348 RCBA_RMW_REG_32(0x2b20, 0, 0x0005db01), /* Power Optimizer */
349 RCBA_RMW_REG_32(0x3a80, 0, 0x05145005), /* 21? */
350 RCBA_END_CONFIG
351};
352
353/* LynxPoint LP PCH Power Management init */
354static void lpt_lp_pm_init(struct device *dev)
355{
356 struct southbridge_intel_lynxpoint_config *config = dev->chip_info;
357 u32 data;
358
359 printk(BIOS_DEBUG, "LynxPoint LP PM init\n");
360
361 pci_write_config8(dev, 0xa9, 0x46);
362
363 pch_config_rcba(lpt_lp_pm_rcba);
364
365 pci_write_config32(dev, 0xac,
366 pci_read_config32(dev, 0xac) | (1 << 21));
367
368 pch_iobp_update(0xCA000000, ~0UL, 0x00000009);
369
370 /* Set RCBA CIR28 0x3A84 based on SATA port enables */
371 data = 0x00001005;
372 /* Port 3 and 2 disabled */
373 if ((config->sata_port_map & ((1 << 3)|(1 << 2))) == 0)
374 data |= (1 << 24) | (1 << 26);
375 /* Port 1 and 0 disabled */
376 if ((config->sata_port_map & ((1 << 1)|(1 << 0))) == 0)
377 data |= (1 << 20) | (1 << 18);
378 RCBA32(0x3a84) = data;
379
Duncan Laurie5cf34ce2013-04-26 10:41:33 -0700380 /* Set RCBA 0x2b1c[29]=1 if DSP disabled */
381 if (RCBA32(FD) & PCH_DISABLE_ADSPD)
382 RCBA32_OR(0x2b1c, (1 << 29));
383
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800384 /* Lock */
385 RCBA32_OR(0x3a6c, 0x00000001);
386
387 /* Set RCBA 0x33D4 after other setup */
388 RCBA32_OR(0x33d4, 0x2fff2fb1);
389
390 /* Set RCBA 0x33C8[15]=1 as last step */
391 RCBA32_OR(0x33c8, (1 << 15));
392}
Aaron Durbin76c37002012-10-30 09:03:43 -0500393
394static void enable_hpet(void)
395{
396 u32 reg32;
397
398 /* Move HPET to default address 0xfed00000 and enable it */
399 reg32 = RCBA32(HPTC);
400 reg32 |= (1 << 7); // HPET Address Enable
401 reg32 &= ~(3 << 0);
402 RCBA32(HPTC) = reg32;
403 /* Read it back to stick. It's affected by posted write syndrome. */
404 reg32 = RCBA32(HPTC);
405}
406
407static void enable_clock_gating(device_t dev)
408{
Duncan Laurie74c0d052012-12-17 11:31:40 -0800409 /* LynxPoint Mobile */
410 u32 reg32;
411 u16 reg16;
412
413 /* DMI */
414 RCBA32_AND_OR(0x2234, ~0UL, 0xf);
415 reg16 = pci_read_config16(dev, GEN_PMCON_1);
416 reg16 |= (1 << 11) | (1 << 12) | (1 << 14);
417 reg16 |= (1 << 2); // PCI CLKRUN# Enable
418 pci_write_config16(dev, GEN_PMCON_1, reg16);
419 RCBA32_OR(0x900, (1 << 14));
420
421 reg32 = RCBA32(CG);
422 reg32 |= (1 << 22); // HDA Dynamic
423 reg32 |= (1 << 31); // LPC Dynamic
424 reg32 |= (1 << 16); // PCIe Dynamic
425 reg32 |= (1 << 27); // HPET Dynamic
426 reg32 |= (1 << 28); // GPIO Dynamic
427 RCBA32(CG) = reg32;
428
429 RCBA32_OR(0x38c0, 0x7); // SPI Dynamic
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800430}
431
432static void enable_lp_clock_gating(device_t dev)
433{
434 /* LynxPoint LP */
435 u32 reg32;
436 u16 reg16;
437
438 /* DMI */
439 RCBA32_AND_OR(0x2234, ~0UL, 0xf);
440 reg16 = pci_read_config16(dev, GEN_PMCON_1);
441 reg16 &= ~((1 << 11) | (1 << 14));
442 reg16 |= (1 << 5) | (1 << 6) | (1 << 7) | (1 << 12) | (1 << 13);
443 reg16 |= (1 << 2); // PCI CLKRUN# Enable
444 pci_write_config16(dev, GEN_PMCON_1, reg16);
445
446 reg32 = pci_read_config32(dev, 0x64);
447 reg32 |= (1 << 6);
448 pci_write_config32(dev, 0x64, reg32);
449
450 RCBA32_AND_OR(0x2614, 0x8bffffff, 0x0a206500);
451 RCBA32_OR(0x900, 0x0000031f);
452
453 reg32 = RCBA32(CG);
Duncan Lauriea2d6a402013-03-22 11:24:45 -0700454 if (RCBA32(0x3454) & (1 << 4))
455 reg32 &= ~(1 << 29); // LPC Dynamic
456 else
457 reg32 |= (1 << 29); // LPC Dynamic
Duncan Laurie5cf34ce2013-04-26 10:41:33 -0700458 reg32 |= (1 << 31); // LP LPC
459 reg32 |= (1 << 30); // LP BLA
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800460 reg32 |= (1 << 28); // GPIO Dynamic
461 reg32 |= (1 << 27); // HPET Dynamic
Duncan Laurie5cf34ce2013-04-26 10:41:33 -0700462 reg32 |= (1 << 26); // Generic Platform Event Clock
463 if (RCBA32(BUC) & PCH_DISABLE_GBE)
464 reg32 |= (1 << 23); // GbE Static
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800465 reg32 |= (1 << 22); // HDA Dynamic
Duncan Laurie5cf34ce2013-04-26 10:41:33 -0700466 reg32 |= (1 << 16); // PCI Dynamic
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800467 RCBA32(CG) = reg32;
468
469 RCBA32_OR(0x3434, 0x7); // LP LPC
470
471 RCBA32_AND_OR(0x333c, 0xffcfffff, 0x00c00000); // SATA
472
473 RCBA32_OR(0x38c0, 0x3c07); // SPI Dynamic
474
475 pch_iobp_update(0xCF000000, ~0UL, 0x00007001);
Duncan Laurie5cf34ce2013-04-26 10:41:33 -0700476 pch_iobp_update(0xCE00C000, ~1UL, 0x00000000); // bit0=0 in BWG 1.4.0
Aaron Durbin76c37002012-10-30 09:03:43 -0500477}
478
Aaron Durbin29ffa542012-12-21 21:21:48 -0600479static void pch_set_acpi_mode(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500480{
Aaron Durbin29ffa542012-12-21 21:21:48 -0600481#if CONFIG_HAVE_SMI_HANDLER
Aaron Durbin76c37002012-10-30 09:03:43 -0500482 if (acpi_slp_type != 3) {
483#if ENABLE_ACPI_MODE_IN_COREBOOT
484 printk(BIOS_DEBUG, "Enabling ACPI via APMC:\n");
Aaron Durbin29ffa542012-12-21 21:21:48 -0600485 outb(APM_CNT_ACPI_ENABLE, APM_CNT);
Aaron Durbin76c37002012-10-30 09:03:43 -0500486 printk(BIOS_DEBUG, "done.\n");
487#else
488 printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n");
Aaron Durbin29ffa542012-12-21 21:21:48 -0600489 outb(APM_CNT_ACPI_DISABLE, APM_CNT);
Aaron Durbin76c37002012-10-30 09:03:43 -0500490 printk(BIOS_DEBUG, "done.\n");
491#endif
492 }
Aaron Durbin29ffa542012-12-21 21:21:48 -0600493#endif /* CONFIG_HAVE_SMI_HANDLER */
Aaron Durbin76c37002012-10-30 09:03:43 -0500494}
Aaron Durbin76c37002012-10-30 09:03:43 -0500495
496static void pch_disable_smm_only_flashing(struct device *dev)
497{
498 u8 reg8;
499
500 printk(BIOS_SPEW, "Enabling BIOS updates outside of SMM... ");
501 reg8 = pci_read_config8(dev, 0xdc); /* BIOS_CNTL */
502 reg8 &= ~(1 << 5);
503 pci_write_config8(dev, 0xdc, reg8);
504}
505
506static void pch_fixups(struct device *dev)
507{
508 u8 gen_pmcon_2;
509
510 /* Indicate DRAM init done for MRC S3 to know it can resume */
511 gen_pmcon_2 = pci_read_config8(dev, GEN_PMCON_2);
512 gen_pmcon_2 |= (1 << 7);
513 pci_write_config8(dev, GEN_PMCON_2, gen_pmcon_2);
514
515 /*
516 * Enable DMI ASPM in the PCH
517 */
518 RCBA32_AND_OR(0x2304, ~(1 << 10), 0);
519 RCBA32_OR(0x21a4, (1 << 11)|(1 << 10));
520 RCBA32_OR(0x21a8, 0x3);
521}
522
523static void pch_decode_init(struct device *dev)
524{
525 config_t *config = dev->chip_info;
526
527 printk(BIOS_DEBUG, "pch_decode_init\n");
528
529 pci_write_config32(dev, LPC_GEN1_DEC, config->gen1_dec);
530 pci_write_config32(dev, LPC_GEN2_DEC, config->gen2_dec);
531 pci_write_config32(dev, LPC_GEN3_DEC, config->gen3_dec);
532 pci_write_config32(dev, LPC_GEN4_DEC, config->gen4_dec);
533}
534
535static void lpc_init(struct device *dev)
536{
537 printk(BIOS_DEBUG, "pch: lpc_init\n");
538
539 /* Set the value for PCI command register. */
540 pci_write_config16(dev, PCI_COMMAND, 0x000f);
541
542 /* IO APIC initialization. */
Paul Menzel373a20c2013-05-03 12:17:02 +0200543 pch_enable_ioapic(dev);
Aaron Durbin76c37002012-10-30 09:03:43 -0500544
545 pch_enable_serial_irqs(dev);
546
547 /* Setup the PIRQ. */
548 pch_pirq_init(dev);
549
550 /* Setup power options. */
551 pch_power_options(dev);
552
553 /* Initialize power management */
Duncan Lauriedeb90f42013-03-08 17:22:37 -0800554 if (pch_is_lp()) {
555 lpt_lp_pm_init(dev);
556 enable_lp_clock_gating(dev);
557 } else {
558 lpt_pm_init(dev);
559 enable_clock_gating(dev);
Aaron Durbin76c37002012-10-30 09:03:43 -0500560 }
561
Aaron Durbin76c37002012-10-30 09:03:43 -0500562 /* Initialize the real time clock. */
563 pch_rtc_init(dev);
564
565 /* Initialize ISA DMA. */
566 isa_dma_init();
567
568 /* Initialize the High Precision Event Timers, if present. */
569 enable_hpet();
570
Aaron Durbin76c37002012-10-30 09:03:43 -0500571 setup_i8259();
572
Aaron Durbin76c37002012-10-30 09:03:43 -0500573 /* Interrupt 9 should be level triggered (SCI) */
574 i8259_configure_irq_trigger(9, 1);
575
576 pch_disable_smm_only_flashing(dev);
577
Aaron Durbin29ffa542012-12-21 21:21:48 -0600578 pch_set_acpi_mode();
Aaron Durbin76c37002012-10-30 09:03:43 -0500579
580 pch_fixups(dev);
581}
582
Aaron Durbin6f561af2012-12-19 14:38:01 -0600583static void pch_lpc_add_mmio_resources(device_t dev)
584{
585 u32 reg;
586 struct resource *res;
587 const u32 default_decode_base = IO_APIC_ADDR;
588
589 /*
590 * Just report all resources from IO-APIC base to 4GiB. Don't mark
591 * them reserved as that may upset the OS if this range is marked
592 * as reserved in the e820.
593 */
594 res = new_resource(dev, OIC);
595 res->base = default_decode_base;
596 res->size = 0 - default_decode_base;
597 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
598
599 /* RCBA */
600 if (DEFAULT_RCBA < default_decode_base) {
601 res = new_resource(dev, RCBA);
602 res->base = DEFAULT_RCBA;
603 res->size = 16 * 1024;
604 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
605 IORESOURCE_FIXED | IORESOURCE_RESERVE;
606 }
607
608 /* Check LPC Memory Decode register. */
609 reg = pci_read_config32(dev, LGMR);
610 if (reg & 1) {
611 reg &= ~0xffff;
612 if (reg < default_decode_base) {
613 res = new_resource(dev, LGMR);
614 res->base = reg;
615 res->size = 16 * 1024;
616 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
617 IORESOURCE_FIXED | IORESOURCE_RESERVE;
618 }
619 }
620}
621
622/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
623#define LPC_DEFAULT_IO_RANGE_LOWER 0
624#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
625
626static inline int pch_io_range_in_default(u16 base, u16 size)
627{
628 /* Does it start above the range? */
629 if (base >= LPC_DEFAULT_IO_RANGE_UPPER)
630 return 0;
631
632 /* Is it entirely contained? */
633 if (base >= LPC_DEFAULT_IO_RANGE_LOWER &&
634 (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
635 return 1;
636
637 /* This will return not in range for partial overlaps. */
638 return 0;
639}
640
641/*
642 * Note: this function assumes there is no overlap with the default LPC device's
643 * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
644 */
645static void pch_lpc_add_io_resource(device_t dev, u16 base, u16 size, int index)
646{
647 struct resource *res;
648
649 if (pch_io_range_in_default(base, size))
650 return;
651
652 res = new_resource(dev, index);
653 res->base = base;
654 res->size = size;
655 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
656}
657
658static void pch_lpc_add_gen_io_resources(device_t dev, int reg_value, int index)
659{
660 /*
661 * Check if the register is enabled. If so and the base exceeds the
662 * device's deafult claim range add the resoure.
663 */
664 if (reg_value & 1) {
665 u16 base = reg_value & 0xfffc;
666 u16 size = (0x3 | ((reg_value >> 16) & 0xfc)) + 1;
667 pch_lpc_add_io_resource(dev, base, size, index);
668 }
669}
670
671static void pch_lpc_add_io_resources(device_t dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500672{
673 struct resource *res;
674 config_t *config = dev->chip_info;
Aaron Durbin76c37002012-10-30 09:03:43 -0500675
Aaron Durbin6f561af2012-12-19 14:38:01 -0600676 /* Add the default claimed IO range for the LPC device. */
677 res = new_resource(dev, 0);
678 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
679 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
680 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
681
682 /* GPIOBASE */
Duncan Laurie7922b462013-03-08 16:34:33 -0800683 pch_lpc_add_io_resource(dev, get_gpiobase(), DEFAULT_GPIOSIZE,
Aaron Durbin6f561af2012-12-19 14:38:01 -0600684 GPIO_BASE);
685
686 /* PMBASE */
Duncan Laurie7922b462013-03-08 16:34:33 -0800687 pch_lpc_add_io_resource(dev, get_pmbase(), 256, PMBASE);
Aaron Durbin6f561af2012-12-19 14:38:01 -0600688
689 /* LPC Generic IO Decode range. */
690 pch_lpc_add_gen_io_resources(dev, config->gen1_dec, LPC_GEN1_DEC);
691 pch_lpc_add_gen_io_resources(dev, config->gen2_dec, LPC_GEN2_DEC);
692 pch_lpc_add_gen_io_resources(dev, config->gen3_dec, LPC_GEN3_DEC);
693 pch_lpc_add_gen_io_resources(dev, config->gen4_dec, LPC_GEN4_DEC);
694}
695
696static void pch_lpc_read_resources(device_t dev)
697{
Duncan Laurie9c07c8f2013-03-22 11:08:39 -0700698 global_nvs_t *gnvs;
699
Aaron Durbin76c37002012-10-30 09:03:43 -0500700 /* Get the normal PCI resources of this device. */
701 pci_dev_read_resources(dev);
702
Aaron Durbin6f561af2012-12-19 14:38:01 -0600703 /* Add non-standard MMIO resources. */
704 pch_lpc_add_mmio_resources(dev);
Aaron Durbin76c37002012-10-30 09:03:43 -0500705
Aaron Durbin6f561af2012-12-19 14:38:01 -0600706 /* Add IO resources. */
707 pch_lpc_add_io_resources(dev);
Duncan Laurie9c07c8f2013-03-22 11:08:39 -0700708
709 /* Allocate ACPI NVS in CBMEM */
710 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(global_nvs_t));
711 if (gnvs)
712 memset(gnvs, 0, sizeof(global_nvs_t));
Aaron Durbin76c37002012-10-30 09:03:43 -0500713}
714
715static void pch_lpc_enable_resources(device_t dev)
716{
717 pch_decode_init(dev);
718 return pci_dev_enable_resources(dev);
719}
720
721static void pch_lpc_enable(device_t dev)
722{
723 /* Enable PCH Display Port */
724 RCBA16(DISPBDF) = 0x0010;
725 RCBA32_OR(FD2, PCH_ENABLE_DBDF);
726
727 pch_enable(dev);
728}
729
730static void set_subsystem(device_t dev, unsigned vendor, unsigned device)
731{
732 if (!vendor || !device) {
733 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
734 pci_read_config32(dev, PCI_VENDOR_ID));
735 } else {
736 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
737 ((device & 0xffff) << 16) | (vendor & 0xffff));
738 }
739}
740
741static struct pci_operations pci_ops = {
742 .set_subsystem = set_subsystem,
743};
744
745static struct device_operations device_ops = {
746 .read_resources = pch_lpc_read_resources,
747 .set_resources = pci_dev_set_resources,
748 .enable_resources = pch_lpc_enable_resources,
749 .init = lpc_init,
750 .enable = pch_lpc_enable,
751 .scan_bus = scan_static_bus,
752 .ops_pci = &pci_ops,
753};
754
755
Aaron Durbinc1989c42012-12-11 17:13:17 -0600756/* IDs for LPC device of Intel 8 Series Chipset (Lynx Point) */
757static const unsigned short pci_device_ids[] = {
758 0x8c41, /* Mobile Full Featured Engineering Sample. */
759 0x8c42, /* Desktop Full Featured Engineering Sample. */
760 0x8c44, /* Z87 SKU */
761 0x8c46, /* Z85 SKU */
762 0x8c49, /* HM86 SKU */
763 0x8c4a, /* H87 SKU */
764 0x8c4b, /* HM87 SKU */
765 0x8c4c, /* Q85 SKU */
766 0x8c4e, /* Q87 SKU */
767 0x8c4f, /* QM87 SKU */
Duncan Laurie74c0d052012-12-17 11:31:40 -0800768 0x9c41, /* LP Full Featured Engineering Sample */
769 0x9c43, /* LP Premium SKU */
770 0x9c45, /* LP Mainstream SKU */
771 0x9c47, /* LP Value SKU */
Aaron Durbinc1989c42012-12-11 17:13:17 -0600772 0 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500773
774static const struct pci_driver pch_lpc __pci_driver = {
775 .ops = &device_ops,
776 .vendor = PCI_VENDOR_ID_INTEL,
777 .devices = pci_device_ids,
778};
779
780