blob: 5ace4f6e8230af979bda040165e84ef50d41d18d [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"
41#if CONFIG_CHROMEOS
42#include <vendorcode/google/chromeos/chromeos.h>
43#endif
44#include <cbfs.h>
45#include <ec/quanta/it8518/ec.h>
46#include "ec.h"
47#include "onboard.h"
48
49static void pch_enable_lpc(void)
50{
51 /*
52 * Enable:
53 * EC Decode Range Port62/66
54 * SuperIO Port2E/2F
55 * PS/2 Keyboard/Mouse Port60/64
56 * FDD Port3F0h-3F5h and Port3F7h
57 */
58 pci_write_config16(PCH_LPC_DEV, LPC_EN, KBC_LPC_EN | MC_LPC_EN |
59 CNF1_LPC_EN | FDD_LPC_EN);
60
61 /* Stout EC Decode Range Port68/6C */
62 pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, (0x68 | 0x40001));
63}
64
65static void rcba_config(void)
66{
67 u32 reg32;
68
69 /*
70 * GFX INTA -> PIRQA (MSI)
71 * D20IP_XHCI XHCI INTA -> PIRQD (MSI)
72 * D26IP_E2P EHCI #2 INTA -> PIRQF
73 * D27IP_ZIP HDA INTA -> PIRQA (MSI)
74 * D28IP_P2IP WLAN INTA -> PIRQD
75 * D28IP_P3IP Card Reader INTB -> PIRQE
76 * D28IP_P6IP LAN INTC -> PIRQB
77 * D29IP_E1P EHCI #1 INTA -> PIRQD
78 * D31IP_SIP SATA INTA -> PIRQB (MSI)
79 * D31IP_SMIP SMBUS INTB -> PIRQH
80 */
81
82 /* Device interrupt pin register (board specific) */
83 RCBA32(D31IP) = (NOINT << D31IP_TTIP) | (NOINT << D31IP_SIP2) |
84 (INTB << D31IP_SMIP) | (INTA << D31IP_SIP);
85 RCBA32(D30IP) = (NOINT << D30IP_PIP);
86 RCBA32(D29IP) = (INTA << D29IP_E1P);
87 RCBA32(D28IP) = (NOINT << D28IP_P1IP) | (INTA << D28IP_P2IP) |
88 (INTB << D28IP_P3IP) | (NOINT << D28IP_P4IP) |
89 (NOINT << D28IP_P5IP) | (INTC << D28IP_P6IP) |
90 (NOINT << D28IP_P7IP) | (NOINT << D28IP_P8IP);
91 RCBA32(D27IP) = (INTA << D27IP_ZIP);
92 RCBA32(D26IP) = (INTA << D26IP_E2P);
93 RCBA32(D25IP) = (NOINT << D25IP_LIP);
94 RCBA32(D22IP) = (NOINT << D22IP_MEI1IP);
95 RCBA32(D20IP) = (INTA << D20IP_XHCIIP);
96
97 /* Device interrupt route registers */
98 DIR_ROUTE(D31IR, PIRQB, PIRQH, PIRQA, PIRQC);
99 DIR_ROUTE(D29IR, PIRQD, PIRQE, PIRQF, PIRQG);
100 DIR_ROUTE(D28IR, PIRQD, PIRQE, PIRQB, PIRQC);
101 DIR_ROUTE(D27IR, PIRQA, PIRQB, PIRQC, PIRQD);
102 DIR_ROUTE(D26IR, PIRQF, PIRQB, PIRQC, PIRQD);
103 DIR_ROUTE(D25IR, PIRQA, PIRQB, PIRQC, PIRQD);
104 DIR_ROUTE(D22IR, PIRQA, PIRQB, PIRQC, PIRQD);
105 DIR_ROUTE(D20IR, PIRQD, PIRQE, PIRQF, PIRQG);
106
107 /* Enable IOAPIC (generic) */
108 RCBA16(OIC) = 0x0100;
109 /* PCH BWG says to read back the IOAPIC enable register */
110 (void) RCBA16(OIC);
111
112 /* Disable unused devices (board specific) */
113 reg32 = RCBA32(FD);
114 reg32 |= PCH_DISABLE_ALWAYS;
115 /* Disable PCI bridge so MRC does not probe this bus */
116 reg32 |= PCH_DISABLE_P2P;
117 RCBA32(FD) = reg32;
118}
119
120// FIXME, this function is generic code that should go to sb/... or
121// nb/../early_init.c
122static void early_pch_init(void)
123{
124 // Nothing to do for stout
125}
126
127 /*
128 * The Stout EC needs to be reset to RW mode. It is important that
129 * the RTC_PWR_STS is not set until ramstage EC init.
130 */
131static void early_ec_init(void)
132{
133 u8 ec_status = ec_read(EC_STATUS_REG);
134 int rec_mode = get_recovery_mode_switch();
135
136 if (((ec_status & 0x3) == EC_IN_RO_MODE) ||
137 ((ec_status & 0x3) == EC_IN_RECOVERY_MODE)) {
138
139 printk(BIOS_DEBUG, "EC Cold Boot Detected\n");
140 if (!rec_mode) {
141 /*
142 * Tell EC to exit RO mode
143 */
144 printk(BIOS_DEBUG, "EC will exit RO mode and boot normally\n");
145 ec_write_cmd(EC_CMD_EXIT_BOOT_BLOCK);
146 die("wait for ec to reset");
147 }
148 } else {
149 printk(BIOS_DEBUG, "EC Warm Boot Detected\n");
150 ec_write_cmd(EC_CMD_WARM_RESET);
151 }
152}
153
154void main(unsigned long bist)
155{
156 int boot_mode = 0;
157 int cbmem_was_initted;
158 u32 pm1_cnt;
159 u16 pm1_sts;
160
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700161 struct pei_data pei_data = {
162 pei_version: PEI_VERSION,
163 mchbar: DEFAULT_MCHBAR,
164 dmibar: DEFAULT_DMIBAR,
165 epbar: DEFAULT_EPBAR,
166 pciexbar: CONFIG_MMCONF_BASE_ADDRESS,
167 smbusbar: SMBUS_IO_BASE,
168 wdbbar: 0x4000000,
169 wdbsize: 0x1000,
170 hpet_address: CONFIG_HPET_ADDRESS,
171 rcba: DEFAULT_RCBABASE,
172 pmbase: DEFAULT_PMBASE,
173 gpiobase: DEFAULT_GPIOBASE,
174 thermalbase: 0xfed08000,
175 system_type: 0, // 0 Mobile, 1 Desktop/Server
176 tseg_size: CONFIG_SMM_TSEG_SIZE,
177 spd_addresses: { 0xA0, 0x00,0xA4,0x00 },
178 ts_addresses: { 0x00, 0x00, 0x00, 0x00 },
179 ec_present: 1,
180 // 0 = leave channel enabled
181 // 1 = disable dimm 0 on channel
182 // 2 = disable dimm 1 on channel
183 // 3 = disable dimm 0+1 on channel
184 dimm_channel0_disabled: 2,
185 dimm_channel1_disabled: 2,
186 max_ddr3_freq: 1600,
187 usb_port_config: {
188 /* enabled usb oc pin length */
189 { 1, 0, 0x0040 }, /* P0: USB 3.0 1 (OC0) */
190 { 1, 0, 0x0040 }, /* P1: USB 3.0 2 (OC0) */
191 { 0, 1, 0x0000 }, /* P2: Empty */
192 { 1, 1, 0x0040 }, /* P3: Camera (no OC) */
193 { 1, 1, 0x0040 }, /* P4: WLAN (no OC) */
194 { 1, 1, 0x0040 }, /* P5: WWAN (no OC) */
195 { 0, 1, 0x0000 }, /* P6: Empty */
196 { 0, 1, 0x0000 }, /* P7: Empty */
197 { 0, 5, 0x0000 }, /* P8: Empty */
198 { 1, 4, 0x0040 }, /* P9: USB 2.0 (AUO4) (OC4) */
199 { 0, 5, 0x0000 }, /* P10: Empty */
200 { 0, 5, 0x0000 }, /* P11: Empty */
201 { 0, 5, 0x0000 }, /* P12: Empty */
202 { 1, 5, 0x0040 }, /* P13: Bluetooth (no OC) */
203 },
204 usb3: {
205 mode: XHCI_MODE,
206 hs_port_switch_mask: XHCI_PORTS,
207 preboot_support: XHCI_PREBOOT,
208 xhci_streams: XHCI_STREAMS,
209 },
210 };
211
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300212 timestamp_init(get_initial_timestamp());
213 timestamp_add_now(TS_START_ROMSTAGE);
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700214
215 if (bist == 0)
216 enable_lapic();
217
218 pch_enable_lpc();
219
220 /* Enable GPIOs */
221 pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1);
222 pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10);
223 setup_pch_gpios(&stout_gpio_map);
224
225 /* Initialize console device(s) */
226 console_init();
227
228 /* Halt if there was a built in self test failure */
229 report_bist_failure(bist);
230
231 if (MCHBAR16(SSKPD) == 0xCAFE) {
232 printk(BIOS_DEBUG, "soft reset detected\n");
233 boot_mode = 1;
234
235 /* System is not happy after keyboard reset... */
236 printk(BIOS_DEBUG, "Issuing CF9 warm reset\n");
237 outb(0x6, 0xcf9);
238 hlt();
239 }
240
241
242 /* Perform some early chipset initialization required
243 * before RAM initialization can work
244 */
245 sandybridge_early_initialization(SANDYBRIDGE_MOBILE);
246 printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n");
247
248 /* Check PM1_STS[15] to see if we are waking from Sx */
249 pm1_sts = inw(DEFAULT_PMBASE + PM1_STS);
250
251 /* Read PM1_CNT[12:10] to determine which Sx state */
252 pm1_cnt = inl(DEFAULT_PMBASE + PM1_CNT);
253
254 if ((pm1_sts & WAK_STS) && ((pm1_cnt >> 10) & 7) == 5) {
255#if CONFIG_HAVE_ACPI_RESUME
256 printk(BIOS_DEBUG, "Resume from S3 detected.\n");
257 boot_mode = 2;
258 /* Clear SLP_TYPE. This will break stage2 but
259 * we care for that when we get there.
260 */
261 outl(pm1_cnt & ~(7 << 10), DEFAULT_PMBASE + PM1_CNT);
262#else
263 printk(BIOS_DEBUG, "Resume from S3 detected, but disabled.\n");
264#endif
265 }
266
267 /* Do ec reset as early as possible, but skip it on S3 resume */
268 if (boot_mode < 2)
269 early_ec_init();
270
271 post_code(0x38);
272 /* Enable SPD ROMs and DDR-III DRAM */
273 enable_smbus();
274
275 /* Prepare USB controller early in S3 resume */
276 if (boot_mode == 2)
277 enable_usb_bar();
278
279 post_code(0x39);
280
281 post_code(0x3a);
282 pei_data.boot_mode = boot_mode;
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300283 timestamp_add_now(TS_BEFORE_INITRAM);
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700284 sdram_initialize(&pei_data);
285
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300286 timestamp_add_now(TS_AFTER_INITRAM);
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700287 post_code(0x3b);
288 /* Perform some initialization that must run before stage2 */
289 early_pch_init();
290 post_code(0x3c);
291
292 rcba_config();
293 post_code(0x3d);
294
295 quick_ram_check();
296 post_code(0x3e);
297
298 MCHBAR16(SSKPD) = 0xCAFE;
299#if CONFIG_EARLY_CBMEM_INIT
300 cbmem_was_initted = !cbmem_initialize();
301#else
Kyösti Mälkkid50cdf12013-06-23 17:01:29 +0300302 cbmem_was_initted = cbmem_reinit();
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700303#endif
304
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
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300333 timestamp_sync();
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700334 timestamp_add_now(TS_END_ROMSTAGE);
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700335#if CONFIG_CONSOLE_CBMEM
336 /* Keep this the last thing this function does. */
337 cbmemc_reinit();
338#endif
339}