blob: d3cd90cf657da6059234c80b2264ffb91dc9ffb0 [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.
Sven Schnelled8129f92011-04-20 09:12:17 +000016 */
17
18// __PRE_RAM__ means: use "unsigned" for device, not a struct.
19
20#include <stdint.h>
21#include <string.h>
22#include <arch/io.h>
Sven Schnelled8129f92011-04-20 09:12:17 +000023#include <device/pci_def.h>
24#include <device/pnp_def.h>
25#include <cpu/x86/lapic.h>
26#include <lib.h>
Kyösti Mälkki12d681b2014-06-14 18:51:34 +030027#include <arch/acpi.h>
Paul Menzelac6ea042013-04-29 23:21:07 +020028#include <cbmem.h>
Nico Huber44c392f2013-05-26 19:37:47 +020029#include <timestamp.h>
Sven Schnelled8129f92011-04-20 09:12:17 +000030#include <pc80/mc146818rtc.h>
31#include <console/console.h>
Sven Schnelled8129f92011-04-20 09:12:17 +000032#include <cpu/x86/bist.h>
Kyösti Mälkki15fa9922016-06-17 10:00:28 +030033#include <cpu/intel/romstage.h>
Patrick Georgi546953c2014-11-29 10:38:17 +010034#include <halt.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110035#include <northbridge/intel/i945/i945.h>
36#include <northbridge/intel/i945/raminit.h>
37#include <southbridge/intel/i82801gx/i82801gx.h>
Sven Schnelled8129f92011-04-20 09:12:17 +000038#include "dock.h"
39
40void setup_ich7_gpios(void)
41{
42 printk(BIOS_DEBUG, " GPIOS...");
43
44 /* T60 GPIO:
45 6: LEGACYIO#
46 7: BDC_PRESENCE#
47 8: H8_WAKE#
48 10: MDI_DETECT
49 12: H8SCI#
50 14: CPUSB#
51 15: CPPE#
52 25: MDC_KILL#
53 27: EXC_PWR_CTRL
54 28: EXC_AUX_CTRL
55 35: CLKREQ_SATA#
56 36: PLANARID0
57 37: PLANARID1
58 38: PLANARID2
59 39: PLANARID3
60 */
61 outl(0x1f48f7c2, DEFAULT_GPIOBASE + 0x00); /* GPIO_USE_SEL */
62 outl(0xe0e0ffc3, DEFAULT_GPIOBASE + 0x04); /* GP_IO_SEL */
63 outl(0xfbfefb7d, DEFAULT_GPIOBASE + 0x0c); /* GP_LVL */
64 /* Output Control Registers */
65 outl(0x00040000, DEFAULT_GPIOBASE + 0x18); /* GPO_BLINK */
66 /* Input Control Registers */
67 outl(0x000039ff, DEFAULT_GPIOBASE + 0x2c); /* GPI_INV */
68 outl(0x000100f0, DEFAULT_GPIOBASE + 0x30); /* GPIO_USE_SEL2 */
69 outl(0x000000f1, DEFAULT_GPIOBASE + 0x34); /* GP_IO_SEL2 */
70 outl(0x000300a3, DEFAULT_GPIOBASE + 0x38); /* GP_LVL2 */
71}
72
73static void ich7_enable_lpc(void)
74{
75 // Enable Serial IRQ
76 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x64, 0xd0);
77 // decode range
78 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x80, 0x0210);
79 // decode range
80 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x82, 0x1f0d);
81
82 /* range 0x1600 - 0x167f */
83 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x84, 0x1601);
84 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x86, 0x007c);
85
86 /* range 0x15e0 - 0x10ef */
87 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x88, 0x15e1);
88 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x8a, 0x000c);
89
90 /* range 0x1680 - 0x169f */
91 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x8c, 0x1681);
92 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x8e, 0x001c);
93}
94
95static void early_superio_config(void)
96{
97 int timeout = 100000;
Antonello Dettoriec4555b2016-09-02 09:12:20 +020098 pnp_devfn_t dev = PNP_DEV(0x2e, 3);
Sven Schnelled8129f92011-04-20 09:12:17 +000099
100 pnp_write_config(dev, 0x29, 0xa0);
101
102 while(!(pnp_read_config(dev, 0x29) & 0x10) && timeout--)
103 udelay(1000);
104
105 /* Enable COM1 */
106 pnp_set_logical_device(dev);
107 pnp_set_iobase(dev, PNP_IDX_IO0, 0x3f8);
108 pnp_set_enable(dev, 1);
109}
110
111static void rcba_config(void)
112{
113 /* Set up virtual channel 0 */
114 RCBA32(0x0014) = 0x80000001;
115 RCBA32(0x001c) = 0x03128010;
116
117 /* Device 1f interrupt pin register */
118 RCBA32(0x3100) = 0x00001230;
119 RCBA32(0x3108) = 0x40004321;
120
121 /* PCIe Interrupts */
122 RCBA32(0x310c) = 0x00004321;
123 /* HD Audio Interrupt */
124 RCBA32(0x3110) = 0x00000002;
125
126 /* dev irq route register */
127 RCBA16(0x3140) = 0x1007;
128 RCBA16(0x3142) = 0x0076;
129 RCBA16(0x3144) = 0x3210;
130 RCBA16(0x3146) = 0x7654;
131 RCBA16(0x3148) = 0x0010;
132
133 /* Enable IOAPIC */
134 RCBA8(0x31ff) = 0x03;
135
Sven Schnelled8129f92011-04-20 09:12:17 +0000136 /* Disable unused devices */
137 RCBA32(0x3418) = FD_PCIE6 | FD_PCIE5 | FD_INTLAN | FD_ACMOD | FD_ACAUD;
138 RCBA32(0x3418) |= (1 << 0); // Required.
139
140 /* Set up I/O Trap #0 for 0xfe00 (SMIC) */
141 RCBA32(0x1e84) = 0x00020001;
142 RCBA32(0x1e80) = 0x0000fe01;
143
144 /* Set up I/O Trap #3 for 0x800-0x80c (Trap) */
145 RCBA32(0x1e9c) = 0x000200f0;
146 RCBA32(0x1e98) = 0x000c0801;
147}
148
149static void early_ich7_init(void)
150{
151 uint8_t reg8;
152 uint32_t reg32;
153
154 // program secondary mlt XXX byte?
155 pci_write_config8(PCI_DEV(0, 0x1e, 0), 0x1b, 0x20);
156
157 // reset rtc power status
158 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xa4);
159 reg8 &= ~(1 << 2);
160 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa4, reg8);
161
162 // usb transient disconnect
163 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xad);
164 reg8 |= (3 << 0);
165 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xad, reg8);
166
167 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xfc);
168 reg32 |= (1 << 29) | (1 << 17);
169 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xfc, reg32);
170
171 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xdc);
172 reg32 |= (1 << 31) | (1 << 27);
173 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xdc, reg32);
174
175 RCBA32(0x0088) = 0x0011d000;
176 RCBA16(0x01fc) = 0x060f;
177 RCBA32(0x01f4) = 0x86000040;
178 RCBA32(0x0214) = 0x10030549;
179 RCBA32(0x0218) = 0x00020504;
180 RCBA8(0x0220) = 0xc5;
181 reg32 = RCBA32(0x3410);
182 reg32 |= (1 << 6);
183 RCBA32(0x3410) = reg32;
184 reg32 = RCBA32(0x3430);
185 reg32 &= ~(3 << 0);
186 reg32 |= (1 << 0);
187 RCBA32(0x3430) = reg32;
188 RCBA32(0x3418) |= (1 << 0);
189 RCBA16(0x0200) = 0x2008;
190 RCBA8(0x2027) = 0x0d;
191 RCBA16(0x3e08) |= (1 << 7);
192 RCBA16(0x3e48) |= (1 << 7);
193 RCBA32(0x3e0e) |= (1 << 7);
194 RCBA32(0x3e4e) |= (1 << 7);
195
196 // next step only on ich7m b0 and later:
197 reg32 = RCBA32(0x2034);
198 reg32 &= ~(0x0f << 16);
199 reg32 |= (5 << 16);
200 RCBA32(0x2034) = reg32;
201}
202
Kyösti Mälkki15fa9922016-06-17 10:00:28 +0300203void mainboard_romstage_entry(unsigned long bist)
Sven Schnelled8129f92011-04-20 09:12:17 +0000204{
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200205 int s3resume = 0;
206 int dock_err;
Sven Schnelled8129f92011-04-20 09:12:17 +0000207 const u8 spd_addrmap[2 * DIMM_SOCKETS] = { 0x50, 0x52, 0x51, 0x53 };
208
Nico Huber44c392f2013-05-26 19:37:47 +0200209
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300210 timestamp_init(get_initial_timestamp());
211 timestamp_add_now(TS_START_ROMSTAGE);
Nico Huber44c392f2013-05-26 19:37:47 +0200212
Sven Schnelled8129f92011-04-20 09:12:17 +0000213 if (bist == 0)
214 enable_lapic();
215
216 /* Force PCIRST# */
217 pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, SBR);
218 udelay(200 * 1000);
219 pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, 0);
220
221 ich7_enable_lpc();
222
Sven Schnelleb5381102011-10-15 17:31:01 +0200223 /* We want early GPIO setup, to be able to detect legacy I/O module */
224 pci_write_config32(PCI_DEV(0, 0x1f, 0), GPIOBASE, DEFAULT_GPIOBASE | 1);
225 /* Enable GPIOs */
226 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x4c /* GC */ , 0x10);
227 setup_ich7_gpios();
Sven Schnelled8129f92011-04-20 09:12:17 +0000228
Sven Schnelleb5381102011-10-15 17:31:01 +0200229 dock_err = dlpc_init();
230
231 /* We prefer Legacy I/O module over docking */
232 if (legacy_io_present()) {
233 legacy_io_init();
234 early_superio_config();
235 } else if (!dock_err && dock_present()) {
Sven Schnelled8129f92011-04-20 09:12:17 +0000236 dock_connect();
237 early_superio_config();
Sven Schnelled8129f92011-04-20 09:12:17 +0000238 }
239
Sven Schnelleb5381102011-10-15 17:31:01 +0200240 /* Setup the console */
Sven Schnelled8129f92011-04-20 09:12:17 +0000241 console_init();
242
243 /* Halt if there was a built in self test failure */
244 report_bist_failure(bist);
245
246 if (MCHBAR16(SSKPD) == 0xCAFE) {
247 printk(BIOS_DEBUG, "soft reset detected, rebooting properly\n");
248 outb(0x6, 0xcf9);
Patrick Georgi546953c2014-11-29 10:38:17 +0100249 halt();
Sven Schnelled8129f92011-04-20 09:12:17 +0000250 }
251
252 /* Perform some early chipset initialization required
253 * before RAM initialization can work
254 */
255 i945_early_initialization();
256
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200257 s3resume = southbridge_detect_s3_resume();
Sven Schnelled8129f92011-04-20 09:12:17 +0000258
259 /* Enable SPD ROMs and DDR-II DRAM */
260 enable_smbus();
261
262#if CONFIG_DEFAULT_CONSOLE_LOGLEVEL > 8
263 dump_spd_registers();
264#endif
265
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300266 timestamp_add_now(TS_BEFORE_INITRAM);
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200267 sdram_initialize(s3resume ? 2 : 0, spd_addrmap);
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300268 timestamp_add_now(TS_AFTER_INITRAM);
Sven Schnelled8129f92011-04-20 09:12:17 +0000269
270 /* Perform some initialization that must run before stage2 */
271 early_ich7_init();
272
273 /* This should probably go away. Until now it is required
274 * and mainboard specific
275 */
276 rcba_config();
277
278 /* Chipset Errata! */
279 fixup_i945_errata();
280
281 /* Initialize the internal PCIe links before we go into stage2 */
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200282 i945_late_initialization(s3resume);
Sven Schnelled8129f92011-04-20 09:12:17 +0000283}