blob: e58ef1bda68c6a6bf7c610621cc13e581e70be79 [file] [log] [blame]
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +00001/*
2 * This file is part of the coreboot project.
Stefan Reinauer5ff7c132011-10-31 12:56:45 -07003 *
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +00004 * Copyright (C) 2007-2009 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
8 * published by the Free Software Foundation; version 2 of
9 * the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000015 */
16
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000017#include <stdint.h>
18#include <string.h>
19#include <arch/io.h>
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000020#include <device/pci_def.h>
21#include <device/pnp_def.h>
22#include <cpu/x86/lapic.h>
Patrick Georgid0835952010-10-05 09:07:10 +000023#include <lib.h>
Kyösti Mälkki12d681b2014-06-14 18:51:34 +030024#include <arch/acpi.h>
Kyösti Mälkkia7c96112013-10-13 20:41:57 +030025#include <cbmem.h>
Edwin Beasanteb50c7d2010-07-06 21:05:04 +000026#include <pc80/mc146818rtc.h>
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000027#include <console/console.h>
28#include <cpu/x86/bist.h>
Kyösti Mälkki15fa9922016-06-17 10:00:28 +030029#include <cpu/intel/romstage.h>
Patrick Georgi546953c2014-11-29 10:38:17 +010030#include <halt.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110031#include <northbridge/intel/i945/i945.h>
32#include <northbridge/intel/i945/raminit.h>
33#include <southbridge/intel/i82801gx/i82801gx.h>
Patrick Georgiad0dda72015-07-13 19:25:01 +020034#include <timestamp.h>
Patrick Georgia4700192011-01-27 07:39:38 +000035#include "option_table.h"
Patrick Georgid0835952010-10-05 09:07:10 +000036
Arthur Heymans62902ca2016-11-29 14:13:43 +010037static void setup_special_ich7_gpios(void)
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000038{
39 u32 gpios;
40
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000041 printk(BIOS_SPEW, "\n Initializing drive bay...\n");
42 gpios = inl(DEFAULT_GPIOBASE + 0x38); // GPIO Level 2
43 gpios |= (1 << 0); // GPIO33 = ODD
44 gpios |= (1 << 1); // GPIO34 = IDE_RST#
45 outl(gpios, DEFAULT_GPIOBASE + 0x38); /* GP_LVL2 */
46
47 gpios = inl(DEFAULT_GPIOBASE + 0x0c); // GPIO Level
48 gpios &= ~(1 << 13); // ??
49 outl(gpios, DEFAULT_GPIOBASE + 0x0c); /* GP_LVL */
50
51 printk(BIOS_SPEW, "\n Initializing Ethernet NIC...\n");
52 gpios = inl(DEFAULT_GPIOBASE + 0x0c); // GPIO Level
53 gpios &= ~(1 << 24); // Enable LAN Power
54 outl(gpios, DEFAULT_GPIOBASE + 0x0c); /* GP_LVL */
55}
56
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000057static void ich7_enable_lpc(void)
58{
Patrick Georgia4700192011-01-27 07:39:38 +000059 int lpt_en = 0;
Arthur Heymansb451df22017-08-15 20:59:09 +020060 if (read_option(lpt, 0) != 0)
61 lpt_en = LPT_LPC_EN;
62
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000063 // Enable Serial IRQ
Arthur Heymansb451df22017-08-15 20:59:09 +020064 pci_write_config8(PCI_DEV(0, 0x1f, 0), SERIRQ_CNTL, 0xd0);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000065 // decode range
Arthur Heymansb451df22017-08-15 20:59:09 +020066 pci_write_config16(PCI_DEV(0, 0x1f, 0), LPC_IO_DEC, 0x0007);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000067 // decode range
Arthur Heymansb451df22017-08-15 20:59:09 +020068 pci_write_config16(PCI_DEV(0, 0x1f, 0), LPC_EN, CNF2_LPC_EN | CNF1_LPC_EN
69 | MC_LPC_EN | KBC_LPC_EN | GAMEH_LPC_EN | GAMEL_LPC_EN
70 | FDD_LPC_EN| lpt_en | COMB_LPC_EN | COMA_LPC_EN);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000071 // Enable 0x02e0 - 0x2ff
Arthur Heymansb451df22017-08-15 20:59:09 +020072 pci_write_config32(PCI_DEV(0, 0x1f, 0), GEN1_DEC, 0x001c02e1);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000073 // Enable 0x600 - 0x6ff
Arthur Heymansb451df22017-08-15 20:59:09 +020074 pci_write_config32(PCI_DEV(0, 0x1f, 0), GEN2_DEC, 0x00fc0601);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000075 // Enable 0x68 - 0x6f
Arthur Heymansb451df22017-08-15 20:59:09 +020076 pci_write_config32(PCI_DEV(0, 0x1f, 0), GEN3_DEC, 0x00040069);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000077}
78
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000079/* This box has two superios, so enabling serial becomes slightly excessive.
80 * We disable a lot of stuff to make sure that there are no conflicts between
81 * the two. Also set up the GPIOs from the beginning. This is the "no schematic
82 * but safe anyways" method.
83 */
Antonello Dettori771d7ec2016-11-08 18:44:46 +010084static void pnp_enter_ext_func_mode(pnp_devfn_t dev)
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000085{
86 unsigned int port = dev >> 8;
87 outb(0x55, port);
88}
89
Antonello Dettori771d7ec2016-11-08 18:44:46 +010090static void pnp_exit_ext_func_mode(pnp_devfn_t dev)
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000091{
92 unsigned int port = dev >> 8;
93 outb(0xaa, port);
94}
95
Antonello Dettori771d7ec2016-11-08 18:44:46 +010096static void pnp_write_register(pnp_devfn_t dev, int reg, int val)
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000097{
98 unsigned int port = dev >> 8;
99 outb(reg, port);
100 outb(val, port+1);
101}
102
103static void early_superio_config(void)
104{
Antonello Dettori771d7ec2016-11-08 18:44:46 +0100105 pnp_devfn_t dev;
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000106
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600107 dev = PNP_DEV(0x4e, 0x00);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000108
109 pnp_enter_ext_func_mode(dev);
110 pnp_write_register(dev, 0x02, 0x0e); // UART power
111 pnp_write_register(dev, 0x1b, (0x3e8 >> 2)); // UART3 base
112 pnp_write_register(dev, 0x1c, (0x2e8 >> 2)); // UART4 base
113 pnp_write_register(dev, 0x1d, (5 << 4) | 11); // UART3,4 IRQ
114 pnp_write_register(dev, 0x1e, 1); // no 32khz clock
115 pnp_write_register(dev, 0x24, (0x3f8 >> 2)); // UART1 base
116 pnp_write_register(dev, 0x28, (4 << 4) | 0); // UART1,2 IRQ
117 pnp_write_register(dev, 0x2c, 0); // DMA0 FIR
118 pnp_write_register(dev, 0x30, (0x600 >> 4)); // Runtime Register Block Base
119
120 pnp_write_register(dev, 0x31, 0xce); // GPIO1 DIR
121 pnp_write_register(dev, 0x32, 0x00); // GPIO1 POL
122 pnp_write_register(dev, 0x33, 0x0f); // GPIO2 DIR
123 pnp_write_register(dev, 0x34, 0x00); // GPIO2 POL
124 pnp_write_register(dev, 0x35, 0xa8); // GPIO3 DIR
125 pnp_write_register(dev, 0x36, 0x00); // GPIO3 POL
126 pnp_write_register(dev, 0x37, 0xa8); // GPIO4 DIR
127 pnp_write_register(dev, 0x38, 0x00); // GPIO4 POL
128
129 pnp_write_register(dev, 0x39, 0x00); // GPIO1 OUT
130 pnp_write_register(dev, 0x40, 0x80); // GPIO2/MISC OUT
131 pnp_write_register(dev, 0x41, 0x00); // GPIO5 OUT
132 pnp_write_register(dev, 0x42, 0xa8); // GPIO5 DIR
133 pnp_write_register(dev, 0x43, 0x00); // GPIO5 POL
134 pnp_write_register(dev, 0x44, 0x00); // GPIO ALT1
135 pnp_write_register(dev, 0x45, 0x50); // GPIO ALT2
136 pnp_write_register(dev, 0x46, 0x00); // GPIO ALT3
137
138 pnp_write_register(dev, 0x48, 0x55); // GPIO ALT5
139 pnp_write_register(dev, 0x49, 0x55); // GPIO ALT6
140 pnp_write_register(dev, 0x4a, 0x55); // GPIO ALT7
141 pnp_write_register(dev, 0x4b, 0x55); // GPIO ALT8
142 pnp_write_register(dev, 0x4c, 0x55); // GPIO ALT9
143 pnp_write_register(dev, 0x4d, 0x55); // GPIO ALT10
144
145 pnp_exit_ext_func_mode(dev);
146}
147
148static void rcba_config(void)
149{
150 /* Set up virtual channel 0 */
151 //RCBA32(0x0014) = 0x80000001;
152 //RCBA32(0x001c) = 0x03128010;
153
154 /* Device 1f interrupt pin register */
Arthur Heymansb451df22017-08-15 20:59:09 +0200155 RCBA32(D31IP) = 0x00042220;
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000156 /* Device 1d interrupt pin register */
Arthur Heymansb451df22017-08-15 20:59:09 +0200157 RCBA32(D28IP) = 0x00214321;
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000158
159 /* dev irq route register */
Arthur Heymansb451df22017-08-15 20:59:09 +0200160 RCBA16(D31IR) = 0x0232;
161 RCBA16(D30IR) = 0x3246;
162 RCBA16(D29IR) = 0x0237;
163 RCBA16(D28IR) = 0x3201;
164 RCBA16(D27IR) = 0x3216;
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000165
166 /* Enable IOAPIC */
Arthur Heymansb451df22017-08-15 20:59:09 +0200167 RCBA8(OIC) = 0x03;
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000168
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000169 /* Disable unused devices */
Arthur Heymansb451df22017-08-15 20:59:09 +0200170 RCBA32(FD) = FD_PCIE6 | FD_PCIE5 | FD_INTLAN | FD_ACMOD | FD_ACAUD | FD_PATA;
171 RCBA32(FD) |= (1 << 0); // Required.
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000172
173 /* Enable PCIe Root Port Clock Gate */
174 // RCBA32(0x341c) = 0x00000001;
175
176
177 /* This should probably go into the ACPI enable trap */
178 /* Set up I/O Trap #0 for 0xfe00 (SMIC) */
179 RCBA32(0x1e84) = 0x00020001;
180 RCBA32(0x1e80) = 0x0000fe01;
181
182 /* Set up I/O Trap #3 for 0x800-0x80c (Trap) */
183 RCBA32(0x1e9c) = 0x000200f0;
184 RCBA32(0x1e98) = 0x000c0801;
185}
186
187static void early_ich7_init(void)
188{
189 uint8_t reg8;
190 uint32_t reg32;
191
192 // program secondary mlt XXX byte?
193 pci_write_config8(PCI_DEV(0, 0x1e, 0), 0x1b, 0x20);
194
195 // reset rtc power status
196 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xa4);
197 reg8 &= ~(1 << 2);
198 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa4, reg8);
199
200 // usb transient disconnect
201 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xad);
202 reg8 |= (3 << 0);
203 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xad, reg8);
204
205 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xfc);
206 reg32 |= (1 << 29) | (1 << 17);
207 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xfc, reg32);
208
209 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xdc);
210 reg32 |= (1 << 31) | (1 << 27);
211 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xdc, reg32);
212
213 RCBA32(0x0088) = 0x0011d000;
214 RCBA16(0x01fc) = 0x060f;
215 RCBA32(0x01f4) = 0x86000040;
216 RCBA32(0x0214) = 0x10030549;
217 RCBA32(0x0218) = 0x00020504;
218 RCBA8(0x0220) = 0xc5;
219 reg32 = RCBA32(0x3410);
220 reg32 |= (1 << 6);
221 RCBA32(0x3410) = reg32;
222 reg32 = RCBA32(0x3430);
223 reg32 &= ~(3 << 0);
224 reg32 |= (1 << 0);
225 RCBA32(0x3430) = reg32;
Arthur Heymansb451df22017-08-15 20:59:09 +0200226 RCBA32(FD) |= (1 << 0);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000227 RCBA16(0x0200) = 0x2008;
228 RCBA8(0x2027) = 0x0d;
229 RCBA16(0x3e08) |= (1 << 7);
230 RCBA16(0x3e48) |= (1 << 7);
231 RCBA32(0x3e0e) |= (1 << 7);
232 RCBA32(0x3e4e) |= (1 << 7);
233
234 // next step only on ich7m b0 and later:
235 reg32 = RCBA32(0x2034);
236 reg32 &= ~(0x0f << 16);
237 reg32 |= (5 << 16);
238 RCBA32(0x2034) = reg32;
239}
240
Kyösti Mälkki15fa9922016-06-17 10:00:28 +0300241void mainboard_romstage_entry(unsigned long bist)
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000242{
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200243 int s3resume = 0;
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000244
Patrick Georgiad0dda72015-07-13 19:25:01 +0200245 timestamp_init(timestamp_get());
246 timestamp_add_now(TS_START_ROMSTAGE);
247
Uwe Hermann7b997052010-11-21 22:47:22 +0000248 if (bist == 0)
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000249 enable_lapic();
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000250
251#if 0
252 /* Force PCIRST# */
253 pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, SBR);
Stefan Reinauerbc8613e2010-08-25 18:35:42 +0000254 udelay(200 * 1000);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000255 pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, 0);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000256#endif
257
258 ich7_enable_lpc();
259 early_superio_config();
260
261 /* Set up the console */
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000262 console_init();
263
264 /* Halt if there was a built in self test failure */
265 report_bist_failure(bist);
266
267 if (MCHBAR16(SSKPD) == 0xCAFE) {
268 printk(BIOS_DEBUG, "soft reset detected, rebooting properly\n");
269 outb(0x6, 0xcf9);
Patrick Georgi546953c2014-11-29 10:38:17 +0100270 halt();
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000271 }
272
273 /* Perform some early chipset initialization required
274 * before RAM initialization can work
275 */
276 i945_early_initialization();
277
Arthur Heymans62902ca2016-11-29 14:13:43 +0100278 setup_special_ich7_gpios();
279
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200280 s3resume = southbridge_detect_s3_resume();
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000281
282 /* Enable SPD ROMs and DDR-II DRAM */
283 enable_smbus();
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700284
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000285#if CONFIG_DEFAULT_CONSOLE_LOGLEVEL > 8
286 dump_spd_registers();
287#endif
288
Paul Menzel6c20b652016-12-29 22:54:02 +0100289 timestamp_add_now(TS_BEFORE_INITRAM);
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200290 sdram_initialize(s3resume ? 2 : 0, NULL);
Paul Menzel6c20b652016-12-29 22:54:02 +0100291 timestamp_add_now(TS_AFTER_INITRAM);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000292
293 /* Perform some initialization that must run before stage2 */
294 early_ich7_init();
295
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700296 /* This should probably go away. Until now it is required
297 * and mainboard specific
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000298 */
299 rcba_config();
300
301 /* Chipset Errata! */
302 fixup_i945_errata();
303
304 /* Initialize the internal PCIe links before we go into stage2 */
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200305 i945_late_initialization(s3resume);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000306}