blob: 346026f45ed597d2f06154d57fe353e227ffb3f6 [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>
25#include <arch/io.h>
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020026#include <device/pci_def.h>
27#include <device/pnp_def.h>
28#include <cpu/x86/lapic.h>
29#include <pc80/mc146818rtc.h>
Kyösti Mälkki6722f8d2014-06-16 09:14:49 +030030#include <arch/acpi.h>
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020031#include <cbmem.h>
32#include <console/console.h>
Kyösti Mälkkie3ddee02014-05-03 10:45:28 +030033#include <bootmode.h>
Edward O'Callaghan1b3acb12014-06-01 18:04:05 +100034#include <superio/ite/common/ite.h>
35#include <superio/ite/it8772f/it8772f.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110036#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>
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020040#include <arch/cpu.h>
41#include <cpu/x86/bist.h>
42#include <cpu/x86/msr.h>
Patrick Georgibd79c5e2014-11-28 22:35:36 +010043#include <halt.h>
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020044#include "gpio.h"
Kyösti Mälkkiafa7b132014-02-13 17:16:22 +020045#if CONFIG_DRIVERS_UART_8250IO
Edward O'Callaghan74834e02015-01-04 04:17:35 +110046#include <superio/smsc/lpc47n207/lpc47n207.h>
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020047#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
Edward O'Callaghan1f9653a2014-07-14 16:31:25 +100061#define DUMMY_DEV PNP_DEV(0x2e, 0)
Edward O'Callaghan1b3acb12014-06-01 18:04:05 +100062#define SERIAL_DEV PNP_DEV(0x2e, IT8772F_SP1)
63#define GPIO_DEV PNP_DEV(0x2e, IT8772F_GPIO)
64
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020065static void pch_enable_lpc(void)
66{
67 /* Set COM1/COM2 decode range */
68 pci_write_config16(PCH_LPC_DEV, LPC_IO_DEC, 0x0010);
69
Kyösti Mälkkiafa7b132014-02-13 17:16:22 +020070#if CONFIG_DRIVERS_UART_8250IO
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020071 /* Enable SuperIO + PS/2 Keyboard/Mouse + COM1 + lpc47n207 config*/
72 pci_write_config16(PCH_LPC_DEV, LPC_EN, CNF1_LPC_EN | KBC_LPC_EN |\
73 CNF2_LPC_EN | COMA_LPC_EN);
74
75 /* map full 256 bytes at 0x1600 to the LPC bus */
76 pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, 0xfc1601);
77
78 try_enabling_LPC47N207_uart();
79#else
80 /* Enable SuperIO + PS/2 Keyboard/Mouse */
81 pci_write_config16(PCH_LPC_DEV, LPC_EN, CNF1_LPC_EN | KBC_LPC_EN);
82#endif
83}
84
85static void rcba_config(void)
86{
87 u32 reg32;
88
Vladimir Serbinenko33b535f2014-10-19 10:13:14 +020089 southbridge_configure_default_intmap();
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020090
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020091 /* Disable unused devices (board specific) */
92 reg32 = RCBA32(FD);
93 reg32 |= PCH_DISABLE_ALWAYS;
94 RCBA32(FD) = reg32;
95}
96
97static void early_pch_init(void)
98{
99 u8 reg8;
100
101 // reset rtc power status
102 reg8 = pci_read_config8(PCH_LPC_DEV, 0xa4);
103 reg8 &= ~(1 << 2);
104 pci_write_config8(PCH_LPC_DEV, 0xa4, reg8);
105}
106
107static void setup_sio_gpios(void)
108{
109 /*
110 * GPIO10 as USBPWRON12#
111 * GPIO12 as USBPWRON13#
112 */
Edward O'Callaghan1f9653a2014-07-14 16:31:25 +1000113 it8772f_gpio_setup(DUMMY_DEV, 1, 0x05, 0x05, 0x00, 0x05, 0x05);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200114
115 /*
116 * GPIO22 as wake SCI#
117 */
Edward O'Callaghan1f9653a2014-07-14 16:31:25 +1000118 it8772f_gpio_setup(DUMMY_DEV, 2, 0x04, 0x04, 0x00, 0x04, 0x04);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200119
120 /*
121 * GPIO32 as EXTSMI#
122 */
Edward O'Callaghan1f9653a2014-07-14 16:31:25 +1000123 it8772f_gpio_setup(DUMMY_DEV, 3, 0x04, 0x04, 0x00, 0x04, 0x04);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200124
125 /*
126 * GPIO45 as LED_POWER#
127 */
Edward O'Callaghan1f9653a2014-07-14 16:31:25 +1000128 it8772f_gpio_setup(DUMMY_DEV, 4, 0x20, 0x20, 0x20, 0x20, 0x20);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200129
130 /*
131 * GPIO51 as USBPWRON8#
132 * GPIO52 as USBPWRON1#
133 */
Edward O'Callaghan1f9653a2014-07-14 16:31:25 +1000134 it8772f_gpio_setup(DUMMY_DEV, 5, 0x06, 0x06, 0x00, 0x06, 0x06);
135 it8772f_gpio_setup(DUMMY_DEV, 6, 0x00, 0x00, 0x00, 0x00, 0x00);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200136}
137
Aaron Durbina0a37272014-08-14 08:35:11 -0500138#include <cpu/intel/romstage.h>
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200139void main(unsigned long bist)
140{
141 int boot_mode = 0;
142 int cbmem_was_initted;
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200143
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200144 struct pei_data pei_data = {
Edward O'Callaghanb27d3602014-05-24 02:40:31 +1000145 .pei_version = PEI_VERSION,
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800146 .mchbar = (uintptr_t)DEFAULT_MCHBAR,
147 .dmibar = (uintptr_t)DEFAULT_DMIBAR,
Edward O'Callaghanb27d3602014-05-24 02:40:31 +1000148 .epbar = DEFAULT_EPBAR,
149 .pciexbar = CONFIG_MMCONF_BASE_ADDRESS,
150 .smbusbar = SMBUS_IO_BASE,
151 .wdbbar = 0x4000000,
152 .wdbsize = 0x1000,
153 .hpet_address = CONFIG_HPET_ADDRESS,
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800154 .rcba = (uintptr_t)DEFAULT_RCBABASE,
Edward O'Callaghanb27d3602014-05-24 02:40:31 +1000155 .pmbase = DEFAULT_PMBASE,
156 .gpiobase = DEFAULT_GPIOBASE,
157 .thermalbase = 0xfed08000,
158 .system_type = 0, // 0 Mobile, 1 Desktop/Server
159 .tseg_size = CONFIG_SMM_TSEG_SIZE,
160 .spd_addresses = { 0xa0, 0x00,0xa4,0x00 },
161 .ts_addresses = { 0x00, 0x00, 0x00, 0x00 },
162 .ec_present = 0,
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200163 // 0 = leave channel enabled
164 // 1 = disable dimm 0 on channel
165 // 2 = disable dimm 1 on channel
166 // 3 = disable dimm 0+1 on channel
Edward O'Callaghanb27d3602014-05-24 02:40:31 +1000167 .dimm_channel0_disabled = 2,
168 .dimm_channel1_disabled = 2,
169 .max_ddr3_freq = 1333,
170 .usb_port_config = {
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200171 { 1, 0, 0x0080 }, /* P0: Front port (OC0) */
172 { 1, 1, 0x0040 }, /* P1: Back port (OC1) */
173 { 1, 0, 0x0040 }, /* P2: MINIPCIE1 (no OC) */
174 { 1, 0, 0x0040 }, /* P3: MMC (no OC) */
175 { 1, 2, 0x0080 }, /* P4: Front port (OC2) */
176 { 0, 0, 0x0000 }, /* P5: Empty */
177 { 0, 0, 0x0000 }, /* P6: Empty */
178 { 0, 0, 0x0000 }, /* P7: Empty */
179 { 1, 4, 0x0040 }, /* P8: Back port (OC4) */
180 { 1, 4, 0x0040 }, /* P9: MINIPCIE3 (no OC) */
181 { 1, 4, 0x0040 }, /* P10: BLUETOOTH (no OC) */
182 { 0, 4, 0x0000 }, /* P11: Empty */
183 { 1, 6, 0x0040 }, /* P12: Back port (OC6) */
184 { 1, 5, 0x0040 }, /* P13: Back port (OC5) */
185 },
186 };
187
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300188 timestamp_init(get_initial_timestamp());
189 timestamp_add_now(TS_START_ROMSTAGE);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200190
191 if (bist == 0)
192 enable_lapic();
193
194 pch_enable_lpc();
195
196 /* Enable GPIOs */
197 pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1);
198 pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10);
199 setup_pch_gpios(&stumpy_gpio_map);
200 setup_sio_gpios();
201
202 /* Early SuperIO setup */
Edward O'Callaghan1f9653a2014-07-14 16:31:25 +1000203 it8772f_ac_resume_southbridge(DUMMY_DEV);
Edward O'Callaghan1b3acb12014-06-01 18:04:05 +1000204 ite_kill_watchdog(GPIO_DEV);
205 ite_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200206 console_init();
207
Kyösti Mälkkie3ddee02014-05-03 10:45:28 +0300208 init_bootmode_straps();
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200209
210 /* Halt if there was a built in self test failure */
211 report_bist_failure(bist);
212
213 if (MCHBAR16(SSKPD) == 0xCAFE) {
214 printk(BIOS_DEBUG, "soft reset detected\n");
215 boot_mode = 1;
216
217 /* System is not happy after keyboard reset... */
218 printk(BIOS_DEBUG, "Issuing CF9 warm reset\n");
219 outb(0x6, 0xcf9);
Patrick Georgibd79c5e2014-11-28 22:35:36 +0100220 halt();
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200221 }
222
223 /* Perform some early chipset initialization required
224 * before RAM initialization can work
225 */
226 sandybridge_early_initialization(SANDYBRIDGE_MOBILE);
227 printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n");
228
Vladimir Serbinenko332f14b2014-09-05 16:29:41 +0200229 boot_mode = southbridge_detect_s3_resume() ? 2 : 0;
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200230
231 post_code(0x38);
232 /* Enable SPD ROMs and DDR-III DRAM */
233 enable_smbus();
234
235 /* Prepare USB controller early in S3 resume */
236 if (boot_mode == 2) {
237 /*
238 * For Stumpy the back USB ports are reset on resume
239 * so default to resetting the controller to make the
240 * kernel happy. There is a CMOS flag to disable the
241 * controller reset in case the kernel can tolerate
242 * the device power loss better in the future.
243 */
244 u8 magic = cmos_read(CMOS_USB_RESET_DISABLE);
245
246 if (magic == USB_RESET_DISABLE_MAGIC) {
247 printk(BIOS_DEBUG, "USB Controller Reset Disabled\n");
248 enable_usb_bar();
249 } else {
250 printk(BIOS_DEBUG, "USB Controller Reset Enabled\n");
251 }
252 } else {
253 /* Ensure USB reset on resume is enabled at boot */
254 cmos_write(0, CMOS_USB_RESET_DISABLE);
255 }
256
257 post_code(0x39);
258 pei_data.boot_mode = boot_mode;
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300259 timestamp_add_now(TS_BEFORE_INITRAM);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200260 sdram_initialize(&pei_data);
261
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300262 timestamp_add_now(TS_AFTER_INITRAM);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200263 post_code(0x3a);
264 /* Perform some initialization that must run before stage2 */
265 early_pch_init();
266 post_code(0x3b);
267
268 rcba_config();
269 post_code(0x3c);
270
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200271 quick_ram_check();
Stefan Reinauerafcaac22012-06-18 15:43:50 -0700272 post_code(0x3e);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200273
Kyösti Mälkki2d8520b2014-01-06 17:20:31 +0200274 cbmem_was_initted = !cbmem_recovery(boot_mode==2);
Kyösti Mälkki78938482014-01-04 11:02:45 +0200275 if (boot_mode!=2)
276 save_mrc_data(&pei_data);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200277
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200278 if (boot_mode==2 && !cbmem_was_initted) {
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200279 /* Failed S3 resume, reset to come up cleanly */
280 outb(0x6, 0xcf9);
Patrick Georgibd79c5e2014-11-28 22:35:36 +0100281 halt();
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200282 }
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200283 northbridge_romstage_finalize(boot_mode==2);
284
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200285 post_code(0x3f);
286#if CONFIG_CHROMEOS
287 init_chromeos(boot_mode);
288#endif
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200289 timestamp_add_now(TS_END_ROMSTAGE);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200290}