blob: 5844aa61683a516cd0c520baf893c80f175819bf [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>
Stefan Reinauer49428d82013-02-21 15:48:37 -080025#include <arch/io.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -080026#include <device/pci.h>
27#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 Reinauer49428d82013-02-21 15:48:37 -080032#include <cbmem.h>
33#include <console/console.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110034#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>
Stefan Reinauer49428d82013-02-21 15:48:37 -080038#include "ec/google/chromeec/ec.h"
39#include <arch/cpu.h>
40#include <cpu/x86/bist.h>
41#include <cpu/x86/msr.h>
Patrick Georgibd79c5e2014-11-28 22:35:36 +010042#include <halt.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -080043#include "gpio.h"
44#if CONFIG_CHROMEOS
45#include <vendorcode/google/chromeos/chromeos.h>
46#endif
47#include <cbfs.h>
48
49#include <southbridge/intel/bd82x6x/chip.h>
50
51static void pch_enable_lpc(void)
52{
53 const struct device *lpc;
54 const struct southbridge_intel_bd82x6x_config *config = NULL;
55
56 lpc = dev_find_slot(0, PCI_DEVFN(0x1f, 0));
57 if (!lpc)
58 return;
59 if (lpc->chip_info)
60 config = lpc->chip_info;
61 if (!config)
62 return;
63
64 /* Set COM1/COM2 decode range */
65 pci_write_config16(PCH_LPC_DEV, LPC_IO_DEC, 0x0010);
66
67 /* Enable PS/2 Keyboard/Mouse, EC areas and COM1 */
68 pci_write_config16(PCH_LPC_DEV, LPC_EN, KBC_LPC_EN | MC_LPC_EN | \
69 GAMEL_LPC_EN | COMA_LPC_EN);
70
71 pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, config->gen1_dec);
72 pci_write_config32(PCH_LPC_DEV, LPC_GEN2_DEC, config->gen2_dec);
73 pci_write_config32(PCH_LPC_DEV, LPC_GEN3_DEC, config->gen3_dec);
74 pci_write_config32(PCH_LPC_DEV, LPC_GEN4_DEC, config->gen4_dec);
75}
76
77static void rcba_config(void)
78{
79 u32 reg32;
80
Vladimir Serbinenko33b535f2014-10-19 10:13:14 +020081 southbridge_configure_default_intmap();
Stefan Reinauer49428d82013-02-21 15:48:37 -080082
83 /* Disable unused devices (board specific) */
84 reg32 = RCBA32(FD);
85 reg32 |= PCH_DISABLE_ALWAYS;
86 RCBA32(FD) = reg32;
87}
88
89static void copy_spd(struct pei_data *peid)
90{
91 const int gpio_vector[] = {41, 42, 43, 10, -1};
Vladimir Serbinenko12874162014-01-12 14:12:15 +010092 char *spd_file;
93 size_t spd_file_len;
Stefan Reinauer49428d82013-02-21 15:48:37 -080094 int spd_index = get_gpios(gpio_vector);
95
96 printk(BIOS_DEBUG, "spd index %d\n", spd_index);
Aaron Durbina30f7e62015-03-31 20:33:53 -050097 spd_file = cbfs_get_file_content(CBFS_DEFAULT_MEDIA, "spd.bin",
98 CBFS_TYPE_SPD, &spd_file_len);
Stefan Reinauer49428d82013-02-21 15:48:37 -080099 if (!spd_file)
100 die("SPD data not found.");
101
Vladimir Serbinenko12874162014-01-12 14:12:15 +0100102 if (spd_file_len < ((spd_index + 1) * sizeof(peid->spd_data[0]))) {
Stefan Reinauer49428d82013-02-21 15:48:37 -0800103 printk(BIOS_ERR, "spd index override to 0 - old hardware?\n");
104 spd_index = 0;
105 }
106
Vladimir Serbinenko12874162014-01-12 14:12:15 +0100107 if (spd_file_len < sizeof(peid->spd_data[0]))
Stefan Reinauer49428d82013-02-21 15:48:37 -0800108 die("Missing SPD data.");
109
110 memcpy(peid->spd_data[0],
Vladimir Serbinenko12874162014-01-12 14:12:15 +0100111 spd_file +
Stefan Reinauer49428d82013-02-21 15:48:37 -0800112 spd_index * sizeof(peid->spd_data[0]),
113 sizeof(peid->spd_data[0]));
114}
115
Aaron Durbina0a37272014-08-14 08:35:11 -0500116#include <cpu/intel/romstage.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -0800117void main(unsigned long bist)
118{
119 int boot_mode = 0;
120 int cbmem_was_initted;
Stefan Reinauer49428d82013-02-21 15:48:37 -0800121
Stefan Reinauer49428d82013-02-21 15:48:37 -0800122 struct pei_data pei_data = {
Edward O'Callaghan6cec8242014-05-24 04:16:57 +1000123 .pei_version = PEI_VERSION,
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800124 .mchbar = (uintptr_t)DEFAULT_MCHBAR,
125 .dmibar = (uintptr_t)DEFAULT_DMIBAR,
Edward O'Callaghan6cec8242014-05-24 04:16:57 +1000126 .epbar = DEFAULT_EPBAR,
127 .pciexbar = CONFIG_MMCONF_BASE_ADDRESS,
128 .smbusbar = SMBUS_IO_BASE,
129 .wdbbar = 0x4000000,
130 .wdbsize = 0x1000,
131 .hpet_address = CONFIG_HPET_ADDRESS,
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800132 .rcba = (uintptr_t)DEFAULT_RCBABASE,
Edward O'Callaghan6cec8242014-05-24 04:16:57 +1000133 .pmbase = DEFAULT_PMBASE,
134 .gpiobase = DEFAULT_GPIOBASE,
135 .thermalbase = 0xfed08000,
136 .system_type = 0, // 0 Mobile, 1 Desktop/Server
137 .tseg_size = CONFIG_SMM_TSEG_SIZE,
138 .ts_addresses = { 0x00, 0x00, 0x00, 0x00 },
139 .ec_present = 1,
140 .ddr3lv_support = 1,
Stefan Reinauer49428d82013-02-21 15:48:37 -0800141 // 0 = leave channel enabled
142 // 1 = disable dimm 0 on channel
143 // 2 = disable dimm 1 on channel
144 // 3 = disable dimm 0+1 on channel
Edward O'Callaghan6cec8242014-05-24 04:16:57 +1000145 .dimm_channel0_disabled = 2,
146 .dimm_channel1_disabled = 2,
147 .max_ddr3_freq = 1600,
148 .usb_port_config = {
Stefan Reinauer49428d82013-02-21 15:48:37 -0800149 /* Empty and onboard Ports 0-7, set to un-used pin OC3 */
150 { 0, 3, 0x0000 }, /* P0: Empty */
151 { 1, 0, 0x0040 }, /* P1: Left USB 1 (OC0) */
152 { 1, 1, 0x0040 }, /* P2: Left USB 2 (OC1) */
153 { 1, 3, 0x0040 }, /* P3: SDCARD (no OC) */
154 { 0, 3, 0x0000 }, /* P4: Empty */
155 { 1, 3, 0x0040 }, /* P5: WWAN (no OC) */
156 { 0, 3, 0x0000 }, /* P6: Empty */
157 { 0, 3, 0x0000 }, /* P7: Empty */
158 /* Empty and onboard Ports 8-13, set to un-used pin OC4 */
159 { 1, 4, 0x0040 }, /* P8: Camera (no OC) */
160 { 1, 4, 0x0040 }, /* P9: Bluetooth (no OC) */
161 { 0, 4, 0x0000 }, /* P10: Empty */
162 { 0, 4, 0x0000 }, /* P11: Empty */
163 { 0, 4, 0x0000 }, /* P12: Empty */
164 { 0, 4, 0x0000 }, /* P13: Empty */
165 },
166 };
167
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300168 timestamp_init(get_initial_timestamp());
169 timestamp_add_now(TS_START_ROMSTAGE);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800170
171 if (bist == 0)
172 enable_lapic();
173
174 pch_enable_lpc();
175
176 /* Enable GPIOs */
177 pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1);
178 pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10);
179 setup_pch_gpios(&link_gpio_map);
180
181 /* Initialize console device(s) */
182 console_init();
183
184 /* Halt if there was a built in self test failure */
185 report_bist_failure(bist);
186
187 if (MCHBAR16(SSKPD) == 0xCAFE) {
188 printk(BIOS_DEBUG, "soft reset detected\n");
189 boot_mode = 1;
190
191 /* System is not happy after keyboard reset... */
192 printk(BIOS_DEBUG, "Issuing CF9 warm reset\n");
193 outb(0x6, 0xcf9);
Patrick Georgibd79c5e2014-11-28 22:35:36 +0100194 halt();
Stefan Reinauer49428d82013-02-21 15:48:37 -0800195 }
196
197 /* Perform some early chipset initialization required
198 * before RAM initialization can work
199 */
200 sandybridge_early_initialization(SANDYBRIDGE_MOBILE);
201 printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n");
202
Vladimir Serbinenko332f14b2014-09-05 16:29:41 +0200203 boot_mode = southbridge_detect_s3_resume() ? 2 : 0;
204 if (boot_mode == 0) {
Stefan Reinauer49428d82013-02-21 15:48:37 -0800205 /* This is the fastest way to let users know
206 * the Intel CPU is now alive.
207 */
208 google_chromeec_kbbacklight(100);
209 }
210
211 post_code(0x38);
212 /* Enable SPD ROMs and DDR-III DRAM */
213 enable_smbus();
214
215 /* Prepare USB controller early in S3 resume */
216 if (boot_mode == 2)
217 enable_usb_bar();
218
219 post_code(0x39);
220
221 copy_spd(&pei_data);
222
223 post_code(0x3a);
224 pei_data.boot_mode = boot_mode;
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300225 timestamp_add_now(TS_BEFORE_INITRAM);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800226 sdram_initialize(&pei_data);
227
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300228 timestamp_add_now(TS_AFTER_INITRAM);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800229 post_code(0x3c);
230
231 rcba_config();
232 post_code(0x3d);
233
234 quick_ram_check();
235 post_code(0x3e);
236
Kyösti Mälkki2d8520b2014-01-06 17:20:31 +0200237 cbmem_was_initted = !cbmem_recovery(boot_mode==2);
Kyösti Mälkki78938482014-01-04 11:02:45 +0200238 if (boot_mode!=2)
239 save_mrc_data(&pei_data);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800240
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200241 if (boot_mode==2 && !cbmem_was_initted) {
Stefan Reinauer49428d82013-02-21 15:48:37 -0800242 /* Failed S3 resume, reset to come up cleanly */
243 outb(0x6, 0xcf9);
Patrick Georgibd79c5e2014-11-28 22:35:36 +0100244 halt();
Stefan Reinauer49428d82013-02-21 15:48:37 -0800245 }
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200246 northbridge_romstage_finalize(boot_mode==2);
247
Stefan Reinauer49428d82013-02-21 15:48:37 -0800248 post_code(0x3f);
249#if CONFIG_CHROMEOS
250 init_chromeos(boot_mode);
251#endif
Stefan Reinauer49428d82013-02-21 15:48:37 -0800252 timestamp_add_now(TS_END_ROMSTAGE);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800253}