blob: 873de91321dfd0a78ec2126d4543a179ac2601fe [file] [log] [blame]
Stefan Reinauer49428d82013-02-21 15:48:37 -08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2007-2010 coresystems GmbH
5 * Copyright (C) 2011 Google Inc.
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/byteorder.h>
26#include <arch/io.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -080027#include <device/pci.h>
28#include <device/pci_def.h>
29#include <device/pnp_def.h>
30#include <cpu/x86/lapic.h>
31#include <pc80/mc146818rtc.h>
Kyösti Mälkki6722f8d2014-06-16 09:14:49 +030032#include <arch/acpi.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -080033#include <cbmem.h>
34#include <console/console.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110035#include <northbridge/intel/sandybridge/sandybridge.h>
36#include <northbridge/intel/sandybridge/raminit.h>
37#include <southbridge/intel/bd82x6x/pch.h>
38#include <southbridge/intel/bd82x6x/gpio.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -080039#include "ec/google/chromeec/ec.h"
40#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 Reinauer49428d82013-02-21 15:48:37 -080044#include "gpio.h"
45#if CONFIG_CHROMEOS
46#include <vendorcode/google/chromeos/chromeos.h>
47#endif
48#include <cbfs.h>
49
50#include <southbridge/intel/bd82x6x/chip.h>
51
52static void pch_enable_lpc(void)
53{
54 const struct device *lpc;
55 const struct southbridge_intel_bd82x6x_config *config = NULL;
56
57 lpc = dev_find_slot(0, PCI_DEVFN(0x1f, 0));
58 if (!lpc)
59 return;
60 if (lpc->chip_info)
61 config = lpc->chip_info;
62 if (!config)
63 return;
64
65 /* Set COM1/COM2 decode range */
66 pci_write_config16(PCH_LPC_DEV, LPC_IO_DEC, 0x0010);
67
68 /* Enable PS/2 Keyboard/Mouse, EC areas and COM1 */
69 pci_write_config16(PCH_LPC_DEV, LPC_EN, KBC_LPC_EN | MC_LPC_EN | \
70 GAMEL_LPC_EN | COMA_LPC_EN);
71
72 pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, config->gen1_dec);
73 pci_write_config32(PCH_LPC_DEV, LPC_GEN2_DEC, config->gen2_dec);
74 pci_write_config32(PCH_LPC_DEV, LPC_GEN3_DEC, config->gen3_dec);
75 pci_write_config32(PCH_LPC_DEV, LPC_GEN4_DEC, config->gen4_dec);
76}
77
78static void rcba_config(void)
79{
80 u32 reg32;
81
Vladimir Serbinenko33b535f2014-10-19 10:13:14 +020082 southbridge_configure_default_intmap();
Stefan Reinauer49428d82013-02-21 15:48:37 -080083
84 /* Disable unused devices (board specific) */
85 reg32 = RCBA32(FD);
86 reg32 |= PCH_DISABLE_ALWAYS;
87 RCBA32(FD) = reg32;
88}
89
90static void copy_spd(struct pei_data *peid)
91{
92 const int gpio_vector[] = {41, 42, 43, 10, -1};
Vladimir Serbinenko12874162014-01-12 14:12:15 +010093 char *spd_file;
94 size_t spd_file_len;
Stefan Reinauer49428d82013-02-21 15:48:37 -080095 int spd_index = get_gpios(gpio_vector);
96
97 printk(BIOS_DEBUG, "spd index %d\n", spd_index);
Vladimir Serbinenko12874162014-01-12 14:12:15 +010098 spd_file = cbfs_get_file_content(CBFS_DEFAULT_MEDIA, "spd.bin", 0xab,
99 &spd_file_len);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800100 if (!spd_file)
101 die("SPD data not found.");
102
Vladimir Serbinenko12874162014-01-12 14:12:15 +0100103 if (spd_file_len < ((spd_index + 1) * sizeof(peid->spd_data[0]))) {
Stefan Reinauer49428d82013-02-21 15:48:37 -0800104 printk(BIOS_ERR, "spd index override to 0 - old hardware?\n");
105 spd_index = 0;
106 }
107
Vladimir Serbinenko12874162014-01-12 14:12:15 +0100108 if (spd_file_len < sizeof(peid->spd_data[0]))
Stefan Reinauer49428d82013-02-21 15:48:37 -0800109 die("Missing SPD data.");
110
111 memcpy(peid->spd_data[0],
Vladimir Serbinenko12874162014-01-12 14:12:15 +0100112 spd_file +
Stefan Reinauer49428d82013-02-21 15:48:37 -0800113 spd_index * sizeof(peid->spd_data[0]),
114 sizeof(peid->spd_data[0]));
115}
116
Aaron Durbina0a37272014-08-14 08:35:11 -0500117#include <cpu/intel/romstage.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -0800118void main(unsigned long bist)
119{
120 int boot_mode = 0;
121 int cbmem_was_initted;
Stefan Reinauer49428d82013-02-21 15:48:37 -0800122
Stefan Reinauer49428d82013-02-21 15:48:37 -0800123 struct pei_data pei_data = {
Edward O'Callaghan6cec8242014-05-24 04:16:57 +1000124 .pei_version = PEI_VERSION,
125 .mchbar = DEFAULT_MCHBAR,
126 .dmibar = DEFAULT_DMIBAR,
127 .epbar = DEFAULT_EPBAR,
128 .pciexbar = CONFIG_MMCONF_BASE_ADDRESS,
129 .smbusbar = SMBUS_IO_BASE,
130 .wdbbar = 0x4000000,
131 .wdbsize = 0x1000,
132 .hpet_address = CONFIG_HPET_ADDRESS,
133 .rcba = DEFAULT_RCBABASE,
134 .pmbase = DEFAULT_PMBASE,
135 .gpiobase = DEFAULT_GPIOBASE,
136 .thermalbase = 0xfed08000,
137 .system_type = 0, // 0 Mobile, 1 Desktop/Server
138 .tseg_size = CONFIG_SMM_TSEG_SIZE,
139 .ts_addresses = { 0x00, 0x00, 0x00, 0x00 },
140 .ec_present = 1,
141 .ddr3lv_support = 1,
Stefan Reinauer49428d82013-02-21 15:48:37 -0800142 // 0 = leave channel enabled
143 // 1 = disable dimm 0 on channel
144 // 2 = disable dimm 1 on channel
145 // 3 = disable dimm 0+1 on channel
Edward O'Callaghan6cec8242014-05-24 04:16:57 +1000146 .dimm_channel0_disabled = 2,
147 .dimm_channel1_disabled = 2,
148 .max_ddr3_freq = 1600,
149 .usb_port_config = {
Stefan Reinauer49428d82013-02-21 15:48:37 -0800150 /* Empty and onboard Ports 0-7, set to un-used pin OC3 */
151 { 0, 3, 0x0000 }, /* P0: Empty */
152 { 1, 0, 0x0040 }, /* P1: Left USB 1 (OC0) */
153 { 1, 1, 0x0040 }, /* P2: Left USB 2 (OC1) */
154 { 1, 3, 0x0040 }, /* P3: SDCARD (no OC) */
155 { 0, 3, 0x0000 }, /* P4: Empty */
156 { 1, 3, 0x0040 }, /* P5: WWAN (no OC) */
157 { 0, 3, 0x0000 }, /* P6: Empty */
158 { 0, 3, 0x0000 }, /* P7: Empty */
159 /* Empty and onboard Ports 8-13, set to un-used pin OC4 */
160 { 1, 4, 0x0040 }, /* P8: Camera (no OC) */
161 { 1, 4, 0x0040 }, /* P9: Bluetooth (no OC) */
162 { 0, 4, 0x0000 }, /* P10: Empty */
163 { 0, 4, 0x0000 }, /* P11: Empty */
164 { 0, 4, 0x0000 }, /* P12: Empty */
165 { 0, 4, 0x0000 }, /* P13: Empty */
166 },
167 };
168
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300169 timestamp_init(get_initial_timestamp());
170 timestamp_add_now(TS_START_ROMSTAGE);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800171
172 if (bist == 0)
173 enable_lapic();
174
175 pch_enable_lpc();
176
177 /* Enable GPIOs */
178 pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1);
179 pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10);
180 setup_pch_gpios(&link_gpio_map);
181
182 /* Initialize console device(s) */
183 console_init();
184
185 /* Halt if there was a built in self test failure */
186 report_bist_failure(bist);
187
188 if (MCHBAR16(SSKPD) == 0xCAFE) {
189 printk(BIOS_DEBUG, "soft reset detected\n");
190 boot_mode = 1;
191
192 /* System is not happy after keyboard reset... */
193 printk(BIOS_DEBUG, "Issuing CF9 warm reset\n");
194 outb(0x6, 0xcf9);
Patrick Georgibd79c5e2014-11-28 22:35:36 +0100195 halt();
Stefan Reinauer49428d82013-02-21 15:48:37 -0800196 }
197
198 /* Perform some early chipset initialization required
199 * before RAM initialization can work
200 */
201 sandybridge_early_initialization(SANDYBRIDGE_MOBILE);
202 printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n");
203
Vladimir Serbinenko332f14b2014-09-05 16:29:41 +0200204 boot_mode = southbridge_detect_s3_resume() ? 2 : 0;
205 if (boot_mode == 0) {
Stefan Reinauer49428d82013-02-21 15:48:37 -0800206 /* This is the fastest way to let users know
207 * the Intel CPU is now alive.
208 */
209 google_chromeec_kbbacklight(100);
210 }
211
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(0x39);
221
222 copy_spd(&pei_data);
223
224 post_code(0x3a);
225 pei_data.boot_mode = boot_mode;
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300226 timestamp_add_now(TS_BEFORE_INITRAM);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800227 sdram_initialize(&pei_data);
228
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300229 timestamp_add_now(TS_AFTER_INITRAM);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800230 post_code(0x3c);
231
232 rcba_config();
233 post_code(0x3d);
234
235 quick_ram_check();
236 post_code(0x3e);
237
Kyösti Mälkki2d8520b2014-01-06 17:20:31 +0200238 cbmem_was_initted = !cbmem_recovery(boot_mode==2);
Kyösti Mälkki78938482014-01-04 11:02:45 +0200239 if (boot_mode!=2)
240 save_mrc_data(&pei_data);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800241
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200242 if (boot_mode==2 && !cbmem_was_initted) {
Stefan Reinauer49428d82013-02-21 15:48:37 -0800243 /* Failed S3 resume, reset to come up cleanly */
244 outb(0x6, 0xcf9);
Patrick Georgibd79c5e2014-11-28 22:35:36 +0100245 halt();
Stefan Reinauer49428d82013-02-21 15:48:37 -0800246 }
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200247 northbridge_romstage_finalize(boot_mode==2);
248
Stefan Reinauer49428d82013-02-21 15:48:37 -0800249 post_code(0x3f);
250#if CONFIG_CHROMEOS
251 init_chromeos(boot_mode);
252#endif
Stefan Reinauer49428d82013-02-21 15:48:37 -0800253 timestamp_add_now(TS_END_ROMSTAGE);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800254}