blob: 74d491f31086ce5005e3ea4ce3f6dc977e79c8bb [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>
Stefan Reinauer155e9b52012-04-27 23:19:58 +020019#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020020#include <device/pci_ops.h>
Stefan Reinauer155e9b52012-04-27 23:19:58 +020021#include <device/pci_def.h>
Stefan Reinauer155e9b52012-04-27 23:19:58 +020022#include <cpu/x86/lapic.h>
Stefan Reinauer155e9b52012-04-27 23:19:58 +020023#include <cbfs.h>
Stefan Reinauer155e9b52012-04-27 23:19:58 +020024#include <console/console.h>
Kyösti Mälkkie3ddee02014-05-03 10:45:28 +030025#include <bootmode.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110026#include <northbridge/intel/sandybridge/sandybridge.h>
27#include <northbridge/intel/sandybridge/raminit.h>
Vladimir Serbinenko0a07c5c2016-02-10 03:01:37 +010028#include <northbridge/intel/sandybridge/raminit_native.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110029#include <southbridge/intel/bd82x6x/pch.h>
Patrick Rudolphe8e66f42016-02-06 17:42:42 +010030#include <southbridge/intel/common/gpio.h>
Patrick Georgibd79c5e2014-11-28 22:35:36 +010031#include <halt.h>
Stefan Reinauer155e9b52012-04-27 23:19:58 +020032#include "option_table.h"
Julius Wernercd49cce2019-03-05 16:53:33 -080033#if CONFIG(DRIVERS_UART_8250IO)
Edward O'Callaghan74834e02015-01-04 04:17:35 +110034#include <superio/smsc/lpc47n207/lpc47n207.h>
Stefan Reinauer155e9b52012-04-27 23:19:58 +020035#endif
Stefan Reinauer155e9b52012-04-27 23:19:58 +020036
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +010037void pch_enable_lpc(void)
Stefan Reinauer155e9b52012-04-27 23:19:58 +020038{
39 /* Set COM1/COM2 decode range */
40 pci_write_config16(PCH_LPC_DEV, LPC_IO_DEC, 0x0010);
41
Julius Wernercd49cce2019-03-05 16:53:33 -080042#if CONFIG(DRIVERS_UART_8250IO)
Stefan Reinauer155e9b52012-04-27 23:19:58 +020043 /* Enable SuperIO + EC + KBC + COM1 + lpc47n207 config*/
44 pci_write_config16(PCH_LPC_DEV, LPC_EN, CNF1_LPC_EN | MC_LPC_EN |
45 KBC_LPC_EN | CNF2_LPC_EN | COMA_LPC_EN);
46
47 /* map full 256 bytes at 0x1600 to the LPC bus */
48 pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, 0xfc1601);
49
50 try_enabling_LPC47N207_uart();
51#else
52 /* Enable SuperIO + EC + KBC */
53 pci_write_config16(PCH_LPC_DEV, LPC_EN, CNF1_LPC_EN | MC_LPC_EN |
54 KBC_LPC_EN);
55#endif
56}
57
Nico Huberff4025c2018-01-14 12:34:43 +010058void mainboard_rcba_config(void)
Stefan Reinauer155e9b52012-04-27 23:19:58 +020059{
Kyösti Mälkki6f499062015-06-06 11:52:24 +030060 /*
61 * GFX INTA -> PIRQA (MSI)
62 * D28IP_P1IP WLAN INTA -> PIRQB
63 * D28IP_P4IP ETH0 INTB -> PIRQC (MSI)
64 * D29IP_E1P EHCI1 INTA -> PIRQD
65 * D26IP_E2P EHCI2 INTA -> PIRQB
66 * D31IP_SIP SATA INTA -> PIRQA (MSI)
67 * D31IP_SMIP SMBUS INTC -> PIRQH
68 * D31IP_TTIP THRT INTB -> PIRQG
69 * D27IP_ZIP HDA INTA -> PIRQG (MSI)
70 *
71 * LIGHTSENSOR -> PIRQE (Edge Triggered)
72 * TRACKPAD -> PIRQF (Edge Triggered)
73 */
74
75 /* Device interrupt pin register (board specific) */
76 RCBA32(D31IP) = (INTB << D31IP_TTIP) | (NOINT << D31IP_SIP2) |
77 (INTC << D31IP_SMIP) | (INTA << D31IP_SIP);
78 RCBA32(D30IP) = (NOINT << D30IP_PIP);
79 RCBA32(D29IP) = (INTA << D29IP_E1P);
80 RCBA32(D28IP) = (INTA << D28IP_P1IP) | (INTC << D28IP_P3IP) |
81 (INTB << D28IP_P4IP);
82 RCBA32(D27IP) = (INTA << D27IP_ZIP);
83 RCBA32(D26IP) = (INTA << D26IP_E2P);
84 RCBA32(D25IP) = (NOINT << D25IP_LIP);
85 RCBA32(D22IP) = (NOINT << D22IP_MEI1IP);
86
87 /* Device interrupt route registers */
88 DIR_ROUTE(D31IR, PIRQA, PIRQG, PIRQH, PIRQB);
89 DIR_ROUTE(D29IR, PIRQD, PIRQE, PIRQG, PIRQH);
90 DIR_ROUTE(D28IR, PIRQB, PIRQC, PIRQD, PIRQE);
91 DIR_ROUTE(D27IR, PIRQG, PIRQH, PIRQA, PIRQB);
92 DIR_ROUTE(D26IR, PIRQB, PIRQC, PIRQD, PIRQA);
93 DIR_ROUTE(D25IR, PIRQA, PIRQB, PIRQC, PIRQD);
94 DIR_ROUTE(D22IR, PIRQA, PIRQB, PIRQC, PIRQD);
Stefan Reinauer155e9b52012-04-27 23:19:58 +020095
96 /* Enable IOAPIC (generic) */
Arthur Heymans58a89532018-06-12 22:58:19 +020097 RCBA16(OIC) = 0x0100;
Stefan Reinauer155e9b52012-04-27 23:19:58 +020098 /* PCH BWG says to read back the IOAPIC enable register */
Arthur Heymans58a89532018-06-12 22:58:19 +020099 (void) RCBA16(OIC);
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200100}
101
Vladimir Serbinenko0a07c5c2016-02-10 03:01:37 +0100102static const uint8_t *locate_spd(void)
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200103{
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200104 typedef const uint8_t spd_blob[256];
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200105 spd_blob *spd_data;
Vladimir Serbinenko12874162014-01-12 14:12:15 +0100106 size_t spd_file_len;
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200107
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200108 u32 gp_lvl2 = inl(DEFAULT_GPIOBASE + 0x38);
109 u8 gpio33, gpio41, gpio49;
110 gpio33 = (gp_lvl2 >> (33-32)) & 1;
111 gpio41 = (gp_lvl2 >> (41-32)) & 1;
112 gpio49 = (gp_lvl2 >> (49-32)) & 1;
113 printk(BIOS_DEBUG, "Memory Straps:\n");
114 printk(BIOS_DEBUG, " - memory capacity %dGB\n",
115 gpio33 ? 2 : 1);
116 printk(BIOS_DEBUG, " - die revision %d\n",
117 gpio41 ? 2 : 1);
118 printk(BIOS_DEBUG, " - vendor %s\n",
119 gpio49 ? "Samsung" : "Other");
120
121 int spd_index = 0;
122
123 switch ((gpio49 << 2) | (gpio41 << 1) | gpio33) {
124 case 0: // Other 1G Rev 1
125 spd_index = 0;
126 break;
127 case 2: // Other 1G Rev 2
128 spd_index = 1;
129 break;
130 case 1: // Other 2G Rev 1
131 case 3: // Other 2G Rev 2
132 spd_index = 2;
133 break;
134 case 4: // Samsung 1G Rev 1
135 spd_index = 3;
136 break;
137 case 6: // Samsung 1G Rev 2
138 spd_index = 4;
139 break;
140 case 5: // Samsung 2G Rev 1
141 case 7: // Samsung 2G Rev 2
142 spd_index = 5;
143 break;
144 }
145
Aaron Durbin899d13d2015-05-15 23:39:23 -0500146 spd_data = cbfs_boot_map_with_leak("spd.bin", CBFS_TYPE_SPD,
147 &spd_file_len);
Vladimir Serbinenko12874162014-01-12 14:12:15 +0100148 if (!spd_data)
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200149 die("SPD data not found.");
Vladimir Serbinenko12874162014-01-12 14:12:15 +0100150 if (spd_file_len < (spd_index + 1) * 256)
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200151 die("Missing SPD data.");
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200152 // leave onboard dimm address at f0, and copy spd data there.
Vladimir Serbinenko0a07c5c2016-02-10 03:01:37 +0100153 return spd_data[spd_index];
154}
155
156void mainboard_fill_pei_data(struct pei_data *pei_data)
157{
158 struct pei_data pei_data_template = {
159 .pei_version = PEI_VERSION,
160 .mchbar = (uintptr_t)DEFAULT_MCHBAR,
161 .dmibar = (uintptr_t)DEFAULT_DMIBAR,
162 .epbar = DEFAULT_EPBAR,
163 .pciexbar = CONFIG_MMCONF_BASE_ADDRESS,
164 .smbusbar = SMBUS_IO_BASE,
165 .wdbbar = 0x4000000,
166 .wdbsize = 0x1000,
167 .hpet_address = CONFIG_HPET_ADDRESS,
168 .rcba = (uintptr_t)DEFAULT_RCBABASE,
169 .pmbase = DEFAULT_PMBASE,
170 .gpiobase = DEFAULT_GPIOBASE,
171 .thermalbase = 0xfed08000,
172 .system_type = 0, // 0 Mobile, 1 Desktop/Server
173 .tseg_size = CONFIG_SMM_TSEG_SIZE,
174 .spd_addresses = { 0xa0, 0x00,0x00,0x00 },
175 .ts_addresses = { 0x30, 0x00, 0x00, 0x00 },
176 .ec_present = 1,
177 // 0 = leave channel enabled
178 // 1 = disable dimm 0 on channel
179 // 2 = disable dimm 1 on channel
180 // 3 = disable dimm 0+1 on channel
181 .dimm_channel0_disabled = 2,
182 .dimm_channel1_disabled = 2,
183 .max_ddr3_freq = 1333,
184 .usb_port_config = {
185 { 1, 0, 0x0080 }, /* P0: Port 0 (OC0) */
186 { 1, 1, 0x0080 }, /* P1: Port 1 (OC1) */
187 { 1, 0, 0x0040 }, /* P2: MINIPCIE1 (no OC) */
188 { 1, 0, 0x0040 }, /* P3: MMC (no OC) */
189 { 0, 0, 0x0000 }, /* P4: Empty */
190 { 0, 0, 0x0000 }, /* P5: Empty */
191 { 0, 0, 0x0000 }, /* P6: Empty */
192 { 0, 0, 0x0000 }, /* P7: Empty */
193 { 1, 4, 0x0040 }, /* P8: MINIPCIE2 (no OC) */
194 { 0, 4, 0x0000 }, /* P9: Empty */
195 { 0, 4, 0x0000 }, /* P10: Empty */
196 { 1, 4, 0x0040 }, /* P11: Camera (no OC) */
197 { 0, 4, 0x0000 }, /* P12: Empty */
198 { 0, 4, 0x0000 }, /* P13: Empty */
199 },
200 };
201 *pei_data = pei_data_template;
202 // leave onboard dimm address at f0, and copy spd data there.
203 memcpy(pei_data->spd_data[0], locate_spd(), 256);
204}
205
206const struct southbridge_usb_port mainboard_usb_ports[] = {
207 /* enabled power usb oc pin */
208 { 1, 1, 0 }, /* P0: Port 0 (OC0) */
209 { 1, 1, 1 }, /* P1: Port 1 (OC1) */
210 { 1, 0, -1 }, /* P2: MINIPCIE1 (no OC) */
211 { 1, 0, -1 }, /* P3: MMC (no OC) */
212 { 0, 0, -1 }, /* P4: Empty */
213 { 0, 0, -1 }, /* P5: Empty */
214 { 0, 0, -1 }, /* P6: Empty */
215 { 0, 0, -1 }, /* P7: Empty */
216 { 1, 0, -1 }, /* P8: MINIPCIE2 (no OC) */
217 { 0, 0, -1 }, /* P9: Empty */
218 { 0, 0, -1 }, /* P10: Empty */
219 { 1, 0, -1 }, /* P11: Camera (no OC) */
220 { 0, 0, -1 }, /* P12: Empty */
221 { 0, 0, -1 }, /* P13: Empty */
222};
223
Kyösti Mälkkie258b9a2016-11-18 19:59:23 +0200224void mainboard_get_spd(spd_raw_data *spd, bool id_only)
Vladimir Serbinenko0a07c5c2016-02-10 03:01:37 +0100225{
Patrick Rudolph25852092016-04-07 18:51:12 +0200226 /* get onboard dimm spd */
Kyösti Mälkki38ab6f22016-10-01 12:54:01 +0300227 memcpy(&spd[2], locate_spd(), 256);
Patrick Rudolph25852092016-04-07 18:51:12 +0200228 /* read removable dimm spd */
Kyösti Mälkkie258b9a2016-11-18 19:59:23 +0200229 read_spd(&spd[0], 0x50, id_only);
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100230}
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200231
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100232void mainboard_early_init(int s3resume)
233{
234 init_bootmode_straps();
235}
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200236
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100237int mainboard_should_reset_usb(int s3resume)
238{
239 return !s3resume;
240}
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200241
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100242void mainboard_config_superio(void)
243{
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200244}