blob: 8348e4f15827389b4daff62e59b997b1634e0a69 [file] [log] [blame]
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -07001/*
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.
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070015 */
16
17#include <stdint.h>
18#include <string.h>
19#include <lib.h>
20#include <timestamp.h>
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070021#include <arch/io.h>
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070022#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>
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070027#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>
Vladimir Serbinenkof004b6b2016-02-10 02:42:16 +010031#include <northbridge/intel/sandybridge/raminit_native.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110032#include <southbridge/intel/bd82x6x/pch.h>
Patrick Rudolphe8e66f42016-02-06 17:42:42 +010033#include <southbridge/intel/common/gpio.h>
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070034#include <arch/cpu.h>
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070035#include <cpu/x86/msr.h>
Patrick Georgibd79c5e2014-11-28 22:35:36 +010036#include <halt.h>
Kyösti Mälkki926a8d12014-04-27 22:17:22 +030037#include <bootmode.h>
Vladimir Serbinenko0e90dae2015-05-18 10:29:06 +020038#include <tpm.h>
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070039#include <cbfs.h>
40#include <ec/quanta/it8518/ec.h>
41#include "ec.h"
42#include "onboard.h"
43
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +010044void pch_enable_lpc(void)
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070045{
46 /*
47 * Enable:
48 * EC Decode Range Port62/66
49 * SuperIO Port2E/2F
50 * PS/2 Keyboard/Mouse Port60/64
51 * FDD Port3F0h-3F5h and Port3F7h
52 */
53 pci_write_config16(PCH_LPC_DEV, LPC_EN, KBC_LPC_EN | MC_LPC_EN |
54 CNF1_LPC_EN | FDD_LPC_EN);
55
56 /* Stout EC Decode Range Port68/6C */
57 pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, (0x68 | 0x40001));
58}
59
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +010060void rcba_config(void)
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070061{
62 u32 reg32;
63
Kyösti Mälkki6f499062015-06-06 11:52:24 +030064 /*
65 * GFX INTA -> PIRQA (MSI)
66 * D20IP_XHCI XHCI INTA -> PIRQD (MSI)
67 * D26IP_E2P EHCI #2 INTA -> PIRQF
68 * D27IP_ZIP HDA INTA -> PIRQA (MSI)
69 * D28IP_P2IP WLAN INTA -> PIRQD
70 * D28IP_P3IP Card Reader INTB -> PIRQE
71 * D28IP_P6IP LAN INTC -> PIRQB
72 * D29IP_E1P EHCI #1 INTA -> PIRQD
73 * D31IP_SIP SATA INTA -> PIRQB (MSI)
74 * D31IP_SMIP SMBUS INTB -> PIRQH
75 */
76
77 /* Device interrupt pin register (board specific) */
78 RCBA32(D31IP) = (NOINT << D31IP_TTIP) | (NOINT << D31IP_SIP2) |
79 (INTB << D31IP_SMIP) | (INTA << D31IP_SIP);
80 RCBA32(D30IP) = (NOINT << D30IP_PIP);
81 RCBA32(D29IP) = (INTA << D29IP_E1P);
82 RCBA32(D28IP) = (NOINT << D28IP_P1IP) | (INTA << D28IP_P2IP) |
83 (INTB << D28IP_P3IP) | (NOINT << D28IP_P4IP) |
84 (NOINT << D28IP_P5IP) | (INTC << D28IP_P6IP) |
85 (NOINT << D28IP_P7IP) | (NOINT << D28IP_P8IP);
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 RCBA32(D20IP) = (INTA << D20IP_XHCIIP);
91
92 /* Device interrupt route registers */
93 DIR_ROUTE(D31IR, PIRQB, PIRQH, PIRQA, PIRQC);
94 DIR_ROUTE(D29IR, PIRQD, PIRQE, PIRQF, PIRQG);
95 DIR_ROUTE(D28IR, PIRQD, PIRQE, PIRQB, PIRQC);
96 DIR_ROUTE(D27IR, PIRQA, PIRQB, PIRQC, PIRQD);
97 DIR_ROUTE(D26IR, PIRQF, PIRQB, PIRQC, PIRQD);
98 DIR_ROUTE(D25IR, PIRQA, PIRQB, PIRQC, PIRQD);
99 DIR_ROUTE(D22IR, PIRQA, PIRQB, PIRQC, PIRQD);
100 DIR_ROUTE(D20IR, PIRQD, PIRQE, PIRQF, PIRQG);
101
102 /* Enable IOAPIC (generic) */
103 RCBA16(OIC) = 0x0100;
104 /* PCH BWG says to read back the IOAPIC enable register */
105 (void) RCBA16(OIC);
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700106
107 /* Disable unused devices (board specific) */
108 reg32 = RCBA32(FD);
109 reg32 |= PCH_DISABLE_ALWAYS;
110 /* Disable PCI bridge so MRC does not probe this bus */
111 reg32 |= PCH_DISABLE_P2P;
112 RCBA32(FD) = reg32;
113}
114
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700115 /*
116 * The Stout EC needs to be reset to RW mode. It is important that
117 * the RTC_PWR_STS is not set until ramstage EC init.
118 */
119static void early_ec_init(void)
120{
121 u8 ec_status = ec_read(EC_STATUS_REG);
Kyösti Mälkki926a8d12014-04-27 22:17:22 +0300122 int rec_mode = IS_ENABLED(CONFIG_BOOTMODE_STRAPS) &&
123 get_recovery_mode_switch();
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700124
125 if (((ec_status & 0x3) == EC_IN_RO_MODE) ||
126 ((ec_status & 0x3) == EC_IN_RECOVERY_MODE)) {
127
128 printk(BIOS_DEBUG, "EC Cold Boot Detected\n");
129 if (!rec_mode) {
130 /*
131 * Tell EC to exit RO mode
132 */
133 printk(BIOS_DEBUG, "EC will exit RO mode and boot normally\n");
134 ec_write_cmd(EC_CMD_EXIT_BOOT_BLOCK);
135 die("wait for ec to reset");
136 }
137 } else {
138 printk(BIOS_DEBUG, "EC Warm Boot Detected\n");
139 ec_write_cmd(EC_CMD_WARM_RESET);
140 }
141}
142
Vladimir Serbinenkof004b6b2016-02-10 02:42:16 +0100143void mainboard_get_spd(spd_raw_data *spd)
144{
145 read_spd(&spd[0], 0x50);
146 read_spd(&spd[2], 0x52);
147}
148
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100149void mainboard_fill_pei_data(struct pei_data *pei_data)
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700150{
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100151 struct pei_data pei_data_template = {
Edward O'Callaghan77896c12014-10-28 10:03:47 +1100152 .pei_version = PEI_VERSION,
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800153 .mchbar = (uintptr_t)DEFAULT_MCHBAR,
154 .dmibar = (uintptr_t)DEFAULT_DMIBAR,
Edward O'Callaghan77896c12014-10-28 10:03:47 +1100155 .epbar = DEFAULT_EPBAR,
156 .pciexbar = CONFIG_MMCONF_BASE_ADDRESS,
157 .smbusbar = SMBUS_IO_BASE,
158 .wdbbar = 0x4000000,
159 .wdbsize = 0x1000,
160 .hpet_address = CONFIG_HPET_ADDRESS,
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800161 .rcba = (uintptr_t)DEFAULT_RCBABASE,
Edward O'Callaghan77896c12014-10-28 10:03:47 +1100162 .pmbase = DEFAULT_PMBASE,
163 .gpiobase = DEFAULT_GPIOBASE,
164 .thermalbase = 0xfed08000,
165 .system_type = 0, // 0 Mobile, 1 Desktop/Server
166 .tseg_size = CONFIG_SMM_TSEG_SIZE,
167 .spd_addresses = { 0xA0, 0x00,0xA4,0x00 },
168 .ts_addresses = { 0x00, 0x00, 0x00, 0x00 },
169 .ec_present = 1,
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700170 // 0 = leave channel enabled
171 // 1 = disable dimm 0 on channel
172 // 2 = disable dimm 1 on channel
173 // 3 = disable dimm 0+1 on channel
Edward O'Callaghan77896c12014-10-28 10:03:47 +1100174 .dimm_channel0_disabled = 2,
175 .dimm_channel1_disabled = 2,
176 .max_ddr3_freq = 1600,
177 .usb_port_config = {
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700178 /* enabled usb oc pin length */
179 { 1, 0, 0x0040 }, /* P0: USB 3.0 1 (OC0) */
180 { 1, 0, 0x0040 }, /* P1: USB 3.0 2 (OC0) */
181 { 0, 1, 0x0000 }, /* P2: Empty */
182 { 1, 1, 0x0040 }, /* P3: Camera (no OC) */
183 { 1, 1, 0x0040 }, /* P4: WLAN (no OC) */
184 { 1, 1, 0x0040 }, /* P5: WWAN (no OC) */
185 { 0, 1, 0x0000 }, /* P6: Empty */
186 { 0, 1, 0x0000 }, /* P7: Empty */
187 { 0, 5, 0x0000 }, /* P8: Empty */
188 { 1, 4, 0x0040 }, /* P9: USB 2.0 (AUO4) (OC4) */
189 { 0, 5, 0x0000 }, /* P10: Empty */
190 { 0, 5, 0x0000 }, /* P11: Empty */
191 { 0, 5, 0x0000 }, /* P12: Empty */
192 { 1, 5, 0x0040 }, /* P13: Bluetooth (no OC) */
193 },
Edward O'Callaghan77896c12014-10-28 10:03:47 +1100194 .usb3 = {
195 .mode = XHCI_MODE,
196 .hs_port_switch_mask = XHCI_PORTS,
197 .preboot_support = XHCI_PREBOOT,
198 .xhci_streams = XHCI_STREAMS,
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700199 },
200 };
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100201 *pei_data = pei_data_template;
202}
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700203
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100204void mainboard_early_init(int s3resume)
205{
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700206 /* Do ec reset as early as possible, but skip it on S3 resume */
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100207 if (!s3resume) {
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700208 early_ec_init();
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700209 }
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100210}
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200211
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100212int mainboard_should_reset_usb(int s3resume)
213{
214 return !s3resume;
215}
216
217void mainboard_config_superio(void)
218{
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700219}
Vladimir Serbinenkof004b6b2016-02-10 02:42:16 +0100220
221const struct southbridge_usb_port mainboard_usb_ports[] = {
222 /* enabled usb oc pin length */
223 {1, 0, 0}, /* P0: USB 3.0 1 (OC0) */
224 {1, 0, 0}, /* P1: USB 3.0 2 (OC0) */
225 {0, 0, 0}, /* P2: Empty */
226 {1, 0, -1}, /* P3: Camera (no OC) */
227 {1, 0, -1}, /* P4: WLAN (no OC) */
228 {1, 0, -1}, /* P5: WWAN (no OC) */
229 {0, 0, 0}, /* P6: Empty */
230 {0, 0, 0}, /* P7: Empty */
231 {0, 0, 0}, /* P8: Empty */
232 {1, 0, 4}, /* P9: USB 2.0 (AUO4) (OC4) */
233 {0, 0, 0}, /* P10: Empty */
234 {0, 0, 0}, /* P11: Empty */
235 {0, 0, 0}, /* P12: Empty */
236 {1, 0, -1}, /* P13: Bluetooth (no OC) */
237};