blob: 70a6f444c7b5e86c1fe38fa9bea3856ca5b1c493 [file] [log] [blame]
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -08001/*
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.
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 Reinauerd7bd4eb2013-02-11 11:11:36 -080027#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 Reinauerd7bd4eb2013-02-11 11:11:36 -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 Reinauerd7bd4eb2013-02-11 11:11:36 -080038#include <arch/cpu.h>
39#include <cpu/x86/bist.h>
40#include <cpu/x86/msr.h>
Patrick Georgibd79c5e2014-11-28 22:35:36 +010041#include <halt.h>
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -080042#include "gpio.h"
43#if CONFIG_CHROMEOS
44#include <vendorcode/google/chromeos/chromeos.h>
45#endif
46#include <cbfs.h>
47
48static void pch_enable_lpc(void)
49{
50 /* EC Decode Range Port60/64 and Port62/66 */
51 /* Enable EC and PS/2 Keyboard/Mouse*/
52 pci_write_config16(PCH_LPC_DEV, LPC_EN, KBC_LPC_EN | MC_LPC_EN);
53
54 /* EC Decode Range Port68/6C */
55 pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, (0x68 & ~3) | 0x40001);
56
57 /* EC Decode Range Port 380-387 */
58 pci_write_config32(PCH_LPC_DEV, LPC_GEN2_DEC, 0x380 | 0x40001);
59
60}
61
62static void rcba_config(void)
63{
64 u32 reg32;
65
Vladimir Serbinenko33b535f2014-10-19 10:13:14 +020066 southbridge_configure_default_intmap();
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -080067
68 /* Disable unused devices (board specific) */
69 reg32 = RCBA32(FD);
70 reg32 |= PCH_DISABLE_ALWAYS;
71 /* Disable PCI bridge so MRC does not probe this bus */
72 reg32 |= PCH_DISABLE_P2P;
73 RCBA32(FD) = reg32;
74}
75
Aaron Durbina0a37272014-08-14 08:35:11 -050076#include <cpu/intel/romstage.h>
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -080077void main(unsigned long bist)
78{
79 int boot_mode = 0;
80 int cbmem_was_initted;
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -080081
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -080082 struct pei_data pei_data = {
Edward O'Callaghan38b98542014-10-29 06:15:57 +110083 .pei_version = PEI_VERSION,
84 .mchbar = DEFAULT_MCHBAR,
85 .dmibar = DEFAULT_DMIBAR,
86 .epbar = DEFAULT_EPBAR,
87 .pciexbar = CONFIG_MMCONF_BASE_ADDRESS,
88 .smbusbar = SMBUS_IO_BASE,
89 .wdbbar = 0x4000000,
90 .wdbsize = 0x1000,
91 .hpet_address = CONFIG_HPET_ADDRESS,
92 .rcba = DEFAULT_RCBABASE,
93 .pmbase = DEFAULT_PMBASE,
94 .gpiobase = DEFAULT_GPIOBASE,
95 .thermalbase = 0xfed08000,
96 .system_type = 0, // 0 Mobile, 1 Desktop/Server
97 .tseg_size = CONFIG_SMM_TSEG_SIZE,
98 .spd_addresses = { 0xA0, 0x00,0xA4,0x00 },
99 .ts_addresses = { 0x00, 0x00, 0x00, 0x00 },
100 .ec_present = 1,
101 .ddr3lv_support = 0,
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -0800102 // 0 = leave channel enabled
103 // 1 = disable dimm 0 on channel
104 // 2 = disable dimm 1 on channel
105 // 3 = disable dimm 0+1 on channel
Edward O'Callaghan38b98542014-10-29 06:15:57 +1100106 .dimm_channel0_disabled = 2,
107 .dimm_channel1_disabled = 2,
108 .max_ddr3_freq = 1600,
109 .usb_port_config = {
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -0800110 /* enabled usb oc pin length */
111 { 1, 0, 0x0040 }, /* P0: Right USB 3.0 #1 (no OC) */
112 { 1, 0, 0x0040 }, /* P1: Right USB 3.0 #2 (no OC) */
113 { 1, 0, 0x0040 }, /* P2: Camera (no OC) */
114 { 0, 0, 0x0000 }, /* P3: Empty */
115 { 0, 0, 0x0000 }, /* P4: Empty */
116 { 0, 0, 0x0000 }, /* P5: Empty */
117 { 0, 0, 0x0000 }, /* P6: Empty */
118 { 0, 0, 0x0000 }, /* P7: Empty */
119 { 0, 4, 0x0000 }, /* P8: Empty */
120 { 1, 4, 0x0080 }, /* P9: Left USB 1 (no OC) */
121 { 1, 4, 0x0040 }, /* P10: Mini PCIe - WLAN / BT (no OC) */
122 { 0, 4, 0x0000 }, /* P11: Empty */
123 { 0, 4, 0x0000 }, /* P12: Empty */
124 { 0, 4, 0x0000 }, /* P13: Empty */
125 },
Edward O'Callaghan38b98542014-10-29 06:15:57 +1100126 .ddr_refresh_rate_config = 2, /* Force double refresh rate */
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -0800127 };
128
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300129 timestamp_init(get_initial_timestamp());
130 timestamp_add_now(TS_START_ROMSTAGE);
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -0800131
132 if (bist == 0)
133 enable_lapic();
134
135 pch_enable_lpc();
136
137 /* Enable GPIOs */
138 pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1);
139 pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10);
140 setup_pch_gpios(&butterfly_gpio_map);
141
142 /* Initialize console device(s) */
143 console_init();
144
145 /* Halt if there was a built in self test failure */
146 report_bist_failure(bist);
147
148 if (MCHBAR16(SSKPD) == 0xCAFE) {
149 printk(BIOS_DEBUG, "soft reset detected\n");
150 boot_mode = 1;
151
152 /* System is not happy after keyboard reset... */
153 printk(BIOS_DEBUG, "Issuing CF9 warm reset\n");
154 outb(0x6, 0xcf9);
Patrick Georgibd79c5e2014-11-28 22:35:36 +0100155 halt();
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -0800156 }
157
158 /* Perform some early chipset initialization required
159 * before RAM initialization can work
160 */
161 sandybridge_early_initialization(SANDYBRIDGE_MOBILE);
162 printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n");
163
Vladimir Serbinenko332f14b2014-09-05 16:29:41 +0200164 boot_mode = southbridge_detect_s3_resume() ? 2 : 0;
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -0800165
166 post_code(0x38);
167 /* Enable SPD ROMs and DDR-III DRAM */
168 enable_smbus();
169
170 /* Prepare USB controller early in S3 resume */
171 if (boot_mode == 2)
172 enable_usb_bar();
173
174 post_code(0x39);
175
176 post_code(0x3a);
177 pei_data.boot_mode = boot_mode;
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300178 timestamp_add_now(TS_BEFORE_INITRAM);
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -0800179 sdram_initialize(&pei_data);
180
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300181 timestamp_add_now(TS_AFTER_INITRAM);
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -0800182 post_code(0x3c);
183
184 rcba_config();
185 post_code(0x3d);
186
187 quick_ram_check();
188 post_code(0x3e);
189
Kyösti Mälkki2d8520b2014-01-06 17:20:31 +0200190 cbmem_was_initted = !cbmem_recovery(boot_mode==2);
Kyösti Mälkki78938482014-01-04 11:02:45 +0200191 if (boot_mode!=2)
192 save_mrc_data(&pei_data);
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -0800193
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200194 if (boot_mode==2 && !cbmem_was_initted) {
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -0800195 /* Failed S3 resume, reset to come up cleanly */
196 outb(0x6, 0xcf9);
Patrick Georgibd79c5e2014-11-28 22:35:36 +0100197 halt();
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -0800198 }
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200199 northbridge_romstage_finalize(boot_mode==2);
200
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -0800201 post_code(0x3f);
202#if CONFIG_CHROMEOS
203 init_chromeos(boot_mode);
204#endif
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -0800205 timestamp_add_now(TS_END_ROMSTAGE);
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -0800206}