blob: 7b367c5b69daf9ce34a9fae8372cffb16953e0e2 [file] [log] [blame]
Vladimir Serbinenkofa1d6882014-10-19 02:50:45 +02001/*
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 Serbinenkofa1d6882014-10-19 02:50:45 +020016 */
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 Gagniuc8b2c8f12015-02-17 04:31:01 -060028#include <device/pci_def.h>
29#include <device/device.h>
Patrick Georgibd79c5e2014-11-28 22:35:36 +010030#include <halt.h>
Vladimir Serbinenkoed54cc72015-05-18 10:31:35 +020031#include <tpm.h>
Alexandru Gagniuc8b2c8f12015-02-17 04:31:01 -060032#include <northbridge/intel/sandybridge/chip.h>
Vladimir Serbinenkofa1d6882014-10-19 02:50:45 +020033#include "southbridge/intel/bd82x6x/pch.h"
34#include "southbridge/intel/bd82x6x/gpio.h"
35
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +010036static void early_pch_init(void)
Alexandru Gagniuc8b2c8f12015-02-17 04:31:01 -060037{
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +010038 u8 reg8;
Alexandru Gagniuc8b2c8f12015-02-17 04:31:01 -060039
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +010040 // 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 Gagniuc8b2c8f12015-02-17 04:31:01 -060044}
45
Vladimir Serbinenkofa1d6882014-10-19 02:50:45 +020046void main(unsigned long bist)
47{
48 int s3resume = 0;
Vladimir Serbinenkofa1d6882014-10-19 02:50:45 +020049
50 if (MCHBAR16(SSKPD) == 0xCAFE) {
51 outb(0x6, 0xcf9);
Patrick Georgibd79c5e2014-11-28 22:35:36 +010052 halt ();
Vladimir Serbinenkofa1d6882014-10-19 02:50:45 +020053 }
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 Serbinenkoffbb3c02016-02-10 01:36:25 +010069 /* Initialize superio */
70 mainboard_config_superio();
71
72 /* USB is inited in MRC if MRC is used. */
Vladimir Serbinenko144eea02016-02-10 02:36:04 +010073 if (CONFIG_USE_NATIVE_RAMINIT) {
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +010074 early_usb_init(mainboard_usb_ports);
75 }
Vladimir Serbinenkofa1d6882014-10-19 02:50:45 +020076
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 Serbinenko609bd942016-01-31 14:00:54 +010092
93 mainboard_early_init(s3resume);
94
Vladimir Serbinenkofa1d6882014-10-19 02:50:45 +020095 /* Enable SPD ROMs and DDR-III DRAM */
96 enable_smbus();
97
98 post_code(0x39);
99
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100100 perform_raminit(s3resume);
Vladimir Serbinenkofa1d6882014-10-19 02:50:45 +0200101
102 timestamp_add_now(TS_AFTER_INITRAM);
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100103
104 post_code(0x3b);
105 /* Perform some initialization that must run before stage2 */
106 early_pch_init();
Vladimir Serbinenkofa1d6882014-10-19 02:50:45 +0200107 post_code(0x3c);
108
Vladimir Serbinenko33b535f2014-10-19 10:13:14 +0200109 southbridge_configure_default_intmap();
Vladimir Serbinenkofa1d6882014-10-19 02:50:45 +0200110 rcba_config();
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100111
Vladimir Serbinenkofa1d6882014-10-19 02:50:45 +0200112 post_code(0x3d);
113
114 northbridge_romstage_finalize(s3resume);
115
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100116 if (CONFIG_LPC_TPM) {
117 init_tpm(s3resume);
118 }
Vladimir Serbinenkoed54cc72015-05-18 10:31:35 +0200119
Vladimir Serbinenkofa1d6882014-10-19 02:50:45 +0200120 post_code(0x3f);
Vladimir Serbinenkofa1d6882014-10-19 02:50:45 +0200121}