blob: 1fad9493c6552f9541b3661a895ca1f375d3e421 [file] [log] [blame]
Stefan Reinauere1ae4b22012-04-27 23:20:58 +02001/*
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>
Hung-Te Line29e2ff2013-01-18 16:50:25 +080025#include <arch/byteorder.h>
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020026#include <arch/io.h>
27#include <arch/romcc_io.h>
28#include <device/pci_def.h>
29#include <device/pnp_def.h>
30#include <cpu/x86/lapic.h>
31#include <pc80/mc146818rtc.h>
32#include <cbmem.h>
33#include <console/console.h>
34#include "superio/ite/it8772f/it8772f.h"
35#include "superio/ite/it8772f/early_serial.c"
36#include "northbridge/intel/sandybridge/sandybridge.h"
37#include "northbridge/intel/sandybridge/raminit.h"
38#include "southbridge/intel/bd82x6x/pch.h"
39#include "southbridge/intel/bd82x6x/gpio.h"
40#include <arch/cpu.h>
41#include <cpu/x86/bist.h>
42#include <cpu/x86/msr.h>
43#include "gpio.h"
44#if CONFIG_CONSOLE_SERIAL8250
45#include "superio/smsc/lpc47n207/lpc47n207.h"
46#include "superio/smsc/lpc47n207/early_serial.c"
47#endif
48#if CONFIG_CHROMEOS
49#include <vendorcode/google/chromeos/chromeos.h>
50#endif
51
52/* Stumpy USB Reset Disable defined in cmos.layout */
53#if CONFIG_USE_OPTION_TABLE
54#include "option_table.h"
55#define CMOS_USB_RESET_DISABLE (CMOS_VSTART_stumpy_usb_reset_disable >> 3)
56#else
57#define CMOS_USB_RESET_DISABLE (400 >> 3)
58#endif
59#define USB_RESET_DISABLE_MAGIC (0xdd) /* Disable if set to this */
60
61static void pch_enable_lpc(void)
62{
63 /* Set COM1/COM2 decode range */
64 pci_write_config16(PCH_LPC_DEV, LPC_IO_DEC, 0x0010);
65
66#if CONFIG_CONSOLE_SERIAL8250
67 /* Enable SuperIO + PS/2 Keyboard/Mouse + COM1 + lpc47n207 config*/
68 pci_write_config16(PCH_LPC_DEV, LPC_EN, CNF1_LPC_EN | KBC_LPC_EN |\
69 CNF2_LPC_EN | COMA_LPC_EN);
70
71 /* map full 256 bytes at 0x1600 to the LPC bus */
72 pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, 0xfc1601);
73
74 try_enabling_LPC47N207_uart();
75#else
76 /* Enable SuperIO + PS/2 Keyboard/Mouse */
77 pci_write_config16(PCH_LPC_DEV, LPC_EN, CNF1_LPC_EN | KBC_LPC_EN);
78#endif
79}
80
81static void rcba_config(void)
82{
83 u32 reg32;
84
85 /*
86 * GFX INTA -> PIRQA (MSI)
87 * D28IP_P1IP WLAN INTA -> PIRQB
88 * D28IP_P4IP ETH0 INTB -> PIRQC
89 * D29IP_E1P EHCI1 INTA -> PIRQD
90 * D26IP_E2P EHCI2 INTA -> PIRQE
91 * D31IP_SIP SATA INTA -> PIRQF (MSI)
92 * D31IP_SMIP SMBUS INTB -> PIRQG
93 * D31IP_TTIP THRT INTC -> PIRQH
94 * D27IP_ZIP HDA INTA -> PIRQG (MSI)
95 */
96
97 /* Device interrupt pin register (board specific) */
98 RCBA32(D31IP) = (INTC << D31IP_TTIP) | (NOINT << D31IP_SIP2) |
99 (INTB << D31IP_SMIP) | (INTA << D31IP_SIP);
100 RCBA32(D30IP) = (NOINT << D30IP_PIP);
101 RCBA32(D29IP) = (INTA << D29IP_E1P);
102 RCBA32(D28IP) = (INTA << D28IP_P1IP) | (INTC << D28IP_P3IP) |
103 (INTB << D28IP_P4IP);
104 RCBA32(D27IP) = (INTA << D27IP_ZIP);
105 RCBA32(D26IP) = (INTA << D26IP_E2P);
106 RCBA32(D25IP) = (NOINT << D25IP_LIP);
107 RCBA32(D22IP) = (NOINT << D22IP_MEI1IP);
108
109 /* Device interrupt route registers */
110 DIR_ROUTE(D31IR, PIRQF, PIRQG, PIRQH, PIRQA);
111 DIR_ROUTE(D29IR, PIRQD, PIRQE, PIRQF, PIRQG);
112 DIR_ROUTE(D28IR, PIRQB, PIRQC, PIRQD, PIRQE);
113 DIR_ROUTE(D27IR, PIRQG, PIRQH, PIRQA, PIRQB);
114 DIR_ROUTE(D26IR, PIRQE, PIRQF, PIRQG, PIRQH);
115 DIR_ROUTE(D25IR, PIRQA, PIRQB, PIRQC, PIRQD);
116 DIR_ROUTE(D22IR, PIRQA, PIRQB, PIRQC, PIRQD);
117
118 /* Enable IOAPIC (generic) */
119 RCBA16(OIC) = 0x0100;
120 /* PCH BWG says to read back the IOAPIC enable register */
121 (void) RCBA16(OIC);
122
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200123 /* Disable unused devices (board specific) */
124 reg32 = RCBA32(FD);
125 reg32 |= PCH_DISABLE_ALWAYS;
126 RCBA32(FD) = reg32;
127}
128
129static void early_pch_init(void)
130{
131 u8 reg8;
132
133 // reset rtc power status
134 reg8 = pci_read_config8(PCH_LPC_DEV, 0xa4);
135 reg8 &= ~(1 << 2);
136 pci_write_config8(PCH_LPC_DEV, 0xa4, reg8);
137}
138
139static void setup_sio_gpios(void)
140{
141 /*
142 * GPIO10 as USBPWRON12#
143 * GPIO12 as USBPWRON13#
144 */
145 it8772f_gpio_setup(1, 0x05, 0x05, 0x00, 0x05, 0x05);
146
147 /*
148 * GPIO22 as wake SCI#
149 */
150 it8772f_gpio_setup(2, 0x04, 0x04, 0x00, 0x04, 0x04);
151
152 /*
153 * GPIO32 as EXTSMI#
154 */
155 it8772f_gpio_setup(3, 0x04, 0x04, 0x00, 0x04, 0x04);
156
157 /*
158 * GPIO45 as LED_POWER#
159 */
160 it8772f_gpio_setup(4, 0x20, 0x20, 0x20, 0x20, 0x20);
161
162 /*
163 * GPIO51 as USBPWRON8#
164 * GPIO52 as USBPWRON1#
165 */
166 it8772f_gpio_setup(5, 0x06, 0x06, 0x00, 0x06, 0x06);
167 it8772f_gpio_setup(6, 0x00, 0x00, 0x00, 0x00, 0x00);
168}
169
170void main(unsigned long bist)
171{
172 int boot_mode = 0;
173 int cbmem_was_initted;
174 u32 pm1_cnt;
175 u16 pm1_sts;
176
177#if CONFIG_COLLECT_TIMESTAMPS
178 tsc_t start_romstage_time;
179 tsc_t before_dram_time;
180 tsc_t after_dram_time;
181 tsc_t base_time = {
182 .lo = pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc),
183 .hi = pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0)
184 };
185#endif
186 struct pei_data pei_data = {
Stefan Reinauere6063fe2012-04-30 14:57:51 -0700187 mchbar: DEFAULT_MCHBAR,
188 dmibar: DEFAULT_DMIBAR,
189 epbar: DEFAULT_EPBAR,
190 pciexbar: CONFIG_MMCONF_BASE_ADDRESS,
191 smbusbar: SMBUS_IO_BASE,
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200192 wdbbar: 0x4000000,
193 wdbsize: 0x1000,
Patrick Georgi9aeb6942012-10-05 21:54:38 +0200194 hpet_address: CONFIG_HPET_ADDRESS,
Stefan Reinauere6063fe2012-04-30 14:57:51 -0700195 rcba: DEFAULT_RCBABASE,
196 pmbase: DEFAULT_PMBASE,
197 gpiobase: DEFAULT_GPIOBASE,
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200198 thermalbase: 0xfed08000,
199 system_type: 0, // 0 Mobile, 1 Desktop/Server
200 tseg_size: CONFIG_SMM_TSEG_SIZE,
201 spd_addresses: { 0x50, 0x00,0x52,0x00 },
202 ts_addresses: { 0x00, 0x00, 0x00, 0x00 },
203 ec_present: 0,
204 // 0 = leave channel enabled
205 // 1 = disable dimm 0 on channel
206 // 2 = disable dimm 1 on channel
207 // 3 = disable dimm 0+1 on channel
208 dimm_channel0_disabled: 2,
209 dimm_channel1_disabled: 2,
210 usb_port_config: {
211 { 1, 0, 0x0080 }, /* P0: Front port (OC0) */
212 { 1, 1, 0x0040 }, /* P1: Back port (OC1) */
213 { 1, 0, 0x0040 }, /* P2: MINIPCIE1 (no OC) */
214 { 1, 0, 0x0040 }, /* P3: MMC (no OC) */
215 { 1, 2, 0x0080 }, /* P4: Front port (OC2) */
216 { 0, 0, 0x0000 }, /* P5: Empty */
217 { 0, 0, 0x0000 }, /* P6: Empty */
218 { 0, 0, 0x0000 }, /* P7: Empty */
219 { 1, 4, 0x0040 }, /* P8: Back port (OC4) */
220 { 1, 4, 0x0040 }, /* P9: MINIPCIE3 (no OC) */
221 { 1, 4, 0x0040 }, /* P10: BLUETOOTH (no OC) */
222 { 0, 4, 0x0000 }, /* P11: Empty */
223 { 1, 6, 0x0040 }, /* P12: Back port (OC6) */
224 { 1, 5, 0x0040 }, /* P13: Back port (OC5) */
225 },
226 };
227
228#if CONFIG_COLLECT_TIMESTAMPS
229 start_romstage_time = rdtsc();
230#endif
231
232 if (bist == 0)
233 enable_lapic();
234
235 pch_enable_lpc();
236
237 /* Enable GPIOs */
238 pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1);
239 pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10);
240 setup_pch_gpios(&stumpy_gpio_map);
241 setup_sio_gpios();
242
243 /* Early SuperIO setup */
244 it8772f_kill_watchdog();
245 it8772f_ac_resume_southbridge();
246 it8772f_enable_serial(PNP_DEV(IT8772F_BASE, IT8772F_SP1),
247 CONFIG_TTYS0_BASE);
248 console_init();
249
250#if CONFIG_CHROMEOS
251 save_chromeos_gpios();
252#endif
253
254 /* Halt if there was a built in self test failure */
255 report_bist_failure(bist);
256
257 if (MCHBAR16(SSKPD) == 0xCAFE) {
258 printk(BIOS_DEBUG, "soft reset detected\n");
259 boot_mode = 1;
260
261 /* System is not happy after keyboard reset... */
262 printk(BIOS_DEBUG, "Issuing CF9 warm reset\n");
263 outb(0x6, 0xcf9);
264 hlt();
265 }
266
267 /* Perform some early chipset initialization required
268 * before RAM initialization can work
269 */
270 sandybridge_early_initialization(SANDYBRIDGE_MOBILE);
271 printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n");
272
273 /* Check PM1_STS[15] to see if we are waking from Sx */
274 pm1_sts = inw(DEFAULT_PMBASE + PM1_STS);
275
276 /* Read PM1_CNT[12:10] to determine which Sx state */
277 pm1_cnt = inl(DEFAULT_PMBASE + PM1_CNT);
278
279 if ((pm1_sts & WAK_STS) && ((pm1_cnt >> 10) & 7) == 5) {
280#if CONFIG_HAVE_ACPI_RESUME
281 printk(BIOS_DEBUG, "Resume from S3 detected.\n");
282 boot_mode = 2;
283 /* Clear SLP_TYPE. This will break stage2 but
284 * we care for that when we get there.
285 */
286 outl(pm1_cnt & ~(7 << 10), DEFAULT_PMBASE + PM1_CNT);
287#else
288 printk(BIOS_DEBUG, "Resume from S3 detected, but disabled.\n");
289#endif
290 }
291
292 post_code(0x38);
293 /* Enable SPD ROMs and DDR-III DRAM */
294 enable_smbus();
295
296 /* Prepare USB controller early in S3 resume */
297 if (boot_mode == 2) {
298 /*
299 * For Stumpy the back USB ports are reset on resume
300 * so default to resetting the controller to make the
301 * kernel happy. There is a CMOS flag to disable the
302 * controller reset in case the kernel can tolerate
303 * the device power loss better in the future.
304 */
305 u8 magic = cmos_read(CMOS_USB_RESET_DISABLE);
306
307 if (magic == USB_RESET_DISABLE_MAGIC) {
308 printk(BIOS_DEBUG, "USB Controller Reset Disabled\n");
309 enable_usb_bar();
310 } else {
311 printk(BIOS_DEBUG, "USB Controller Reset Enabled\n");
312 }
313 } else {
314 /* Ensure USB reset on resume is enabled at boot */
315 cmos_write(0, CMOS_USB_RESET_DISABLE);
316 }
317
318 post_code(0x39);
319 pei_data.boot_mode = boot_mode;
320#if CONFIG_COLLECT_TIMESTAMPS
321 before_dram_time = rdtsc();
322#endif
323 sdram_initialize(&pei_data);
324
325#if CONFIG_COLLECT_TIMESTAMPS
326 after_dram_time = rdtsc();
327#endif
328 post_code(0x3a);
329 /* Perform some initialization that must run before stage2 */
330 early_pch_init();
331 post_code(0x3b);
332
333 rcba_config();
334 post_code(0x3c);
335
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200336 quick_ram_check();
Stefan Reinauerafcaac22012-06-18 15:43:50 -0700337 post_code(0x3e);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200338
339 MCHBAR16(SSKPD) = 0xCAFE;
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200340 cbmem_was_initted = !cbmem_initialize();
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200341
342#if CONFIG_HAVE_ACPI_RESUME
343 /* If there is no high memory area, we didn't boot before, so
344 * this is not a resume. In that case we just create the cbmem toc.
345 */
346
347 *(u32 *)CBMEM_BOOT_MODE = 0;
348 *(u32 *)CBMEM_RESUME_BACKUP = 0;
349
350 if ((boot_mode == 2) && cbmem_was_initted) {
351 void *resume_backup_memory = cbmem_find(CBMEM_ID_RESUME);
352 if (resume_backup_memory) {
353 *(u32 *)CBMEM_BOOT_MODE = boot_mode;
354 *(u32 *)CBMEM_RESUME_BACKUP = (u32)resume_backup_memory;
355 }
356 /* Magic for S3 resume */
357 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafed00d);
358 } else if (boot_mode == 2) {
359 /* Failed S3 resume, reset to come up cleanly */
360 outb(0x6, 0xcf9);
361 hlt();
362 } else {
363 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafebabe);
364 }
365#endif
366 post_code(0x3f);
367#if CONFIG_CHROMEOS
368 init_chromeos(boot_mode);
369#endif
370#if CONFIG_COLLECT_TIMESTAMPS
371 timestamp_init(base_time);
372 timestamp_add(TS_START_ROMSTAGE, start_romstage_time );
373 timestamp_add(TS_BEFORE_INITRAM, before_dram_time );
374 timestamp_add(TS_AFTER_INITRAM, after_dram_time );
375 timestamp_add_now(TS_END_ROMSTAGE);
376#endif
377#if CONFIG_CONSOLE_CBMEM
378 /* Keep this the last thing this function does. */
379 cbmemc_reinit();
380#endif
381}