blob: 6ab7007dbb6006b77d6966e7a99179749a47e910 [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>
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020027#include <device/pci_def.h>
28#include <device/pnp_def.h>
29#include <cpu/x86/lapic.h>
30#include <pc80/mc146818rtc.h>
Kyösti Mälkki6722f8d2014-06-16 09:14:49 +030031#include <arch/acpi.h>
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020032#include <cbmem.h>
33#include <console/console.h>
Kyösti Mälkkie3ddee02014-05-03 10:45:28 +030034#include <bootmode.h>
Edward O'Callaghan1b3acb12014-06-01 18:04:05 +100035#include <superio/ite/common/ite.h>
36#include <superio/ite/it8772f/it8772f.h>
37/* FIXME: SUPERIO include.c */
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020038#include "superio/ite/it8772f/early_serial.c"
39#include "northbridge/intel/sandybridge/sandybridge.h"
40#include "northbridge/intel/sandybridge/raminit.h"
41#include "southbridge/intel/bd82x6x/pch.h"
42#include "southbridge/intel/bd82x6x/gpio.h"
43#include <arch/cpu.h>
44#include <cpu/x86/bist.h>
45#include <cpu/x86/msr.h>
46#include "gpio.h"
Kyösti Mälkkiafa7b132014-02-13 17:16:22 +020047#if CONFIG_DRIVERS_UART_8250IO
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020048#include "superio/smsc/lpc47n207/lpc47n207.h"
49#include "superio/smsc/lpc47n207/early_serial.c"
50#endif
51#if CONFIG_CHROMEOS
52#include <vendorcode/google/chromeos/chromeos.h>
53#endif
54
55/* Stumpy USB Reset Disable defined in cmos.layout */
56#if CONFIG_USE_OPTION_TABLE
57#include "option_table.h"
58#define CMOS_USB_RESET_DISABLE (CMOS_VSTART_stumpy_usb_reset_disable >> 3)
59#else
60#define CMOS_USB_RESET_DISABLE (400 >> 3)
61#endif
62#define USB_RESET_DISABLE_MAGIC (0xdd) /* Disable if set to this */
63
Edward O'Callaghan1b3acb12014-06-01 18:04:05 +100064#define SERIAL_DEV PNP_DEV(0x2e, IT8772F_SP1)
65#define GPIO_DEV PNP_DEV(0x2e, IT8772F_GPIO)
66
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020067static void pch_enable_lpc(void)
68{
69 /* Set COM1/COM2 decode range */
70 pci_write_config16(PCH_LPC_DEV, LPC_IO_DEC, 0x0010);
71
Kyösti Mälkkiafa7b132014-02-13 17:16:22 +020072#if CONFIG_DRIVERS_UART_8250IO
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020073 /* Enable SuperIO + PS/2 Keyboard/Mouse + COM1 + lpc47n207 config*/
74 pci_write_config16(PCH_LPC_DEV, LPC_EN, CNF1_LPC_EN | KBC_LPC_EN |\
75 CNF2_LPC_EN | COMA_LPC_EN);
76
77 /* map full 256 bytes at 0x1600 to the LPC bus */
78 pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, 0xfc1601);
79
80 try_enabling_LPC47N207_uart();
81#else
82 /* Enable SuperIO + PS/2 Keyboard/Mouse */
83 pci_write_config16(PCH_LPC_DEV, LPC_EN, CNF1_LPC_EN | KBC_LPC_EN);
84#endif
85}
86
87static void rcba_config(void)
88{
89 u32 reg32;
90
91 /*
92 * GFX INTA -> PIRQA (MSI)
93 * D28IP_P1IP WLAN INTA -> PIRQB
94 * D28IP_P4IP ETH0 INTB -> PIRQC
95 * D29IP_E1P EHCI1 INTA -> PIRQD
96 * D26IP_E2P EHCI2 INTA -> PIRQE
97 * D31IP_SIP SATA INTA -> PIRQF (MSI)
98 * D31IP_SMIP SMBUS INTB -> PIRQG
99 * D31IP_TTIP THRT INTC -> PIRQH
100 * D27IP_ZIP HDA INTA -> PIRQG (MSI)
101 */
102
103 /* Device interrupt pin register (board specific) */
104 RCBA32(D31IP) = (INTC << D31IP_TTIP) | (NOINT << D31IP_SIP2) |
105 (INTB << D31IP_SMIP) | (INTA << D31IP_SIP);
106 RCBA32(D30IP) = (NOINT << D30IP_PIP);
107 RCBA32(D29IP) = (INTA << D29IP_E1P);
108 RCBA32(D28IP) = (INTA << D28IP_P1IP) | (INTC << D28IP_P3IP) |
109 (INTB << D28IP_P4IP);
110 RCBA32(D27IP) = (INTA << D27IP_ZIP);
111 RCBA32(D26IP) = (INTA << D26IP_E2P);
112 RCBA32(D25IP) = (NOINT << D25IP_LIP);
113 RCBA32(D22IP) = (NOINT << D22IP_MEI1IP);
114
115 /* Device interrupt route registers */
116 DIR_ROUTE(D31IR, PIRQF, PIRQG, PIRQH, PIRQA);
117 DIR_ROUTE(D29IR, PIRQD, PIRQE, PIRQF, PIRQG);
118 DIR_ROUTE(D28IR, PIRQB, PIRQC, PIRQD, PIRQE);
119 DIR_ROUTE(D27IR, PIRQG, PIRQH, PIRQA, PIRQB);
120 DIR_ROUTE(D26IR, PIRQE, PIRQF, PIRQG, PIRQH);
121 DIR_ROUTE(D25IR, PIRQA, PIRQB, PIRQC, PIRQD);
122 DIR_ROUTE(D22IR, PIRQA, PIRQB, PIRQC, PIRQD);
123
124 /* Enable IOAPIC (generic) */
125 RCBA16(OIC) = 0x0100;
126 /* PCH BWG says to read back the IOAPIC enable register */
127 (void) RCBA16(OIC);
128
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200129 /* Disable unused devices (board specific) */
130 reg32 = RCBA32(FD);
131 reg32 |= PCH_DISABLE_ALWAYS;
132 RCBA32(FD) = reg32;
133}
134
135static void early_pch_init(void)
136{
137 u8 reg8;
138
139 // reset rtc power status
140 reg8 = pci_read_config8(PCH_LPC_DEV, 0xa4);
141 reg8 &= ~(1 << 2);
142 pci_write_config8(PCH_LPC_DEV, 0xa4, reg8);
143}
144
145static void setup_sio_gpios(void)
146{
147 /*
148 * GPIO10 as USBPWRON12#
149 * GPIO12 as USBPWRON13#
150 */
151 it8772f_gpio_setup(1, 0x05, 0x05, 0x00, 0x05, 0x05);
152
153 /*
154 * GPIO22 as wake SCI#
155 */
156 it8772f_gpio_setup(2, 0x04, 0x04, 0x00, 0x04, 0x04);
157
158 /*
159 * GPIO32 as EXTSMI#
160 */
161 it8772f_gpio_setup(3, 0x04, 0x04, 0x00, 0x04, 0x04);
162
163 /*
164 * GPIO45 as LED_POWER#
165 */
166 it8772f_gpio_setup(4, 0x20, 0x20, 0x20, 0x20, 0x20);
167
168 /*
169 * GPIO51 as USBPWRON8#
170 * GPIO52 as USBPWRON1#
171 */
172 it8772f_gpio_setup(5, 0x06, 0x06, 0x00, 0x06, 0x06);
173 it8772f_gpio_setup(6, 0x00, 0x00, 0x00, 0x00, 0x00);
174}
175
176void main(unsigned long bist)
177{
178 int boot_mode = 0;
179 int cbmem_was_initted;
180 u32 pm1_cnt;
181 u16 pm1_sts;
182
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200183 struct pei_data pei_data = {
Edward O'Callaghanb27d3602014-05-24 02:40:31 +1000184 .pei_version = PEI_VERSION,
185 .mchbar = DEFAULT_MCHBAR,
186 .dmibar = DEFAULT_DMIBAR,
187 .epbar = DEFAULT_EPBAR,
188 .pciexbar = CONFIG_MMCONF_BASE_ADDRESS,
189 .smbusbar = SMBUS_IO_BASE,
190 .wdbbar = 0x4000000,
191 .wdbsize = 0x1000,
192 .hpet_address = CONFIG_HPET_ADDRESS,
193 .rcba = DEFAULT_RCBABASE,
194 .pmbase = DEFAULT_PMBASE,
195 .gpiobase = DEFAULT_GPIOBASE,
196 .thermalbase = 0xfed08000,
197 .system_type = 0, // 0 Mobile, 1 Desktop/Server
198 .tseg_size = CONFIG_SMM_TSEG_SIZE,
199 .spd_addresses = { 0xa0, 0x00,0xa4,0x00 },
200 .ts_addresses = { 0x00, 0x00, 0x00, 0x00 },
201 .ec_present = 0,
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200202 // 0 = leave channel enabled
203 // 1 = disable dimm 0 on channel
204 // 2 = disable dimm 1 on channel
205 // 3 = disable dimm 0+1 on channel
Edward O'Callaghanb27d3602014-05-24 02:40:31 +1000206 .dimm_channel0_disabled = 2,
207 .dimm_channel1_disabled = 2,
208 .max_ddr3_freq = 1333,
209 .usb_port_config = {
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200210 { 1, 0, 0x0080 }, /* P0: Front port (OC0) */
211 { 1, 1, 0x0040 }, /* P1: Back port (OC1) */
212 { 1, 0, 0x0040 }, /* P2: MINIPCIE1 (no OC) */
213 { 1, 0, 0x0040 }, /* P3: MMC (no OC) */
214 { 1, 2, 0x0080 }, /* P4: Front port (OC2) */
215 { 0, 0, 0x0000 }, /* P5: Empty */
216 { 0, 0, 0x0000 }, /* P6: Empty */
217 { 0, 0, 0x0000 }, /* P7: Empty */
218 { 1, 4, 0x0040 }, /* P8: Back port (OC4) */
219 { 1, 4, 0x0040 }, /* P9: MINIPCIE3 (no OC) */
220 { 1, 4, 0x0040 }, /* P10: BLUETOOTH (no OC) */
221 { 0, 4, 0x0000 }, /* P11: Empty */
222 { 1, 6, 0x0040 }, /* P12: Back port (OC6) */
223 { 1, 5, 0x0040 }, /* P13: Back port (OC5) */
224 },
225 };
226
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300227 timestamp_init(get_initial_timestamp());
228 timestamp_add_now(TS_START_ROMSTAGE);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200229
230 if (bist == 0)
231 enable_lapic();
232
233 pch_enable_lpc();
234
235 /* Enable GPIOs */
236 pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1);
237 pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10);
238 setup_pch_gpios(&stumpy_gpio_map);
239 setup_sio_gpios();
240
241 /* Early SuperIO setup */
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200242 it8772f_ac_resume_southbridge();
Edward O'Callaghan1b3acb12014-06-01 18:04:05 +1000243 ite_kill_watchdog(GPIO_DEV);
244 ite_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200245 console_init();
246
Kyösti Mälkkie3ddee02014-05-03 10:45:28 +0300247 init_bootmode_straps();
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200248
249 /* Halt if there was a built in self test failure */
250 report_bist_failure(bist);
251
252 if (MCHBAR16(SSKPD) == 0xCAFE) {
253 printk(BIOS_DEBUG, "soft reset detected\n");
254 boot_mode = 1;
255
256 /* System is not happy after keyboard reset... */
257 printk(BIOS_DEBUG, "Issuing CF9 warm reset\n");
258 outb(0x6, 0xcf9);
259 hlt();
260 }
261
262 /* Perform some early chipset initialization required
263 * before RAM initialization can work
264 */
265 sandybridge_early_initialization(SANDYBRIDGE_MOBILE);
266 printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n");
267
268 /* Check PM1_STS[15] to see if we are waking from Sx */
269 pm1_sts = inw(DEFAULT_PMBASE + PM1_STS);
270
271 /* Read PM1_CNT[12:10] to determine which Sx state */
272 pm1_cnt = inl(DEFAULT_PMBASE + PM1_CNT);
273
274 if ((pm1_sts & WAK_STS) && ((pm1_cnt >> 10) & 7) == 5) {
Kyösti Mälkki6722f8d2014-06-16 09:14:49 +0300275 if (acpi_s3_resume_allowed()) {
276 printk(BIOS_DEBUG, "Resume from S3 detected.\n");
277 boot_mode = 2;
278 /* Clear SLP_TYPE. This will break stage2 but
279 * we care for that when we get there.
280 */
281 outl(pm1_cnt & ~(7 << 10), DEFAULT_PMBASE + PM1_CNT);
282 } else {
283 printk(BIOS_DEBUG, "Resume from S3 detected, but disabled.\n");
284 }
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200285 }
286
287 post_code(0x38);
288 /* Enable SPD ROMs and DDR-III DRAM */
289 enable_smbus();
290
291 /* Prepare USB controller early in S3 resume */
292 if (boot_mode == 2) {
293 /*
294 * For Stumpy the back USB ports are reset on resume
295 * so default to resetting the controller to make the
296 * kernel happy. There is a CMOS flag to disable the
297 * controller reset in case the kernel can tolerate
298 * the device power loss better in the future.
299 */
300 u8 magic = cmos_read(CMOS_USB_RESET_DISABLE);
301
302 if (magic == USB_RESET_DISABLE_MAGIC) {
303 printk(BIOS_DEBUG, "USB Controller Reset Disabled\n");
304 enable_usb_bar();
305 } else {
306 printk(BIOS_DEBUG, "USB Controller Reset Enabled\n");
307 }
308 } else {
309 /* Ensure USB reset on resume is enabled at boot */
310 cmos_write(0, CMOS_USB_RESET_DISABLE);
311 }
312
313 post_code(0x39);
314 pei_data.boot_mode = boot_mode;
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300315 timestamp_add_now(TS_BEFORE_INITRAM);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200316 sdram_initialize(&pei_data);
317
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300318 timestamp_add_now(TS_AFTER_INITRAM);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200319 post_code(0x3a);
320 /* Perform some initialization that must run before stage2 */
321 early_pch_init();
322 post_code(0x3b);
323
324 rcba_config();
325 post_code(0x3c);
326
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200327 quick_ram_check();
Stefan Reinauerafcaac22012-06-18 15:43:50 -0700328 post_code(0x3e);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200329
330 MCHBAR16(SSKPD) = 0xCAFE;
Kyösti Mälkki2d8520b2014-01-06 17:20:31 +0200331 cbmem_was_initted = !cbmem_recovery(boot_mode==2);
Kyösti Mälkki78938482014-01-04 11:02:45 +0200332 if (boot_mode!=2)
333 save_mrc_data(&pei_data);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200334
335#if CONFIG_HAVE_ACPI_RESUME
336 /* If there is no high memory area, we didn't boot before, so
337 * this is not a resume. In that case we just create the cbmem toc.
338 */
339
340 *(u32 *)CBMEM_BOOT_MODE = 0;
341 *(u32 *)CBMEM_RESUME_BACKUP = 0;
342
343 if ((boot_mode == 2) && cbmem_was_initted) {
344 void *resume_backup_memory = cbmem_find(CBMEM_ID_RESUME);
345 if (resume_backup_memory) {
346 *(u32 *)CBMEM_BOOT_MODE = boot_mode;
347 *(u32 *)CBMEM_RESUME_BACKUP = (u32)resume_backup_memory;
348 }
349 /* Magic for S3 resume */
350 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafed00d);
351 } else if (boot_mode == 2) {
352 /* Failed S3 resume, reset to come up cleanly */
353 outb(0x6, 0xcf9);
354 hlt();
355 } else {
356 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafebabe);
357 }
358#endif
359 post_code(0x3f);
360#if CONFIG_CHROMEOS
361 init_chromeos(boot_mode);
362#endif
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200363 timestamp_add_now(TS_END_ROMSTAGE);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200364}