blob: dcfd27ff89926bcae0894c3629c19465b336f04b [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>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020020#include <device/pci_ops.h>
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000021#include <device/pci_def.h>
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000022#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 Georgia4700192011-01-27 07:39:38 +000032#include "option_table.h"
Patrick Georgid0835952010-10-05 09:07:10 +000033
Arthur Heymans62902ca2016-11-29 14:13:43 +010034static void setup_special_ich7_gpios(void)
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000035{
36 u32 gpios;
37
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000038 printk(BIOS_SPEW, "\n Initializing drive bay...\n");
39 gpios = inl(DEFAULT_GPIOBASE + 0x38); // GPIO Level 2
40 gpios |= (1 << 0); // GPIO33 = ODD
41 gpios |= (1 << 1); // GPIO34 = IDE_RST#
42 outl(gpios, DEFAULT_GPIOBASE + 0x38); /* GP_LVL2 */
43
44 gpios = inl(DEFAULT_GPIOBASE + 0x0c); // GPIO Level
45 gpios &= ~(1 << 13); // ??
46 outl(gpios, DEFAULT_GPIOBASE + 0x0c); /* GP_LVL */
47
48 printk(BIOS_SPEW, "\n Initializing Ethernet NIC...\n");
49 gpios = inl(DEFAULT_GPIOBASE + 0x0c); // GPIO Level
50 gpios &= ~(1 << 24); // Enable LAN Power
51 outl(gpios, DEFAULT_GPIOBASE + 0x0c); /* GP_LVL */
52}
53
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000054static void ich7_enable_lpc(void)
55{
Patrick Georgia4700192011-01-27 07:39:38 +000056 int lpt_en = 0;
Arthur Heymansb451df22017-08-15 20:59:09 +020057 if (read_option(lpt, 0) != 0)
58 lpt_en = LPT_LPC_EN;
59
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000060 // Enable Serial IRQ
Arthur Heymansb451df22017-08-15 20:59:09 +020061 pci_write_config8(PCI_DEV(0, 0x1f, 0), SERIRQ_CNTL, 0xd0);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000062 // decode range
Arthur Heymansb451df22017-08-15 20:59:09 +020063 pci_write_config16(PCI_DEV(0, 0x1f, 0), LPC_IO_DEC, 0x0007);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000064 // decode range
Arthur Heymansb451df22017-08-15 20:59:09 +020065 pci_write_config16(PCI_DEV(0, 0x1f, 0), LPC_EN, CNF2_LPC_EN | CNF1_LPC_EN
66 | MC_LPC_EN | KBC_LPC_EN | GAMEH_LPC_EN | GAMEL_LPC_EN
67 | FDD_LPC_EN| lpt_en | COMB_LPC_EN | COMA_LPC_EN);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000068 // Enable 0x02e0 - 0x2ff
Arthur Heymansb451df22017-08-15 20:59:09 +020069 pci_write_config32(PCI_DEV(0, 0x1f, 0), GEN1_DEC, 0x001c02e1);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000070 // Enable 0x600 - 0x6ff
Arthur Heymansb451df22017-08-15 20:59:09 +020071 pci_write_config32(PCI_DEV(0, 0x1f, 0), GEN2_DEC, 0x00fc0601);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000072 // Enable 0x68 - 0x6f
Arthur Heymansb451df22017-08-15 20:59:09 +020073 pci_write_config32(PCI_DEV(0, 0x1f, 0), GEN3_DEC, 0x00040069);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000074}
75
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000076/* This box has two superios, so enabling serial becomes slightly excessive.
77 * We disable a lot of stuff to make sure that there are no conflicts between
78 * the two. Also set up the GPIOs from the beginning. This is the "no schematic
79 * but safe anyways" method.
80 */
Antonello Dettori771d7ec2016-11-08 18:44:46 +010081static void pnp_enter_ext_func_mode(pnp_devfn_t dev)
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000082{
83 unsigned int port = dev >> 8;
84 outb(0x55, port);
85}
86
Antonello Dettori771d7ec2016-11-08 18:44:46 +010087static void pnp_exit_ext_func_mode(pnp_devfn_t dev)
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000088{
89 unsigned int port = dev >> 8;
90 outb(0xaa, port);
91}
92
Antonello Dettori771d7ec2016-11-08 18:44:46 +010093static void pnp_write_register(pnp_devfn_t dev, int reg, int val)
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000094{
95 unsigned int port = dev >> 8;
96 outb(reg, port);
97 outb(val, port+1);
98}
99
100static void early_superio_config(void)
101{
Antonello Dettori771d7ec2016-11-08 18:44:46 +0100102 pnp_devfn_t dev;
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000103
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600104 dev = PNP_DEV(0x4e, 0x00);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000105
106 pnp_enter_ext_func_mode(dev);
107 pnp_write_register(dev, 0x02, 0x0e); // UART power
108 pnp_write_register(dev, 0x1b, (0x3e8 >> 2)); // UART3 base
109 pnp_write_register(dev, 0x1c, (0x2e8 >> 2)); // UART4 base
110 pnp_write_register(dev, 0x1d, (5 << 4) | 11); // UART3,4 IRQ
111 pnp_write_register(dev, 0x1e, 1); // no 32khz clock
112 pnp_write_register(dev, 0x24, (0x3f8 >> 2)); // UART1 base
113 pnp_write_register(dev, 0x28, (4 << 4) | 0); // UART1,2 IRQ
114 pnp_write_register(dev, 0x2c, 0); // DMA0 FIR
115 pnp_write_register(dev, 0x30, (0x600 >> 4)); // Runtime Register Block Base
116
117 pnp_write_register(dev, 0x31, 0xce); // GPIO1 DIR
118 pnp_write_register(dev, 0x32, 0x00); // GPIO1 POL
119 pnp_write_register(dev, 0x33, 0x0f); // GPIO2 DIR
120 pnp_write_register(dev, 0x34, 0x00); // GPIO2 POL
121 pnp_write_register(dev, 0x35, 0xa8); // GPIO3 DIR
122 pnp_write_register(dev, 0x36, 0x00); // GPIO3 POL
123 pnp_write_register(dev, 0x37, 0xa8); // GPIO4 DIR
124 pnp_write_register(dev, 0x38, 0x00); // GPIO4 POL
125
126 pnp_write_register(dev, 0x39, 0x00); // GPIO1 OUT
127 pnp_write_register(dev, 0x40, 0x80); // GPIO2/MISC OUT
128 pnp_write_register(dev, 0x41, 0x00); // GPIO5 OUT
129 pnp_write_register(dev, 0x42, 0xa8); // GPIO5 DIR
130 pnp_write_register(dev, 0x43, 0x00); // GPIO5 POL
131 pnp_write_register(dev, 0x44, 0x00); // GPIO ALT1
132 pnp_write_register(dev, 0x45, 0x50); // GPIO ALT2
133 pnp_write_register(dev, 0x46, 0x00); // GPIO ALT3
134
135 pnp_write_register(dev, 0x48, 0x55); // GPIO ALT5
136 pnp_write_register(dev, 0x49, 0x55); // GPIO ALT6
137 pnp_write_register(dev, 0x4a, 0x55); // GPIO ALT7
138 pnp_write_register(dev, 0x4b, 0x55); // GPIO ALT8
139 pnp_write_register(dev, 0x4c, 0x55); // GPIO ALT9
140 pnp_write_register(dev, 0x4d, 0x55); // GPIO ALT10
141
142 pnp_exit_ext_func_mode(dev);
143}
144
145static void rcba_config(void)
146{
147 /* Set up virtual channel 0 */
148 //RCBA32(0x0014) = 0x80000001;
149 //RCBA32(0x001c) = 0x03128010;
150
151 /* Device 1f interrupt pin register */
Arthur Heymansb451df22017-08-15 20:59:09 +0200152 RCBA32(D31IP) = 0x00042220;
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000153 /* Device 1d interrupt pin register */
Arthur Heymansb451df22017-08-15 20:59:09 +0200154 RCBA32(D28IP) = 0x00214321;
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000155
156 /* dev irq route register */
Arthur Heymansb451df22017-08-15 20:59:09 +0200157 RCBA16(D31IR) = 0x0232;
158 RCBA16(D30IR) = 0x3246;
159 RCBA16(D29IR) = 0x0237;
160 RCBA16(D28IR) = 0x3201;
161 RCBA16(D27IR) = 0x3216;
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000162
163 /* Enable IOAPIC */
Arthur Heymansb451df22017-08-15 20:59:09 +0200164 RCBA8(OIC) = 0x03;
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000165
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000166 /* Disable unused devices */
Arthur Heymans6267f5d2018-12-15 23:46:48 +0100167 RCBA32(FD) |= FD_INTLAN;
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000168
169 /* Enable PCIe Root Port Clock Gate */
170 // RCBA32(0x341c) = 0x00000001;
171
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000172 /* This should probably go into the ACPI enable trap */
173 /* Set up I/O Trap #0 for 0xfe00 (SMIC) */
174 RCBA32(0x1e84) = 0x00020001;
175 RCBA32(0x1e80) = 0x0000fe01;
176
177 /* Set up I/O Trap #3 for 0x800-0x80c (Trap) */
178 RCBA32(0x1e9c) = 0x000200f0;
179 RCBA32(0x1e98) = 0x000c0801;
180}
181
182static void early_ich7_init(void)
183{
184 uint8_t reg8;
185 uint32_t reg32;
186
187 // program secondary mlt XXX byte?
188 pci_write_config8(PCI_DEV(0, 0x1e, 0), 0x1b, 0x20);
189
190 // reset rtc power status
191 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xa4);
192 reg8 &= ~(1 << 2);
193 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa4, reg8);
194
195 // usb transient disconnect
196 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xad);
197 reg8 |= (3 << 0);
198 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xad, reg8);
199
200 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xfc);
201 reg32 |= (1 << 29) | (1 << 17);
202 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xfc, reg32);
203
204 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xdc);
205 reg32 |= (1 << 31) | (1 << 27);
206 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xdc, reg32);
207
208 RCBA32(0x0088) = 0x0011d000;
209 RCBA16(0x01fc) = 0x060f;
210 RCBA32(0x01f4) = 0x86000040;
211 RCBA32(0x0214) = 0x10030549;
212 RCBA32(0x0218) = 0x00020504;
213 RCBA8(0x0220) = 0xc5;
214 reg32 = RCBA32(0x3410);
215 reg32 |= (1 << 6);
216 RCBA32(0x3410) = reg32;
217 reg32 = RCBA32(0x3430);
218 reg32 &= ~(3 << 0);
219 reg32 |= (1 << 0);
220 RCBA32(0x3430) = reg32;
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000221 RCBA16(0x0200) = 0x2008;
222 RCBA8(0x2027) = 0x0d;
223 RCBA16(0x3e08) |= (1 << 7);
224 RCBA16(0x3e48) |= (1 << 7);
225 RCBA32(0x3e0e) |= (1 << 7);
226 RCBA32(0x3e4e) |= (1 << 7);
227
228 // next step only on ich7m b0 and later:
229 reg32 = RCBA32(0x2034);
230 reg32 &= ~(0x0f << 16);
231 reg32 |= (5 << 16);
232 RCBA32(0x2034) = reg32;
233}
234
Kyösti Mälkki15fa9922016-06-17 10:00:28 +0300235void mainboard_romstage_entry(unsigned long bist)
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000236{
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200237 int s3resume = 0;
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000238
Uwe Hermann7b997052010-11-21 22:47:22 +0000239 if (bist == 0)
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000240 enable_lapic();
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000241
242#if 0
243 /* Force PCIRST# */
244 pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, SBR);
Stefan Reinauerbc8613e2010-08-25 18:35:42 +0000245 udelay(200 * 1000);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000246 pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, 0);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000247#endif
248
249 ich7_enable_lpc();
250 early_superio_config();
251
252 /* Set up the console */
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000253 console_init();
254
255 /* Halt if there was a built in self test failure */
256 report_bist_failure(bist);
257
258 if (MCHBAR16(SSKPD) == 0xCAFE) {
259 printk(BIOS_DEBUG, "soft reset detected, rebooting properly\n");
260 outb(0x6, 0xcf9);
Patrick Georgi546953c2014-11-29 10:38:17 +0100261 halt();
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000262 }
263
264 /* Perform some early chipset initialization required
265 * before RAM initialization can work
266 */
267 i945_early_initialization();
268
Arthur Heymans62902ca2016-11-29 14:13:43 +0100269 setup_special_ich7_gpios();
270
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200271 s3resume = southbridge_detect_s3_resume();
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000272
273 /* Enable SPD ROMs and DDR-II DRAM */
274 enable_smbus();
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700275
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000276#if CONFIG_DEFAULT_CONSOLE_LOGLEVEL > 8
277 dump_spd_registers();
278#endif
279
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200280 sdram_initialize(s3resume ? 2 : 0, NULL);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000281
282 /* Perform some initialization that must run before stage2 */
283 early_ich7_init();
284
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700285 /* This should probably go away. Until now it is required
286 * and mainboard specific
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000287 */
288 rcba_config();
289
290 /* Chipset Errata! */
291 fixup_i945_errata();
292
293 /* Initialize the internal PCIe links before we go into stage2 */
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200294 i945_late_initialization(s3resume);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000295}