blob: 350c2dead3ebcdd7fd935107e032685e940a25e3 [file] [log] [blame]
Sven Schnelled8129f92011-04-20 09:12:17 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2007-2009 coresystems GmbH
5 * Copyright (C) 2011 Sven Schnelle <svens@stackframe.org>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; version 2 of
10 * 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.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
20 * MA 02110-1301 USA
21 */
22
23// __PRE_RAM__ means: use "unsigned" for device, not a struct.
24
25#include <stdint.h>
26#include <string.h>
27#include <arch/io.h>
Sven Schnelled8129f92011-04-20 09:12:17 +000028#include <device/pci_def.h>
29#include <device/pnp_def.h>
30#include <cpu/x86/lapic.h>
31#include <lib.h>
Kyösti Mälkki12d681b2014-06-14 18:51:34 +030032#include <arch/acpi.h>
Paul Menzelac6ea042013-04-29 23:21:07 +020033#include <cbmem.h>
Nico Huber44c392f2013-05-26 19:37:47 +020034#include <timestamp.h>
Sven Schnelled8129f92011-04-20 09:12:17 +000035#include <pc80/mc146818rtc.h>
36#include <console/console.h>
Sven Schnelled8129f92011-04-20 09:12:17 +000037#include <cpu/x86/bist.h>
Patrick Georgi546953c2014-11-29 10:38:17 +010038#include <halt.h>
Sven Schnelled8129f92011-04-20 09:12:17 +000039#include "northbridge/intel/i945/i945.h"
40#include "northbridge/intel/i945/raminit.h"
41#include "southbridge/intel/i82801gx/i82801gx.h"
42#include "dock.h"
43
44void setup_ich7_gpios(void)
45{
46 printk(BIOS_DEBUG, " GPIOS...");
47
48 /* T60 GPIO:
49 6: LEGACYIO#
50 7: BDC_PRESENCE#
51 8: H8_WAKE#
52 10: MDI_DETECT
53 12: H8SCI#
54 14: CPUSB#
55 15: CPPE#
56 25: MDC_KILL#
57 27: EXC_PWR_CTRL
58 28: EXC_AUX_CTRL
59 35: CLKREQ_SATA#
60 36: PLANARID0
61 37: PLANARID1
62 38: PLANARID2
63 39: PLANARID3
64 */
65 outl(0x1f48f7c2, DEFAULT_GPIOBASE + 0x00); /* GPIO_USE_SEL */
66 outl(0xe0e0ffc3, DEFAULT_GPIOBASE + 0x04); /* GP_IO_SEL */
67 outl(0xfbfefb7d, DEFAULT_GPIOBASE + 0x0c); /* GP_LVL */
68 /* Output Control Registers */
69 outl(0x00040000, DEFAULT_GPIOBASE + 0x18); /* GPO_BLINK */
70 /* Input Control Registers */
71 outl(0x000039ff, DEFAULT_GPIOBASE + 0x2c); /* GPI_INV */
72 outl(0x000100f0, DEFAULT_GPIOBASE + 0x30); /* GPIO_USE_SEL2 */
73 outl(0x000000f1, DEFAULT_GPIOBASE + 0x34); /* GP_IO_SEL2 */
74 outl(0x000300a3, DEFAULT_GPIOBASE + 0x38); /* GP_LVL2 */
75}
76
77static void ich7_enable_lpc(void)
78{
79 // Enable Serial IRQ
80 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x64, 0xd0);
81 // decode range
82 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x80, 0x0210);
83 // decode range
84 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x82, 0x1f0d);
85
86 /* range 0x1600 - 0x167f */
87 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x84, 0x1601);
88 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x86, 0x007c);
89
90 /* range 0x15e0 - 0x10ef */
91 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x88, 0x15e1);
92 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x8a, 0x000c);
93
94 /* range 0x1680 - 0x169f */
95 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x8c, 0x1681);
96 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x8e, 0x001c);
97}
98
99static void early_superio_config(void)
100{
101 int timeout = 100000;
102 device_t dev = PNP_DEV(0x2e, 3);
103
104 pnp_write_config(dev, 0x29, 0xa0);
105
106 while(!(pnp_read_config(dev, 0x29) & 0x10) && timeout--)
107 udelay(1000);
108
109 /* Enable COM1 */
110 pnp_set_logical_device(dev);
111 pnp_set_iobase(dev, PNP_IDX_IO0, 0x3f8);
112 pnp_set_enable(dev, 1);
113}
114
115static void rcba_config(void)
116{
117 /* Set up virtual channel 0 */
118 RCBA32(0x0014) = 0x80000001;
119 RCBA32(0x001c) = 0x03128010;
120
121 /* Device 1f interrupt pin register */
122 RCBA32(0x3100) = 0x00001230;
123 RCBA32(0x3108) = 0x40004321;
124
125 /* PCIe Interrupts */
126 RCBA32(0x310c) = 0x00004321;
127 /* HD Audio Interrupt */
128 RCBA32(0x3110) = 0x00000002;
129
130 /* dev irq route register */
131 RCBA16(0x3140) = 0x1007;
132 RCBA16(0x3142) = 0x0076;
133 RCBA16(0x3144) = 0x3210;
134 RCBA16(0x3146) = 0x7654;
135 RCBA16(0x3148) = 0x0010;
136
137 /* Enable IOAPIC */
138 RCBA8(0x31ff) = 0x03;
139
140 /* Enable upper 128bytes of CMOS */
141 RCBA32(0x3400) = (1 << 2);
142
143 /* Disable unused devices */
144 RCBA32(0x3418) = FD_PCIE6 | FD_PCIE5 | FD_INTLAN | FD_ACMOD | FD_ACAUD;
145 RCBA32(0x3418) |= (1 << 0); // Required.
146
147 /* Set up I/O Trap #0 for 0xfe00 (SMIC) */
148 RCBA32(0x1e84) = 0x00020001;
149 RCBA32(0x1e80) = 0x0000fe01;
150
151 /* Set up I/O Trap #3 for 0x800-0x80c (Trap) */
152 RCBA32(0x1e9c) = 0x000200f0;
153 RCBA32(0x1e98) = 0x000c0801;
154}
155
156static void early_ich7_init(void)
157{
158 uint8_t reg8;
159 uint32_t reg32;
160
161 // program secondary mlt XXX byte?
162 pci_write_config8(PCI_DEV(0, 0x1e, 0), 0x1b, 0x20);
163
164 // reset rtc power status
165 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xa4);
166 reg8 &= ~(1 << 2);
167 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa4, reg8);
168
169 // usb transient disconnect
170 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xad);
171 reg8 |= (3 << 0);
172 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xad, reg8);
173
174 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xfc);
175 reg32 |= (1 << 29) | (1 << 17);
176 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xfc, reg32);
177
178 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xdc);
179 reg32 |= (1 << 31) | (1 << 27);
180 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xdc, reg32);
181
182 RCBA32(0x0088) = 0x0011d000;
183 RCBA16(0x01fc) = 0x060f;
184 RCBA32(0x01f4) = 0x86000040;
185 RCBA32(0x0214) = 0x10030549;
186 RCBA32(0x0218) = 0x00020504;
187 RCBA8(0x0220) = 0xc5;
188 reg32 = RCBA32(0x3410);
189 reg32 |= (1 << 6);
190 RCBA32(0x3410) = reg32;
191 reg32 = RCBA32(0x3430);
192 reg32 &= ~(3 << 0);
193 reg32 |= (1 << 0);
194 RCBA32(0x3430) = reg32;
195 RCBA32(0x3418) |= (1 << 0);
196 RCBA16(0x0200) = 0x2008;
197 RCBA8(0x2027) = 0x0d;
198 RCBA16(0x3e08) |= (1 << 7);
199 RCBA16(0x3e48) |= (1 << 7);
200 RCBA32(0x3e0e) |= (1 << 7);
201 RCBA32(0x3e4e) |= (1 << 7);
202
203 // next step only on ich7m b0 and later:
204 reg32 = RCBA32(0x2034);
205 reg32 &= ~(0x0f << 16);
206 reg32 |= (5 << 16);
207 RCBA32(0x2034) = reg32;
208}
209
Aaron Durbina0a37272014-08-14 08:35:11 -0500210#include <cpu/intel/romstage.h>
Sven Schnelled8129f92011-04-20 09:12:17 +0000211void main(unsigned long bist)
212{
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200213 int s3resume = 0;
214 int dock_err;
Sven Schnelled8129f92011-04-20 09:12:17 +0000215 const u8 spd_addrmap[2 * DIMM_SOCKETS] = { 0x50, 0x52, 0x51, 0x53 };
216
Nico Huber44c392f2013-05-26 19:37:47 +0200217
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300218 timestamp_init(get_initial_timestamp());
219 timestamp_add_now(TS_START_ROMSTAGE);
Nico Huber44c392f2013-05-26 19:37:47 +0200220
Sven Schnelled8129f92011-04-20 09:12:17 +0000221 if (bist == 0)
222 enable_lapic();
223
224 /* Force PCIRST# */
225 pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, SBR);
226 udelay(200 * 1000);
227 pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, 0);
228
229 ich7_enable_lpc();
230
Sven Schnelleb5381102011-10-15 17:31:01 +0200231 /* We want early GPIO setup, to be able to detect legacy I/O module */
232 pci_write_config32(PCI_DEV(0, 0x1f, 0), GPIOBASE, DEFAULT_GPIOBASE | 1);
233 /* Enable GPIOs */
234 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x4c /* GC */ , 0x10);
235 setup_ich7_gpios();
Sven Schnelled8129f92011-04-20 09:12:17 +0000236
Sven Schnelleb5381102011-10-15 17:31:01 +0200237 dock_err = dlpc_init();
238
239 /* We prefer Legacy I/O module over docking */
240 if (legacy_io_present()) {
241 legacy_io_init();
242 early_superio_config();
243 } else if (!dock_err && dock_present()) {
Sven Schnelled8129f92011-04-20 09:12:17 +0000244 dock_connect();
245 early_superio_config();
Sven Schnelled8129f92011-04-20 09:12:17 +0000246 }
247
Sven Schnelleb5381102011-10-15 17:31:01 +0200248 /* Setup the console */
Sven Schnelled8129f92011-04-20 09:12:17 +0000249 console_init();
250
251 /* Halt if there was a built in self test failure */
252 report_bist_failure(bist);
253
254 if (MCHBAR16(SSKPD) == 0xCAFE) {
255 printk(BIOS_DEBUG, "soft reset detected, rebooting properly\n");
256 outb(0x6, 0xcf9);
Patrick Georgi546953c2014-11-29 10:38:17 +0100257 halt();
Sven Schnelled8129f92011-04-20 09:12:17 +0000258 }
259
260 /* Perform some early chipset initialization required
261 * before RAM initialization can work
262 */
263 i945_early_initialization();
264
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200265 s3resume = southbridge_detect_s3_resume();
Sven Schnelled8129f92011-04-20 09:12:17 +0000266
267 /* Enable SPD ROMs and DDR-II DRAM */
268 enable_smbus();
269
270#if CONFIG_DEFAULT_CONSOLE_LOGLEVEL > 8
271 dump_spd_registers();
272#endif
273
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300274 timestamp_add_now(TS_BEFORE_INITRAM);
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200275 sdram_initialize(s3resume ? 2 : 0, spd_addrmap);
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300276 timestamp_add_now(TS_AFTER_INITRAM);
Sven Schnelled8129f92011-04-20 09:12:17 +0000277
278 /* Perform some initialization that must run before stage2 */
279 early_ich7_init();
280
281 /* This should probably go away. Until now it is required
282 * and mainboard specific
283 */
284 rcba_config();
285
286 /* Chipset Errata! */
287 fixup_i945_errata();
288
289 /* Initialize the internal PCIe links before we go into stage2 */
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200290 i945_late_initialization(s3resume);
Paul Menzelac6ea042013-04-29 23:21:07 +0200291
Nico Huber44c392f2013-05-26 19:37:47 +0200292 timestamp_add_now(TS_END_ROMSTAGE);
Sven Schnelled8129f92011-04-20 09:12:17 +0000293}