blob: a0970df56291bd0cf80d2e6deda9b7b60812067d [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.
Stefan Reinauer49428d82013-02-21 15:48:37 -080015 */
16
17#include <stdint.h>
18#include <string.h>
19#include <lib.h>
20#include <timestamp.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -080021#include <arch/io.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -080022#include <device/pci.h>
23#include <device/pci_def.h>
24#include <device/pnp_def.h>
25#include <cpu/x86/lapic.h>
26#include <pc80/mc146818rtc.h>
Kyösti Mälkki6722f8d2014-06-16 09:14:49 +030027#include <arch/acpi.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -080028#include <cbmem.h>
29#include <console/console.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 Reinauer49428d82013-02-21 15:48:37 -080034#include "ec/google/chromeec/ec.h"
35#include <arch/cpu.h>
36#include <cpu/x86/bist.h>
37#include <cpu/x86/msr.h>
Patrick Georgibd79c5e2014-11-28 22:35:36 +010038#include <halt.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -080039#include "gpio.h"
Vladimir Serbinenko0e90dae2015-05-18 10:29:06 +020040#include <tpm.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -080041#include <cbfs.h>
42
43#include <southbridge/intel/bd82x6x/chip.h>
44
45static void pch_enable_lpc(void)
46{
47 const struct device *lpc;
48 const struct southbridge_intel_bd82x6x_config *config = NULL;
49
50 lpc = dev_find_slot(0, PCI_DEVFN(0x1f, 0));
51 if (!lpc)
52 return;
53 if (lpc->chip_info)
54 config = lpc->chip_info;
55 if (!config)
56 return;
57
58 /* Set COM1/COM2 decode range */
59 pci_write_config16(PCH_LPC_DEV, LPC_IO_DEC, 0x0010);
60
61 /* Enable PS/2 Keyboard/Mouse, EC areas and COM1 */
62 pci_write_config16(PCH_LPC_DEV, LPC_EN, KBC_LPC_EN | MC_LPC_EN | \
63 GAMEL_LPC_EN | COMA_LPC_EN);
64
65 pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, config->gen1_dec);
66 pci_write_config32(PCH_LPC_DEV, LPC_GEN2_DEC, config->gen2_dec);
67 pci_write_config32(PCH_LPC_DEV, LPC_GEN3_DEC, config->gen3_dec);
68 pci_write_config32(PCH_LPC_DEV, LPC_GEN4_DEC, config->gen4_dec);
69}
70
71static void rcba_config(void)
72{
73 u32 reg32;
74
Kyösti Mälkki6f499062015-06-06 11:52:24 +030075 /*
76 * GFX INTA -> PIRQA (MSI)
77 * D28IP_P3IP WLAN INTA -> PIRQB
78 * D29IP_E1P EHCI1 INTA -> PIRQD
79 * D26IP_E2P EHCI2 INTA -> PIRQF
80 * D31IP_SIP SATA INTA -> PIRQF (MSI)
81 * D31IP_SMIP SMBUS INTB -> PIRQH
82 * D31IP_TTIP THRT INTC -> PIRQA
83 * D27IP_ZIP HDA INTA -> PIRQA (MSI)
84 *
85 * TRACKPAD -> PIRQE (Edge Triggered)
86 * TOUCHSCREEN -> PIRQG (Edge Triggered)
87 */
88
89 /* Device interrupt pin register (board specific) */
90 RCBA32(D31IP) = (INTC << D31IP_TTIP) | (NOINT << D31IP_SIP2) |
91 (INTB << D31IP_SMIP) | (INTA << D31IP_SIP);
92 RCBA32(D30IP) = (NOINT << D30IP_PIP);
93 RCBA32(D29IP) = (INTA << D29IP_E1P);
94 RCBA32(D28IP) = (INTA << D28IP_P3IP);
95 RCBA32(D27IP) = (INTA << D27IP_ZIP);
96 RCBA32(D26IP) = (INTA << D26IP_E2P);
97 RCBA32(D25IP) = (NOINT << D25IP_LIP);
98 RCBA32(D22IP) = (NOINT << D22IP_MEI1IP);
99
100 /* Device interrupt route registers */
101 DIR_ROUTE(D31IR, PIRQB, PIRQH, PIRQA, PIRQC);
102 DIR_ROUTE(D29IR, PIRQD, PIRQE, PIRQF, PIRQG);
103 DIR_ROUTE(D28IR, PIRQB, PIRQC, PIRQD, PIRQE);
104 DIR_ROUTE(D27IR, PIRQA, PIRQH, PIRQA, PIRQB);
105 DIR_ROUTE(D26IR, PIRQF, PIRQE, PIRQG, PIRQH);
106 DIR_ROUTE(D25IR, PIRQA, PIRQB, PIRQC, PIRQD);
107 DIR_ROUTE(D22IR, PIRQA, PIRQB, PIRQC, PIRQD);
108
109 /* Enable IOAPIC (generic) */
110 RCBA16(OIC) = 0x0100;
111 /* PCH BWG says to read back the IOAPIC enable register */
112 (void) RCBA16(OIC);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800113
114 /* Disable unused devices (board specific) */
115 reg32 = RCBA32(FD);
116 reg32 |= PCH_DISABLE_ALWAYS;
117 RCBA32(FD) = reg32;
118}
119
120static void copy_spd(struct pei_data *peid)
121{
122 const int gpio_vector[] = {41, 42, 43, 10, -1};
Vladimir Serbinenko12874162014-01-12 14:12:15 +0100123 char *spd_file;
124 size_t spd_file_len;
Stefan Reinauer49428d82013-02-21 15:48:37 -0800125 int spd_index = get_gpios(gpio_vector);
126
127 printk(BIOS_DEBUG, "spd index %d\n", spd_index);
Aaron Durbin899d13d2015-05-15 23:39:23 -0500128 spd_file = cbfs_boot_map_with_leak("spd.bin", CBFS_TYPE_SPD,
129 &spd_file_len);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800130 if (!spd_file)
131 die("SPD data not found.");
132
Vladimir Serbinenko12874162014-01-12 14:12:15 +0100133 if (spd_file_len < ((spd_index + 1) * sizeof(peid->spd_data[0]))) {
Stefan Reinauer49428d82013-02-21 15:48:37 -0800134 printk(BIOS_ERR, "spd index override to 0 - old hardware?\n");
135 spd_index = 0;
136 }
137
Vladimir Serbinenko12874162014-01-12 14:12:15 +0100138 if (spd_file_len < sizeof(peid->spd_data[0]))
Stefan Reinauer49428d82013-02-21 15:48:37 -0800139 die("Missing SPD data.");
140
141 memcpy(peid->spd_data[0],
Vladimir Serbinenko12874162014-01-12 14:12:15 +0100142 spd_file +
Stefan Reinauer49428d82013-02-21 15:48:37 -0800143 spd_index * sizeof(peid->spd_data[0]),
144 sizeof(peid->spd_data[0]));
145}
146
Aaron Durbina0a37272014-08-14 08:35:11 -0500147#include <cpu/intel/romstage.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -0800148void main(unsigned long bist)
149{
150 int boot_mode = 0;
151 int cbmem_was_initted;
Stefan Reinauer49428d82013-02-21 15:48:37 -0800152
Stefan Reinauer49428d82013-02-21 15:48:37 -0800153 struct pei_data pei_data = {
Edward O'Callaghan6cec8242014-05-24 04:16:57 +1000154 .pei_version = PEI_VERSION,
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800155 .mchbar = (uintptr_t)DEFAULT_MCHBAR,
156 .dmibar = (uintptr_t)DEFAULT_DMIBAR,
Edward O'Callaghan6cec8242014-05-24 04:16:57 +1000157 .epbar = DEFAULT_EPBAR,
158 .pciexbar = CONFIG_MMCONF_BASE_ADDRESS,
159 .smbusbar = SMBUS_IO_BASE,
160 .wdbbar = 0x4000000,
161 .wdbsize = 0x1000,
162 .hpet_address = CONFIG_HPET_ADDRESS,
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800163 .rcba = (uintptr_t)DEFAULT_RCBABASE,
Edward O'Callaghan6cec8242014-05-24 04:16:57 +1000164 .pmbase = DEFAULT_PMBASE,
165 .gpiobase = DEFAULT_GPIOBASE,
166 .thermalbase = 0xfed08000,
167 .system_type = 0, // 0 Mobile, 1 Desktop/Server
168 .tseg_size = CONFIG_SMM_TSEG_SIZE,
169 .ts_addresses = { 0x00, 0x00, 0x00, 0x00 },
170 .ec_present = 1,
171 .ddr3lv_support = 1,
Stefan Reinauer49428d82013-02-21 15:48:37 -0800172 // 0 = leave channel enabled
173 // 1 = disable dimm 0 on channel
174 // 2 = disable dimm 1 on channel
175 // 3 = disable dimm 0+1 on channel
Edward O'Callaghan6cec8242014-05-24 04:16:57 +1000176 .dimm_channel0_disabled = 2,
177 .dimm_channel1_disabled = 2,
178 .max_ddr3_freq = 1600,
179 .usb_port_config = {
Stefan Reinauer49428d82013-02-21 15:48:37 -0800180 /* Empty and onboard Ports 0-7, set to un-used pin OC3 */
181 { 0, 3, 0x0000 }, /* P0: Empty */
182 { 1, 0, 0x0040 }, /* P1: Left USB 1 (OC0) */
183 { 1, 1, 0x0040 }, /* P2: Left USB 2 (OC1) */
184 { 1, 3, 0x0040 }, /* P3: SDCARD (no OC) */
185 { 0, 3, 0x0000 }, /* P4: Empty */
186 { 1, 3, 0x0040 }, /* P5: WWAN (no OC) */
187 { 0, 3, 0x0000 }, /* P6: Empty */
188 { 0, 3, 0x0000 }, /* P7: Empty */
189 /* Empty and onboard Ports 8-13, set to un-used pin OC4 */
190 { 1, 4, 0x0040 }, /* P8: Camera (no OC) */
191 { 1, 4, 0x0040 }, /* P9: Bluetooth (no OC) */
192 { 0, 4, 0x0000 }, /* P10: Empty */
193 { 0, 4, 0x0000 }, /* P11: Empty */
194 { 0, 4, 0x0000 }, /* P12: Empty */
195 { 0, 4, 0x0000 }, /* P13: Empty */
196 },
197 };
198
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300199 timestamp_init(get_initial_timestamp());
200 timestamp_add_now(TS_START_ROMSTAGE);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800201
202 if (bist == 0)
203 enable_lapic();
204
205 pch_enable_lpc();
206
207 /* Enable GPIOs */
208 pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1);
209 pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10);
210 setup_pch_gpios(&link_gpio_map);
211
212 /* Initialize console device(s) */
213 console_init();
214
215 /* Halt if there was a built in self test failure */
216 report_bist_failure(bist);
217
218 if (MCHBAR16(SSKPD) == 0xCAFE) {
219 printk(BIOS_DEBUG, "soft reset detected\n");
220 boot_mode = 1;
221
222 /* System is not happy after keyboard reset... */
223 printk(BIOS_DEBUG, "Issuing CF9 warm reset\n");
224 outb(0x6, 0xcf9);
Patrick Georgibd79c5e2014-11-28 22:35:36 +0100225 halt();
Stefan Reinauer49428d82013-02-21 15:48:37 -0800226 }
227
228 /* Perform some early chipset initialization required
229 * before RAM initialization can work
230 */
231 sandybridge_early_initialization(SANDYBRIDGE_MOBILE);
232 printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n");
233
Vladimir Serbinenko332f14b2014-09-05 16:29:41 +0200234 boot_mode = southbridge_detect_s3_resume() ? 2 : 0;
235 if (boot_mode == 0) {
Stefan Reinauer49428d82013-02-21 15:48:37 -0800236 /* This is the fastest way to let users know
237 * the Intel CPU is now alive.
238 */
239 google_chromeec_kbbacklight(100);
240 }
241
242 post_code(0x38);
243 /* Enable SPD ROMs and DDR-III DRAM */
244 enable_smbus();
245
246 /* Prepare USB controller early in S3 resume */
247 if (boot_mode == 2)
248 enable_usb_bar();
249
250 post_code(0x39);
251
252 copy_spd(&pei_data);
253
254 post_code(0x3a);
255 pei_data.boot_mode = boot_mode;
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300256 timestamp_add_now(TS_BEFORE_INITRAM);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800257 sdram_initialize(&pei_data);
258
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300259 timestamp_add_now(TS_AFTER_INITRAM);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800260 post_code(0x3c);
261
262 rcba_config();
263 post_code(0x3d);
264
265 quick_ram_check();
266 post_code(0x3e);
267
Kyösti Mälkki2d8520b2014-01-06 17:20:31 +0200268 cbmem_was_initted = !cbmem_recovery(boot_mode==2);
Kyösti Mälkki78938482014-01-04 11:02:45 +0200269 if (boot_mode!=2)
270 save_mrc_data(&pei_data);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800271
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200272 if (boot_mode==2 && !cbmem_was_initted) {
Stefan Reinauer49428d82013-02-21 15:48:37 -0800273 /* Failed S3 resume, reset to come up cleanly */
274 outb(0x6, 0xcf9);
Patrick Georgibd79c5e2014-11-28 22:35:36 +0100275 halt();
Stefan Reinauer49428d82013-02-21 15:48:37 -0800276 }
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200277 northbridge_romstage_finalize(boot_mode==2);
278
Stefan Reinauer49428d82013-02-21 15:48:37 -0800279 post_code(0x3f);
Vladimir Serbinenko0e90dae2015-05-18 10:29:06 +0200280 if (CONFIG_LPC_TPM) {
281 init_tpm(boot_mode == 2);
282 }
Stefan Reinauer49428d82013-02-21 15:48:37 -0800283}