blob: 5cf24b20301620e7b9111813ab975b253dfcc618 [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.
Stefan Reinauer6651da32012-04-27 23:16:30 +020015 */
16
17#include <stdint.h>
18#include <string.h>
19#include <lib.h>
20#include <timestamp.h>
21#include <arch/io.h>
Stefan Reinauer6651da32012-04-27 23:16:30 +020022#include <device/pci_def.h>
23#include <device/pnp_def.h>
24#include <cpu/x86/lapic.h>
25#include <pc80/mc146818rtc.h>
Kyösti Mälkki6722f8d2014-06-16 09:14:49 +030026#include <arch/acpi.h>
Stefan Reinauer6651da32012-04-27 23:16:30 +020027#include <cbmem.h>
28#include <console/console.h>
Edward O'Callaghan74834e02015-01-04 04:17:35 +110029#include <superio/smsc/sio1007/chip.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110030#include <northbridge/intel/sandybridge/sandybridge.h>
31#include <northbridge/intel/sandybridge/raminit.h>
32#include <southbridge/intel/bd82x6x/pch.h>
33#include <southbridge/intel/bd82x6x/gpio.h>
Stefan Reinauer6651da32012-04-27 23:16:30 +020034#include <arch/cpu.h>
35#include <cpu/x86/bist.h>
36#include <cpu/x86/msr.h>
Patrick Georgibd79c5e2014-11-28 22:35:36 +010037#include <halt.h>
Vladimir Serbinenko0e90dae2015-05-18 10:29:06 +020038#include <tpm.h>
Stefan Reinauer6651da32012-04-27 23:16:30 +020039#include "gpio.h"
Stefan Reinauer6651da32012-04-27 23:16:30 +020040
Marc Jonesc4b6f3b2013-11-05 17:47:37 -070041#define SIO_PORT 0x164e
42
Stefan Reinauer6651da32012-04-27 23:16:30 +020043static void pch_enable_lpc(void)
44{
45 device_t dev = PCH_LPC_DEV;
Stefan Reinauer6651da32012-04-27 23:16:30 +020046
47 /* Set COM1/COM2 decode range */
48 pci_write_config16(dev, LPC_IO_DEC, 0x0010);
49
Marc Jonesc4b6f3b2013-11-05 17:47:37 -070050 /* Enable SuperIO + PS/2 Keyboard/Mouse */
51 u16 lpc_config = CNF1_LPC_EN | CNF2_LPC_EN | KBC_LPC_EN;
Stefan Reinauer6651da32012-04-27 23:16:30 +020052 pci_write_config16(dev, LPC_EN, lpc_config);
53
54 /* Map 256 bytes at 0x1600 to the LPC bus. */
55 pci_write_config32(dev, LPC_GEN1_DEC, 0xfc1601);
56
Marc Jonesc4b6f3b2013-11-05 17:47:37 -070057 /* Map a range for the runtime_port registers to the LPC bus. */
Stefan Reinauer6651da32012-04-27 23:16:30 +020058 pci_write_config32(dev, LPC_GEN2_DEC, 0xc0181);
59
Marc Jonesc4b6f3b2013-11-05 17:47:37 -070060 /* Enable COM1 */
61 if (sio1007_enable_uart_at(SIO_PORT)) {
62 pci_write_config16(dev, LPC_EN,
63 lpc_config | COMA_LPC_EN);
Stefan Reinauer6651da32012-04-27 23:16:30 +020064 }
65}
66
67static void rcba_config(void)
68{
69 u32 reg32;
70
Vladimir Serbinenko33b535f2014-10-19 10:13:14 +020071 southbridge_configure_default_intmap();
Stefan Reinauer6651da32012-04-27 23:16:30 +020072
Stefan Reinauer6651da32012-04-27 23:16:30 +020073 /* Disable unused devices (board specific) */
74 reg32 = RCBA32(FD);
75 reg32 |= PCH_DISABLE_ALWAYS;
76 RCBA32(FD) = reg32;
77}
78
79// FIXME, this function is generic code that should go to sb/... or
80// nb/../early_init.c
81static void early_pch_init(void)
82{
83 u8 reg8;
84
85 // reset rtc power status
86 reg8 = pci_read_config8(PCH_LPC_DEV, 0xa4);
87 reg8 &= ~(1 << 2);
88 pci_write_config8(PCH_LPC_DEV, 0xa4, reg8);
Stefan Reinauer6651da32012-04-27 23:16:30 +020089}
90
91static void setup_sio_gpios(void)
92{
Marc Jonesc4b6f3b2013-11-05 17:47:37 -070093 const u16 port = SIO_PORT;
Stefan Reinauer6651da32012-04-27 23:16:30 +020094 const u16 runtime_port = 0x180;
95
96 /* Turn on configuration mode. */
97 outb(0x55, port);
98
99 /* Set the GPIO direction, polarity, and type. */
100 sio1007_setreg(port, 0x31, 1 << 0, 1 << 0);
101 sio1007_setreg(port, 0x32, 0 << 0, 1 << 0);
102 sio1007_setreg(port, 0x33, 0 << 0, 1 << 0);
103
104 /* Set the base address for the runtime register block. */
105 sio1007_setreg(port, 0x30, runtime_port >> 4, 0xff);
106 sio1007_setreg(port, 0x21, runtime_port >> 12, 0xff);
107
108 /* Turn on address decoding for it. */
109 sio1007_setreg(port, 0x3a, 1 << 1, 1 << 1);
110
111 /* Set the value of GPIO 10 by changing GP1, bit 0. */
112 u8 byte;
113 byte = inb(runtime_port + 0xc);
114 byte |= (1 << 0);
115 outb(byte, runtime_port + 0xc);
116
117 /* Turn off address decoding for it. */
118 sio1007_setreg(port, 0x3a, 0 << 1, 1 << 1);
119
120 /* Turn off configuration mode. */
121 outb(0xaa, port);
122}
123
Aaron Durbina0a37272014-08-14 08:35:11 -0500124#include <cpu/intel/romstage.h>
Stefan Reinauer6651da32012-04-27 23:16:30 +0200125void main(unsigned long bist)
126{
127 int boot_mode = 0;
128 int cbmem_was_initted;
Stefan Reinauer6651da32012-04-27 23:16:30 +0200129
Stefan Reinauer6651da32012-04-27 23:16:30 +0200130 struct pei_data pei_data = {
Edward O'Callaghanea4ae2f2014-05-24 02:08:04 +1000131 .pei_version = PEI_VERSION,
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800132 .mchbar = (uintptr_t)DEFAULT_MCHBAR,
133 .dmibar = (uintptr_t)DEFAULT_DMIBAR,
Edward O'Callaghanea4ae2f2014-05-24 02:08:04 +1000134 .epbar = DEFAULT_EPBAR,
135 .pciexbar = CONFIG_MMCONF_BASE_ADDRESS,
136 .smbusbar = SMBUS_IO_BASE,
137 .wdbbar = 0x4000000,
138 .wdbsize = 0x1000,
139 .hpet_address = CONFIG_HPET_ADDRESS,
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800140 .rcba = (uintptr_t)DEFAULT_RCBABASE,
Edward O'Callaghanea4ae2f2014-05-24 02:08:04 +1000141 .pmbase = DEFAULT_PMBASE,
142 .gpiobase = DEFAULT_GPIOBASE,
143 .thermalbase = 0xfed08000,
144 .system_type = 0, // 0 Mobile, 1 Desktop/Server
145 .tseg_size = CONFIG_SMM_TSEG_SIZE,
146 .spd_addresses = { 0xa0, 0x00, 0xa4, 0x00 },
147 .ts_addresses = { 0x00, 0x00, 0x00, 0x00 },
148 .ec_present = 0,
Stefan Reinauer6651da32012-04-27 23:16:30 +0200149 // 0 = leave channel enabled
150 // 1 = disable dimm 0 on channel
151 // 2 = disable dimm 1 on channel
152 // 3 = disable dimm 0+1 on channel
Edward O'Callaghanea4ae2f2014-05-24 02:08:04 +1000153 .dimm_channel0_disabled = 2,
154 .dimm_channel1_disabled = 2,
155 .max_ddr3_freq = 1600,
156 .usb_port_config = {
Stefan Reinauer6651da32012-04-27 23:16:30 +0200157 { 1, 0, 0x0040 }, /* P0: Front port (OC0) */
158 { 1, 1, 0x0040 }, /* P1: Back port (OC1) */
159 { 1, 0, 0x0040 }, /* P2: MINIPCIE1 (no OC) */
160 { 1, 0, 0x0040 }, /* P3: MMC (no OC) */
161 { 1, 2, 0x0040 }, /* P4: Front port (OC2) */
162 { 0, 0, 0x0000 }, /* P5: Empty */
163 { 0, 0, 0x0000 }, /* P6: Empty */
164 { 0, 0, 0x0000 }, /* P7: Empty */
165 { 1, 4, 0x0040 }, /* P8: Back port (OC4) */
166 { 1, 4, 0x0040 }, /* P9: MINIPCIE3 (no OC) */
167 { 1, 4, 0x0040 }, /* P10: BLUETOOTH (no OC) */
168 { 0, 4, 0x0000 }, /* P11: Empty */
169 { 1, 6, 0x0040 }, /* P12: Back port (OC6) */
170 { 1, 5, 0x0040 }, /* P13: Back port (OC5) */
171 },
172 };
173
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300174 timestamp_init(get_initial_timestamp());
175 timestamp_add_now(TS_START_ROMSTAGE);
Stefan Reinauer6651da32012-04-27 23:16:30 +0200176
177 if (bist == 0)
178 enable_lapic();
179
180 pch_enable_lpc();
181
182 /* Enable GPIOs */
183 pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1);
184 pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10);
Gabe Black599e2042012-03-30 14:33:02 -0700185 setup_pch_gpios(&emeraldlake2_gpio_map);
Stefan Reinauer6651da32012-04-27 23:16:30 +0200186 setup_sio_gpios();
187
188 /* Early SuperIO setup */
189 console_init();
190
191 /* Halt if there was a built in self test failure */
192 report_bist_failure(bist);
193
194 if (MCHBAR16(SSKPD) == 0xCAFE) {
195 printk(BIOS_DEBUG, "soft reset detected\n");
196 boot_mode = 1;
197
198 /* System is not happy after keyboard reset... */
199 printk(BIOS_DEBUG, "Issuing CF9 warm reset\n");
200 outb(0x6, 0xcf9);
Patrick Georgibd79c5e2014-11-28 22:35:36 +0100201 halt();
Stefan Reinauer6651da32012-04-27 23:16:30 +0200202 }
203
204 /* Perform some early chipset initialization required
205 * before RAM initialization can work
206 */
207 sandybridge_early_initialization(SANDYBRIDGE_MOBILE);
208 printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n");
209
Vladimir Serbinenko332f14b2014-09-05 16:29:41 +0200210 boot_mode = southbridge_detect_s3_resume() ? 2 : 0;
Stefan Reinauer6651da32012-04-27 23:16:30 +0200211
212 post_code(0x38);
213 /* Enable SPD ROMs and DDR-III DRAM */
214 enable_smbus();
215
216 /* Prepare USB controller early in S3 resume */
217 if (boot_mode == 2)
218 enable_usb_bar();
219
220 post_code(0x3a);
221 pei_data.boot_mode = boot_mode;
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300222 timestamp_add_now(TS_BEFORE_INITRAM);
Stefan Reinauer6651da32012-04-27 23:16:30 +0200223 sdram_initialize(&pei_data);
224
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300225 timestamp_add_now(TS_AFTER_INITRAM);
Stefan Reinauer6651da32012-04-27 23:16:30 +0200226 post_code(0x3b);
227 /* Perform some initialization that must run before stage2 */
228 early_pch_init();
229 post_code(0x3c);
230
231 /* This should probably go away. Until now it is required
232 * and mainboard specific
233 */
234 rcba_config();
235 post_code(0x3d);
236
Stefan Reinauer6651da32012-04-27 23:16:30 +0200237 quick_ram_check();
Stefan Reinauerafcaac22012-06-18 15:43:50 -0700238 post_code(0x3e);
Stefan Reinauer6651da32012-04-27 23:16:30 +0200239
Kyösti Mälkki2d8520b2014-01-06 17:20:31 +0200240 cbmem_was_initted = !cbmem_recovery(boot_mode==2);
Kyösti Mälkki78938482014-01-04 11:02:45 +0200241 if (boot_mode!=2)
242 save_mrc_data(&pei_data);
Stefan Reinauer6651da32012-04-27 23:16:30 +0200243
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200244 if (boot_mode==2 && !cbmem_was_initted) {
Stefan Reinauer6651da32012-04-27 23:16:30 +0200245 /* Failed S3 resume, reset to come up cleanly */
246 outb(0x6, 0xcf9);
Patrick Georgibd79c5e2014-11-28 22:35:36 +0100247 halt();
Stefan Reinauer6651da32012-04-27 23:16:30 +0200248 }
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200249 northbridge_romstage_finalize(boot_mode==2);
250
Stefan Reinauer6651da32012-04-27 23:16:30 +0200251 post_code(0x3f);
Vladimir Serbinenko0e90dae2015-05-18 10:29:06 +0200252 if (CONFIG_LPC_TPM) {
253 init_tpm(boot_mode == 2);
254 }
Stefan Reinauer6651da32012-04-27 23:16:30 +0200255}