blob: 18c833ad3813e1af021fd76b091d6f6d9ea0a7c5 [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>
35#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"
39#include "ec/google/chromeec/ec.h"
40#include <arch/cpu.h>
41#include <cpu/x86/bist.h>
42#include <cpu/x86/msr.h>
43#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
81 /*
82 * GFX INTA -> PIRQA (MSI)
83 * D28IP_P3IP WLAN INTA -> PIRQB
84 * D29IP_E1P EHCI1 INTA -> PIRQD
85 * D26IP_E2P EHCI2 INTA -> PIRQF
86 * D31IP_SIP SATA INTA -> PIRQF (MSI)
87 * D31IP_SMIP SMBUS INTB -> PIRQH
88 * D31IP_TTIP THRT INTC -> PIRQA
89 * D27IP_ZIP HDA INTA -> PIRQA (MSI)
90 *
91 * TRACKPAD -> PIRQE (Edge Triggered)
92 * TOUCHSCREEN -> PIRQG (Edge Triggered)
93 */
94
95 /* Device interrupt pin register (board specific) */
96 RCBA32(D31IP) = (INTC << D31IP_TTIP) | (NOINT << D31IP_SIP2) |
97 (INTB << D31IP_SMIP) | (INTA << D31IP_SIP);
98 RCBA32(D30IP) = (NOINT << D30IP_PIP);
99 RCBA32(D29IP) = (INTA << D29IP_E1P);
100 RCBA32(D28IP) = (INTA << D28IP_P3IP);
101 RCBA32(D27IP) = (INTA << D27IP_ZIP);
102 RCBA32(D26IP) = (INTA << D26IP_E2P);
103 RCBA32(D25IP) = (NOINT << D25IP_LIP);
104 RCBA32(D22IP) = (NOINT << D22IP_MEI1IP);
105
106 /* Device interrupt route registers */
107 DIR_ROUTE(D31IR, PIRQB, PIRQH, PIRQA, PIRQC);
108 DIR_ROUTE(D29IR, PIRQD, PIRQE, PIRQF, PIRQG);
109 DIR_ROUTE(D28IR, PIRQB, PIRQC, PIRQD, PIRQE);
110 DIR_ROUTE(D27IR, PIRQA, PIRQH, PIRQA, PIRQB);
111 DIR_ROUTE(D26IR, PIRQF, PIRQE, PIRQG, PIRQH);
112 DIR_ROUTE(D25IR, PIRQA, PIRQB, PIRQC, PIRQD);
113 DIR_ROUTE(D22IR, PIRQA, PIRQB, PIRQC, PIRQD);
114
115 /* Enable IOAPIC (generic) */
116 RCBA16(OIC) = 0x0100;
117 /* PCH BWG says to read back the IOAPIC enable register */
118 (void) RCBA16(OIC);
119
120 /* Disable unused devices (board specific) */
121 reg32 = RCBA32(FD);
122 reg32 |= PCH_DISABLE_ALWAYS;
123 RCBA32(FD) = reg32;
124}
125
126static void copy_spd(struct pei_data *peid)
127{
128 const int gpio_vector[] = {41, 42, 43, 10, -1};
Vladimir Serbinenko12874162014-01-12 14:12:15 +0100129 char *spd_file;
130 size_t spd_file_len;
Stefan Reinauer49428d82013-02-21 15:48:37 -0800131 int spd_index = get_gpios(gpio_vector);
132
133 printk(BIOS_DEBUG, "spd index %d\n", spd_index);
Vladimir Serbinenko12874162014-01-12 14:12:15 +0100134 spd_file = cbfs_get_file_content(CBFS_DEFAULT_MEDIA, "spd.bin", 0xab,
135 &spd_file_len);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800136 if (!spd_file)
137 die("SPD data not found.");
138
Vladimir Serbinenko12874162014-01-12 14:12:15 +0100139 if (spd_file_len < ((spd_index + 1) * sizeof(peid->spd_data[0]))) {
Stefan Reinauer49428d82013-02-21 15:48:37 -0800140 printk(BIOS_ERR, "spd index override to 0 - old hardware?\n");
141 spd_index = 0;
142 }
143
Vladimir Serbinenko12874162014-01-12 14:12:15 +0100144 if (spd_file_len < sizeof(peid->spd_data[0]))
Stefan Reinauer49428d82013-02-21 15:48:37 -0800145 die("Missing SPD data.");
146
147 memcpy(peid->spd_data[0],
Vladimir Serbinenko12874162014-01-12 14:12:15 +0100148 spd_file +
Stefan Reinauer49428d82013-02-21 15:48:37 -0800149 spd_index * sizeof(peid->spd_data[0]),
150 sizeof(peid->spd_data[0]));
151}
152
153void main(unsigned long bist)
154{
155 int boot_mode = 0;
156 int cbmem_was_initted;
157 u32 pm1_cnt;
158 u16 pm1_sts;
159
Stefan Reinauer49428d82013-02-21 15:48:37 -0800160 struct pei_data pei_data = {
Edward O'Callaghan6cec8242014-05-24 04:16:57 +1000161 .pei_version = PEI_VERSION,
162 .mchbar = DEFAULT_MCHBAR,
163 .dmibar = DEFAULT_DMIBAR,
164 .epbar = DEFAULT_EPBAR,
165 .pciexbar = CONFIG_MMCONF_BASE_ADDRESS,
166 .smbusbar = SMBUS_IO_BASE,
167 .wdbbar = 0x4000000,
168 .wdbsize = 0x1000,
169 .hpet_address = CONFIG_HPET_ADDRESS,
170 .rcba = DEFAULT_RCBABASE,
171 .pmbase = DEFAULT_PMBASE,
172 .gpiobase = DEFAULT_GPIOBASE,
173 .thermalbase = 0xfed08000,
174 .system_type = 0, // 0 Mobile, 1 Desktop/Server
175 .tseg_size = CONFIG_SMM_TSEG_SIZE,
176 .ts_addresses = { 0x00, 0x00, 0x00, 0x00 },
177 .ec_present = 1,
178 .ddr3lv_support = 1,
Stefan Reinauer49428d82013-02-21 15:48:37 -0800179 // 0 = leave channel enabled
180 // 1 = disable dimm 0 on channel
181 // 2 = disable dimm 1 on channel
182 // 3 = disable dimm 0+1 on channel
Edward O'Callaghan6cec8242014-05-24 04:16:57 +1000183 .dimm_channel0_disabled = 2,
184 .dimm_channel1_disabled = 2,
185 .max_ddr3_freq = 1600,
186 .usb_port_config = {
Stefan Reinauer49428d82013-02-21 15:48:37 -0800187 /* Empty and onboard Ports 0-7, set to un-used pin OC3 */
188 { 0, 3, 0x0000 }, /* P0: Empty */
189 { 1, 0, 0x0040 }, /* P1: Left USB 1 (OC0) */
190 { 1, 1, 0x0040 }, /* P2: Left USB 2 (OC1) */
191 { 1, 3, 0x0040 }, /* P3: SDCARD (no OC) */
192 { 0, 3, 0x0000 }, /* P4: Empty */
193 { 1, 3, 0x0040 }, /* P5: WWAN (no OC) */
194 { 0, 3, 0x0000 }, /* P6: Empty */
195 { 0, 3, 0x0000 }, /* P7: Empty */
196 /* Empty and onboard Ports 8-13, set to un-used pin OC4 */
197 { 1, 4, 0x0040 }, /* P8: Camera (no OC) */
198 { 1, 4, 0x0040 }, /* P9: Bluetooth (no OC) */
199 { 0, 4, 0x0000 }, /* P10: Empty */
200 { 0, 4, 0x0000 }, /* P11: Empty */
201 { 0, 4, 0x0000 }, /* P12: Empty */
202 { 0, 4, 0x0000 }, /* P13: Empty */
203 },
204 };
205
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300206 timestamp_init(get_initial_timestamp());
207 timestamp_add_now(TS_START_ROMSTAGE);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800208
209 if (bist == 0)
210 enable_lapic();
211
212 pch_enable_lpc();
213
214 /* Enable GPIOs */
215 pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1);
216 pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10);
217 setup_pch_gpios(&link_gpio_map);
218
219 /* Initialize console device(s) */
220 console_init();
221
222 /* Halt if there was a built in self test failure */
223 report_bist_failure(bist);
224
225 if (MCHBAR16(SSKPD) == 0xCAFE) {
226 printk(BIOS_DEBUG, "soft reset detected\n");
227 boot_mode = 1;
228
229 /* System is not happy after keyboard reset... */
230 printk(BIOS_DEBUG, "Issuing CF9 warm reset\n");
231 outb(0x6, 0xcf9);
232 hlt();
233 }
234
235 /* Perform some early chipset initialization required
236 * before RAM initialization can work
237 */
238 sandybridge_early_initialization(SANDYBRIDGE_MOBILE);
239 printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n");
240
241 /* Check PM1_STS[15] to see if we are waking from Sx */
242 pm1_sts = inw(DEFAULT_PMBASE + PM1_STS);
243
244 /* Read PM1_CNT[12:10] to determine which Sx state */
245 pm1_cnt = inl(DEFAULT_PMBASE + PM1_CNT);
246
247 if ((pm1_sts & WAK_STS) && ((pm1_cnt >> 10) & 7) == 5) {
Kyösti Mälkki6722f8d2014-06-16 09:14:49 +0300248 if (acpi_s3_resume_allowed()) {
249 printk(BIOS_DEBUG, "Resume from S3 detected.\n");
250 boot_mode = 2;
251 /* Clear SLP_TYPE. This will break stage2 but
252 * we care for that when we get there.
253 */
254 outl(pm1_cnt & ~(7 << 10), DEFAULT_PMBASE + PM1_CNT);
255 } else {
256 printk(BIOS_DEBUG, "Resume from S3 detected, but disabled.\n");
257 }
Stefan Reinauer49428d82013-02-21 15:48:37 -0800258 } else {
259 /* This is the fastest way to let users know
260 * the Intel CPU is now alive.
261 */
262 google_chromeec_kbbacklight(100);
263 }
264
265 post_code(0x38);
266 /* Enable SPD ROMs and DDR-III DRAM */
267 enable_smbus();
268
269 /* Prepare USB controller early in S3 resume */
270 if (boot_mode == 2)
271 enable_usb_bar();
272
273 post_code(0x39);
274
275 copy_spd(&pei_data);
276
277 post_code(0x3a);
278 pei_data.boot_mode = boot_mode;
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300279 timestamp_add_now(TS_BEFORE_INITRAM);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800280 sdram_initialize(&pei_data);
281
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300282 timestamp_add_now(TS_AFTER_INITRAM);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800283 post_code(0x3c);
284
285 rcba_config();
286 post_code(0x3d);
287
288 quick_ram_check();
289 post_code(0x3e);
290
291 MCHBAR16(SSKPD) = 0xCAFE;
Kyösti Mälkki2d8520b2014-01-06 17:20:31 +0200292 cbmem_was_initted = !cbmem_recovery(boot_mode==2);
Kyösti Mälkki78938482014-01-04 11:02:45 +0200293 if (boot_mode!=2)
294 save_mrc_data(&pei_data);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800295
296#if CONFIG_HAVE_ACPI_RESUME
297 /* If there is no high memory area, we didn't boot before, so
298 * this is not a resume. In that case we just create the cbmem toc.
299 */
300
301 *(u32 *)CBMEM_BOOT_MODE = 0;
302 *(u32 *)CBMEM_RESUME_BACKUP = 0;
303
304 if ((boot_mode == 2) && cbmem_was_initted) {
305 void *resume_backup_memory = cbmem_find(CBMEM_ID_RESUME);
306 if (resume_backup_memory) {
307 *(u32 *)CBMEM_BOOT_MODE = boot_mode;
308 *(u32 *)CBMEM_RESUME_BACKUP = (u32)resume_backup_memory;
309 }
310 /* Magic for S3 resume */
311 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafed00d);
312 } else if (boot_mode == 2) {
313 /* Failed S3 resume, reset to come up cleanly */
314 outb(0x6, 0xcf9);
315 hlt();
316 } else {
317 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafebabe);
318 }
319#endif
320 post_code(0x3f);
321#if CONFIG_CHROMEOS
322 init_chromeos(boot_mode);
323#endif
Stefan Reinauer49428d82013-02-21 15:48:37 -0800324 timestamp_add_now(TS_END_ROMSTAGE);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800325}