blob: 791afe97bfa713604420cdd9cd18d6aa6b0f8243 [file] [log] [blame]
Stefan Reinauer155e9b52012-04-27 23:19:58 +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.
Stefan Reinauer155e9b52012-04-27 23:19:58 +020015 */
16
17#include <stdint.h>
18#include <string.h>
19#include <lib.h>
20#include <timestamp.h>
21#include <arch/io.h>
Stefan Reinauer155e9b52012-04-27 23:19:58 +020022#include <device/pci_def.h>
23#include <device/pnp_def.h>
24#include <cpu/x86/lapic.h>
25#include <pc80/mc146818rtc.h>
26#include <cbfs.h>
Kyösti Mälkki6722f8d2014-06-16 09:14:49 +030027#include <arch/acpi.h>
Stefan Reinauer155e9b52012-04-27 23:19:58 +020028#include <cbmem.h>
29#include <console/console.h>
Kyösti Mälkkie3ddee02014-05-03 10:45:28 +030030#include <bootmode.h>
Vladimir Serbinenko0e90dae2015-05-18 10:29:06 +020031#include <tpm.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110032#include <northbridge/intel/sandybridge/sandybridge.h>
33#include <northbridge/intel/sandybridge/raminit.h>
34#include <southbridge/intel/bd82x6x/pch.h>
Stefan Reinauer155e9b52012-04-27 23:19:58 +020035#include <arch/cpu.h>
Stefan Reinauer155e9b52012-04-27 23:19:58 +020036#include <cpu/x86/msr.h>
Patrick Georgibd79c5e2014-11-28 22:35:36 +010037#include <halt.h>
Stefan Reinauer155e9b52012-04-27 23:19:58 +020038#include "option_table.h"
Kyösti Mälkkiafa7b132014-02-13 17:16:22 +020039#if CONFIG_DRIVERS_UART_8250IO
Edward O'Callaghan74834e02015-01-04 04:17:35 +110040#include <superio/smsc/lpc47n207/lpc47n207.h>
Stefan Reinauer155e9b52012-04-27 23:19:58 +020041#endif
Stefan Reinauer155e9b52012-04-27 23:19:58 +020042
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +010043void pch_enable_lpc(void)
Stefan Reinauer155e9b52012-04-27 23:19:58 +020044{
45 /* Set COM1/COM2 decode range */
46 pci_write_config16(PCH_LPC_DEV, LPC_IO_DEC, 0x0010);
47
Kyösti Mälkkiafa7b132014-02-13 17:16:22 +020048#if CONFIG_DRIVERS_UART_8250IO
Stefan Reinauer155e9b52012-04-27 23:19:58 +020049 /* Enable SuperIO + EC + KBC + COM1 + lpc47n207 config*/
50 pci_write_config16(PCH_LPC_DEV, LPC_EN, CNF1_LPC_EN | MC_LPC_EN |
51 KBC_LPC_EN | CNF2_LPC_EN | COMA_LPC_EN);
52
53 /* map full 256 bytes at 0x1600 to the LPC bus */
54 pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, 0xfc1601);
55
56 try_enabling_LPC47N207_uart();
57#else
58 /* Enable SuperIO + EC + KBC */
59 pci_write_config16(PCH_LPC_DEV, LPC_EN, CNF1_LPC_EN | MC_LPC_EN |
60 KBC_LPC_EN);
61#endif
62}
63
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +010064void rcba_config(void)
Stefan Reinauer155e9b52012-04-27 23:19:58 +020065{
66 u32 reg32;
67
Kyösti Mälkki6f499062015-06-06 11:52:24 +030068 /*
69 * GFX INTA -> PIRQA (MSI)
70 * D28IP_P1IP WLAN INTA -> PIRQB
71 * D28IP_P4IP ETH0 INTB -> PIRQC (MSI)
72 * D29IP_E1P EHCI1 INTA -> PIRQD
73 * D26IP_E2P EHCI2 INTA -> PIRQB
74 * D31IP_SIP SATA INTA -> PIRQA (MSI)
75 * D31IP_SMIP SMBUS INTC -> PIRQH
76 * D31IP_TTIP THRT INTB -> PIRQG
77 * D27IP_ZIP HDA INTA -> PIRQG (MSI)
78 *
79 * LIGHTSENSOR -> PIRQE (Edge Triggered)
80 * TRACKPAD -> PIRQF (Edge Triggered)
81 */
82
83 /* Device interrupt pin register (board specific) */
84 RCBA32(D31IP) = (INTB << D31IP_TTIP) | (NOINT << D31IP_SIP2) |
85 (INTC << D31IP_SMIP) | (INTA << D31IP_SIP);
86 RCBA32(D30IP) = (NOINT << D30IP_PIP);
87 RCBA32(D29IP) = (INTA << D29IP_E1P);
88 RCBA32(D28IP) = (INTA << D28IP_P1IP) | (INTC << D28IP_P3IP) |
89 (INTB << D28IP_P4IP);
90 RCBA32(D27IP) = (INTA << D27IP_ZIP);
91 RCBA32(D26IP) = (INTA << D26IP_E2P);
92 RCBA32(D25IP) = (NOINT << D25IP_LIP);
93 RCBA32(D22IP) = (NOINT << D22IP_MEI1IP);
94
95 /* Device interrupt route registers */
96 DIR_ROUTE(D31IR, PIRQA, PIRQG, PIRQH, PIRQB);
97 DIR_ROUTE(D29IR, PIRQD, PIRQE, PIRQG, PIRQH);
98 DIR_ROUTE(D28IR, PIRQB, PIRQC, PIRQD, PIRQE);
99 DIR_ROUTE(D27IR, PIRQG, PIRQH, PIRQA, PIRQB);
100 DIR_ROUTE(D26IR, PIRQB, PIRQC, PIRQD, PIRQA);
101 DIR_ROUTE(D25IR, PIRQA, PIRQB, PIRQC, PIRQD);
102 DIR_ROUTE(D22IR, PIRQA, PIRQB, PIRQC, PIRQD);
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200103
104 /* Enable IOAPIC (generic) */
105 RCBA16(OIC) = 0x0100;
106 /* PCH BWG says to read back the IOAPIC enable register */
107 (void) RCBA16(OIC);
108
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200109 /* Disable unused devices (board specific) */
110 reg32 = RCBA32(FD);
111 reg32 |= PCH_DISABLE_ALWAYS;
112 RCBA32(FD) = reg32;
113}
114
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100115void mainboard_fill_pei_data(struct pei_data *pei_data)
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200116{
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100117 struct pei_data pei_data_template = {
Edward O'Callaghanc9714bc2014-10-29 06:16:51 +1100118 .pei_version = PEI_VERSION,
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800119 .mchbar = (uintptr_t)DEFAULT_MCHBAR,
120 .dmibar = (uintptr_t)DEFAULT_DMIBAR,
Edward O'Callaghanc9714bc2014-10-29 06:16:51 +1100121 .epbar = DEFAULT_EPBAR,
122 .pciexbar = CONFIG_MMCONF_BASE_ADDRESS,
123 .smbusbar = SMBUS_IO_BASE,
124 .wdbbar = 0x4000000,
125 .wdbsize = 0x1000,
126 .hpet_address = CONFIG_HPET_ADDRESS,
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800127 .rcba = (uintptr_t)DEFAULT_RCBABASE,
Edward O'Callaghanc9714bc2014-10-29 06:16:51 +1100128 .pmbase = DEFAULT_PMBASE,
129 .gpiobase = DEFAULT_GPIOBASE,
130 .thermalbase = 0xfed08000,
131 .system_type = 0, // 0 Mobile, 1 Desktop/Server
132 .tseg_size = CONFIG_SMM_TSEG_SIZE,
133 .spd_addresses = { 0xa0, 0x00,0x00,0x00 },
134 .ts_addresses = { 0x30, 0x00, 0x00, 0x00 },
135 .ec_present = 1,
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200136 // 0 = leave channel enabled
137 // 1 = disable dimm 0 on channel
138 // 2 = disable dimm 1 on channel
139 // 3 = disable dimm 0+1 on channel
Edward O'Callaghanc9714bc2014-10-29 06:16:51 +1100140 .dimm_channel0_disabled = 2,
141 .dimm_channel1_disabled = 2,
142 .max_ddr3_freq = 1333,
143 .usb_port_config = {
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200144 { 1, 0, 0x0080 }, /* P0: Port 0 (OC0) */
145 { 1, 1, 0x0080 }, /* P1: Port 1 (OC1) */
146 { 1, 0, 0x0040 }, /* P2: MINIPCIE1 (no OC) */
147 { 1, 0, 0x0040 }, /* P3: MMC (no OC) */
148 { 0, 0, 0x0000 }, /* P4: Empty */
149 { 0, 0, 0x0000 }, /* P5: Empty */
150 { 0, 0, 0x0000 }, /* P6: Empty */
151 { 0, 0, 0x0000 }, /* P7: Empty */
152 { 1, 4, 0x0040 }, /* P8: MINIPCIE2 (no OC) */
153 { 0, 4, 0x0000 }, /* P9: Empty */
154 { 0, 4, 0x0000 }, /* P10: Empty */
155 { 1, 4, 0x0040 }, /* P11: Camera (no OC) */
156 { 0, 4, 0x0000 }, /* P12: Empty */
157 { 0, 4, 0x0000 }, /* P13: Empty */
158 },
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200159 };
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100160 *pei_data = pei_data_template;
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200161 typedef const uint8_t spd_blob[256];
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200162 spd_blob *spd_data;
Vladimir Serbinenko12874162014-01-12 14:12:15 +0100163 size_t spd_file_len;
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200164
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200165 u32 gp_lvl2 = inl(DEFAULT_GPIOBASE + 0x38);
166 u8 gpio33, gpio41, gpio49;
167 gpio33 = (gp_lvl2 >> (33-32)) & 1;
168 gpio41 = (gp_lvl2 >> (41-32)) & 1;
169 gpio49 = (gp_lvl2 >> (49-32)) & 1;
170 printk(BIOS_DEBUG, "Memory Straps:\n");
171 printk(BIOS_DEBUG, " - memory capacity %dGB\n",
172 gpio33 ? 2 : 1);
173 printk(BIOS_DEBUG, " - die revision %d\n",
174 gpio41 ? 2 : 1);
175 printk(BIOS_DEBUG, " - vendor %s\n",
176 gpio49 ? "Samsung" : "Other");
177
178 int spd_index = 0;
179
180 switch ((gpio49 << 2) | (gpio41 << 1) | gpio33) {
181 case 0: // Other 1G Rev 1
182 spd_index = 0;
183 break;
184 case 2: // Other 1G Rev 2
185 spd_index = 1;
186 break;
187 case 1: // Other 2G Rev 1
188 case 3: // Other 2G Rev 2
189 spd_index = 2;
190 break;
191 case 4: // Samsung 1G Rev 1
192 spd_index = 3;
193 break;
194 case 6: // Samsung 1G Rev 2
195 spd_index = 4;
196 break;
197 case 5: // Samsung 2G Rev 1
198 case 7: // Samsung 2G Rev 2
199 spd_index = 5;
200 break;
201 }
202
Aaron Durbin899d13d2015-05-15 23:39:23 -0500203 spd_data = cbfs_boot_map_with_leak("spd.bin", CBFS_TYPE_SPD,
204 &spd_file_len);
Vladimir Serbinenko12874162014-01-12 14:12:15 +0100205 if (!spd_data)
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200206 die("SPD data not found.");
Vladimir Serbinenko12874162014-01-12 14:12:15 +0100207 if (spd_file_len < (spd_index + 1) * 256)
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200208 die("Missing SPD data.");
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200209 // leave onboard dimm address at f0, and copy spd data there.
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100210 memcpy(pei_data->spd_data[0], spd_data[spd_index], 256);
211}
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200212
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100213void mainboard_early_init(int s3resume)
214{
215 init_bootmode_straps();
216}
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200217
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100218int mainboard_should_reset_usb(int s3resume)
219{
220 return !s3resume;
221}
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200222
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100223void mainboard_config_superio(void)
224{
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200225}