blob: e769fc522bdeba502c151735e0ad41caf9f8dd86 [file] [log] [blame]
Stefan Reinauer1a08f582009-10-28 16:52:48 +00001/*
2 * This file is part of the coreboot project.
Stefan Reinauer14e22772010-04-27 06:56:47 +00003 *
Stefan Reinauer1a08f582009-10-28 16:52:48 +00004 * Copyright (C) 2007-2008 coresystems GmbH
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
Uwe Hermann2d2f0c12009-10-28 17:36:11 +00008 * published by the Free Software Foundation; version 2 of the License.
Stefan Reinauer1a08f582009-10-28 16:52:48 +00009 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Stefan Reinauer1a08f582009-10-28 16:52:48 +000014 */
15
Myles Watson1d6d45e2009-11-06 17:02:51 +000016// __PRE_RAM__ means: use "unsigned" for device, not a struct.
Stefan Reinauer5e328232010-03-29 19:19:16 +000017
Stefan Reinauer1a08f582009-10-28 16:52:48 +000018#include <stdint.h>
19#include <string.h>
20#include <arch/io.h>
Stefan Reinauer1a08f582009-10-28 16:52:48 +000021#include <device/pci_def.h>
22#include <device/pnp_def.h>
23#include <cpu/x86/lapic.h>
Patrick Georgid0835952010-10-05 09:07:10 +000024#include <lib.h>
Kyösti Mälkki12d681b2014-06-14 18:51:34 +030025#include <arch/acpi.h>
Kyösti Mälkkia7c96112013-10-13 20:41:57 +030026#include <cbmem.h>
Paul Menzel6c20b652016-12-29 22:54:02 +010027#include <timestamp.h>
Edward O'Callaghancf5ac3d2014-06-03 08:40:34 +100028#include <superio/smsc/lpc47m15x/lpc47m15x.h>
Edwin Beasanteb50c7d2010-07-06 21:05:04 +000029#include <pc80/mc146818rtc.h>
Stefan Reinauer8a7d34b2010-02-22 09:15:13 +000030#include <console/console.h>
Stefan Reinauer1a08f582009-10-28 16:52:48 +000031#include <cpu/x86/bist.h>
Kyösti Mälkki408d3922016-06-17 10:43:48 +030032#include <cpu/intel/romstage.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110033#include <northbridge/intel/i945/i945.h>
34#include <northbridge/intel/i945/raminit.h>
35#include <southbridge/intel/i82801gx/i82801gx.h>
Patrick Georgid0835952010-10-05 09:07:10 +000036
Edward O'Callaghancf5ac3d2014-06-03 08:40:34 +100037#define SERIAL_DEV PNP_DEV(0x2e, LPC47M15X_SP1)
38#define PME_DEV PNP_DEV(0x2e, LPC47M15X_PME)
Uwe Hermann57b2ff82010-11-21 17:29:59 +000039
Stefan Reinauer1a08f582009-10-28 16:52:48 +000040static void ich7_enable_lpc(void)
41{
42 // Enable Serial IRQ
43 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x64, 0xd0);
44 // Set COM1/COM2 decode range
45 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x80, 0x0010);
46 // Enable COM1
47 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x82, 0x140d);
48 // Enable SuperIO Power Management Events
49 pci_write_config32(PCI_DEV(0, 0x1f, 0), 0x84, 0x007c0681);
50}
51
Stefan Reinauer1a08f582009-10-28 16:52:48 +000052static void rcba_config(void)
53{
54 /* Set up virtual channel 0 */
55 //RCBA32(0x0014) = 0x80000001;
56 //RCBA32(0x001c) = 0x03128010;
57
58 /* Device 1f interrupt pin register */
59 RCBA32(0x3100) = 0x00042210;
60 /* Device 1d interrupt pin register */
61 RCBA32(0x310c) = 0x00214321;
62
63 /* dev irq route register */
64 RCBA16(0x3140) = 0x0132;
65 RCBA16(0x3142) = 0x0146;
66 RCBA16(0x3144) = 0x0237;
67 RCBA16(0x3146) = 0x3201;
68 RCBA16(0x3148) = 0x0146;
69
70 /* Enable IOAPIC */
71 RCBA8(0x31ff) = 0x03;
72
Stefan Reinauer1a08f582009-10-28 16:52:48 +000073 /* Disable unused devices */
74 //RCBA32(0x3418) = FD_PCIE6|FD_PCIE5|FD_PCIE4|FD_ACMOD|FD_ACAUD|FD_PATA;
75 // RCBA32(0x3418) |= (1 << 0); // Required.
76 // FIXME look me up!
77 RCBA32(0x3418) = 0x003204e1;
78
79 /* Enable PCIe Root Port Clock Gate */
80 // RCBA32(0x341c) = 0x00000001;
81}
82
83static void early_ich7_init(void)
84{
85 uint8_t reg8;
86 uint32_t reg32;
87
88 // program secondary mlt XXX byte?
89 pci_write_config8(PCI_DEV(0, 0x1e, 0), 0x1b, 0x20);
90
91 // reset rtc power status
92 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xa4);
93 reg8 &= ~(1 << 2);
94 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa4, reg8);
95
96 // usb transient disconnect
97 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xad);
98 reg8 |= (3 << 0);
99 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xad, reg8);
100
101 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xfc);
102 reg32 |= (1 << 29) | (1 << 17);
103 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xfc, reg32);
104
105 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xdc);
106 reg32 |= (1 << 31) | (1 << 27);
107 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xdc, reg32);
108
109 RCBA32(0x0088) = 0x0011d000;
110 RCBA16(0x01fc) = 0x060f;
111 RCBA32(0x01f4) = 0x86000040;
112 RCBA32(0x0214) = 0x10030549;
113 RCBA32(0x0218) = 0x00020504;
114 RCBA8(0x0220) = 0xc5;
115 reg32 = RCBA32(0x3410);
116 reg32 |= (1 << 6);
117 RCBA32(0x3410) = reg32;
118 reg32 = RCBA32(0x3430);
119 reg32 &= ~(3 << 0);
120 reg32 |= (1 << 0);
121 RCBA32(0x3430) = reg32;
122 RCBA32(0x3418) |= (1 << 0);
123 RCBA16(0x0200) = 0x2008;
124 RCBA8(0x2027) = 0x0d;
125 RCBA16(0x3e08) |= (1 << 7);
126 RCBA16(0x3e48) |= (1 << 7);
127 RCBA32(0x3e0e) |= (1 << 7);
128 RCBA32(0x3e4e) |= (1 << 7);
129
130 // next step only on ich7m b0 and later:
131 reg32 = RCBA32(0x2034);
132 reg32 &= ~(0x0f << 16);
133 reg32 |= (5 << 16);
134 RCBA32(0x2034) = reg32;
135}
136
Kyösti Mälkki408d3922016-06-17 10:43:48 +0300137void mainboard_romstage_entry(unsigned long bist)
Stefan Reinauer1a08f582009-10-28 16:52:48 +0000138{
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200139 int s3resume = 0, boot_mode = 0;
Stefan Reinauer1a08f582009-10-28 16:52:48 +0000140
Paul Menzel6c20b652016-12-29 22:54:02 +0100141
142 timestamp_init(get_initial_timestamp());
143 timestamp_add_now(TS_START_ROMSTAGE);
144
Uwe Hermann7b997052010-11-21 22:47:22 +0000145 if (bist == 0)
Stefan Reinauer1a08f582009-10-28 16:52:48 +0000146 enable_lapic();
Stefan Reinauer1a08f582009-10-28 16:52:48 +0000147
148 ich7_enable_lpc();
Edward O'Callaghancf5ac3d2014-06-03 08:40:34 +1000149 /* Enable SuperIO PM */
150 lpc47m15x_enable_serial(PME_DEV, 0x680);
151 lpc47m15x_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE); /* 0x3f8 */
Stefan Reinauer1a08f582009-10-28 16:52:48 +0000152
153 /* Set up the console */
Stefan Reinauer1a08f582009-10-28 16:52:48 +0000154 console_init();
155
156 /* Halt if there was a built in self test failure */
157 report_bist_failure(bist);
158
159 if (MCHBAR16(SSKPD) == 0xCAFE) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000160 printk(BIOS_DEBUG, "soft reset detected.\n");
Stefan Reinauer1a08f582009-10-28 16:52:48 +0000161 boot_mode = 1;
162 }
163
164 /* Perform some early chipset initialization required
165 * before RAM initialization can work
166 */
167 i945_early_initialization();
168
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200169 s3resume = southbridge_detect_s3_resume();
Stefan Reinauer1a08f582009-10-28 16:52:48 +0000170
171 /* Enable SPD ROMs and DDR-II DRAM */
172 enable_smbus();
Stefan Reinauer14e22772010-04-27 06:56:47 +0000173
Stefan Reinauer1a08f582009-10-28 16:52:48 +0000174#if CONFIG_DEFAULT_CONSOLE_LOGLEVEL > 8
175 dump_spd_registers();
176#endif
177
Paul Menzel6c20b652016-12-29 22:54:02 +0100178 timestamp_add_now(TS_BEFORE_INITRAM);
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200179 sdram_initialize(s3resume ? 2 : boot_mode, NULL);
Paul Menzel6c20b652016-12-29 22:54:02 +0100180 timestamp_add_now(TS_AFTER_INITRAM);
Stefan Reinauer1a08f582009-10-28 16:52:48 +0000181
182 /* Perform some initialization that must run before stage2 */
183 early_ich7_init();
184
Stefan Reinauer14e22772010-04-27 06:56:47 +0000185 /* This should probably go away. Until now it is required
186 * and mainboard specific
Stefan Reinauer1a08f582009-10-28 16:52:48 +0000187 */
188 rcba_config();
189
190 /* Chipset Errata! */
191 fixup_i945_errata();
192
193 /* Initialize the internal PCIe links before we go into stage2 */
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200194 i945_late_initialization(s3resume);
Stefan Reinauer1a08f582009-10-28 16:52:48 +0000195}