Vladimir Serbinenko | fa1d688 | 2014-10-19 02:50:45 +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 | * Copyright (C) 2014 Vladimir Serbinenko |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; version 2 of the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
Vladimir Serbinenko | fa1d688 | 2014-10-19 02:50:45 +0200 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include <stdint.h> |
| 19 | #include <string.h> |
| 20 | #include <console/console.h> |
| 21 | #include <arch/io.h> |
| 22 | #include <lib.h> |
| 23 | #include <cpu/x86/lapic.h> |
| 24 | #include <timestamp.h> |
| 25 | #include "sandybridge.h" |
| 26 | #include <cpu/x86/bist.h> |
| 27 | #include <cpu/intel/romstage.h> |
Alexandru Gagniuc | 8b2c8f1 | 2015-02-17 04:31:01 -0600 | [diff] [blame] | 28 | #include <device/pci_def.h> |
| 29 | #include <device/device.h> |
Patrick Georgi | bd79c5e | 2014-11-28 22:35:36 +0100 | [diff] [blame] | 30 | #include <halt.h> |
Vladimir Serbinenko | ed54cc7 | 2015-05-18 10:31:35 +0200 | [diff] [blame] | 31 | #include <tpm.h> |
Alexandru Gagniuc | 8b2c8f1 | 2015-02-17 04:31:01 -0600 | [diff] [blame] | 32 | #include <northbridge/intel/sandybridge/chip.h> |
Vladimir Serbinenko | fa1d688 | 2014-10-19 02:50:45 +0200 | [diff] [blame] | 33 | #include "southbridge/intel/bd82x6x/pch.h" |
Patrick Rudolph | e8e66f4 | 2016-02-06 17:42:42 +0100 | [diff] [blame] | 34 | #include <southbridge/intel/common/gpio.h> |
Vladimir Serbinenko | fa1d688 | 2014-10-19 02:50:45 +0200 | [diff] [blame] | 35 | |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 36 | static void early_pch_init(void) |
Alexandru Gagniuc | 8b2c8f1 | 2015-02-17 04:31:01 -0600 | [diff] [blame] | 37 | { |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 38 | u8 reg8; |
Alexandru Gagniuc | 8b2c8f1 | 2015-02-17 04:31:01 -0600 | [diff] [blame] | 39 | |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 40 | // reset rtc power status |
| 41 | reg8 = pci_read_config8(PCH_LPC_DEV, 0xa4); |
| 42 | reg8 &= ~(1 << 2); |
| 43 | pci_write_config8(PCH_LPC_DEV, 0xa4, reg8); |
Alexandru Gagniuc | 8b2c8f1 | 2015-02-17 04:31:01 -0600 | [diff] [blame] | 44 | } |
| 45 | |
Vladimir Serbinenko | fa1d688 | 2014-10-19 02:50:45 +0200 | [diff] [blame] | 46 | void main(unsigned long bist) |
| 47 | { |
| 48 | int s3resume = 0; |
Vladimir Serbinenko | fa1d688 | 2014-10-19 02:50:45 +0200 | [diff] [blame] | 49 | |
| 50 | if (MCHBAR16(SSKPD) == 0xCAFE) { |
| 51 | outb(0x6, 0xcf9); |
Patrick Georgi | bd79c5e | 2014-11-28 22:35:36 +0100 | [diff] [blame] | 52 | halt (); |
Vladimir Serbinenko | fa1d688 | 2014-10-19 02:50:45 +0200 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | timestamp_init(get_initial_timestamp()); |
| 56 | timestamp_add_now(TS_START_ROMSTAGE); |
| 57 | |
| 58 | if (bist == 0) |
| 59 | enable_lapic(); |
| 60 | |
| 61 | pch_enable_lpc(); |
| 62 | |
| 63 | /* Enable GPIOs */ |
| 64 | pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1); |
| 65 | pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10); |
| 66 | |
| 67 | setup_pch_gpios(&mainboard_gpio_map); |
| 68 | |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 69 | /* Initialize superio */ |
| 70 | mainboard_config_superio(); |
| 71 | |
| 72 | /* USB is inited in MRC if MRC is used. */ |
Vladimir Serbinenko | 144eea0 | 2016-02-10 02:36:04 +0100 | [diff] [blame] | 73 | if (CONFIG_USE_NATIVE_RAMINIT) { |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 74 | early_usb_init(mainboard_usb_ports); |
| 75 | } |
Vladimir Serbinenko | fa1d688 | 2014-10-19 02:50:45 +0200 | [diff] [blame] | 76 | |
| 77 | /* Initialize console device(s) */ |
| 78 | console_init(); |
| 79 | |
| 80 | /* Halt if there was a built in self test failure */ |
| 81 | report_bist_failure(bist); |
| 82 | |
| 83 | /* Perform some early chipset initialization required |
| 84 | * before RAM initialization can work |
| 85 | */ |
| 86 | sandybridge_early_initialization(SANDYBRIDGE_MOBILE); |
| 87 | printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n"); |
| 88 | |
| 89 | s3resume = southbridge_detect_s3_resume(); |
| 90 | |
| 91 | post_code(0x38); |
Vladimir Serbinenko | 609bd94 | 2016-01-31 14:00:54 +0100 | [diff] [blame] | 92 | |
| 93 | mainboard_early_init(s3resume); |
| 94 | |
Vladimir Serbinenko | fa1d688 | 2014-10-19 02:50:45 +0200 | [diff] [blame] | 95 | /* Enable SPD ROMs and DDR-III DRAM */ |
| 96 | enable_smbus(); |
| 97 | |
| 98 | post_code(0x39); |
| 99 | |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 100 | perform_raminit(s3resume); |
Vladimir Serbinenko | fa1d688 | 2014-10-19 02:50:45 +0200 | [diff] [blame] | 101 | |
| 102 | timestamp_add_now(TS_AFTER_INITRAM); |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 103 | |
| 104 | post_code(0x3b); |
| 105 | /* Perform some initialization that must run before stage2 */ |
| 106 | early_pch_init(); |
Vladimir Serbinenko | fa1d688 | 2014-10-19 02:50:45 +0200 | [diff] [blame] | 107 | post_code(0x3c); |
| 108 | |
Vladimir Serbinenko | 33b535f | 2014-10-19 10:13:14 +0200 | [diff] [blame] | 109 | southbridge_configure_default_intmap(); |
Vladimir Serbinenko | fa1d688 | 2014-10-19 02:50:45 +0200 | [diff] [blame] | 110 | rcba_config(); |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 111 | |
Vladimir Serbinenko | fa1d688 | 2014-10-19 02:50:45 +0200 | [diff] [blame] | 112 | post_code(0x3d); |
| 113 | |
| 114 | northbridge_romstage_finalize(s3resume); |
| 115 | |
Denis 'GNUtoo' Carikli | 0e92bb0 | 2016-02-20 17:32:03 +0100 | [diff] [blame^] | 116 | if (IS_ENABLED(CONFIG_LPC_TPM)) { |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 117 | init_tpm(s3resume); |
| 118 | } |
Vladimir Serbinenko | ed54cc7 | 2015-05-18 10:31:35 +0200 | [diff] [blame] | 119 | |
Vladimir Serbinenko | fa1d688 | 2014-10-19 02:50:45 +0200 | [diff] [blame] | 120 | post_code(0x3f); |
Vladimir Serbinenko | fa1d688 | 2014-10-19 02:50:45 +0200 | [diff] [blame] | 121 | } |