blob: 820a33318436bf041527d46d2fdcf52e033d2e74 [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>
Kyösti Mälkki12d681b2014-06-14 18:51:34 +030023#include <arch/acpi.h>
Edwin Beasanteb50c7d2010-07-06 21:05:04 +000024#include <pc80/mc146818rtc.h>
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000025#include <console/console.h>
26#include <cpu/x86/bist.h>
Kyösti Mälkki15fa9922016-06-17 10:00:28 +030027#include <cpu/intel/romstage.h>
Patrick Georgi546953c2014-11-29 10:38:17 +010028#include <halt.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110029#include <northbridge/intel/i945/i945.h>
30#include <northbridge/intel/i945/raminit.h>
31#include <southbridge/intel/i82801gx/i82801gx.h>
Patrick Georgiad0dda72015-07-13 19:25:01 +020032#include <timestamp.h>
Patrick Georgia4700192011-01-27 07:39:38 +000033#include "option_table.h"
Patrick Georgid0835952010-10-05 09:07:10 +000034
Arthur Heymans62902ca2016-11-29 14:13:43 +010035static void setup_special_ich7_gpios(void)
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000036{
37 u32 gpios;
38
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000039 printk(BIOS_SPEW, "\n Initializing drive bay...\n");
40 gpios = inl(DEFAULT_GPIOBASE + 0x38); // GPIO Level 2
41 gpios |= (1 << 0); // GPIO33 = ODD
42 gpios |= (1 << 1); // GPIO34 = IDE_RST#
43 outl(gpios, DEFAULT_GPIOBASE + 0x38); /* GP_LVL2 */
44
45 gpios = inl(DEFAULT_GPIOBASE + 0x0c); // GPIO Level
46 gpios &= ~(1 << 13); // ??
47 outl(gpios, DEFAULT_GPIOBASE + 0x0c); /* GP_LVL */
48
49 printk(BIOS_SPEW, "\n Initializing Ethernet NIC...\n");
50 gpios = inl(DEFAULT_GPIOBASE + 0x0c); // GPIO Level
51 gpios &= ~(1 << 24); // Enable LAN Power
52 outl(gpios, DEFAULT_GPIOBASE + 0x0c); /* GP_LVL */
53}
54
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000055static void ich7_enable_lpc(void)
56{
Patrick Georgia4700192011-01-27 07:39:38 +000057 int lpt_en = 0;
Arthur Heymansb451df22017-08-15 20:59:09 +020058 if (read_option(lpt, 0) != 0)
59 lpt_en = LPT_LPC_EN;
60
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000061 // Enable Serial IRQ
Arthur Heymansb451df22017-08-15 20:59:09 +020062 pci_write_config8(PCI_DEV(0, 0x1f, 0), SERIRQ_CNTL, 0xd0);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000063 // decode range
Arthur Heymansb451df22017-08-15 20:59:09 +020064 pci_write_config16(PCI_DEV(0, 0x1f, 0), LPC_IO_DEC, 0x0007);
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_EN, CNF2_LPC_EN | CNF1_LPC_EN
67 | MC_LPC_EN | KBC_LPC_EN | GAMEH_LPC_EN | GAMEL_LPC_EN
68 | FDD_LPC_EN| lpt_en | COMB_LPC_EN | COMA_LPC_EN);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000069 // Enable 0x02e0 - 0x2ff
Arthur Heymansb451df22017-08-15 20:59:09 +020070 pci_write_config32(PCI_DEV(0, 0x1f, 0), GEN1_DEC, 0x001c02e1);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000071 // Enable 0x600 - 0x6ff
Arthur Heymansb451df22017-08-15 20:59:09 +020072 pci_write_config32(PCI_DEV(0, 0x1f, 0), GEN2_DEC, 0x00fc0601);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000073 // Enable 0x68 - 0x6f
Arthur Heymansb451df22017-08-15 20:59:09 +020074 pci_write_config32(PCI_DEV(0, 0x1f, 0), GEN3_DEC, 0x00040069);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000075}
76
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000077/* This box has two superios, so enabling serial becomes slightly excessive.
78 * We disable a lot of stuff to make sure that there are no conflicts between
79 * the two. Also set up the GPIOs from the beginning. This is the "no schematic
80 * but safe anyways" method.
81 */
Antonello Dettori771d7ec2016-11-08 18:44:46 +010082static void pnp_enter_ext_func_mode(pnp_devfn_t dev)
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000083{
84 unsigned int port = dev >> 8;
85 outb(0x55, port);
86}
87
Antonello Dettori771d7ec2016-11-08 18:44:46 +010088static void pnp_exit_ext_func_mode(pnp_devfn_t dev)
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000089{
90 unsigned int port = dev >> 8;
91 outb(0xaa, port);
92}
93
Antonello Dettori771d7ec2016-11-08 18:44:46 +010094static void pnp_write_register(pnp_devfn_t dev, int reg, int val)
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000095{
96 unsigned int port = dev >> 8;
97 outb(reg, port);
98 outb(val, port+1);
99}
100
101static void early_superio_config(void)
102{
Antonello Dettori771d7ec2016-11-08 18:44:46 +0100103 pnp_devfn_t dev;
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000104
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600105 dev = PNP_DEV(0x4e, 0x00);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000106
107 pnp_enter_ext_func_mode(dev);
108 pnp_write_register(dev, 0x02, 0x0e); // UART power
109 pnp_write_register(dev, 0x1b, (0x3e8 >> 2)); // UART3 base
110 pnp_write_register(dev, 0x1c, (0x2e8 >> 2)); // UART4 base
111 pnp_write_register(dev, 0x1d, (5 << 4) | 11); // UART3,4 IRQ
112 pnp_write_register(dev, 0x1e, 1); // no 32khz clock
113 pnp_write_register(dev, 0x24, (0x3f8 >> 2)); // UART1 base
114 pnp_write_register(dev, 0x28, (4 << 4) | 0); // UART1,2 IRQ
115 pnp_write_register(dev, 0x2c, 0); // DMA0 FIR
116 pnp_write_register(dev, 0x30, (0x600 >> 4)); // Runtime Register Block Base
117
118 pnp_write_register(dev, 0x31, 0xce); // GPIO1 DIR
119 pnp_write_register(dev, 0x32, 0x00); // GPIO1 POL
120 pnp_write_register(dev, 0x33, 0x0f); // GPIO2 DIR
121 pnp_write_register(dev, 0x34, 0x00); // GPIO2 POL
122 pnp_write_register(dev, 0x35, 0xa8); // GPIO3 DIR
123 pnp_write_register(dev, 0x36, 0x00); // GPIO3 POL
124 pnp_write_register(dev, 0x37, 0xa8); // GPIO4 DIR
125 pnp_write_register(dev, 0x38, 0x00); // GPIO4 POL
126
127 pnp_write_register(dev, 0x39, 0x00); // GPIO1 OUT
128 pnp_write_register(dev, 0x40, 0x80); // GPIO2/MISC OUT
129 pnp_write_register(dev, 0x41, 0x00); // GPIO5 OUT
130 pnp_write_register(dev, 0x42, 0xa8); // GPIO5 DIR
131 pnp_write_register(dev, 0x43, 0x00); // GPIO5 POL
132 pnp_write_register(dev, 0x44, 0x00); // GPIO ALT1
133 pnp_write_register(dev, 0x45, 0x50); // GPIO ALT2
134 pnp_write_register(dev, 0x46, 0x00); // GPIO ALT3
135
136 pnp_write_register(dev, 0x48, 0x55); // GPIO ALT5
137 pnp_write_register(dev, 0x49, 0x55); // GPIO ALT6
138 pnp_write_register(dev, 0x4a, 0x55); // GPIO ALT7
139 pnp_write_register(dev, 0x4b, 0x55); // GPIO ALT8
140 pnp_write_register(dev, 0x4c, 0x55); // GPIO ALT9
141 pnp_write_register(dev, 0x4d, 0x55); // GPIO ALT10
142
143 pnp_exit_ext_func_mode(dev);
144}
145
146static void rcba_config(void)
147{
148 /* Set up virtual channel 0 */
149 //RCBA32(0x0014) = 0x80000001;
150 //RCBA32(0x001c) = 0x03128010;
151
152 /* Device 1f interrupt pin register */
Arthur Heymansb451df22017-08-15 20:59:09 +0200153 RCBA32(D31IP) = 0x00042220;
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000154 /* Device 1d interrupt pin register */
Arthur Heymansb451df22017-08-15 20:59:09 +0200155 RCBA32(D28IP) = 0x00214321;
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000156
157 /* dev irq route register */
Arthur Heymansb451df22017-08-15 20:59:09 +0200158 RCBA16(D31IR) = 0x0232;
159 RCBA16(D30IR) = 0x3246;
160 RCBA16(D29IR) = 0x0237;
161 RCBA16(D28IR) = 0x3201;
162 RCBA16(D27IR) = 0x3216;
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000163
164 /* Enable IOAPIC */
Arthur Heymansb451df22017-08-15 20:59:09 +0200165 RCBA8(OIC) = 0x03;
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000166
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000167 /* Disable unused devices */
Arthur Heymans6267f5d2018-12-15 23:46:48 +0100168 RCBA32(FD) |= FD_INTLAN;
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000169
170 /* Enable PCIe Root Port Clock Gate */
171 // RCBA32(0x341c) = 0x00000001;
172
173
174 /* This should probably go into the ACPI enable trap */
175 /* Set up I/O Trap #0 for 0xfe00 (SMIC) */
176 RCBA32(0x1e84) = 0x00020001;
177 RCBA32(0x1e80) = 0x0000fe01;
178
179 /* Set up I/O Trap #3 for 0x800-0x80c (Trap) */
180 RCBA32(0x1e9c) = 0x000200f0;
181 RCBA32(0x1e98) = 0x000c0801;
182}
183
184static void early_ich7_init(void)
185{
186 uint8_t reg8;
187 uint32_t reg32;
188
189 // program secondary mlt XXX byte?
190 pci_write_config8(PCI_DEV(0, 0x1e, 0), 0x1b, 0x20);
191
192 // reset rtc power status
193 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xa4);
194 reg8 &= ~(1 << 2);
195 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa4, reg8);
196
197 // usb transient disconnect
198 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xad);
199 reg8 |= (3 << 0);
200 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xad, reg8);
201
202 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xfc);
203 reg32 |= (1 << 29) | (1 << 17);
204 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xfc, reg32);
205
206 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xdc);
207 reg32 |= (1 << 31) | (1 << 27);
208 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xdc, reg32);
209
210 RCBA32(0x0088) = 0x0011d000;
211 RCBA16(0x01fc) = 0x060f;
212 RCBA32(0x01f4) = 0x86000040;
213 RCBA32(0x0214) = 0x10030549;
214 RCBA32(0x0218) = 0x00020504;
215 RCBA8(0x0220) = 0xc5;
216 reg32 = RCBA32(0x3410);
217 reg32 |= (1 << 6);
218 RCBA32(0x3410) = reg32;
219 reg32 = RCBA32(0x3430);
220 reg32 &= ~(3 << 0);
221 reg32 |= (1 << 0);
222 RCBA32(0x3430) = reg32;
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000223 RCBA16(0x0200) = 0x2008;
224 RCBA8(0x2027) = 0x0d;
225 RCBA16(0x3e08) |= (1 << 7);
226 RCBA16(0x3e48) |= (1 << 7);
227 RCBA32(0x3e0e) |= (1 << 7);
228 RCBA32(0x3e4e) |= (1 << 7);
229
230 // next step only on ich7m b0 and later:
231 reg32 = RCBA32(0x2034);
232 reg32 &= ~(0x0f << 16);
233 reg32 |= (5 << 16);
234 RCBA32(0x2034) = reg32;
235}
236
Kyösti Mälkki15fa9922016-06-17 10:00:28 +0300237void mainboard_romstage_entry(unsigned long bist)
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000238{
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200239 int s3resume = 0;
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000240
Patrick Georgiad0dda72015-07-13 19:25:01 +0200241 timestamp_init(timestamp_get());
242 timestamp_add_now(TS_START_ROMSTAGE);
243
Uwe Hermann7b997052010-11-21 22:47:22 +0000244 if (bist == 0)
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000245 enable_lapic();
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000246
247#if 0
248 /* Force PCIRST# */
249 pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, SBR);
Stefan Reinauerbc8613e2010-08-25 18:35:42 +0000250 udelay(200 * 1000);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000251 pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, 0);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000252#endif
253
254 ich7_enable_lpc();
255 early_superio_config();
256
257 /* Set up the console */
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000258 console_init();
259
260 /* Halt if there was a built in self test failure */
261 report_bist_failure(bist);
262
263 if (MCHBAR16(SSKPD) == 0xCAFE) {
264 printk(BIOS_DEBUG, "soft reset detected, rebooting properly\n");
265 outb(0x6, 0xcf9);
Patrick Georgi546953c2014-11-29 10:38:17 +0100266 halt();
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000267 }
268
269 /* Perform some early chipset initialization required
270 * before RAM initialization can work
271 */
272 i945_early_initialization();
273
Arthur Heymans62902ca2016-11-29 14:13:43 +0100274 setup_special_ich7_gpios();
275
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200276 s3resume = southbridge_detect_s3_resume();
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000277
278 /* Enable SPD ROMs and DDR-II DRAM */
279 enable_smbus();
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700280
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000281#if CONFIG_DEFAULT_CONSOLE_LOGLEVEL > 8
282 dump_spd_registers();
283#endif
284
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200285 sdram_initialize(s3resume ? 2 : 0, NULL);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000286
287 /* Perform some initialization that must run before stage2 */
288 early_ich7_init();
289
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700290 /* This should probably go away. Until now it is required
291 * and mainboard specific
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000292 */
293 rcba_config();
294
295 /* Chipset Errata! */
296 fixup_i945_errata();
297
298 /* Initialize the internal PCIe links before we go into stage2 */
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200299 i945_late_initialization(s3resume);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000300}