blob: f53c07d0d90449c0b441198cda10085f8c33d590 [file] [log] [blame]
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2007-2010 coresystems GmbH
5 * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <stdint.h>
22#include <string.h>
23#include <lib.h>
24#include <timestamp.h>
25#include <arch/byteorder.h>
26#include <arch/io.h>
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070027#include <device/pci_def.h>
28#include <device/pnp_def.h>
29#include <cpu/x86/lapic.h>
30#include <pc80/mc146818rtc.h>
31#include <cbmem.h>
32#include <console/console.h>
33#include "northbridge/intel/sandybridge/sandybridge.h"
34#include "northbridge/intel/sandybridge/raminit.h"
35#include "southbridge/intel/bd82x6x/pch.h"
36#include "southbridge/intel/bd82x6x/gpio.h"
37#include <arch/cpu.h>
38#include <cpu/x86/bist.h>
39#include <cpu/x86/msr.h>
40#include "gpio.h"
Kyösti Mälkki926a8d12014-04-27 22:17:22 +030041#include <bootmode.h>
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070042#if CONFIG_CHROMEOS
43#include <vendorcode/google/chromeos/chromeos.h>
44#endif
45#include <cbfs.h>
46#include <ec/quanta/it8518/ec.h>
47#include "ec.h"
48#include "onboard.h"
49
50static void pch_enable_lpc(void)
51{
52 /*
53 * Enable:
54 * EC Decode Range Port62/66
55 * SuperIO Port2E/2F
56 * PS/2 Keyboard/Mouse Port60/64
57 * FDD Port3F0h-3F5h and Port3F7h
58 */
59 pci_write_config16(PCH_LPC_DEV, LPC_EN, KBC_LPC_EN | MC_LPC_EN |
60 CNF1_LPC_EN | FDD_LPC_EN);
61
62 /* Stout EC Decode Range Port68/6C */
63 pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, (0x68 | 0x40001));
64}
65
66static void rcba_config(void)
67{
68 u32 reg32;
69
70 /*
71 * GFX INTA -> PIRQA (MSI)
72 * D20IP_XHCI XHCI INTA -> PIRQD (MSI)
73 * D26IP_E2P EHCI #2 INTA -> PIRQF
74 * D27IP_ZIP HDA INTA -> PIRQA (MSI)
75 * D28IP_P2IP WLAN INTA -> PIRQD
76 * D28IP_P3IP Card Reader INTB -> PIRQE
77 * D28IP_P6IP LAN INTC -> PIRQB
78 * D29IP_E1P EHCI #1 INTA -> PIRQD
79 * D31IP_SIP SATA INTA -> PIRQB (MSI)
80 * D31IP_SMIP SMBUS INTB -> PIRQH
81 */
82
83 /* Device interrupt pin register (board specific) */
84 RCBA32(D31IP) = (NOINT << D31IP_TTIP) | (NOINT << D31IP_SIP2) |
85 (INTB << D31IP_SMIP) | (INTA << D31IP_SIP);
86 RCBA32(D30IP) = (NOINT << D30IP_PIP);
87 RCBA32(D29IP) = (INTA << D29IP_E1P);
88 RCBA32(D28IP) = (NOINT << D28IP_P1IP) | (INTA << D28IP_P2IP) |
89 (INTB << D28IP_P3IP) | (NOINT << D28IP_P4IP) |
90 (NOINT << D28IP_P5IP) | (INTC << D28IP_P6IP) |
91 (NOINT << D28IP_P7IP) | (NOINT << D28IP_P8IP);
92 RCBA32(D27IP) = (INTA << D27IP_ZIP);
93 RCBA32(D26IP) = (INTA << D26IP_E2P);
94 RCBA32(D25IP) = (NOINT << D25IP_LIP);
95 RCBA32(D22IP) = (NOINT << D22IP_MEI1IP);
96 RCBA32(D20IP) = (INTA << D20IP_XHCIIP);
97
98 /* Device interrupt route registers */
99 DIR_ROUTE(D31IR, PIRQB, PIRQH, PIRQA, PIRQC);
100 DIR_ROUTE(D29IR, PIRQD, PIRQE, PIRQF, PIRQG);
101 DIR_ROUTE(D28IR, PIRQD, PIRQE, PIRQB, PIRQC);
102 DIR_ROUTE(D27IR, PIRQA, PIRQB, PIRQC, PIRQD);
103 DIR_ROUTE(D26IR, PIRQF, PIRQB, PIRQC, PIRQD);
104 DIR_ROUTE(D25IR, PIRQA, PIRQB, PIRQC, PIRQD);
105 DIR_ROUTE(D22IR, PIRQA, PIRQB, PIRQC, PIRQD);
106 DIR_ROUTE(D20IR, PIRQD, PIRQE, PIRQF, PIRQG);
107
108 /* Enable IOAPIC (generic) */
109 RCBA16(OIC) = 0x0100;
110 /* PCH BWG says to read back the IOAPIC enable register */
111 (void) RCBA16(OIC);
112
113 /* Disable unused devices (board specific) */
114 reg32 = RCBA32(FD);
115 reg32 |= PCH_DISABLE_ALWAYS;
116 /* Disable PCI bridge so MRC does not probe this bus */
117 reg32 |= PCH_DISABLE_P2P;
118 RCBA32(FD) = reg32;
119}
120
121// FIXME, this function is generic code that should go to sb/... or
122// nb/../early_init.c
123static void early_pch_init(void)
124{
125 // Nothing to do for stout
126}
127
128 /*
129 * The Stout EC needs to be reset to RW mode. It is important that
130 * the RTC_PWR_STS is not set until ramstage EC init.
131 */
132static void early_ec_init(void)
133{
134 u8 ec_status = ec_read(EC_STATUS_REG);
Kyösti Mälkki926a8d12014-04-27 22:17:22 +0300135 int rec_mode = IS_ENABLED(CONFIG_BOOTMODE_STRAPS) &&
136 get_recovery_mode_switch();
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700137
138 if (((ec_status & 0x3) == EC_IN_RO_MODE) ||
139 ((ec_status & 0x3) == EC_IN_RECOVERY_MODE)) {
140
141 printk(BIOS_DEBUG, "EC Cold Boot Detected\n");
142 if (!rec_mode) {
143 /*
144 * Tell EC to exit RO mode
145 */
146 printk(BIOS_DEBUG, "EC will exit RO mode and boot normally\n");
147 ec_write_cmd(EC_CMD_EXIT_BOOT_BLOCK);
148 die("wait for ec to reset");
149 }
150 } else {
151 printk(BIOS_DEBUG, "EC Warm Boot Detected\n");
152 ec_write_cmd(EC_CMD_WARM_RESET);
153 }
154}
155
156void main(unsigned long bist)
157{
158 int boot_mode = 0;
159 int cbmem_was_initted;
160 u32 pm1_cnt;
161 u16 pm1_sts;
162
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700163 struct pei_data pei_data = {
164 pei_version: PEI_VERSION,
165 mchbar: DEFAULT_MCHBAR,
166 dmibar: DEFAULT_DMIBAR,
167 epbar: DEFAULT_EPBAR,
168 pciexbar: CONFIG_MMCONF_BASE_ADDRESS,
169 smbusbar: SMBUS_IO_BASE,
170 wdbbar: 0x4000000,
171 wdbsize: 0x1000,
172 hpet_address: CONFIG_HPET_ADDRESS,
173 rcba: DEFAULT_RCBABASE,
174 pmbase: DEFAULT_PMBASE,
175 gpiobase: DEFAULT_GPIOBASE,
176 thermalbase: 0xfed08000,
177 system_type: 0, // 0 Mobile, 1 Desktop/Server
178 tseg_size: CONFIG_SMM_TSEG_SIZE,
179 spd_addresses: { 0xA0, 0x00,0xA4,0x00 },
180 ts_addresses: { 0x00, 0x00, 0x00, 0x00 },
181 ec_present: 1,
182 // 0 = leave channel enabled
183 // 1 = disable dimm 0 on channel
184 // 2 = disable dimm 1 on channel
185 // 3 = disable dimm 0+1 on channel
186 dimm_channel0_disabled: 2,
187 dimm_channel1_disabled: 2,
188 max_ddr3_freq: 1600,
189 usb_port_config: {
190 /* enabled usb oc pin length */
191 { 1, 0, 0x0040 }, /* P0: USB 3.0 1 (OC0) */
192 { 1, 0, 0x0040 }, /* P1: USB 3.0 2 (OC0) */
193 { 0, 1, 0x0000 }, /* P2: Empty */
194 { 1, 1, 0x0040 }, /* P3: Camera (no OC) */
195 { 1, 1, 0x0040 }, /* P4: WLAN (no OC) */
196 { 1, 1, 0x0040 }, /* P5: WWAN (no OC) */
197 { 0, 1, 0x0000 }, /* P6: Empty */
198 { 0, 1, 0x0000 }, /* P7: Empty */
199 { 0, 5, 0x0000 }, /* P8: Empty */
200 { 1, 4, 0x0040 }, /* P9: USB 2.0 (AUO4) (OC4) */
201 { 0, 5, 0x0000 }, /* P10: Empty */
202 { 0, 5, 0x0000 }, /* P11: Empty */
203 { 0, 5, 0x0000 }, /* P12: Empty */
204 { 1, 5, 0x0040 }, /* P13: Bluetooth (no OC) */
205 },
206 usb3: {
207 mode: XHCI_MODE,
208 hs_port_switch_mask: XHCI_PORTS,
209 preboot_support: XHCI_PREBOOT,
210 xhci_streams: XHCI_STREAMS,
211 },
212 };
213
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300214 timestamp_init(get_initial_timestamp());
215 timestamp_add_now(TS_START_ROMSTAGE);
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700216
217 if (bist == 0)
218 enable_lapic();
219
220 pch_enable_lpc();
221
222 /* Enable GPIOs */
223 pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1);
224 pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10);
225 setup_pch_gpios(&stout_gpio_map);
226
227 /* Initialize console device(s) */
228 console_init();
229
230 /* Halt if there was a built in self test failure */
231 report_bist_failure(bist);
232
233 if (MCHBAR16(SSKPD) == 0xCAFE) {
234 printk(BIOS_DEBUG, "soft reset detected\n");
235 boot_mode = 1;
236
237 /* System is not happy after keyboard reset... */
238 printk(BIOS_DEBUG, "Issuing CF9 warm reset\n");
239 outb(0x6, 0xcf9);
240 hlt();
241 }
242
243
244 /* Perform some early chipset initialization required
245 * before RAM initialization can work
246 */
247 sandybridge_early_initialization(SANDYBRIDGE_MOBILE);
248 printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n");
249
250 /* Check PM1_STS[15] to see if we are waking from Sx */
251 pm1_sts = inw(DEFAULT_PMBASE + PM1_STS);
252
253 /* Read PM1_CNT[12:10] to determine which Sx state */
254 pm1_cnt = inl(DEFAULT_PMBASE + PM1_CNT);
255
256 if ((pm1_sts & WAK_STS) && ((pm1_cnt >> 10) & 7) == 5) {
257#if CONFIG_HAVE_ACPI_RESUME
258 printk(BIOS_DEBUG, "Resume from S3 detected.\n");
259 boot_mode = 2;
260 /* Clear SLP_TYPE. This will break stage2 but
261 * we care for that when we get there.
262 */
263 outl(pm1_cnt & ~(7 << 10), DEFAULT_PMBASE + PM1_CNT);
264#else
265 printk(BIOS_DEBUG, "Resume from S3 detected, but disabled.\n");
266#endif
267 }
268
269 /* Do ec reset as early as possible, but skip it on S3 resume */
270 if (boot_mode < 2)
271 early_ec_init();
272
273 post_code(0x38);
274 /* Enable SPD ROMs and DDR-III DRAM */
275 enable_smbus();
276
277 /* Prepare USB controller early in S3 resume */
278 if (boot_mode == 2)
279 enable_usb_bar();
280
281 post_code(0x39);
282
283 post_code(0x3a);
284 pei_data.boot_mode = boot_mode;
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300285 timestamp_add_now(TS_BEFORE_INITRAM);
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700286 sdram_initialize(&pei_data);
287
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300288 timestamp_add_now(TS_AFTER_INITRAM);
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700289 post_code(0x3b);
290 /* Perform some initialization that must run before stage2 */
291 early_pch_init();
292 post_code(0x3c);
293
294 rcba_config();
295 post_code(0x3d);
296
297 quick_ram_check();
298 post_code(0x3e);
299
300 MCHBAR16(SSKPD) = 0xCAFE;
Kyösti Mälkki2d8520b2014-01-06 17:20:31 +0200301 cbmem_was_initted = !cbmem_recovery(boot_mode==2);
Kyösti Mälkki78938482014-01-04 11:02:45 +0200302 if (boot_mode!=2)
303 save_mrc_data(&pei_data);
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700304
305#if CONFIG_HAVE_ACPI_RESUME
306 /* If there is no high memory area, we didn't boot before, so
307 * this is not a resume. In that case we just create the cbmem toc.
308 */
309
310 *(u32 *)CBMEM_BOOT_MODE = 0;
311 *(u32 *)CBMEM_RESUME_BACKUP = 0;
312
313 if ((boot_mode == 2) && cbmem_was_initted) {
314 void *resume_backup_memory = cbmem_find(CBMEM_ID_RESUME);
315 if (resume_backup_memory) {
316 *(u32 *)CBMEM_BOOT_MODE = boot_mode;
317 *(u32 *)CBMEM_RESUME_BACKUP = (u32)resume_backup_memory;
318 }
319 /* Magic for S3 resume */
320 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafed00d);
321 } else if (boot_mode == 2) {
322 /* Failed S3 resume, reset to come up cleanly */
323 outb(0x6, 0xcf9);
324 hlt();
325 } else {
326 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafebabe);
327 }
328#endif
329 post_code(0x3f);
330#if CONFIG_CHROMEOS
331 init_chromeos(boot_mode);
332#endif
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700333 timestamp_add_now(TS_END_ROMSTAGE);
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700334}