Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2007-2010 coresystems GmbH |
| 5 | * Copyright (C) 2011 Google Inc. |
| 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. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
| 21 | #include <stdint.h> |
| 22 | #include <string.h> |
| 23 | #include <lib.h> |
| 24 | #include <timestamp.h> |
| 25 | #include <arch/byteorder.h> |
| 26 | #include <arch/io.h> |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 27 | #include <device/pci.h> |
| 28 | #include <device/pci_def.h> |
| 29 | #include <device/pnp_def.h> |
| 30 | #include <cpu/x86/lapic.h> |
| 31 | #include <pc80/mc146818rtc.h> |
Kyösti Mälkki | 6722f8d | 2014-06-16 09:14:49 +0300 | [diff] [blame] | 32 | #include <arch/acpi.h> |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 33 | #include <cbmem.h> |
| 34 | #include <console/console.h> |
| 35 | #include "northbridge/intel/sandybridge/sandybridge.h" |
| 36 | #include "northbridge/intel/sandybridge/raminit.h" |
| 37 | #include "southbridge/intel/bd82x6x/pch.h" |
| 38 | #include "southbridge/intel/bd82x6x/gpio.h" |
| 39 | #include "ec/google/chromeec/ec.h" |
| 40 | #include <arch/cpu.h> |
| 41 | #include <cpu/x86/bist.h> |
| 42 | #include <cpu/x86/msr.h> |
Patrick Georgi | bd79c5e | 2014-11-28 22:35:36 +0100 | [diff] [blame^] | 43 | #include <halt.h> |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 44 | #include "gpio.h" |
| 45 | #if CONFIG_CHROMEOS |
| 46 | #include <vendorcode/google/chromeos/chromeos.h> |
| 47 | #endif |
| 48 | #include <cbfs.h> |
| 49 | |
| 50 | #include <southbridge/intel/bd82x6x/chip.h> |
| 51 | |
| 52 | static void pch_enable_lpc(void) |
| 53 | { |
| 54 | const struct device *lpc; |
| 55 | const struct southbridge_intel_bd82x6x_config *config = NULL; |
| 56 | |
| 57 | lpc = dev_find_slot(0, PCI_DEVFN(0x1f, 0)); |
| 58 | if (!lpc) |
| 59 | return; |
| 60 | if (lpc->chip_info) |
| 61 | config = lpc->chip_info; |
| 62 | if (!config) |
| 63 | return; |
| 64 | |
| 65 | /* Set COM1/COM2 decode range */ |
| 66 | pci_write_config16(PCH_LPC_DEV, LPC_IO_DEC, 0x0010); |
| 67 | |
| 68 | /* Enable PS/2 Keyboard/Mouse, EC areas and COM1 */ |
| 69 | pci_write_config16(PCH_LPC_DEV, LPC_EN, KBC_LPC_EN | MC_LPC_EN | \ |
| 70 | GAMEL_LPC_EN | COMA_LPC_EN); |
| 71 | |
| 72 | pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, config->gen1_dec); |
| 73 | pci_write_config32(PCH_LPC_DEV, LPC_GEN2_DEC, config->gen2_dec); |
| 74 | pci_write_config32(PCH_LPC_DEV, LPC_GEN3_DEC, config->gen3_dec); |
| 75 | pci_write_config32(PCH_LPC_DEV, LPC_GEN4_DEC, config->gen4_dec); |
| 76 | } |
| 77 | |
| 78 | static void rcba_config(void) |
| 79 | { |
| 80 | u32 reg32; |
| 81 | |
Vladimir Serbinenko | 33b535f | 2014-10-19 10:13:14 +0200 | [diff] [blame] | 82 | southbridge_configure_default_intmap(); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 83 | |
| 84 | /* Disable unused devices (board specific) */ |
| 85 | reg32 = RCBA32(FD); |
| 86 | reg32 |= PCH_DISABLE_ALWAYS; |
| 87 | RCBA32(FD) = reg32; |
| 88 | } |
| 89 | |
| 90 | static void copy_spd(struct pei_data *peid) |
| 91 | { |
| 92 | const int gpio_vector[] = {41, 42, 43, 10, -1}; |
Vladimir Serbinenko | 1287416 | 2014-01-12 14:12:15 +0100 | [diff] [blame] | 93 | char *spd_file; |
| 94 | size_t spd_file_len; |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 95 | int spd_index = get_gpios(gpio_vector); |
| 96 | |
| 97 | printk(BIOS_DEBUG, "spd index %d\n", spd_index); |
Vladimir Serbinenko | 1287416 | 2014-01-12 14:12:15 +0100 | [diff] [blame] | 98 | spd_file = cbfs_get_file_content(CBFS_DEFAULT_MEDIA, "spd.bin", 0xab, |
| 99 | &spd_file_len); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 100 | if (!spd_file) |
| 101 | die("SPD data not found."); |
| 102 | |
Vladimir Serbinenko | 1287416 | 2014-01-12 14:12:15 +0100 | [diff] [blame] | 103 | if (spd_file_len < ((spd_index + 1) * sizeof(peid->spd_data[0]))) { |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 104 | printk(BIOS_ERR, "spd index override to 0 - old hardware?\n"); |
| 105 | spd_index = 0; |
| 106 | } |
| 107 | |
Vladimir Serbinenko | 1287416 | 2014-01-12 14:12:15 +0100 | [diff] [blame] | 108 | if (spd_file_len < sizeof(peid->spd_data[0])) |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 109 | die("Missing SPD data."); |
| 110 | |
| 111 | memcpy(peid->spd_data[0], |
Vladimir Serbinenko | 1287416 | 2014-01-12 14:12:15 +0100 | [diff] [blame] | 112 | spd_file + |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 113 | spd_index * sizeof(peid->spd_data[0]), |
| 114 | sizeof(peid->spd_data[0])); |
| 115 | } |
| 116 | |
Aaron Durbin | a0a3727 | 2014-08-14 08:35:11 -0500 | [diff] [blame] | 117 | #include <cpu/intel/romstage.h> |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 118 | void main(unsigned long bist) |
| 119 | { |
| 120 | int boot_mode = 0; |
| 121 | int cbmem_was_initted; |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 122 | |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 123 | struct pei_data pei_data = { |
Edward O'Callaghan | 6cec824 | 2014-05-24 04:16:57 +1000 | [diff] [blame] | 124 | .pei_version = PEI_VERSION, |
| 125 | .mchbar = DEFAULT_MCHBAR, |
| 126 | .dmibar = DEFAULT_DMIBAR, |
| 127 | .epbar = DEFAULT_EPBAR, |
| 128 | .pciexbar = CONFIG_MMCONF_BASE_ADDRESS, |
| 129 | .smbusbar = SMBUS_IO_BASE, |
| 130 | .wdbbar = 0x4000000, |
| 131 | .wdbsize = 0x1000, |
| 132 | .hpet_address = CONFIG_HPET_ADDRESS, |
| 133 | .rcba = DEFAULT_RCBABASE, |
| 134 | .pmbase = DEFAULT_PMBASE, |
| 135 | .gpiobase = DEFAULT_GPIOBASE, |
| 136 | .thermalbase = 0xfed08000, |
| 137 | .system_type = 0, // 0 Mobile, 1 Desktop/Server |
| 138 | .tseg_size = CONFIG_SMM_TSEG_SIZE, |
| 139 | .ts_addresses = { 0x00, 0x00, 0x00, 0x00 }, |
| 140 | .ec_present = 1, |
| 141 | .ddr3lv_support = 1, |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 142 | // 0 = leave channel enabled |
| 143 | // 1 = disable dimm 0 on channel |
| 144 | // 2 = disable dimm 1 on channel |
| 145 | // 3 = disable dimm 0+1 on channel |
Edward O'Callaghan | 6cec824 | 2014-05-24 04:16:57 +1000 | [diff] [blame] | 146 | .dimm_channel0_disabled = 2, |
| 147 | .dimm_channel1_disabled = 2, |
| 148 | .max_ddr3_freq = 1600, |
| 149 | .usb_port_config = { |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 150 | /* Empty and onboard Ports 0-7, set to un-used pin OC3 */ |
| 151 | { 0, 3, 0x0000 }, /* P0: Empty */ |
| 152 | { 1, 0, 0x0040 }, /* P1: Left USB 1 (OC0) */ |
| 153 | { 1, 1, 0x0040 }, /* P2: Left USB 2 (OC1) */ |
| 154 | { 1, 3, 0x0040 }, /* P3: SDCARD (no OC) */ |
| 155 | { 0, 3, 0x0000 }, /* P4: Empty */ |
| 156 | { 1, 3, 0x0040 }, /* P5: WWAN (no OC) */ |
| 157 | { 0, 3, 0x0000 }, /* P6: Empty */ |
| 158 | { 0, 3, 0x0000 }, /* P7: Empty */ |
| 159 | /* Empty and onboard Ports 8-13, set to un-used pin OC4 */ |
| 160 | { 1, 4, 0x0040 }, /* P8: Camera (no OC) */ |
| 161 | { 1, 4, 0x0040 }, /* P9: Bluetooth (no OC) */ |
| 162 | { 0, 4, 0x0000 }, /* P10: Empty */ |
| 163 | { 0, 4, 0x0000 }, /* P11: Empty */ |
| 164 | { 0, 4, 0x0000 }, /* P12: Empty */ |
| 165 | { 0, 4, 0x0000 }, /* P13: Empty */ |
| 166 | }, |
| 167 | }; |
| 168 | |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 169 | timestamp_init(get_initial_timestamp()); |
| 170 | timestamp_add_now(TS_START_ROMSTAGE); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 171 | |
| 172 | if (bist == 0) |
| 173 | enable_lapic(); |
| 174 | |
| 175 | pch_enable_lpc(); |
| 176 | |
| 177 | /* Enable GPIOs */ |
| 178 | pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1); |
| 179 | pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10); |
| 180 | setup_pch_gpios(&link_gpio_map); |
| 181 | |
| 182 | /* Initialize console device(s) */ |
| 183 | console_init(); |
| 184 | |
| 185 | /* Halt if there was a built in self test failure */ |
| 186 | report_bist_failure(bist); |
| 187 | |
| 188 | if (MCHBAR16(SSKPD) == 0xCAFE) { |
| 189 | printk(BIOS_DEBUG, "soft reset detected\n"); |
| 190 | boot_mode = 1; |
| 191 | |
| 192 | /* System is not happy after keyboard reset... */ |
| 193 | printk(BIOS_DEBUG, "Issuing CF9 warm reset\n"); |
| 194 | outb(0x6, 0xcf9); |
Patrick Georgi | bd79c5e | 2014-11-28 22:35:36 +0100 | [diff] [blame^] | 195 | halt(); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | /* Perform some early chipset initialization required |
| 199 | * before RAM initialization can work |
| 200 | */ |
| 201 | sandybridge_early_initialization(SANDYBRIDGE_MOBILE); |
| 202 | printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n"); |
| 203 | |
Vladimir Serbinenko | 332f14b | 2014-09-05 16:29:41 +0200 | [diff] [blame] | 204 | boot_mode = southbridge_detect_s3_resume() ? 2 : 0; |
| 205 | if (boot_mode == 0) { |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 206 | /* This is the fastest way to let users know |
| 207 | * the Intel CPU is now alive. |
| 208 | */ |
| 209 | google_chromeec_kbbacklight(100); |
| 210 | } |
| 211 | |
| 212 | post_code(0x38); |
| 213 | /* Enable SPD ROMs and DDR-III DRAM */ |
| 214 | enable_smbus(); |
| 215 | |
| 216 | /* Prepare USB controller early in S3 resume */ |
| 217 | if (boot_mode == 2) |
| 218 | enable_usb_bar(); |
| 219 | |
| 220 | post_code(0x39); |
| 221 | |
| 222 | copy_spd(&pei_data); |
| 223 | |
| 224 | post_code(0x3a); |
| 225 | pei_data.boot_mode = boot_mode; |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 226 | timestamp_add_now(TS_BEFORE_INITRAM); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 227 | sdram_initialize(&pei_data); |
| 228 | |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 229 | timestamp_add_now(TS_AFTER_INITRAM); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 230 | post_code(0x3c); |
| 231 | |
| 232 | rcba_config(); |
| 233 | post_code(0x3d); |
| 234 | |
| 235 | quick_ram_check(); |
| 236 | post_code(0x3e); |
| 237 | |
Kyösti Mälkki | 2d8520b | 2014-01-06 17:20:31 +0200 | [diff] [blame] | 238 | cbmem_was_initted = !cbmem_recovery(boot_mode==2); |
Kyösti Mälkki | 7893848 | 2014-01-04 11:02:45 +0200 | [diff] [blame] | 239 | if (boot_mode!=2) |
| 240 | save_mrc_data(&pei_data); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 241 | |
Vladimir Serbinenko | c845b43 | 2014-09-05 03:37:44 +0200 | [diff] [blame] | 242 | if (boot_mode==2 && !cbmem_was_initted) { |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 243 | /* Failed S3 resume, reset to come up cleanly */ |
| 244 | outb(0x6, 0xcf9); |
Patrick Georgi | bd79c5e | 2014-11-28 22:35:36 +0100 | [diff] [blame^] | 245 | halt(); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 246 | } |
Vladimir Serbinenko | c845b43 | 2014-09-05 03:37:44 +0200 | [diff] [blame] | 247 | northbridge_romstage_finalize(boot_mode==2); |
| 248 | |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 249 | post_code(0x3f); |
| 250 | #if CONFIG_CHROMEOS |
| 251 | init_chromeos(boot_mode); |
| 252 | #endif |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 253 | timestamp_add_now(TS_END_ROMSTAGE); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 254 | } |