blob: 625903d3f6182a1bd9ac2c72137bcd77a9aa19c1 [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>
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020037#include "northbridge/intel/sandybridge/sandybridge.h"
38#include "northbridge/intel/sandybridge/raminit.h"
39#include "southbridge/intel/bd82x6x/pch.h"
40#include "southbridge/intel/bd82x6x/gpio.h"
41#include <arch/cpu.h>
42#include <cpu/x86/bist.h>
43#include <cpu/x86/msr.h>
44#include "gpio.h"
Kyösti Mälkkiafa7b132014-02-13 17:16:22 +020045#if CONFIG_DRIVERS_UART_8250IO
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020046#include "superio/smsc/lpc47n207/lpc47n207.h"
47#include "superio/smsc/lpc47n207/early_serial.c"
48#endif
49#if CONFIG_CHROMEOS
50#include <vendorcode/google/chromeos/chromeos.h>
51#endif
52
53/* Stumpy USB Reset Disable defined in cmos.layout */
54#if CONFIG_USE_OPTION_TABLE
55#include "option_table.h"
56#define CMOS_USB_RESET_DISABLE (CMOS_VSTART_stumpy_usb_reset_disable >> 3)
57#else
58#define CMOS_USB_RESET_DISABLE (400 >> 3)
59#endif
60#define USB_RESET_DISABLE_MAGIC (0xdd) /* Disable if set to this */
61
Edward O'Callaghan1f9653a2014-07-14 16:31:25 +100062#define DUMMY_DEV PNP_DEV(0x2e, 0)
Edward O'Callaghan1b3acb12014-06-01 18:04:05 +100063#define SERIAL_DEV PNP_DEV(0x2e, IT8772F_SP1)
64#define GPIO_DEV PNP_DEV(0x2e, IT8772F_GPIO)
65
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020066static void pch_enable_lpc(void)
67{
68 /* Set COM1/COM2 decode range */
69 pci_write_config16(PCH_LPC_DEV, LPC_IO_DEC, 0x0010);
70
Kyösti Mälkkiafa7b132014-02-13 17:16:22 +020071#if CONFIG_DRIVERS_UART_8250IO
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020072 /* Enable SuperIO + PS/2 Keyboard/Mouse + COM1 + lpc47n207 config*/
73 pci_write_config16(PCH_LPC_DEV, LPC_EN, CNF1_LPC_EN | KBC_LPC_EN |\
74 CNF2_LPC_EN | COMA_LPC_EN);
75
76 /* map full 256 bytes at 0x1600 to the LPC bus */
77 pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, 0xfc1601);
78
79 try_enabling_LPC47N207_uart();
80#else
81 /* Enable SuperIO + PS/2 Keyboard/Mouse */
82 pci_write_config16(PCH_LPC_DEV, LPC_EN, CNF1_LPC_EN | KBC_LPC_EN);
83#endif
84}
85
86static void rcba_config(void)
87{
88 u32 reg32;
89
90 /*
91 * GFX INTA -> PIRQA (MSI)
92 * D28IP_P1IP WLAN INTA -> PIRQB
93 * D28IP_P4IP ETH0 INTB -> PIRQC
94 * D29IP_E1P EHCI1 INTA -> PIRQD
95 * D26IP_E2P EHCI2 INTA -> PIRQE
96 * D31IP_SIP SATA INTA -> PIRQF (MSI)
97 * D31IP_SMIP SMBUS INTB -> PIRQG
98 * D31IP_TTIP THRT INTC -> PIRQH
99 * D27IP_ZIP HDA INTA -> PIRQG (MSI)
100 */
101
102 /* Device interrupt pin register (board specific) */
103 RCBA32(D31IP) = (INTC << D31IP_TTIP) | (NOINT << D31IP_SIP2) |
104 (INTB << D31IP_SMIP) | (INTA << D31IP_SIP);
105 RCBA32(D30IP) = (NOINT << D30IP_PIP);
106 RCBA32(D29IP) = (INTA << D29IP_E1P);
107 RCBA32(D28IP) = (INTA << D28IP_P1IP) | (INTC << D28IP_P3IP) |
108 (INTB << D28IP_P4IP);
109 RCBA32(D27IP) = (INTA << D27IP_ZIP);
110 RCBA32(D26IP) = (INTA << D26IP_E2P);
111 RCBA32(D25IP) = (NOINT << D25IP_LIP);
112 RCBA32(D22IP) = (NOINT << D22IP_MEI1IP);
113
114 /* Device interrupt route registers */
115 DIR_ROUTE(D31IR, PIRQF, PIRQG, PIRQH, PIRQA);
116 DIR_ROUTE(D29IR, PIRQD, PIRQE, PIRQF, PIRQG);
117 DIR_ROUTE(D28IR, PIRQB, PIRQC, PIRQD, PIRQE);
118 DIR_ROUTE(D27IR, PIRQG, PIRQH, PIRQA, PIRQB);
119 DIR_ROUTE(D26IR, PIRQE, PIRQF, PIRQG, PIRQH);
120 DIR_ROUTE(D25IR, PIRQA, PIRQB, PIRQC, PIRQD);
121 DIR_ROUTE(D22IR, PIRQA, PIRQB, PIRQC, PIRQD);
122
123 /* Enable IOAPIC (generic) */
124 RCBA16(OIC) = 0x0100;
125 /* PCH BWG says to read back the IOAPIC enable register */
126 (void) RCBA16(OIC);
127
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200128 /* Disable unused devices (board specific) */
129 reg32 = RCBA32(FD);
130 reg32 |= PCH_DISABLE_ALWAYS;
131 RCBA32(FD) = reg32;
132}
133
134static void early_pch_init(void)
135{
136 u8 reg8;
137
138 // reset rtc power status
139 reg8 = pci_read_config8(PCH_LPC_DEV, 0xa4);
140 reg8 &= ~(1 << 2);
141 pci_write_config8(PCH_LPC_DEV, 0xa4, reg8);
142}
143
144static void setup_sio_gpios(void)
145{
146 /*
147 * GPIO10 as USBPWRON12#
148 * GPIO12 as USBPWRON13#
149 */
Edward O'Callaghan1f9653a2014-07-14 16:31:25 +1000150 it8772f_gpio_setup(DUMMY_DEV, 1, 0x05, 0x05, 0x00, 0x05, 0x05);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200151
152 /*
153 * GPIO22 as wake SCI#
154 */
Edward O'Callaghan1f9653a2014-07-14 16:31:25 +1000155 it8772f_gpio_setup(DUMMY_DEV, 2, 0x04, 0x04, 0x00, 0x04, 0x04);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200156
157 /*
158 * GPIO32 as EXTSMI#
159 */
Edward O'Callaghan1f9653a2014-07-14 16:31:25 +1000160 it8772f_gpio_setup(DUMMY_DEV, 3, 0x04, 0x04, 0x00, 0x04, 0x04);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200161
162 /*
163 * GPIO45 as LED_POWER#
164 */
Edward O'Callaghan1f9653a2014-07-14 16:31:25 +1000165 it8772f_gpio_setup(DUMMY_DEV, 4, 0x20, 0x20, 0x20, 0x20, 0x20);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200166
167 /*
168 * GPIO51 as USBPWRON8#
169 * GPIO52 as USBPWRON1#
170 */
Edward O'Callaghan1f9653a2014-07-14 16:31:25 +1000171 it8772f_gpio_setup(DUMMY_DEV, 5, 0x06, 0x06, 0x00, 0x06, 0x06);
172 it8772f_gpio_setup(DUMMY_DEV, 6, 0x00, 0x00, 0x00, 0x00, 0x00);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200173}
174
Aaron Durbina0a37272014-08-14 08:35:11 -0500175#include <cpu/intel/romstage.h>
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200176void main(unsigned long bist)
177{
178 int boot_mode = 0;
179 int cbmem_was_initted;
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200180
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200181 struct pei_data pei_data = {
Edward O'Callaghanb27d3602014-05-24 02:40:31 +1000182 .pei_version = PEI_VERSION,
183 .mchbar = DEFAULT_MCHBAR,
184 .dmibar = DEFAULT_DMIBAR,
185 .epbar = DEFAULT_EPBAR,
186 .pciexbar = CONFIG_MMCONF_BASE_ADDRESS,
187 .smbusbar = SMBUS_IO_BASE,
188 .wdbbar = 0x4000000,
189 .wdbsize = 0x1000,
190 .hpet_address = CONFIG_HPET_ADDRESS,
191 .rcba = DEFAULT_RCBABASE,
192 .pmbase = DEFAULT_PMBASE,
193 .gpiobase = DEFAULT_GPIOBASE,
194 .thermalbase = 0xfed08000,
195 .system_type = 0, // 0 Mobile, 1 Desktop/Server
196 .tseg_size = CONFIG_SMM_TSEG_SIZE,
197 .spd_addresses = { 0xa0, 0x00,0xa4,0x00 },
198 .ts_addresses = { 0x00, 0x00, 0x00, 0x00 },
199 .ec_present = 0,
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200200 // 0 = leave channel enabled
201 // 1 = disable dimm 0 on channel
202 // 2 = disable dimm 1 on channel
203 // 3 = disable dimm 0+1 on channel
Edward O'Callaghanb27d3602014-05-24 02:40:31 +1000204 .dimm_channel0_disabled = 2,
205 .dimm_channel1_disabled = 2,
206 .max_ddr3_freq = 1333,
207 .usb_port_config = {
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200208 { 1, 0, 0x0080 }, /* P0: Front port (OC0) */
209 { 1, 1, 0x0040 }, /* P1: Back port (OC1) */
210 { 1, 0, 0x0040 }, /* P2: MINIPCIE1 (no OC) */
211 { 1, 0, 0x0040 }, /* P3: MMC (no OC) */
212 { 1, 2, 0x0080 }, /* P4: Front port (OC2) */
213 { 0, 0, 0x0000 }, /* P5: Empty */
214 { 0, 0, 0x0000 }, /* P6: Empty */
215 { 0, 0, 0x0000 }, /* P7: Empty */
216 { 1, 4, 0x0040 }, /* P8: Back port (OC4) */
217 { 1, 4, 0x0040 }, /* P9: MINIPCIE3 (no OC) */
218 { 1, 4, 0x0040 }, /* P10: BLUETOOTH (no OC) */
219 { 0, 4, 0x0000 }, /* P11: Empty */
220 { 1, 6, 0x0040 }, /* P12: Back port (OC6) */
221 { 1, 5, 0x0040 }, /* P13: Back port (OC5) */
222 },
223 };
224
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300225 timestamp_init(get_initial_timestamp());
226 timestamp_add_now(TS_START_ROMSTAGE);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200227
228 if (bist == 0)
229 enable_lapic();
230
231 pch_enable_lpc();
232
233 /* Enable GPIOs */
234 pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1);
235 pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10);
236 setup_pch_gpios(&stumpy_gpio_map);
237 setup_sio_gpios();
238
239 /* Early SuperIO setup */
Edward O'Callaghan1f9653a2014-07-14 16:31:25 +1000240 it8772f_ac_resume_southbridge(DUMMY_DEV);
Edward O'Callaghan1b3acb12014-06-01 18:04:05 +1000241 ite_kill_watchdog(GPIO_DEV);
242 ite_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200243 console_init();
244
Kyösti Mälkkie3ddee02014-05-03 10:45:28 +0300245 init_bootmode_straps();
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200246
247 /* Halt if there was a built in self test failure */
248 report_bist_failure(bist);
249
250 if (MCHBAR16(SSKPD) == 0xCAFE) {
251 printk(BIOS_DEBUG, "soft reset detected\n");
252 boot_mode = 1;
253
254 /* System is not happy after keyboard reset... */
255 printk(BIOS_DEBUG, "Issuing CF9 warm reset\n");
256 outb(0x6, 0xcf9);
257 hlt();
258 }
259
260 /* Perform some early chipset initialization required
261 * before RAM initialization can work
262 */
263 sandybridge_early_initialization(SANDYBRIDGE_MOBILE);
264 printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n");
265
Vladimir Serbinenko332f14b2014-09-05 16:29:41 +0200266 boot_mode = southbridge_detect_s3_resume() ? 2 : 0;
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200267
268 post_code(0x38);
269 /* Enable SPD ROMs and DDR-III DRAM */
270 enable_smbus();
271
272 /* Prepare USB controller early in S3 resume */
273 if (boot_mode == 2) {
274 /*
275 * For Stumpy the back USB ports are reset on resume
276 * so default to resetting the controller to make the
277 * kernel happy. There is a CMOS flag to disable the
278 * controller reset in case the kernel can tolerate
279 * the device power loss better in the future.
280 */
281 u8 magic = cmos_read(CMOS_USB_RESET_DISABLE);
282
283 if (magic == USB_RESET_DISABLE_MAGIC) {
284 printk(BIOS_DEBUG, "USB Controller Reset Disabled\n");
285 enable_usb_bar();
286 } else {
287 printk(BIOS_DEBUG, "USB Controller Reset Enabled\n");
288 }
289 } else {
290 /* Ensure USB reset on resume is enabled at boot */
291 cmos_write(0, CMOS_USB_RESET_DISABLE);
292 }
293
294 post_code(0x39);
295 pei_data.boot_mode = boot_mode;
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300296 timestamp_add_now(TS_BEFORE_INITRAM);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200297 sdram_initialize(&pei_data);
298
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300299 timestamp_add_now(TS_AFTER_INITRAM);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200300 post_code(0x3a);
301 /* Perform some initialization that must run before stage2 */
302 early_pch_init();
303 post_code(0x3b);
304
305 rcba_config();
306 post_code(0x3c);
307
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200308 quick_ram_check();
Stefan Reinauerafcaac22012-06-18 15:43:50 -0700309 post_code(0x3e);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200310
Kyösti Mälkki2d8520b2014-01-06 17:20:31 +0200311 cbmem_was_initted = !cbmem_recovery(boot_mode==2);
Kyösti Mälkki78938482014-01-04 11:02:45 +0200312 if (boot_mode!=2)
313 save_mrc_data(&pei_data);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200314
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200315 if (boot_mode==2 && !cbmem_was_initted) {
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200316 /* Failed S3 resume, reset to come up cleanly */
317 outb(0x6, 0xcf9);
318 hlt();
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200319 }
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200320 northbridge_romstage_finalize(boot_mode==2);
321
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200322 post_code(0x3f);
323#if CONFIG_CHROMEOS
324 init_chromeos(boot_mode);
325#endif
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200326 timestamp_add_now(TS_END_ROMSTAGE);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200327}