blob: e4864515a9000ea617bf0ee22a408e5ca4117748 [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);
Furquan Shaikh0325dc62016-07-25 13:02:36 -0700122 int rec_mode = get_recovery_mode_switch();
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700123
124 if (((ec_status & 0x3) == EC_IN_RO_MODE) ||
125 ((ec_status & 0x3) == EC_IN_RECOVERY_MODE)) {
126
127 printk(BIOS_DEBUG, "EC Cold Boot Detected\n");
128 if (!rec_mode) {
129 /*
130 * Tell EC to exit RO mode
131 */
132 printk(BIOS_DEBUG, "EC will exit RO mode and boot normally\n");
133 ec_write_cmd(EC_CMD_EXIT_BOOT_BLOCK);
134 die("wait for ec to reset");
135 }
136 } else {
137 printk(BIOS_DEBUG, "EC Warm Boot Detected\n");
138 ec_write_cmd(EC_CMD_WARM_RESET);
139 }
140}
141
Vladimir Serbinenkof004b6b2016-02-10 02:42:16 +0100142void mainboard_get_spd(spd_raw_data *spd)
143{
144 read_spd(&spd[0], 0x50);
145 read_spd(&spd[2], 0x52);
146}
147
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100148void mainboard_fill_pei_data(struct pei_data *pei_data)
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700149{
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100150 struct pei_data pei_data_template = {
Edward O'Callaghan77896c12014-10-28 10:03:47 +1100151 .pei_version = PEI_VERSION,
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800152 .mchbar = (uintptr_t)DEFAULT_MCHBAR,
153 .dmibar = (uintptr_t)DEFAULT_DMIBAR,
Edward O'Callaghan77896c12014-10-28 10:03:47 +1100154 .epbar = DEFAULT_EPBAR,
155 .pciexbar = CONFIG_MMCONF_BASE_ADDRESS,
156 .smbusbar = SMBUS_IO_BASE,
157 .wdbbar = 0x4000000,
158 .wdbsize = 0x1000,
159 .hpet_address = CONFIG_HPET_ADDRESS,
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800160 .rcba = (uintptr_t)DEFAULT_RCBABASE,
Edward O'Callaghan77896c12014-10-28 10:03:47 +1100161 .pmbase = DEFAULT_PMBASE,
162 .gpiobase = DEFAULT_GPIOBASE,
163 .thermalbase = 0xfed08000,
164 .system_type = 0, // 0 Mobile, 1 Desktop/Server
165 .tseg_size = CONFIG_SMM_TSEG_SIZE,
166 .spd_addresses = { 0xA0, 0x00,0xA4,0x00 },
167 .ts_addresses = { 0x00, 0x00, 0x00, 0x00 },
168 .ec_present = 1,
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700169 // 0 = leave channel enabled
170 // 1 = disable dimm 0 on channel
171 // 2 = disable dimm 1 on channel
172 // 3 = disable dimm 0+1 on channel
Edward O'Callaghan77896c12014-10-28 10:03:47 +1100173 .dimm_channel0_disabled = 2,
174 .dimm_channel1_disabled = 2,
175 .max_ddr3_freq = 1600,
176 .usb_port_config = {
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700177 /* enabled usb oc pin length */
178 { 1, 0, 0x0040 }, /* P0: USB 3.0 1 (OC0) */
179 { 1, 0, 0x0040 }, /* P1: USB 3.0 2 (OC0) */
180 { 0, 1, 0x0000 }, /* P2: Empty */
181 { 1, 1, 0x0040 }, /* P3: Camera (no OC) */
182 { 1, 1, 0x0040 }, /* P4: WLAN (no OC) */
183 { 1, 1, 0x0040 }, /* P5: WWAN (no OC) */
184 { 0, 1, 0x0000 }, /* P6: Empty */
185 { 0, 1, 0x0000 }, /* P7: Empty */
186 { 0, 5, 0x0000 }, /* P8: Empty */
187 { 1, 4, 0x0040 }, /* P9: USB 2.0 (AUO4) (OC4) */
188 { 0, 5, 0x0000 }, /* P10: Empty */
189 { 0, 5, 0x0000 }, /* P11: Empty */
190 { 0, 5, 0x0000 }, /* P12: Empty */
191 { 1, 5, 0x0040 }, /* P13: Bluetooth (no OC) */
192 },
Edward O'Callaghan77896c12014-10-28 10:03:47 +1100193 .usb3 = {
194 .mode = XHCI_MODE,
195 .hs_port_switch_mask = XHCI_PORTS,
196 .preboot_support = XHCI_PREBOOT,
197 .xhci_streams = XHCI_STREAMS,
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700198 },
199 };
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100200 *pei_data = pei_data_template;
201}
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700202
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100203void mainboard_early_init(int s3resume)
204{
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700205 /* Do ec reset as early as possible, but skip it on S3 resume */
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100206 if (!s3resume) {
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700207 early_ec_init();
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700208 }
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100209}
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200210
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100211int mainboard_should_reset_usb(int s3resume)
212{
213 return !s3resume;
214}
215
216void mainboard_config_superio(void)
217{
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700218}
Vladimir Serbinenkof004b6b2016-02-10 02:42:16 +0100219
220const struct southbridge_usb_port mainboard_usb_ports[] = {
Elyes HAOUAS48a01292016-09-29 18:57:56 +0200221 /* enabled usb oc pin length */
222 {1, 0, 0}, /* P0: USB 3.0 1 (OC0) */
223 {1, 0, 0}, /* P1: USB 3.0 2 (OC0) */
224 {0, 0, 0}, /* P2: Empty */
225 {1, 0, -1}, /* P3: Camera (no OC) */
226 {1, 0, -1}, /* P4: WLAN (no OC) */
227 {1, 0, -1}, /* P5: WWAN (no OC) */
228 {0, 0, 0}, /* P6: Empty */
229 {0, 0, 0}, /* P7: Empty */
230 {0, 0, 0}, /* P8: Empty */
231 {1, 0, 4}, /* P9: USB 2.0 (AUO4) (OC4) */
232 {0, 0, 0}, /* P10: Empty */
233 {0, 0, 0}, /* P11: Empty */
234 {0, 0, 0}, /* P12: Empty */
235 {1, 0, -1}, /* P13: Bluetooth (no OC) */
Vladimir Serbinenkof004b6b2016-02-10 02:42:16 +0100236};