Stefan Reinauer | 155e9b5 | 2012-04-27 23:19:58 +0200 | [diff] [blame] | 1 | /* |
| 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 Reinauer | 155e9b5 | 2012-04-27 23:19:58 +0200 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <stdint.h> |
| 18 | #include <string.h> |
Stefan Reinauer | 155e9b5 | 2012-04-27 23:19:58 +0200 | [diff] [blame] | 19 | #include <arch/io.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 20 | #include <device/pci_ops.h> |
Stefan Reinauer | 155e9b5 | 2012-04-27 23:19:58 +0200 | [diff] [blame] | 21 | #include <device/pci_def.h> |
Stefan Reinauer | 155e9b5 | 2012-04-27 23:19:58 +0200 | [diff] [blame] | 22 | #include <cpu/x86/lapic.h> |
Stefan Reinauer | 155e9b5 | 2012-04-27 23:19:58 +0200 | [diff] [blame] | 23 | #include <cbfs.h> |
Stefan Reinauer | 155e9b5 | 2012-04-27 23:19:58 +0200 | [diff] [blame] | 24 | #include <console/console.h> |
Kyösti Mälkki | e3ddee0 | 2014-05-03 10:45:28 +0300 | [diff] [blame] | 25 | #include <bootmode.h> |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 26 | #include <northbridge/intel/sandybridge/sandybridge.h> |
| 27 | #include <northbridge/intel/sandybridge/raminit.h> |
Vladimir Serbinenko | 0a07c5c | 2016-02-10 03:01:37 +0100 | [diff] [blame] | 28 | #include <northbridge/intel/sandybridge/raminit_native.h> |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 29 | #include <southbridge/intel/bd82x6x/pch.h> |
Patrick Rudolph | e8e66f4 | 2016-02-06 17:42:42 +0100 | [diff] [blame] | 30 | #include <southbridge/intel/common/gpio.h> |
Stefan Reinauer | 155e9b5 | 2012-04-27 23:19:58 +0200 | [diff] [blame] | 31 | #include "option_table.h" |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 32 | #if CONFIG(DRIVERS_UART_8250IO) |
Edward O'Callaghan | 74834e0 | 2015-01-04 04:17:35 +1100 | [diff] [blame] | 33 | #include <superio/smsc/lpc47n207/lpc47n207.h> |
Stefan Reinauer | 155e9b5 | 2012-04-27 23:19:58 +0200 | [diff] [blame] | 34 | #endif |
Stefan Reinauer | 155e9b5 | 2012-04-27 23:19:58 +0200 | [diff] [blame] | 35 | |
Arthur Heymans | 2b28a16 | 2019-11-12 17:21:08 +0100 | [diff] [blame] | 36 | void mainboard_pch_lpc_setup(void) |
Stefan Reinauer | 155e9b5 | 2012-04-27 23:19:58 +0200 | [diff] [blame] | 37 | { |
| 38 | /* Set COM1/COM2 decode range */ |
| 39 | pci_write_config16(PCH_LPC_DEV, LPC_IO_DEC, 0x0010); |
| 40 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 41 | #if CONFIG(DRIVERS_UART_8250IO) |
Stefan Reinauer | 155e9b5 | 2012-04-27 23:19:58 +0200 | [diff] [blame] | 42 | /* Enable SuperIO + EC + KBC + COM1 + lpc47n207 config*/ |
| 43 | pci_write_config16(PCH_LPC_DEV, LPC_EN, CNF1_LPC_EN | MC_LPC_EN | |
| 44 | KBC_LPC_EN | CNF2_LPC_EN | COMA_LPC_EN); |
| 45 | |
Stefan Reinauer | 155e9b5 | 2012-04-27 23:19:58 +0200 | [diff] [blame] | 46 | try_enabling_LPC47N207_uart(); |
| 47 | #else |
| 48 | /* Enable SuperIO + EC + KBC */ |
| 49 | pci_write_config16(PCH_LPC_DEV, LPC_EN, CNF1_LPC_EN | MC_LPC_EN | |
| 50 | KBC_LPC_EN); |
| 51 | #endif |
| 52 | } |
| 53 | |
Arthur Heymans | 9c53834 | 2019-11-12 16:42:33 +0100 | [diff] [blame] | 54 | void mainboard_late_rcba_config(void) |
Stefan Reinauer | 155e9b5 | 2012-04-27 23:19:58 +0200 | [diff] [blame] | 55 | { |
Kyösti Mälkki | 6f49906 | 2015-06-06 11:52:24 +0300 | [diff] [blame] | 56 | /* |
| 57 | * GFX INTA -> PIRQA (MSI) |
| 58 | * D28IP_P1IP WLAN INTA -> PIRQB |
| 59 | * D28IP_P4IP ETH0 INTB -> PIRQC (MSI) |
| 60 | * D29IP_E1P EHCI1 INTA -> PIRQD |
| 61 | * D26IP_E2P EHCI2 INTA -> PIRQB |
| 62 | * D31IP_SIP SATA INTA -> PIRQA (MSI) |
| 63 | * D31IP_SMIP SMBUS INTC -> PIRQH |
| 64 | * D31IP_TTIP THRT INTB -> PIRQG |
| 65 | * D27IP_ZIP HDA INTA -> PIRQG (MSI) |
| 66 | * |
| 67 | * LIGHTSENSOR -> PIRQE (Edge Triggered) |
| 68 | * TRACKPAD -> PIRQF (Edge Triggered) |
| 69 | */ |
| 70 | |
| 71 | /* Device interrupt pin register (board specific) */ |
| 72 | RCBA32(D31IP) = (INTB << D31IP_TTIP) | (NOINT << D31IP_SIP2) | |
| 73 | (INTC << D31IP_SMIP) | (INTA << D31IP_SIP); |
| 74 | RCBA32(D30IP) = (NOINT << D30IP_PIP); |
| 75 | RCBA32(D29IP) = (INTA << D29IP_E1P); |
| 76 | RCBA32(D28IP) = (INTA << D28IP_P1IP) | (INTC << D28IP_P3IP) | |
| 77 | (INTB << D28IP_P4IP); |
| 78 | RCBA32(D27IP) = (INTA << D27IP_ZIP); |
| 79 | RCBA32(D26IP) = (INTA << D26IP_E2P); |
| 80 | RCBA32(D25IP) = (NOINT << D25IP_LIP); |
| 81 | RCBA32(D22IP) = (NOINT << D22IP_MEI1IP); |
| 82 | |
| 83 | /* Device interrupt route registers */ |
| 84 | DIR_ROUTE(D31IR, PIRQA, PIRQG, PIRQH, PIRQB); |
| 85 | DIR_ROUTE(D29IR, PIRQD, PIRQE, PIRQG, PIRQH); |
| 86 | DIR_ROUTE(D28IR, PIRQB, PIRQC, PIRQD, PIRQE); |
| 87 | DIR_ROUTE(D27IR, PIRQG, PIRQH, PIRQA, PIRQB); |
| 88 | DIR_ROUTE(D26IR, PIRQB, PIRQC, PIRQD, PIRQA); |
| 89 | DIR_ROUTE(D25IR, PIRQA, PIRQB, PIRQC, PIRQD); |
| 90 | DIR_ROUTE(D22IR, PIRQA, PIRQB, PIRQC, PIRQD); |
Stefan Reinauer | 155e9b5 | 2012-04-27 23:19:58 +0200 | [diff] [blame] | 91 | |
| 92 | /* Enable IOAPIC (generic) */ |
Arthur Heymans | 58a8953 | 2018-06-12 22:58:19 +0200 | [diff] [blame] | 93 | RCBA16(OIC) = 0x0100; |
Stefan Reinauer | 155e9b5 | 2012-04-27 23:19:58 +0200 | [diff] [blame] | 94 | /* PCH BWG says to read back the IOAPIC enable register */ |
Arthur Heymans | 58a8953 | 2018-06-12 22:58:19 +0200 | [diff] [blame] | 95 | (void) RCBA16(OIC); |
Stefan Reinauer | 155e9b5 | 2012-04-27 23:19:58 +0200 | [diff] [blame] | 96 | } |
| 97 | |
Vladimir Serbinenko | 0a07c5c | 2016-02-10 03:01:37 +0100 | [diff] [blame] | 98 | static const uint8_t *locate_spd(void) |
Stefan Reinauer | 155e9b5 | 2012-04-27 23:19:58 +0200 | [diff] [blame] | 99 | { |
Stefan Reinauer | 155e9b5 | 2012-04-27 23:19:58 +0200 | [diff] [blame] | 100 | typedef const uint8_t spd_blob[256]; |
Stefan Reinauer | 155e9b5 | 2012-04-27 23:19:58 +0200 | [diff] [blame] | 101 | spd_blob *spd_data; |
Vladimir Serbinenko | 1287416 | 2014-01-12 14:12:15 +0100 | [diff] [blame] | 102 | size_t spd_file_len; |
Stefan Reinauer | 155e9b5 | 2012-04-27 23:19:58 +0200 | [diff] [blame] | 103 | |
Stefan Reinauer | 155e9b5 | 2012-04-27 23:19:58 +0200 | [diff] [blame] | 104 | u32 gp_lvl2 = inl(DEFAULT_GPIOBASE + 0x38); |
| 105 | u8 gpio33, gpio41, gpio49; |
| 106 | gpio33 = (gp_lvl2 >> (33-32)) & 1; |
| 107 | gpio41 = (gp_lvl2 >> (41-32)) & 1; |
| 108 | gpio49 = (gp_lvl2 >> (49-32)) & 1; |
| 109 | printk(BIOS_DEBUG, "Memory Straps:\n"); |
| 110 | printk(BIOS_DEBUG, " - memory capacity %dGB\n", |
| 111 | gpio33 ? 2 : 1); |
| 112 | printk(BIOS_DEBUG, " - die revision %d\n", |
| 113 | gpio41 ? 2 : 1); |
| 114 | printk(BIOS_DEBUG, " - vendor %s\n", |
| 115 | gpio49 ? "Samsung" : "Other"); |
| 116 | |
| 117 | int spd_index = 0; |
| 118 | |
| 119 | switch ((gpio49 << 2) | (gpio41 << 1) | gpio33) { |
| 120 | case 0: // Other 1G Rev 1 |
| 121 | spd_index = 0; |
| 122 | break; |
| 123 | case 2: // Other 1G Rev 2 |
| 124 | spd_index = 1; |
| 125 | break; |
| 126 | case 1: // Other 2G Rev 1 |
| 127 | case 3: // Other 2G Rev 2 |
| 128 | spd_index = 2; |
| 129 | break; |
| 130 | case 4: // Samsung 1G Rev 1 |
| 131 | spd_index = 3; |
| 132 | break; |
| 133 | case 6: // Samsung 1G Rev 2 |
| 134 | spd_index = 4; |
| 135 | break; |
| 136 | case 5: // Samsung 2G Rev 1 |
| 137 | case 7: // Samsung 2G Rev 2 |
| 138 | spd_index = 5; |
| 139 | break; |
| 140 | } |
| 141 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 142 | spd_data = cbfs_boot_map_with_leak("spd.bin", CBFS_TYPE_SPD, |
| 143 | &spd_file_len); |
Vladimir Serbinenko | 1287416 | 2014-01-12 14:12:15 +0100 | [diff] [blame] | 144 | if (!spd_data) |
Stefan Reinauer | 155e9b5 | 2012-04-27 23:19:58 +0200 | [diff] [blame] | 145 | die("SPD data not found."); |
Vladimir Serbinenko | 1287416 | 2014-01-12 14:12:15 +0100 | [diff] [blame] | 146 | if (spd_file_len < (spd_index + 1) * 256) |
Stefan Reinauer | 155e9b5 | 2012-04-27 23:19:58 +0200 | [diff] [blame] | 147 | die("Missing SPD data."); |
Vladimir Serbinenko | 0a07c5c | 2016-02-10 03:01:37 +0100 | [diff] [blame] | 148 | return spd_data[spd_index]; |
| 149 | } |
| 150 | |
| 151 | void mainboard_fill_pei_data(struct pei_data *pei_data) |
| 152 | { |
| 153 | struct pei_data pei_data_template = { |
| 154 | .pei_version = PEI_VERSION, |
| 155 | .mchbar = (uintptr_t)DEFAULT_MCHBAR, |
| 156 | .dmibar = (uintptr_t)DEFAULT_DMIBAR, |
| 157 | .epbar = DEFAULT_EPBAR, |
| 158 | .pciexbar = CONFIG_MMCONF_BASE_ADDRESS, |
| 159 | .smbusbar = SMBUS_IO_BASE, |
| 160 | .wdbbar = 0x4000000, |
| 161 | .wdbsize = 0x1000, |
| 162 | .hpet_address = CONFIG_HPET_ADDRESS, |
| 163 | .rcba = (uintptr_t)DEFAULT_RCBABASE, |
| 164 | .pmbase = DEFAULT_PMBASE, |
| 165 | .gpiobase = DEFAULT_GPIOBASE, |
| 166 | .thermalbase = 0xfed08000, |
| 167 | .system_type = 0, // 0 Mobile, 1 Desktop/Server |
| 168 | .tseg_size = CONFIG_SMM_TSEG_SIZE, |
| 169 | .spd_addresses = { 0xa0, 0x00,0x00,0x00 }, |
| 170 | .ts_addresses = { 0x30, 0x00, 0x00, 0x00 }, |
| 171 | .ec_present = 1, |
| 172 | // 0 = leave channel enabled |
| 173 | // 1 = disable dimm 0 on channel |
| 174 | // 2 = disable dimm 1 on channel |
| 175 | // 3 = disable dimm 0+1 on channel |
| 176 | .dimm_channel0_disabled = 2, |
| 177 | .dimm_channel1_disabled = 2, |
| 178 | .max_ddr3_freq = 1333, |
| 179 | .usb_port_config = { |
| 180 | { 1, 0, 0x0080 }, /* P0: Port 0 (OC0) */ |
| 181 | { 1, 1, 0x0080 }, /* P1: Port 1 (OC1) */ |
| 182 | { 1, 0, 0x0040 }, /* P2: MINIPCIE1 (no OC) */ |
| 183 | { 1, 0, 0x0040 }, /* P3: MMC (no OC) */ |
| 184 | { 0, 0, 0x0000 }, /* P4: Empty */ |
| 185 | { 0, 0, 0x0000 }, /* P5: Empty */ |
| 186 | { 0, 0, 0x0000 }, /* P6: Empty */ |
| 187 | { 0, 0, 0x0000 }, /* P7: Empty */ |
| 188 | { 1, 4, 0x0040 }, /* P8: MINIPCIE2 (no OC) */ |
| 189 | { 0, 4, 0x0000 }, /* P9: Empty */ |
| 190 | { 0, 4, 0x0000 }, /* P10: Empty */ |
| 191 | { 1, 4, 0x0040 }, /* P11: Camera (no OC) */ |
| 192 | { 0, 4, 0x0000 }, /* P12: Empty */ |
| 193 | { 0, 4, 0x0000 }, /* P13: Empty */ |
| 194 | }, |
| 195 | }; |
| 196 | *pei_data = pei_data_template; |
Patrick Rudolph | 59b4255 | 2019-05-08 12:44:15 +0200 | [diff] [blame] | 197 | memcpy(pei_data->spd_data[2], locate_spd(), 256); |
Vladimir Serbinenko | 0a07c5c | 2016-02-10 03:01:37 +0100 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | const struct southbridge_usb_port mainboard_usb_ports[] = { |
| 201 | /* enabled power usb oc pin */ |
| 202 | { 1, 1, 0 }, /* P0: Port 0 (OC0) */ |
| 203 | { 1, 1, 1 }, /* P1: Port 1 (OC1) */ |
| 204 | { 1, 0, -1 }, /* P2: MINIPCIE1 (no OC) */ |
| 205 | { 1, 0, -1 }, /* P3: MMC (no OC) */ |
| 206 | { 0, 0, -1 }, /* P4: Empty */ |
| 207 | { 0, 0, -1 }, /* P5: Empty */ |
| 208 | { 0, 0, -1 }, /* P6: Empty */ |
| 209 | { 0, 0, -1 }, /* P7: Empty */ |
| 210 | { 1, 0, -1 }, /* P8: MINIPCIE2 (no OC) */ |
| 211 | { 0, 0, -1 }, /* P9: Empty */ |
| 212 | { 0, 0, -1 }, /* P10: Empty */ |
| 213 | { 1, 0, -1 }, /* P11: Camera (no OC) */ |
| 214 | { 0, 0, -1 }, /* P12: Empty */ |
| 215 | { 0, 0, -1 }, /* P13: Empty */ |
| 216 | }; |
| 217 | |
Kyösti Mälkki | e258b9a | 2016-11-18 19:59:23 +0200 | [diff] [blame] | 218 | void mainboard_get_spd(spd_raw_data *spd, bool id_only) |
Vladimir Serbinenko | 0a07c5c | 2016-02-10 03:01:37 +0100 | [diff] [blame] | 219 | { |
Patrick Rudolph | 2585209 | 2016-04-07 18:51:12 +0200 | [diff] [blame] | 220 | /* get onboard dimm spd */ |
Kyösti Mälkki | 38ab6f2 | 2016-10-01 12:54:01 +0300 | [diff] [blame] | 221 | memcpy(&spd[2], locate_spd(), 256); |
Patrick Rudolph | 2585209 | 2016-04-07 18:51:12 +0200 | [diff] [blame] | 222 | /* read removable dimm spd */ |
Kyösti Mälkki | e258b9a | 2016-11-18 19:59:23 +0200 | [diff] [blame] | 223 | read_spd(&spd[0], 0x50, id_only); |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 224 | } |
Stefan Reinauer | 155e9b5 | 2012-04-27 23:19:58 +0200 | [diff] [blame] | 225 | |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 226 | void mainboard_early_init(int s3resume) |
| 227 | { |
| 228 | init_bootmode_straps(); |
| 229 | } |
Stefan Reinauer | 155e9b5 | 2012-04-27 23:19:58 +0200 | [diff] [blame] | 230 | |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 231 | int mainboard_should_reset_usb(int s3resume) |
| 232 | { |
| 233 | return !s3resume; |
| 234 | } |