blob: 738e2851afa8c04f678b3cf9ef50837cf051fa6f [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"
Patrick Rudolphe8e66f42016-02-06 17:42:42 +010034#include <southbridge/intel/common/gpio.h>
Vladimir Serbinenkofa1d6882014-10-19 02:50:45 +020035
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
Kyösti Mälkki75d139b2016-06-17 10:00:28 +030046/* Platform has no romstage entry point under mainboard directory,
47 * so this one is named with prefix mainboard.
48 */
49void mainboard_romstage_entry(unsigned long bist)
Vladimir Serbinenkofa1d6882014-10-19 02:50:45 +020050{
51 int s3resume = 0;
Vladimir Serbinenkofa1d6882014-10-19 02:50:45 +020052
53 if (MCHBAR16(SSKPD) == 0xCAFE) {
54 outb(0x6, 0xcf9);
Patrick Georgibd79c5e2014-11-28 22:35:36 +010055 halt ();
Vladimir Serbinenkofa1d6882014-10-19 02:50:45 +020056 }
57
58 timestamp_init(get_initial_timestamp());
59 timestamp_add_now(TS_START_ROMSTAGE);
60
61 if (bist == 0)
62 enable_lapic();
63
64 pch_enable_lpc();
65
66 /* Enable GPIOs */
67 pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1);
68 pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10);
69
70 setup_pch_gpios(&mainboard_gpio_map);
71
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +010072 /* Initialize superio */
73 mainboard_config_superio();
74
Martin Roth128c1042016-11-18 09:29:03 -070075 /* USB is initialized in MRC if MRC is used. */
Vladimir Serbinenko144eea02016-02-10 02:36:04 +010076 if (CONFIG_USE_NATIVE_RAMINIT) {
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +010077 early_usb_init(mainboard_usb_ports);
78 }
Vladimir Serbinenkofa1d6882014-10-19 02:50:45 +020079
80 /* Initialize console device(s) */
81 console_init();
82
83 /* Halt if there was a built in self test failure */
84 report_bist_failure(bist);
85
86 /* Perform some early chipset initialization required
87 * before RAM initialization can work
88 */
89 sandybridge_early_initialization(SANDYBRIDGE_MOBILE);
90 printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n");
91
92 s3resume = southbridge_detect_s3_resume();
93
94 post_code(0x38);
Vladimir Serbinenko609bd942016-01-31 14:00:54 +010095
96 mainboard_early_init(s3resume);
97
Vladimir Serbinenkofa1d6882014-10-19 02:50:45 +020098 /* Enable SPD ROMs and DDR-III DRAM */
99 enable_smbus();
100
101 post_code(0x39);
102
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100103 perform_raminit(s3resume);
Vladimir Serbinenkofa1d6882014-10-19 02:50:45 +0200104
105 timestamp_add_now(TS_AFTER_INITRAM);
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100106
107 post_code(0x3b);
108 /* Perform some initialization that must run before stage2 */
109 early_pch_init();
Vladimir Serbinenkofa1d6882014-10-19 02:50:45 +0200110 post_code(0x3c);
111
Vladimir Serbinenko33b535f2014-10-19 10:13:14 +0200112 southbridge_configure_default_intmap();
Vladimir Serbinenkofa1d6882014-10-19 02:50:45 +0200113 rcba_config();
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100114
Vladimir Serbinenkofa1d6882014-10-19 02:50:45 +0200115 post_code(0x3d);
116
117 northbridge_romstage_finalize(s3resume);
118
Denis 'GNUtoo' Carikli0e92bb02016-02-20 17:32:03 +0100119 if (IS_ENABLED(CONFIG_LPC_TPM)) {
Vladimir Serbinenkoffbb3c02016-02-10 01:36:25 +0100120 init_tpm(s3resume);
121 }
Vladimir Serbinenkoed54cc72015-05-18 10:31:35 +0200122
Vladimir Serbinenkofa1d6882014-10-19 02:50:45 +0200123 post_code(0x3f);
Vladimir Serbinenkofa1d6882014-10-19 02:50:45 +0200124}