blob: d50093e08d9bfa681f01fae68a81d413f82cd06f [file] [log] [blame]
Stefan Reinauer6651da32012-04-27 23:16:30 +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 Reinauer6651da32012-04-27 23:16:30 +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 Reinauer6651da32012-04-27 23:16:30 +020031#include <cbmem.h>
32#include <console/console.h>
Marc Jones04134a52013-10-30 16:18:07 -060033#include "superio/smsc/sio1007/chip.h"
Stefan Reinauer6651da32012-04-27 23:16:30 +020034#include "northbridge/intel/sandybridge/sandybridge.h"
35#include "northbridge/intel/sandybridge/raminit.h"
36#include "southbridge/intel/bd82x6x/pch.h"
37#include "southbridge/intel/bd82x6x/gpio.h"
38#include <arch/cpu.h>
39#include <cpu/x86/bist.h>
40#include <cpu/x86/msr.h>
41#include "gpio.h"
42#if CONFIG_CHROMEOS
43#include <vendorcode/google/chromeos/chromeos.h>
44#endif
45
Marc Jonesc4b6f3b2013-11-05 17:47:37 -070046#define SIO_PORT 0x164e
47
Stefan Reinauer6651da32012-04-27 23:16:30 +020048static void pch_enable_lpc(void)
49{
50 device_t dev = PCH_LPC_DEV;
Stefan Reinauer6651da32012-04-27 23:16:30 +020051
52 /* Set COM1/COM2 decode range */
53 pci_write_config16(dev, LPC_IO_DEC, 0x0010);
54
Marc Jonesc4b6f3b2013-11-05 17:47:37 -070055 /* Enable SuperIO + PS/2 Keyboard/Mouse */
56 u16 lpc_config = CNF1_LPC_EN | CNF2_LPC_EN | KBC_LPC_EN;
Stefan Reinauer6651da32012-04-27 23:16:30 +020057 pci_write_config16(dev, LPC_EN, lpc_config);
58
59 /* Map 256 bytes at 0x1600 to the LPC bus. */
60 pci_write_config32(dev, LPC_GEN1_DEC, 0xfc1601);
61
Marc Jonesc4b6f3b2013-11-05 17:47:37 -070062 /* Map a range for the runtime_port registers to the LPC bus. */
Stefan Reinauer6651da32012-04-27 23:16:30 +020063 pci_write_config32(dev, LPC_GEN2_DEC, 0xc0181);
64
Marc Jonesc4b6f3b2013-11-05 17:47:37 -070065 /* Enable COM1 */
66 if (sio1007_enable_uart_at(SIO_PORT)) {
67 pci_write_config16(dev, LPC_EN,
68 lpc_config | COMA_LPC_EN);
Stefan Reinauer6651da32012-04-27 23:16:30 +020069 }
70}
71
72static void rcba_config(void)
73{
74 u32 reg32;
75
Vladimir Serbinenko33b535f2014-10-19 10:13:14 +020076 southbridge_configure_default_intmap();
Stefan Reinauer6651da32012-04-27 23:16:30 +020077
Stefan Reinauer6651da32012-04-27 23:16:30 +020078 /* Disable unused devices (board specific) */
79 reg32 = RCBA32(FD);
80 reg32 |= PCH_DISABLE_ALWAYS;
81 RCBA32(FD) = reg32;
82}
83
84// FIXME, this function is generic code that should go to sb/... or
85// nb/../early_init.c
86static void early_pch_init(void)
87{
88 u8 reg8;
89
90 // reset rtc power status
91 reg8 = pci_read_config8(PCH_LPC_DEV, 0xa4);
92 reg8 &= ~(1 << 2);
93 pci_write_config8(PCH_LPC_DEV, 0xa4, reg8);
Stefan Reinauer6651da32012-04-27 23:16:30 +020094}
95
96static void setup_sio_gpios(void)
97{
Marc Jonesc4b6f3b2013-11-05 17:47:37 -070098 const u16 port = SIO_PORT;
Stefan Reinauer6651da32012-04-27 23:16:30 +020099 const u16 runtime_port = 0x180;
100
101 /* Turn on configuration mode. */
102 outb(0x55, port);
103
104 /* Set the GPIO direction, polarity, and type. */
105 sio1007_setreg(port, 0x31, 1 << 0, 1 << 0);
106 sio1007_setreg(port, 0x32, 0 << 0, 1 << 0);
107 sio1007_setreg(port, 0x33, 0 << 0, 1 << 0);
108
109 /* Set the base address for the runtime register block. */
110 sio1007_setreg(port, 0x30, runtime_port >> 4, 0xff);
111 sio1007_setreg(port, 0x21, runtime_port >> 12, 0xff);
112
113 /* Turn on address decoding for it. */
114 sio1007_setreg(port, 0x3a, 1 << 1, 1 << 1);
115
116 /* Set the value of GPIO 10 by changing GP1, bit 0. */
117 u8 byte;
118 byte = inb(runtime_port + 0xc);
119 byte |= (1 << 0);
120 outb(byte, runtime_port + 0xc);
121
122 /* Turn off address decoding for it. */
123 sio1007_setreg(port, 0x3a, 0 << 1, 1 << 1);
124
125 /* Turn off configuration mode. */
126 outb(0xaa, port);
127}
128
Aaron Durbina0a37272014-08-14 08:35:11 -0500129#include <cpu/intel/romstage.h>
Stefan Reinauer6651da32012-04-27 23:16:30 +0200130void main(unsigned long bist)
131{
132 int boot_mode = 0;
133 int cbmem_was_initted;
Stefan Reinauer6651da32012-04-27 23:16:30 +0200134
Stefan Reinauer6651da32012-04-27 23:16:30 +0200135 struct pei_data pei_data = {
Edward O'Callaghanea4ae2f2014-05-24 02:08:04 +1000136 .pei_version = PEI_VERSION,
137 .mchbar = DEFAULT_MCHBAR,
138 .dmibar = DEFAULT_DMIBAR,
139 .epbar = DEFAULT_EPBAR,
140 .pciexbar = CONFIG_MMCONF_BASE_ADDRESS,
141 .smbusbar = SMBUS_IO_BASE,
142 .wdbbar = 0x4000000,
143 .wdbsize = 0x1000,
144 .hpet_address = CONFIG_HPET_ADDRESS,
145 .rcba = DEFAULT_RCBABASE,
146 .pmbase = DEFAULT_PMBASE,
147 .gpiobase = DEFAULT_GPIOBASE,
148 .thermalbase = 0xfed08000,
149 .system_type = 0, // 0 Mobile, 1 Desktop/Server
150 .tseg_size = CONFIG_SMM_TSEG_SIZE,
151 .spd_addresses = { 0xa0, 0x00, 0xa4, 0x00 },
152 .ts_addresses = { 0x00, 0x00, 0x00, 0x00 },
153 .ec_present = 0,
Stefan Reinauer6651da32012-04-27 23:16:30 +0200154 // 0 = leave channel enabled
155 // 1 = disable dimm 0 on channel
156 // 2 = disable dimm 1 on channel
157 // 3 = disable dimm 0+1 on channel
Edward O'Callaghanea4ae2f2014-05-24 02:08:04 +1000158 .dimm_channel0_disabled = 2,
159 .dimm_channel1_disabled = 2,
160 .max_ddr3_freq = 1600,
161 .usb_port_config = {
Stefan Reinauer6651da32012-04-27 23:16:30 +0200162 { 1, 0, 0x0040 }, /* P0: Front port (OC0) */
163 { 1, 1, 0x0040 }, /* P1: Back port (OC1) */
164 { 1, 0, 0x0040 }, /* P2: MINIPCIE1 (no OC) */
165 { 1, 0, 0x0040 }, /* P3: MMC (no OC) */
166 { 1, 2, 0x0040 }, /* P4: Front port (OC2) */
167 { 0, 0, 0x0000 }, /* P5: Empty */
168 { 0, 0, 0x0000 }, /* P6: Empty */
169 { 0, 0, 0x0000 }, /* P7: Empty */
170 { 1, 4, 0x0040 }, /* P8: Back port (OC4) */
171 { 1, 4, 0x0040 }, /* P9: MINIPCIE3 (no OC) */
172 { 1, 4, 0x0040 }, /* P10: BLUETOOTH (no OC) */
173 { 0, 4, 0x0000 }, /* P11: Empty */
174 { 1, 6, 0x0040 }, /* P12: Back port (OC6) */
175 { 1, 5, 0x0040 }, /* P13: Back port (OC5) */
176 },
177 };
178
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300179 timestamp_init(get_initial_timestamp());
180 timestamp_add_now(TS_START_ROMSTAGE);
Stefan Reinauer6651da32012-04-27 23:16:30 +0200181
182 if (bist == 0)
183 enable_lapic();
184
185 pch_enable_lpc();
186
187 /* Enable GPIOs */
188 pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1);
189 pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10);
Gabe Black599e2042012-03-30 14:33:02 -0700190 setup_pch_gpios(&emeraldlake2_gpio_map);
Stefan Reinauer6651da32012-04-27 23:16:30 +0200191 setup_sio_gpios();
192
193 /* Early SuperIO setup */
194 console_init();
195
196 /* Halt if there was a built in self test failure */
197 report_bist_failure(bist);
198
199 if (MCHBAR16(SSKPD) == 0xCAFE) {
200 printk(BIOS_DEBUG, "soft reset detected\n");
201 boot_mode = 1;
202
203 /* System is not happy after keyboard reset... */
204 printk(BIOS_DEBUG, "Issuing CF9 warm reset\n");
205 outb(0x6, 0xcf9);
206 hlt();
207 }
208
209 /* Perform some early chipset initialization required
210 * before RAM initialization can work
211 */
212 sandybridge_early_initialization(SANDYBRIDGE_MOBILE);
213 printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n");
214
Vladimir Serbinenko332f14b2014-09-05 16:29:41 +0200215 boot_mode = southbridge_detect_s3_resume() ? 2 : 0;
Stefan Reinauer6651da32012-04-27 23:16:30 +0200216
217 post_code(0x38);
218 /* Enable SPD ROMs and DDR-III DRAM */
219 enable_smbus();
220
221 /* Prepare USB controller early in S3 resume */
222 if (boot_mode == 2)
223 enable_usb_bar();
224
225 post_code(0x3a);
226 pei_data.boot_mode = boot_mode;
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300227 timestamp_add_now(TS_BEFORE_INITRAM);
Stefan Reinauer6651da32012-04-27 23:16:30 +0200228 sdram_initialize(&pei_data);
229
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300230 timestamp_add_now(TS_AFTER_INITRAM);
Stefan Reinauer6651da32012-04-27 23:16:30 +0200231 post_code(0x3b);
232 /* Perform some initialization that must run before stage2 */
233 early_pch_init();
234 post_code(0x3c);
235
236 /* This should probably go away. Until now it is required
237 * and mainboard specific
238 */
239 rcba_config();
240 post_code(0x3d);
241
Stefan Reinauer6651da32012-04-27 23:16:30 +0200242 quick_ram_check();
Stefan Reinauerafcaac22012-06-18 15:43:50 -0700243 post_code(0x3e);
Stefan Reinauer6651da32012-04-27 23:16:30 +0200244
Kyösti Mälkki2d8520b2014-01-06 17:20:31 +0200245 cbmem_was_initted = !cbmem_recovery(boot_mode==2);
Kyösti Mälkki78938482014-01-04 11:02:45 +0200246 if (boot_mode!=2)
247 save_mrc_data(&pei_data);
Stefan Reinauer6651da32012-04-27 23:16:30 +0200248
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200249 if (boot_mode==2 && !cbmem_was_initted) {
Stefan Reinauer6651da32012-04-27 23:16:30 +0200250 /* Failed S3 resume, reset to come up cleanly */
251 outb(0x6, 0xcf9);
252 hlt();
Stefan Reinauer6651da32012-04-27 23:16:30 +0200253 }
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200254 northbridge_romstage_finalize(boot_mode==2);
255
Stefan Reinauer6651da32012-04-27 23:16:30 +0200256 post_code(0x3f);
257#if CONFIG_CHROMEOS
258 init_chromeos(boot_mode);
259#endif
Stefan Reinauer6651da32012-04-27 23:16:30 +0200260 timestamp_add_now(TS_END_ROMSTAGE);
Stefan Reinauer6651da32012-04-27 23:16:30 +0200261}