Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [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 | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <stdint.h> |
| 18 | #include <string.h> |
| 19 | #include <lib.h> |
| 20 | #include <timestamp.h> |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 21 | #include <arch/io.h> |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 22 | #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älkki | 6722f8d | 2014-06-16 09:14:49 +0300 | [diff] [blame] | 26 | #include <arch/acpi.h> |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 27 | #include <cbmem.h> |
| 28 | #include <console/console.h> |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 29 | #include <northbridge/intel/sandybridge/sandybridge.h> |
| 30 | #include <northbridge/intel/sandybridge/raminit.h> |
Vladimir Serbinenko | f004b6b | 2016-02-10 02:42:16 +0100 | [diff] [blame] | 31 | #include <northbridge/intel/sandybridge/raminit_native.h> |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 32 | #include <southbridge/intel/bd82x6x/pch.h> |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 33 | #include <arch/cpu.h> |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 34 | #include <cpu/x86/msr.h> |
Patrick Georgi | bd79c5e | 2014-11-28 22:35:36 +0100 | [diff] [blame] | 35 | #include <halt.h> |
Kyösti Mälkki | 926a8d1 | 2014-04-27 22:17:22 +0300 | [diff] [blame] | 36 | #include <bootmode.h> |
Vladimir Serbinenko | 0e90dae | 2015-05-18 10:29:06 +0200 | [diff] [blame] | 37 | #include <tpm.h> |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 38 | #include <cbfs.h> |
| 39 | #include <ec/quanta/it8518/ec.h> |
| 40 | #include "ec.h" |
| 41 | #include "onboard.h" |
| 42 | |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 43 | void pch_enable_lpc(void) |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 44 | { |
| 45 | /* |
| 46 | * Enable: |
| 47 | * EC Decode Range Port62/66 |
| 48 | * SuperIO Port2E/2F |
| 49 | * PS/2 Keyboard/Mouse Port60/64 |
| 50 | * FDD Port3F0h-3F5h and Port3F7h |
| 51 | */ |
| 52 | pci_write_config16(PCH_LPC_DEV, LPC_EN, KBC_LPC_EN | MC_LPC_EN | |
| 53 | CNF1_LPC_EN | FDD_LPC_EN); |
| 54 | |
| 55 | /* Stout EC Decode Range Port68/6C */ |
| 56 | pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, (0x68 | 0x40001)); |
| 57 | } |
| 58 | |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 59 | void rcba_config(void) |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 60 | { |
| 61 | u32 reg32; |
| 62 | |
Kyösti Mälkki | 6f49906 | 2015-06-06 11:52:24 +0300 | [diff] [blame] | 63 | /* |
| 64 | * GFX INTA -> PIRQA (MSI) |
| 65 | * D20IP_XHCI XHCI INTA -> PIRQD (MSI) |
| 66 | * D26IP_E2P EHCI #2 INTA -> PIRQF |
| 67 | * D27IP_ZIP HDA INTA -> PIRQA (MSI) |
| 68 | * D28IP_P2IP WLAN INTA -> PIRQD |
| 69 | * D28IP_P3IP Card Reader INTB -> PIRQE |
| 70 | * D28IP_P6IP LAN INTC -> PIRQB |
| 71 | * D29IP_E1P EHCI #1 INTA -> PIRQD |
| 72 | * D31IP_SIP SATA INTA -> PIRQB (MSI) |
| 73 | * D31IP_SMIP SMBUS INTB -> PIRQH |
| 74 | */ |
| 75 | |
| 76 | /* Device interrupt pin register (board specific) */ |
| 77 | RCBA32(D31IP) = (NOINT << D31IP_TTIP) | (NOINT << D31IP_SIP2) | |
| 78 | (INTB << D31IP_SMIP) | (INTA << D31IP_SIP); |
| 79 | RCBA32(D30IP) = (NOINT << D30IP_PIP); |
| 80 | RCBA32(D29IP) = (INTA << D29IP_E1P); |
| 81 | RCBA32(D28IP) = (NOINT << D28IP_P1IP) | (INTA << D28IP_P2IP) | |
| 82 | (INTB << D28IP_P3IP) | (NOINT << D28IP_P4IP) | |
| 83 | (NOINT << D28IP_P5IP) | (INTC << D28IP_P6IP) | |
| 84 | (NOINT << D28IP_P7IP) | (NOINT << D28IP_P8IP); |
| 85 | RCBA32(D27IP) = (INTA << D27IP_ZIP); |
| 86 | RCBA32(D26IP) = (INTA << D26IP_E2P); |
| 87 | RCBA32(D25IP) = (NOINT << D25IP_LIP); |
| 88 | RCBA32(D22IP) = (NOINT << D22IP_MEI1IP); |
| 89 | RCBA32(D20IP) = (INTA << D20IP_XHCIIP); |
| 90 | |
| 91 | /* Device interrupt route registers */ |
| 92 | DIR_ROUTE(D31IR, PIRQB, PIRQH, PIRQA, PIRQC); |
| 93 | DIR_ROUTE(D29IR, PIRQD, PIRQE, PIRQF, PIRQG); |
| 94 | DIR_ROUTE(D28IR, PIRQD, PIRQE, PIRQB, PIRQC); |
| 95 | DIR_ROUTE(D27IR, PIRQA, PIRQB, PIRQC, PIRQD); |
| 96 | DIR_ROUTE(D26IR, PIRQF, PIRQB, PIRQC, PIRQD); |
| 97 | DIR_ROUTE(D25IR, PIRQA, PIRQB, PIRQC, PIRQD); |
| 98 | DIR_ROUTE(D22IR, PIRQA, PIRQB, PIRQC, PIRQD); |
| 99 | DIR_ROUTE(D20IR, PIRQD, PIRQE, PIRQF, PIRQG); |
| 100 | |
| 101 | /* Enable IOAPIC (generic) */ |
| 102 | RCBA16(OIC) = 0x0100; |
| 103 | /* PCH BWG says to read back the IOAPIC enable register */ |
| 104 | (void) RCBA16(OIC); |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 105 | |
| 106 | /* Disable unused devices (board specific) */ |
| 107 | reg32 = RCBA32(FD); |
| 108 | reg32 |= PCH_DISABLE_ALWAYS; |
| 109 | /* Disable PCI bridge so MRC does not probe this bus */ |
| 110 | reg32 |= PCH_DISABLE_P2P; |
| 111 | RCBA32(FD) = reg32; |
| 112 | } |
| 113 | |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 114 | /* |
| 115 | * The Stout EC needs to be reset to RW mode. It is important that |
| 116 | * the RTC_PWR_STS is not set until ramstage EC init. |
| 117 | */ |
| 118 | static void early_ec_init(void) |
| 119 | { |
| 120 | u8 ec_status = ec_read(EC_STATUS_REG); |
Kyösti Mälkki | 926a8d1 | 2014-04-27 22:17:22 +0300 | [diff] [blame] | 121 | int rec_mode = IS_ENABLED(CONFIG_BOOTMODE_STRAPS) && |
| 122 | get_recovery_mode_switch(); |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 123 | |
| 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 Serbinenko | f004b6b | 2016-02-10 02:42:16 +0100 | [diff] [blame] | 142 | void mainboard_get_spd(spd_raw_data *spd) |
| 143 | { |
| 144 | read_spd(&spd[0], 0x50); |
| 145 | read_spd(&spd[2], 0x52); |
| 146 | } |
| 147 | |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 148 | void mainboard_fill_pei_data(struct pei_data *pei_data) |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 149 | { |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 150 | struct pei_data pei_data_template = { |
Edward O'Callaghan | 77896c1 | 2014-10-28 10:03:47 +1100 | [diff] [blame] | 151 | .pei_version = PEI_VERSION, |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 152 | .mchbar = (uintptr_t)DEFAULT_MCHBAR, |
| 153 | .dmibar = (uintptr_t)DEFAULT_DMIBAR, |
Edward O'Callaghan | 77896c1 | 2014-10-28 10:03:47 +1100 | [diff] [blame] | 154 | .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 Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 160 | .rcba = (uintptr_t)DEFAULT_RCBABASE, |
Edward O'Callaghan | 77896c1 | 2014-10-28 10:03:47 +1100 | [diff] [blame] | 161 | .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 Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 169 | // 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'Callaghan | 77896c1 | 2014-10-28 10:03:47 +1100 | [diff] [blame] | 173 | .dimm_channel0_disabled = 2, |
| 174 | .dimm_channel1_disabled = 2, |
| 175 | .max_ddr3_freq = 1600, |
| 176 | .usb_port_config = { |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 177 | /* 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'Callaghan | 77896c1 | 2014-10-28 10:03:47 +1100 | [diff] [blame] | 193 | .usb3 = { |
| 194 | .mode = XHCI_MODE, |
| 195 | .hs_port_switch_mask = XHCI_PORTS, |
| 196 | .preboot_support = XHCI_PREBOOT, |
| 197 | .xhci_streams = XHCI_STREAMS, |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 198 | }, |
| 199 | }; |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 200 | *pei_data = pei_data_template; |
| 201 | } |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 202 | |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 203 | void mainboard_early_init(int s3resume) |
| 204 | { |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 205 | /* Do ec reset as early as possible, but skip it on S3 resume */ |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 206 | if (!s3resume) { |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 207 | early_ec_init(); |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 208 | } |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 209 | } |
Vladimir Serbinenko | c845b43 | 2014-09-05 03:37:44 +0200 | [diff] [blame] | 210 | |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 211 | int mainboard_should_reset_usb(int s3resume) |
| 212 | { |
| 213 | return !s3resume; |
| 214 | } |
| 215 | |
| 216 | void mainboard_config_superio(void) |
| 217 | { |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 218 | } |
Vladimir Serbinenko | f004b6b | 2016-02-10 02:42:16 +0100 | [diff] [blame] | 219 | |
| 220 | const struct southbridge_usb_port mainboard_usb_ports[] = { |
| 221 | /* 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) */ |
| 236 | }; |