blob: a2c377877304f6f4c4e597ed4beb2d61d832c5e7 [file] [log] [blame]
Zaolina823f9b2014-05-06 21:31:45 +02001/*
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 * Copyright (C) 2014 Vladimir Serbinenko
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include <stdint.h>
23#include <string.h>
24#include <lib.h>
25#include <timestamp.h>
26#include <arch/byteorder.h>
27#include <arch/io.h>
28#include <device/pci_def.h>
29#include <device/pnp_def.h>
30#include <cpu/x86/lapic.h>
31#include <pc80/mc146818rtc.h>
32#include <cbmem.h>
33#include <console/console.h>
34#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>
38#include <arch/cpu.h>
39#include <cpu/x86/bist.h>
40#include <cpu/x86/msr.h>
41#include <cbfs.h>
42
43static void pch_enable_lpc(void)
44{
45 /* T520 EC Decode Range Port60/64, Port62/66 */
46 /* Enable EC, PS/2 Keyboard/Mouse */
47 pci_write_config16(PCH_LPC_DEV, LPC_EN,
48 CNF2_LPC_EN | CNF1_LPC_EN | MC_LPC_EN | KBC_LPC_EN |
49 COMA_LPC_EN);
50
51 pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, 0x7c1601);
52 pci_write_config32(PCH_LPC_DEV, LPC_GEN2_DEC, 0xc15e1);
53 pci_write_config32(PCH_LPC_DEV, LPC_GEN4_DEC, 0x0c06a1);
54
55 pci_write_config16(PCH_LPC_DEV, LPC_IO_DEC, 0x10);
56
57 pci_write_config32(PCH_LPC_DEV, 0xac,
58 0x80010000);
59}
60
61static void rcba_config(void)
62{
63 /*
64 * GFX INTA -> PIRQA (MSI)
65 * D28IP_P1IP WLAN INTA -> PIRQB
66 * D28IP_P2IP ETH0 INTB -> PIRQF
67 * D28IP_P3IP SDCARD INTC -> PIRQD
68 * D29IP_E1P EHCI1 INTA -> PIRQD
69 * D26IP_E2P EHCI2 INTA -> PIRQF
70 * D31IP_SIP SATA INTA -> PIRQB (MSI)
71 * D31IP_SMIP SMBUS INTB -> PIRQH
72 * D31IP_TTIP THRT INTC -> PIRQA
73 * D27IP_ZIP HDA INTA -> PIRQA (MSI)
74 *
75 * Trackpad interrupt is edge triggered and cannot be shared.
76 * TRACKPAD -> PIRQG
77
78 */
79
80 /* Device interrupt pin register (board specific) */
81 RCBA32(D31IP) = (INTC << D31IP_TTIP) | (NOINT << D31IP_SIP2) |
82 (INTB << D31IP_SMIP) | (INTA << D31IP_SIP);
83 RCBA32(D29IP) = (INTA << D29IP_E1P);
84 RCBA32(D28IP) = (INTA << D28IP_P1IP) | (INTB << D28IP_P2IP) |
85 (INTC << D28IP_P3IP);
86 RCBA32(D27IP) = (INTA << D27IP_ZIP);
87 RCBA32(D26IP) = (INTA << D26IP_E2P);
88 RCBA32(D25IP) = (NOINT << D25IP_LIP);
89 RCBA32(D22IP) = (NOINT << D22IP_MEI1IP);
90
91 /* Device interrupt route registers */
92 DIR_ROUTE(D31IR, PIRQB, PIRQH, PIRQA, PIRQC);
93 DIR_ROUTE(D29IR, PIRQD, PIRQE, PIRQF, PIRQG);
94 DIR_ROUTE(D28IR, PIRQB, PIRQF, PIRQD, PIRQE);
95 DIR_ROUTE(D27IR, PIRQA, PIRQH, PIRQA, PIRQB);
96 DIR_ROUTE(D26IR, PIRQF, PIRQE, PIRQG, PIRQH);
97 DIR_ROUTE(D25IR, PIRQA, PIRQB, PIRQC, PIRQD);
98 DIR_ROUTE(D22IR, PIRQA, PIRQB, PIRQC, PIRQD);
99
100 /* Enable IOAPIC (generic) */
101 RCBA16(OIC) = 0x0100;
102 /* PCH BWG says to read back the IOAPIC enable register */
103 (void) RCBA16(OIC);
104
105 /* Disable unused devices (board specific) */
106 RCBA32(FD) = 0x17f81fe3;
107 RCBA32(BUC) = 0;
108}
109
110void main(unsigned long bist)
111{
112 int boot_mode = 0;
113 int cbmem_was_initted;
114 u32 pm1_cnt;
115 u16 pm1_sts;
116
117 if (MCHBAR16(SSKPD) == 0xCAFE) {
118 outb(0x6, 0xcf9);
119 hlt ();
120 }
121
122 struct pei_data pei_data = {
123 .pei_version = PEI_VERSION,
124 .mchbar = DEFAULT_MCHBAR,
125 .dmibar = DEFAULT_DMIBAR,
126 .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,
132 .rcba = DEFAULT_RCBABASE,
133 .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 .spd_addresses = { 0xA0, 0x00,0xA2,0x00 },
139 .ts_addresses = { 0x00, 0x00, 0x00, 0x00 },
140 .ec_present = 1,
141 .gbe_enable = 1,
142 .ddr3lv_support = 0,
143 // 0 = leave channel enabled
144 // 1 = disable dimm 0 on channel
145 // 2 = disable dimm 1 on channel
146 // 3 = disable dimm 0+1 on channel
147 .dimm_channel0_disabled = 2,
148 .dimm_channel1_disabled = 2,
149 .max_ddr3_freq = 1600,
150 .usb_port_config = {
151 /* enabled usb oc pin length */
152 { 1, 0, 0x0080 }, /* P0 (left, fan side), OC 0 */
153 { 1, 1, 0x0080 }, /* P1 (left touchpad side), OC 1 */
154 { 1, 0, 0x0040 }, /* P2: dock, OC 3 */
155 { 1, 0, 0x0040 }, /* P3: wwan, no OC */
156 { 1, 0, 0x0080 }, /* P4: Wacom tablet on X230t, otherwise empty */
157 { 1, 0, 0x0080 }, /* P5: Expresscard, no OC */
158 { 0, 0, 0x0000 }, /* P6: Empty */
159 { 1, 0, 0x0080 }, /* P7: dock, no OC */
160 { 1, 4, 0x0080 }, /* P8: Empty */
161 { 1, 5, 0x0080 }, /* P9: Right (EHCI debug), OC 5 */
162 { 1, 0, 0x0040 }, /* P10: fingerprint reader, no OC */
163 { 1, 0, 0x0040 }, /* P11: bluetooth, no OC. */
164 { 1, 0, 0x0040 }, /* P12: wlan, no OC */
165 { 1, 0, 0x0080 }, /* P13: webcam, no OC */
166 },
167 .ddr_refresh_rate_config = 2, /* Force double refresh rate */
168 };
169
170 timestamp_init(get_initial_timestamp());
171 timestamp_add_now(TS_START_ROMSTAGE);
172
173 if (bist == 0)
174 enable_lapic();
175
176 pch_enable_lpc();
177
178 /* Enable GPIOs */
179 pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1);
180 pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10);
181
182 outl(0x3962a5ff, DEFAULT_GPIOBASE);
183 outl(0x8ebf6aff, DEFAULT_GPIOBASE + 4);
184 outl(0x66957f3b, DEFAULT_GPIOBASE + 0xc);
185 outl(0x00080000, DEFAULT_GPIOBASE + 0x20);
186 outl(0x00002082, DEFAULT_GPIOBASE + 0x2c);
187 outl(0x02ff06de, DEFAULT_GPIOBASE + 0x30);
188 outl(0x1f47f9f5, DEFAULT_GPIOBASE + 0x34);
189 outl(0xbdbffd47, DEFAULT_GPIOBASE + 0x38);
190 outl(0x000000f0, DEFAULT_GPIOBASE + 0x40);
191 outl(0x00000ff0, DEFAULT_GPIOBASE + 0x44);
192 outl(0x00000f4f, DEFAULT_GPIOBASE + 0x48);
193 outl(0x01000000, DEFAULT_GPIOBASE + 0x60);
194
195 /* Initialize console device(s) */
196 console_init();
197
198 /* Halt if there was a built in self test failure */
199 report_bist_failure(bist);
200
201 /* Perform some early chipset initialization required
202 * before RAM initialization can work
203 */
204 sandybridge_early_initialization(SANDYBRIDGE_MOBILE);
205 printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n");
206
207 /* Check PM1_STS[15] to see if we are waking from Sx */
208 pm1_sts = inw(DEFAULT_PMBASE + PM1_STS);
209
210 /* Read PM1_CNT[12:10] to determine which Sx state */
211 pm1_cnt = inl(DEFAULT_PMBASE + PM1_CNT);
212
213 if ((pm1_sts & WAK_STS) && ((pm1_cnt >> 10) & 7) == 5) {
214#if CONFIG_HAVE_ACPI_RESUME
215 printk(BIOS_DEBUG, "Resume from S3 detected.\n");
216 boot_mode = 2;
217 /* Clear SLP_TYPE. This will break stage2 but
218 * we care for that when we get there.
219 */
220 outl(pm1_cnt & ~(7 << 10), DEFAULT_PMBASE + PM1_CNT);
221#else
222 printk(BIOS_DEBUG, "Resume from S3 detected, but disabled.\n");
223#endif
224 }
225
226 post_code(0x38);
227 /* Enable SPD ROMs and DDR-III DRAM */
228 enable_smbus();
229
230 /* Prepare USB controller early in S3 resume */
231 if (boot_mode == 2)
232 enable_usb_bar();
233
234 post_code(0x39);
235 post_code(0x3a);
236
237 pei_data.boot_mode = boot_mode;
238 timestamp_add_now(TS_BEFORE_INITRAM);
239
240 /* MRC.bin has a bug and sometimes halts (instead of reboot?).
241 */
242 if (boot_mode != 2) {
243 RCBA32(GCS) = RCBA32(GCS) & ~(1 << 5); /* reset */
244 outw((0 << 11), DEFAULT_PMBASE | 0x60 | 0x08); /* let timer go */
245 }
246
247 sdram_initialize(&pei_data);
248
249 if (boot_mode != 2) {
250 RCBA32(GCS) = RCBA32(GCS) | (1 << 5); /* No reset */
251 outw((1 << 11), DEFAULT_PMBASE | 0x60 | 0x08); /* halt timer */
252 }
253
254 timestamp_add_now(TS_AFTER_INITRAM);
255 post_code(0x3c);
256
257 rcba_config();
258 post_code(0x3d);
259
260 quick_ram_check();
261 post_code(0x3e);
262
263 MCHBAR16(SSKPD) = 0xCAFE;
264 cbmem_was_initted = !cbmem_recovery(boot_mode == 2);
265 if (boot_mode != 2) {
266 save_mrc_data(&pei_data);
267 }
268
269#if CONFIG_HAVE_ACPI_RESUME
270 /* If there is no high memory area, we didn't boot before, so
271 * this is not a resume. In that case we just create the cbmem toc.
272 */
273
274 *(u32 *)CBMEM_BOOT_MODE = 0;
275 *(u32 *)CBMEM_RESUME_BACKUP = 0;
276
277 if ((boot_mode == 2) && cbmem_was_initted) {
278 void *resume_backup_memory = cbmem_find(CBMEM_ID_RESUME);
279 if (resume_backup_memory) {
280 *(u32 *)CBMEM_BOOT_MODE = boot_mode;
281 *(u32 *)CBMEM_RESUME_BACKUP = (u32)resume_backup_memory;
282 }
283 /* Magic for S3 resume */
284 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafed00d);
285 } else if (boot_mode == 2) {
286 /* Failed S3 resume, reset to come up cleanly */
287 outb(0x6, 0xcf9);
288 hlt();
289 } else {
290 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafebabe);
291 }
292#endif
293 post_code(0x3f);
294 timestamp_add_now(TS_END_ROMSTAGE);
295}