blob: 4a9efa656f24768a5ab318e9bc73b12c2528dc86 [file] [log] [blame]
Nico Huberefe1fed2013-04-29 18:00:57 +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 *
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.
Nico Huberefe1fed2013-04-29 18:00:57 +020015 */
16
17#include <stdint.h>
18#include <string.h>
19#include <lib.h>
20#include <timestamp.h>
21#include <arch/io.h>
22#include <device/pci_def.h>
23#include <device/pnp_def.h>
24#include <cpu/x86/lapic.h>
25#include <pc80/mc146818rtc.h>
Kyösti Mälkki6722f8d2014-06-16 09:14:49 +030026#include <arch/acpi.h>
Nico Huberefe1fed2013-04-29 18:00:57 +020027#include <cbmem.h>
28#include <console/console.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110029#include <northbridge/intel/sandybridge/sandybridge.h>
30#include <northbridge/intel/sandybridge/raminit.h>
31#include <southbridge/intel/bd82x6x/pch.h>
32#include <southbridge/intel/bd82x6x/gpio.h>
Nico Huberefe1fed2013-04-29 18:00:57 +020033#include <arch/cpu.h>
34#include <cpu/x86/bist.h>
35#include <cpu/x86/msr.h>
Patrick Georgibd79c5e2014-11-28 22:35:36 +010036#include <halt.h>
Nico Huberefe1fed2013-04-29 18:00:57 +020037#include "gpio.h"
38
39static void pch_enable_lpc(void)
40{
41 /* Set COM3/COM1 decode ranges: 0x3e8/0x3f8 */
42 pci_write_config16(PCH_LPC_DEV, LPC_IO_DEC, 0x0070);
43
44 /* Enable KBC on 0x06/0x64 (KBC),
45 * EC on 0x62/0x66 (MC),
46 * EC on 0x20c-0x20f (GAMEH),
47 * Super I/O on 0x2e/0x2f (CNF1),
48 * COM1/COM3 decode ranges. */
49 pci_write_config16(PCH_LPC_DEV, LPC_EN,
50 KBC_LPC_EN | MC_LPC_EN |
51 CNF1_LPC_EN | GAMEH_LPC_EN |
52 COMA_LPC_EN | COMB_LPC_EN);
53}
54
55static void rcba_config(void)
56{
57 u32 reg32;
58
Vladimir Serbinenko33b535f2014-10-19 10:13:14 +020059 southbridge_configure_default_intmap();
Nico Huberefe1fed2013-04-29 18:00:57 +020060
61 /* Disable unused devices (board specific) */
62 reg32 = RCBA32(FD);
63 reg32 |= PCH_DISABLE_ALWAYS;
64 /* Disable PCI bridge so MRC does not probe this bus */
65 reg32 |= PCH_DISABLE_P2P;
66 RCBA32(FD) = reg32;
67}
68
69static void pnp_enter_ext_func_mode(device_t dev)
70{
71 u16 port = dev >> 8;
72 outb(0x87, port);
73 outb(0x87, port);
74}
75
76static void pnp_exit_ext_func_mode(device_t dev)
77{
78 u16 port = dev >> 8;
79 outb(0xaa, port);
80}
81
82static void superio_gpio_config(void)
83{
Nico Huber40f9ce92013-10-22 11:07:23 +020084 int lvds_3v = 0; // 0 (5V) or 1 (3V3)
85 int dis_bl_inv = 1; // backlight inversion: 1 = disabled, 0 = enabled
Nico Huberefe1fed2013-04-29 18:00:57 +020086 device_t dev = PNP_DEV(0x2e, 0x9);
87 pnp_enter_ext_func_mode(dev);
Nico Huber40f9ce92013-10-22 11:07:23 +020088 pnp_write_config(dev, 0x29, 0x02); /* Pins 119, 120 are GPIO21, 20 */
89 pnp_write_config(dev, 0x30, 0x03); /* Enable GPIO2+3 */
90 pnp_write_config(dev, 0x2a, 0x01); /* Pins 62, 63, 65, 66 are
91 GPIO27, 26, 25, 24 */
92 pnp_write_config(dev, 0x2c, 0xc3); /* Pin 90 is GPIO32,
93 Pins 78~85 are UART B */
94 pnp_write_config(dev, 0x2d, 0x00); /* Pins 67, 68, 70~73, 75, 77 are
95 GPIO57~50 */
Nico Huberefe1fed2013-04-29 18:00:57 +020096 pnp_set_logical_device(dev);
97 /* Values can only be changed, when devices are enabled. */
Nico Huberefe1fed2013-04-29 18:00:57 +020098 pnp_write_config(dev, 0xe3, 0xdd); /* GPIO2 bits 1, 5 are output */
Nico Huber40f9ce92013-10-22 11:07:23 +020099 pnp_write_config(dev, 0xe4, (dis_bl_inv << 5) | (lvds_3v << 1)); /* GPIO2 bits 1, 5 */
Nico Huberefe1fed2013-04-29 18:00:57 +0200100 pnp_exit_ext_func_mode(dev);
101}
102
Aaron Durbina0a37272014-08-14 08:35:11 -0500103#include <cpu/intel/romstage.h>
Nico Huberefe1fed2013-04-29 18:00:57 +0200104void main(unsigned long bist)
105{
106 int boot_mode = 0;
107 int cbmem_was_initted;
Nico Huberefe1fed2013-04-29 18:00:57 +0200108
Nico Huberefe1fed2013-04-29 18:00:57 +0200109 struct pei_data pei_data = {
Edward O'Callaghan6f49f692014-05-24 02:04:52 +1000110 .pei_version = PEI_VERSION,
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800111 .mchbar = (uintptr_t)DEFAULT_MCHBAR,
112 .dmibar = (uintptr_t)DEFAULT_DMIBAR,
Edward O'Callaghan6f49f692014-05-24 02:04:52 +1000113 .epbar = DEFAULT_EPBAR,
114 .pciexbar = CONFIG_MMCONF_BASE_ADDRESS,
115 .smbusbar = SMBUS_IO_BASE,
116 .wdbbar = 0x4000000,
117 .wdbsize = 0x1000,
118 .hpet_address = CONFIG_HPET_ADDRESS,
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800119 .rcba = (uintptr_t)DEFAULT_RCBABASE,
Edward O'Callaghan6f49f692014-05-24 02:04:52 +1000120 .pmbase = DEFAULT_PMBASE,
121 .gpiobase = DEFAULT_GPIOBASE,
122 .thermalbase = 0xfed08000,
123 .system_type = 0, // 0 Mobile, 1 Desktop/Server
124 .tseg_size = CONFIG_SMM_TSEG_SIZE,
125 .spd_addresses = { 0xA0, 0x00,0xA4,0x00 },
126 .ts_addresses = { 0x00, 0x00, 0x00, 0x00 },
127 .ec_present = 1,
128 .gbe_enable = 1,
129 .ddr3lv_support = 0,
Nico Huberefe1fed2013-04-29 18:00:57 +0200130 // 0 = leave channel enabled
131 // 1 = disable dimm 0 on channel
132 // 2 = disable dimm 1 on channel
133 // 3 = disable dimm 0+1 on channel
Edward O'Callaghan6f49f692014-05-24 02:04:52 +1000134 .dimm_channel0_disabled = 2,
135 .dimm_channel1_disabled = 2,
136 .max_ddr3_freq = 1600,
137 .usb_port_config = {
Nico Huberefe1fed2013-04-29 18:00:57 +0200138 /* enabled usb oc pin length */
139 { 1, 0, 0x0040 }, /* P0: lower left USB 3.0 (OC0) */
140 { 1, 0, 0x0040 }, /* P1: upper left USB 3.0 (OC0) */
141 { 1, 0, 0x0040 }, /* P2: lower right USB 3.0 (OC0) */
142 { 1, 0, 0x0040 }, /* P3: upper right USB 3.0 (OC0) */
143 { 1, 0, 0x0040 }, /* P4: lower USB 2.0 (OC0) */
144 { 1, 0, 0x0040 }, /* P5: upper USB 2.0 (OC0) */
145 { 1, 0, 0x0040 }, /* P6: front panel USB 2.0 (OC0) */
146 { 1, 0, 0x0040 }, /* P7: front panel USB 2.0 (OC0) */
147 { 1, 4, 0x0040 }, /* P8: internal USB 2.0 (OC4) */
148 { 1, 4, 0x0040 }, /* P9: internal USB 2.0 (OC4) */
149 { 1, 4, 0x0040 }, /* P10: internal USB 2.0 (OC4) */
150 { 1, 4, 0x0040 }, /* P11: internal USB 2.0 (OC4) */
151 { 1, 4, 0x0040 }, /* P12: internal USB 2.0 (OC4) */
152 { 1, 4, 0x0040 }, /* P13: internal USB 2.0 (OC4) */
153 },
Edward O'Callaghan6f49f692014-05-24 02:04:52 +1000154 .usb3 = {
155 .mode = 3, /* Smart Auto? */
156 .hs_port_switch_mask = 0xf, /* All four ports. */
157 .preboot_support = 1, /* preOS driver? */
158 .xhci_streams = 1, /* Enable. */
Nico Huberefe1fed2013-04-29 18:00:57 +0200159 },
Edward O'Callaghan6f49f692014-05-24 02:04:52 +1000160 .pcie_init = 1,
Nico Huberefe1fed2013-04-29 18:00:57 +0200161 };
162
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300163 timestamp_init(get_initial_timestamp());
164 timestamp_add_now(TS_START_ROMSTAGE);
Nico Huberefe1fed2013-04-29 18:00:57 +0200165
166 if (bist == 0)
167 enable_lapic();
168
169 pch_enable_lpc();
170
171 /* Enable GPIOs */
172 pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1);
173 pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10);
174 setup_pch_gpios(&ktqm77_gpio_map);
175 superio_gpio_config();
176
177 /* Initialize console device(s) */
178 console_init();
179
180 /* Halt if there was a built in self test failure */
181 report_bist_failure(bist);
182
183 if (MCHBAR16(SSKPD) == 0xCAFE) {
184 printk(BIOS_DEBUG, "soft reset detected\n");
185 boot_mode = 1;
186
187 /* System is not happy after keyboard reset... */
188 printk(BIOS_DEBUG, "Issuing CF9 warm reset\n");
189 outb(0x6, 0xcf9);
Patrick Georgibd79c5e2014-11-28 22:35:36 +0100190 halt();
Nico Huberefe1fed2013-04-29 18:00:57 +0200191 }
192
193 /* Perform some early chipset initialization required
194 * before RAM initialization can work
195 */
196 sandybridge_early_initialization(SANDYBRIDGE_MOBILE);
197 printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n");
198
199 /* Enable PEG10 (1x16) */
200 pci_write_config32(PCI_DEV(0, 0, 0), DEVEN,
201 pci_read_config32(PCI_DEV(0, 0, 0), DEVEN) |
202 DEVEN_PEG10);
203
Vladimir Serbinenko332f14b2014-09-05 16:29:41 +0200204 boot_mode = southbridge_detect_s3_resume() ? 2 : 0;
Nico Huberefe1fed2013-04-29 18:00:57 +0200205
206 post_code(0x38);
207 /* Enable SPD ROMs and DDR-III DRAM */
208 enable_smbus();
209
210 /* Prepare USB controller early in S3 resume */
211 if (boot_mode == 2)
212 enable_usb_bar();
213
214 post_code(0x39);
215
216 post_code(0x3a);
217 pei_data.boot_mode = boot_mode;
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300218 timestamp_add_now(TS_BEFORE_INITRAM);
Nico Huberefe1fed2013-04-29 18:00:57 +0200219 sdram_initialize(&pei_data);
220
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300221 timestamp_add_now(TS_AFTER_INITRAM);
Nico Huberefe1fed2013-04-29 18:00:57 +0200222 post_code(0x3c);
223
224 rcba_config();
225 post_code(0x3d);
226
227 quick_ram_check();
228 post_code(0x3e);
229
Kyösti Mälkki2d8520b2014-01-06 17:20:31 +0200230 cbmem_was_initted = !cbmem_recovery(boot_mode==2);
Kyösti Mälkki78938482014-01-04 11:02:45 +0200231 if (boot_mode!=2)
232 save_mrc_data(&pei_data);
Nico Huberefe1fed2013-04-29 18:00:57 +0200233
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200234 if (boot_mode==2 && !cbmem_was_initted) {
Nico Huberefe1fed2013-04-29 18:00:57 +0200235 /* Failed S3 resume, reset to come up cleanly */
236 outb(0x6, 0xcf9);
Patrick Georgibd79c5e2014-11-28 22:35:36 +0100237 halt();
Nico Huberefe1fed2013-04-29 18:00:57 +0200238 }
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200239 northbridge_romstage_finalize(boot_mode==2);
240
Nico Huberefe1fed2013-04-29 18:00:57 +0200241 post_code(0x3f);
Nico Huberefe1fed2013-04-29 18:00:57 +0200242}