Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20: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. |
| 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 |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 18 | * Foundation, Inc. |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include <stdint.h> |
| 22 | #include <string.h> |
| 23 | #include <lib.h> |
| 24 | #include <timestamp.h> |
| 25 | #include <arch/io.h> |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 26 | #include <device/pci_def.h> |
| 27 | #include <device/pnp_def.h> |
| 28 | #include <cpu/x86/lapic.h> |
| 29 | #include <pc80/mc146818rtc.h> |
Kyösti Mälkki | 6722f8d | 2014-06-16 09:14:49 +0300 | [diff] [blame] | 30 | #include <arch/acpi.h> |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 31 | #include <cbmem.h> |
| 32 | #include <console/console.h> |
Kyösti Mälkki | e3ddee0 | 2014-05-03 10:45:28 +0300 | [diff] [blame] | 33 | #include <bootmode.h> |
Edward O'Callaghan | 1b3acb1 | 2014-06-01 18:04:05 +1000 | [diff] [blame] | 34 | #include <superio/ite/common/ite.h> |
| 35 | #include <superio/ite/it8772f/it8772f.h> |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 36 | #include <northbridge/intel/sandybridge/sandybridge.h> |
| 37 | #include <northbridge/intel/sandybridge/raminit.h> |
| 38 | #include <southbridge/intel/bd82x6x/pch.h> |
| 39 | #include <southbridge/intel/bd82x6x/gpio.h> |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 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> |
Vladimir Serbinenko | 0e90dae | 2015-05-18 10:29:06 +0200 | [diff] [blame] | 44 | #include <tpm.h> |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 45 | #include "gpio.h" |
Kyösti Mälkki | afa7b13 | 2014-02-13 17:16:22 +0200 | [diff] [blame] | 46 | #if CONFIG_DRIVERS_UART_8250IO |
Edward O'Callaghan | 74834e0 | 2015-01-04 04:17:35 +1100 | [diff] [blame] | 47 | #include <superio/smsc/lpc47n207/lpc47n207.h> |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 48 | #endif |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 49 | |
| 50 | /* Stumpy USB Reset Disable defined in cmos.layout */ |
| 51 | #if CONFIG_USE_OPTION_TABLE |
| 52 | #include "option_table.h" |
| 53 | #define CMOS_USB_RESET_DISABLE (CMOS_VSTART_stumpy_usb_reset_disable >> 3) |
| 54 | #else |
| 55 | #define CMOS_USB_RESET_DISABLE (400 >> 3) |
| 56 | #endif |
| 57 | #define USB_RESET_DISABLE_MAGIC (0xdd) /* Disable if set to this */ |
| 58 | |
Edward O'Callaghan | 1f9653a | 2014-07-14 16:31:25 +1000 | [diff] [blame] | 59 | #define DUMMY_DEV PNP_DEV(0x2e, 0) |
Edward O'Callaghan | 1b3acb1 | 2014-06-01 18:04:05 +1000 | [diff] [blame] | 60 | #define SERIAL_DEV PNP_DEV(0x2e, IT8772F_SP1) |
| 61 | #define GPIO_DEV PNP_DEV(0x2e, IT8772F_GPIO) |
| 62 | |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 63 | static void pch_enable_lpc(void) |
| 64 | { |
| 65 | /* Set COM1/COM2 decode range */ |
| 66 | pci_write_config16(PCH_LPC_DEV, LPC_IO_DEC, 0x0010); |
| 67 | |
Kyösti Mälkki | afa7b13 | 2014-02-13 17:16:22 +0200 | [diff] [blame] | 68 | #if CONFIG_DRIVERS_UART_8250IO |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 69 | /* Enable SuperIO + PS/2 Keyboard/Mouse + COM1 + lpc47n207 config*/ |
| 70 | pci_write_config16(PCH_LPC_DEV, LPC_EN, CNF1_LPC_EN | KBC_LPC_EN |\ |
| 71 | CNF2_LPC_EN | COMA_LPC_EN); |
| 72 | |
| 73 | /* map full 256 bytes at 0x1600 to the LPC bus */ |
| 74 | pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, 0xfc1601); |
| 75 | |
| 76 | try_enabling_LPC47N207_uart(); |
| 77 | #else |
| 78 | /* Enable SuperIO + PS/2 Keyboard/Mouse */ |
| 79 | pci_write_config16(PCH_LPC_DEV, LPC_EN, CNF1_LPC_EN | KBC_LPC_EN); |
| 80 | #endif |
| 81 | } |
| 82 | |
| 83 | static void rcba_config(void) |
| 84 | { |
| 85 | u32 reg32; |
| 86 | |
Vladimir Serbinenko | 33b535f | 2014-10-19 10:13:14 +0200 | [diff] [blame] | 87 | southbridge_configure_default_intmap(); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 88 | |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 89 | /* Disable unused devices (board specific) */ |
| 90 | reg32 = RCBA32(FD); |
| 91 | reg32 |= PCH_DISABLE_ALWAYS; |
| 92 | RCBA32(FD) = reg32; |
| 93 | } |
| 94 | |
| 95 | static void early_pch_init(void) |
| 96 | { |
| 97 | u8 reg8; |
| 98 | |
| 99 | // reset rtc power status |
| 100 | reg8 = pci_read_config8(PCH_LPC_DEV, 0xa4); |
| 101 | reg8 &= ~(1 << 2); |
| 102 | pci_write_config8(PCH_LPC_DEV, 0xa4, reg8); |
| 103 | } |
| 104 | |
| 105 | static void setup_sio_gpios(void) |
| 106 | { |
| 107 | /* |
| 108 | * GPIO10 as USBPWRON12# |
| 109 | * GPIO12 as USBPWRON13# |
| 110 | */ |
Edward O'Callaghan | 1f9653a | 2014-07-14 16:31:25 +1000 | [diff] [blame] | 111 | it8772f_gpio_setup(DUMMY_DEV, 1, 0x05, 0x05, 0x00, 0x05, 0x05); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 112 | |
| 113 | /* |
| 114 | * GPIO22 as wake SCI# |
| 115 | */ |
Edward O'Callaghan | 1f9653a | 2014-07-14 16:31:25 +1000 | [diff] [blame] | 116 | it8772f_gpio_setup(DUMMY_DEV, 2, 0x04, 0x04, 0x00, 0x04, 0x04); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 117 | |
| 118 | /* |
| 119 | * GPIO32 as EXTSMI# |
| 120 | */ |
Edward O'Callaghan | 1f9653a | 2014-07-14 16:31:25 +1000 | [diff] [blame] | 121 | it8772f_gpio_setup(DUMMY_DEV, 3, 0x04, 0x04, 0x00, 0x04, 0x04); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 122 | |
| 123 | /* |
| 124 | * GPIO45 as LED_POWER# |
| 125 | */ |
Edward O'Callaghan | 1f9653a | 2014-07-14 16:31:25 +1000 | [diff] [blame] | 126 | it8772f_gpio_setup(DUMMY_DEV, 4, 0x20, 0x20, 0x20, 0x20, 0x20); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 127 | |
| 128 | /* |
| 129 | * GPIO51 as USBPWRON8# |
| 130 | * GPIO52 as USBPWRON1# |
| 131 | */ |
Edward O'Callaghan | 1f9653a | 2014-07-14 16:31:25 +1000 | [diff] [blame] | 132 | it8772f_gpio_setup(DUMMY_DEV, 5, 0x06, 0x06, 0x00, 0x06, 0x06); |
| 133 | it8772f_gpio_setup(DUMMY_DEV, 6, 0x00, 0x00, 0x00, 0x00, 0x00); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 134 | } |
| 135 | |
Aaron Durbin | a0a3727 | 2014-08-14 08:35:11 -0500 | [diff] [blame] | 136 | #include <cpu/intel/romstage.h> |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 137 | void main(unsigned long bist) |
| 138 | { |
| 139 | int boot_mode = 0; |
| 140 | int cbmem_was_initted; |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 141 | |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 142 | struct pei_data pei_data = { |
Edward O'Callaghan | b27d360 | 2014-05-24 02:40:31 +1000 | [diff] [blame] | 143 | .pei_version = PEI_VERSION, |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 144 | .mchbar = (uintptr_t)DEFAULT_MCHBAR, |
| 145 | .dmibar = (uintptr_t)DEFAULT_DMIBAR, |
Edward O'Callaghan | b27d360 | 2014-05-24 02:40:31 +1000 | [diff] [blame] | 146 | .epbar = DEFAULT_EPBAR, |
| 147 | .pciexbar = CONFIG_MMCONF_BASE_ADDRESS, |
| 148 | .smbusbar = SMBUS_IO_BASE, |
| 149 | .wdbbar = 0x4000000, |
| 150 | .wdbsize = 0x1000, |
| 151 | .hpet_address = CONFIG_HPET_ADDRESS, |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 152 | .rcba = (uintptr_t)DEFAULT_RCBABASE, |
Edward O'Callaghan | b27d360 | 2014-05-24 02:40:31 +1000 | [diff] [blame] | 153 | .pmbase = DEFAULT_PMBASE, |
| 154 | .gpiobase = DEFAULT_GPIOBASE, |
| 155 | .thermalbase = 0xfed08000, |
| 156 | .system_type = 0, // 0 Mobile, 1 Desktop/Server |
| 157 | .tseg_size = CONFIG_SMM_TSEG_SIZE, |
| 158 | .spd_addresses = { 0xa0, 0x00,0xa4,0x00 }, |
| 159 | .ts_addresses = { 0x00, 0x00, 0x00, 0x00 }, |
| 160 | .ec_present = 0, |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 161 | // 0 = leave channel enabled |
| 162 | // 1 = disable dimm 0 on channel |
| 163 | // 2 = disable dimm 1 on channel |
| 164 | // 3 = disable dimm 0+1 on channel |
Edward O'Callaghan | b27d360 | 2014-05-24 02:40:31 +1000 | [diff] [blame] | 165 | .dimm_channel0_disabled = 2, |
| 166 | .dimm_channel1_disabled = 2, |
| 167 | .max_ddr3_freq = 1333, |
| 168 | .usb_port_config = { |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 169 | { 1, 0, 0x0080 }, /* P0: Front port (OC0) */ |
| 170 | { 1, 1, 0x0040 }, /* P1: Back port (OC1) */ |
| 171 | { 1, 0, 0x0040 }, /* P2: MINIPCIE1 (no OC) */ |
| 172 | { 1, 0, 0x0040 }, /* P3: MMC (no OC) */ |
| 173 | { 1, 2, 0x0080 }, /* P4: Front port (OC2) */ |
| 174 | { 0, 0, 0x0000 }, /* P5: Empty */ |
| 175 | { 0, 0, 0x0000 }, /* P6: Empty */ |
| 176 | { 0, 0, 0x0000 }, /* P7: Empty */ |
| 177 | { 1, 4, 0x0040 }, /* P8: Back port (OC4) */ |
| 178 | { 1, 4, 0x0040 }, /* P9: MINIPCIE3 (no OC) */ |
| 179 | { 1, 4, 0x0040 }, /* P10: BLUETOOTH (no OC) */ |
| 180 | { 0, 4, 0x0000 }, /* P11: Empty */ |
| 181 | { 1, 6, 0x0040 }, /* P12: Back port (OC6) */ |
| 182 | { 1, 5, 0x0040 }, /* P13: Back port (OC5) */ |
| 183 | }, |
| 184 | }; |
| 185 | |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 186 | timestamp_init(get_initial_timestamp()); |
| 187 | timestamp_add_now(TS_START_ROMSTAGE); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 188 | |
| 189 | if (bist == 0) |
| 190 | enable_lapic(); |
| 191 | |
| 192 | pch_enable_lpc(); |
| 193 | |
| 194 | /* Enable GPIOs */ |
| 195 | pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1); |
| 196 | pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10); |
| 197 | setup_pch_gpios(&stumpy_gpio_map); |
| 198 | setup_sio_gpios(); |
| 199 | |
| 200 | /* Early SuperIO setup */ |
Edward O'Callaghan | 1f9653a | 2014-07-14 16:31:25 +1000 | [diff] [blame] | 201 | it8772f_ac_resume_southbridge(DUMMY_DEV); |
Edward O'Callaghan | 1b3acb1 | 2014-06-01 18:04:05 +1000 | [diff] [blame] | 202 | ite_kill_watchdog(GPIO_DEV); |
| 203 | ite_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 204 | console_init(); |
| 205 | |
Kyösti Mälkki | e3ddee0 | 2014-05-03 10:45:28 +0300 | [diff] [blame] | 206 | init_bootmode_straps(); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 207 | |
| 208 | /* Halt if there was a built in self test failure */ |
| 209 | report_bist_failure(bist); |
| 210 | |
| 211 | if (MCHBAR16(SSKPD) == 0xCAFE) { |
| 212 | printk(BIOS_DEBUG, "soft reset detected\n"); |
| 213 | boot_mode = 1; |
| 214 | |
| 215 | /* System is not happy after keyboard reset... */ |
| 216 | printk(BIOS_DEBUG, "Issuing CF9 warm reset\n"); |
| 217 | outb(0x6, 0xcf9); |
Patrick Georgi | bd79c5e | 2014-11-28 22:35:36 +0100 | [diff] [blame] | 218 | halt(); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | /* Perform some early chipset initialization required |
| 222 | * before RAM initialization can work |
| 223 | */ |
| 224 | sandybridge_early_initialization(SANDYBRIDGE_MOBILE); |
| 225 | printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n"); |
| 226 | |
Vladimir Serbinenko | 332f14b | 2014-09-05 16:29:41 +0200 | [diff] [blame] | 227 | boot_mode = southbridge_detect_s3_resume() ? 2 : 0; |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 228 | |
| 229 | post_code(0x38); |
| 230 | /* Enable SPD ROMs and DDR-III DRAM */ |
| 231 | enable_smbus(); |
| 232 | |
| 233 | /* Prepare USB controller early in S3 resume */ |
| 234 | if (boot_mode == 2) { |
| 235 | /* |
| 236 | * For Stumpy the back USB ports are reset on resume |
| 237 | * so default to resetting the controller to make the |
| 238 | * kernel happy. There is a CMOS flag to disable the |
| 239 | * controller reset in case the kernel can tolerate |
| 240 | * the device power loss better in the future. |
| 241 | */ |
| 242 | u8 magic = cmos_read(CMOS_USB_RESET_DISABLE); |
| 243 | |
| 244 | if (magic == USB_RESET_DISABLE_MAGIC) { |
| 245 | printk(BIOS_DEBUG, "USB Controller Reset Disabled\n"); |
| 246 | enable_usb_bar(); |
| 247 | } else { |
| 248 | printk(BIOS_DEBUG, "USB Controller Reset Enabled\n"); |
| 249 | } |
| 250 | } else { |
| 251 | /* Ensure USB reset on resume is enabled at boot */ |
| 252 | cmos_write(0, CMOS_USB_RESET_DISABLE); |
| 253 | } |
| 254 | |
| 255 | post_code(0x39); |
| 256 | pei_data.boot_mode = boot_mode; |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 257 | timestamp_add_now(TS_BEFORE_INITRAM); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 258 | sdram_initialize(&pei_data); |
| 259 | |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 260 | timestamp_add_now(TS_AFTER_INITRAM); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 261 | post_code(0x3a); |
| 262 | /* Perform some initialization that must run before stage2 */ |
| 263 | early_pch_init(); |
| 264 | post_code(0x3b); |
| 265 | |
| 266 | rcba_config(); |
| 267 | post_code(0x3c); |
| 268 | |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 269 | quick_ram_check(); |
Stefan Reinauer | afcaac2 | 2012-06-18 15:43:50 -0700 | [diff] [blame] | 270 | post_code(0x3e); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 271 | |
Kyösti Mälkki | 2d8520b | 2014-01-06 17:20:31 +0200 | [diff] [blame] | 272 | cbmem_was_initted = !cbmem_recovery(boot_mode==2); |
Kyösti Mälkki | 7893848 | 2014-01-04 11:02:45 +0200 | [diff] [blame] | 273 | if (boot_mode!=2) |
| 274 | save_mrc_data(&pei_data); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 275 | |
Vladimir Serbinenko | c845b43 | 2014-09-05 03:37:44 +0200 | [diff] [blame] | 276 | if (boot_mode==2 && !cbmem_was_initted) { |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 277 | /* Failed S3 resume, reset to come up cleanly */ |
| 278 | outb(0x6, 0xcf9); |
Patrick Georgi | bd79c5e | 2014-11-28 22:35:36 +0100 | [diff] [blame] | 279 | halt(); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 280 | } |
Vladimir Serbinenko | c845b43 | 2014-09-05 03:37:44 +0200 | [diff] [blame] | 281 | northbridge_romstage_finalize(boot_mode==2); |
| 282 | |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 283 | post_code(0x3f); |
Vladimir Serbinenko | 0e90dae | 2015-05-18 10:29:06 +0200 | [diff] [blame] | 284 | if (CONFIG_LPC_TPM) { |
| 285 | init_tpm(boot_mode == 2); |
| 286 | } |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 287 | } |