blob: a7fd007a3ee5a8d859538e85fcfaa6d215b85d0f [file] [log] [blame]
Stefan Reinauer838c5a52010-01-17 14:08:17 +00001/*
2 * This file is part of the coreboot project.
Stefan Reinauer14e22772010-04-27 06:56:47 +00003 *
Stefan Reinauer838c5a52010-01-17 14:08:17 +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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 * MA 02110-1301 USA
20 */
21
22// __PRE_RAM__ means: use "unsigned" for device, not a struct.
Stefan Reinauer5e328232010-03-29 19:19:16 +000023
Stefan Reinauer838c5a52010-01-17 14:08:17 +000024#include <stdint.h>
25#include <string.h>
26#include <arch/io.h>
Stefan Reinauer838c5a52010-01-17 14:08:17 +000027#include <device/pci_def.h>
28#include <device/pnp_def.h>
29#include <cpu/x86/lapic.h>
Patrick Georgid0835952010-10-05 09:07:10 +000030#include <lib.h>
Kyösti Mälkki12d681b2014-06-14 18:51:34 +030031#include <arch/acpi.h>
Kyösti Mälkkia7c96112013-10-13 20:41:57 +030032#include <cbmem.h>
Edwin Beasanteb50c7d2010-07-06 21:05:04 +000033#include <pc80/mc146818rtc.h>
Stefan Reinauer8a7d34b2010-02-22 09:15:13 +000034#include <console/console.h>
Stefan Reinauer838c5a52010-01-17 14:08:17 +000035#include <cpu/x86/bist.h>
Patrick Georgi546953c2014-11-29 10:38:17 +010036#include <halt.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110037#include <northbridge/intel/i945/i945.h>
38#include <northbridge/intel/i945/raminit.h>
39#include <southbridge/intel/i82801gx/i82801gx.h>
Patrick Georgia4700192011-01-27 07:39:38 +000040#include "option_table.h"
Patrick Georgid0835952010-10-05 09:07:10 +000041
Patrick Georgid0835952010-10-05 09:07:10 +000042void setup_ich7_gpios(void)
Stefan Reinauer838c5a52010-01-17 14:08:17 +000043{
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000044 printk(BIOS_DEBUG, " GPIOS...");
Stefan Reinauer838c5a52010-01-17 14:08:17 +000045 /* General Registers */
46 outl(0xbfc0f7c0, DEFAULT_GPIOBASE + 0x00); /* GPIO_USE_SEL */
47 outl(0x70a87d83, DEFAULT_GPIOBASE + 0x04); /* GP_IO_SEL */
Patrick Georgief329652011-01-14 07:41:42 +000048 // ------------------------------------------------------------
49 // 0 - GPO6 - Enable power of SATA channel 0
50 // 0 - GPO9 - Wireless LAN power on
51 // 0 - GPO15 - FAN on
52 // 1 - GPO22 - FWH WP
53 // 1 - GPO24 - GPS on
54 // 0 - GPO25 - External Antenna Mux on
55 // 0 - GPO26 - BT on
56 // 0 - GPO27 - GSM on
57 outl(0x01400000, DEFAULT_GPIOBASE + 0x0c); /* GP_LVL */
58 // ------------------------------------------------------------
Stefan Reinauer838c5a52010-01-17 14:08:17 +000059 /* Output Control Registers */
60 outl(0x00000000, DEFAULT_GPIOBASE + 0x18); /* GPO_BLINK */
61 /* Input Control Registers */
62 outl(0x00002180, DEFAULT_GPIOBASE + 0x2c); /* GPI_INV */
63 outl(0x000100e8, DEFAULT_GPIOBASE + 0x30); /* GPIO_USE_SEL2 */
64 outl(0x00000030, DEFAULT_GPIOBASE + 0x34); /* GP_IO_SEL2 */
Patrick Georgief329652011-01-14 07:41:42 +000065 // ------------------------------------------------------------
66 // 1 - GPO48 - FWH TBL#
67 outl(0x00010000, DEFAULT_GPIOBASE + 0x38); /* GP_LVL */
68 // ------------------------------------------------------------
Stefan Reinauer838c5a52010-01-17 14:08:17 +000069}
70
Stefan Reinauer838c5a52010-01-17 14:08:17 +000071static void ich7_enable_lpc(void)
72{
Patrick Georgia4700192011-01-27 07:39:38 +000073 int lpt_en = 0;
Patrick Georgib2517532011-05-10 21:53:13 +000074 if (read_option(lpt, 0) != 0) {
Patrick Georgia4700192011-01-27 07:39:38 +000075 lpt_en = 1<<2; // enable LPT
76 }
Stefan Reinauer838c5a52010-01-17 14:08:17 +000077 // Enable Serial IRQ
78 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x64, 0xd0);
79 // decode range
80 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x80, 0x0007);
81 // decode range
Patrick Georgia4700192011-01-27 07:39:38 +000082 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x82, 0x3f0b | lpt_en);
Stefan Reinauer838c5a52010-01-17 14:08:17 +000083 // Enable 0x02e0
84 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x84, 0x02e1);
85 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x86, 0x001c);
86 // COM3 decode
87 pci_write_config32(PCI_DEV(0, 0x1f, 0), 0x88, 0x00fc0601);
88 // COM4 decode
89 pci_write_config32(PCI_DEV(0, 0x1f, 0), 0x8c, 0x00040069);
90}
91
Stefan Reinauer838c5a52010-01-17 14:08:17 +000092/* This box has two superios, so enabling serial becomes slightly excessive.
93 * We disable a lot of stuff to make sure that there are no conflicts between
94 * the two. Also set up the GPIOs from the beginning. This is the "no schematic
95 * but safe anyways" method.
96 */
97static inline void pnp_enter_ext_func_mode(device_t dev)
98{
99 unsigned int port = dev >> 8;
100 outb(0x55, port);
101}
102
103static void pnp_exit_ext_func_mode(device_t dev)
104{
105 unsigned int port = dev >> 8;
106 outb(0xaa, port);
107}
108
109static void pnp_write_register(device_t dev, int reg, int val)
110{
111 unsigned int port = dev >> 8;
112 outb(reg, port);
113 outb(val, port+1);
114}
115
116static void early_superio_config(void)
117{
118 device_t dev;
119
120 dev=PNP_DEV(0x2e, 0x00);
121
122 pnp_enter_ext_func_mode(dev);
123 pnp_write_register(dev, 0x01, 0x94); // Extended Parport modes
124 pnp_write_register(dev, 0x02, 0x88); // UART power on
125 pnp_write_register(dev, 0x03, 0x72); // Floppy
126 pnp_write_register(dev, 0x04, 0x01); // EPP + SPP
127 pnp_write_register(dev, 0x14, 0x03); // Floppy
128 pnp_write_register(dev, 0x20, (0x3f0 >> 2)); // Floppy
129 pnp_write_register(dev, 0x23, (0x378 >> 2)); // PP base
130 pnp_write_register(dev, 0x24, (0x3f8 >> 2)); // UART1 base
131 pnp_write_register(dev, 0x25, (0x2f8 >> 2)); // UART2 base
132 pnp_write_register(dev, 0x26, (2 << 4) | 0); // FDC + PP DMA
133 pnp_write_register(dev, 0x27, (6 << 4) | 7); // FDC + PP DMA
134 pnp_write_register(dev, 0x28, (4 << 4) | 3); // UART1,2 IRQ
135 /* These are the SMI status registers in the SIO: */
136 pnp_write_register(dev, 0x30, (0x600 >> 4)); // Runtime Register Block Base
137
138 pnp_write_register(dev, 0x31, 0x00); // GPIO1 DIR
139 pnp_write_register(dev, 0x32, 0x00); // GPIO1 POL
140 pnp_write_register(dev, 0x33, 0x40); // GPIO2 DIR
141 pnp_write_register(dev, 0x34, 0x00); // GPIO2 POL
142 pnp_write_register(dev, 0x35, 0xff); // GPIO3 DIR
143 pnp_write_register(dev, 0x36, 0x00); // GPIO3 POL
144 pnp_write_register(dev, 0x37, 0xe0); // GPIO4 DIR
145 pnp_write_register(dev, 0x38, 0x00); // GPIO4 POL
146 pnp_write_register(dev, 0x39, 0x80); // GPIO4 POL
147
148 pnp_exit_ext_func_mode(dev);
149}
150
151static void rcba_config(void)
152{
153 /* Set up virtual channel 0 */
154 //RCBA32(0x0014) = 0x80000001;
155 //RCBA32(0x001c) = 0x03128010;
156
157 /* Device 1f interrupt pin register */
158 RCBA32(0x3100) = 0x00042220;
159 /* Device 1d interrupt pin register */
160 RCBA32(0x310c) = 0x00214321;
161
162 /* dev irq route register */
163 RCBA16(0x3140) = 0x0232;
164 RCBA16(0x3142) = 0x3246;
165 RCBA16(0x3144) = 0x0237;
166 RCBA16(0x3146) = 0x3201;
167 RCBA16(0x3148) = 0x3216;
168
169 /* Enable IOAPIC */
170 RCBA8(0x31ff) = 0x03;
171
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000172 /* Disable unused devices */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000173 RCBA32(0x3418) = FD_PCIE6 | FD_PCIE5 | FD_PCIE3 | FD_PCIE2 |
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000174 FD_INTLAN | FD_ACMOD | FD_HDAUD | FD_PATA;
175 RCBA32(0x3418) |= (1 << 0); // Required.
176
177 /* Enable PCIe Root Port Clock Gate */
178 // RCBA32(0x341c) = 0x00000001;
179
180 /* This should probably go into the ACPI OS Init trap */
181
182 /* Set up I/O Trap #0 for 0xfe00 (SMIC) */
183 RCBA32(0x1e84) = 0x00020001;
184 RCBA32(0x1e80) = 0x0000fe01;
185
186 /* Set up I/O Trap #3 for 0x800-0x80c (Trap) */
187 RCBA32(0x1e9c) = 0x000200f0;
188 RCBA32(0x1e98) = 0x000c0801;
189}
190
191static void early_ich7_init(void)
192{
193 uint8_t reg8;
194 uint32_t reg32;
195
196 // program secondary mlt XXX byte?
197 pci_write_config8(PCI_DEV(0, 0x1e, 0), 0x1b, 0x20);
198
199 // reset rtc power status
200 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xa4);
201 reg8 &= ~(1 << 2);
202 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa4, reg8);
203
204 // usb transient disconnect
205 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xad);
206 reg8 |= (3 << 0);
207 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xad, reg8);
208
209 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xfc);
210 reg32 |= (1 << 29) | (1 << 17);
211 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xfc, reg32);
212
213 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xdc);
214 reg32 |= (1 << 31) | (1 << 27);
215 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xdc, reg32);
216
217 RCBA32(0x0088) = 0x0011d000;
218 RCBA16(0x01fc) = 0x060f;
219 RCBA32(0x01f4) = 0x86000040;
220 RCBA32(0x0214) = 0x10030549;
221 RCBA32(0x0218) = 0x00020504;
222 RCBA8(0x0220) = 0xc5;
223 reg32 = RCBA32(0x3410);
224 reg32 |= (1 << 6);
225 RCBA32(0x3410) = reg32;
226 reg32 = RCBA32(0x3430);
227 reg32 &= ~(3 << 0);
228 reg32 |= (1 << 0);
229 RCBA32(0x3430) = reg32;
230 RCBA32(0x3418) |= (1 << 0);
231 RCBA16(0x0200) = 0x2008;
232 RCBA8(0x2027) = 0x0d;
233 RCBA16(0x3e08) |= (1 << 7);
234 RCBA16(0x3e48) |= (1 << 7);
235 RCBA32(0x3e0e) |= (1 << 7);
236 RCBA32(0x3e4e) |= (1 << 7);
237
238 // next step only on ich7m b0 and later:
239 reg32 = RCBA32(0x2034);
240 reg32 &= ~(0x0f << 16);
241 reg32 |= (5 << 16);
242 RCBA32(0x2034) = reg32;
243}
244
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000245static void init_artec_dongle(void)
246{
247 // Enable 4MB decoding
248 outb(0xf1, 0x88);
249 outb(0xf4, 0x88);
250}
251
Aaron Durbina0a37272014-08-14 08:35:11 -0500252#include <cpu/intel/romstage.h>
Stefan Reinauer3e1f5242010-04-12 23:04:29 +0000253void main(unsigned long bist)
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000254{
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200255 int s3resume = 0;
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000256
Uwe Hermann7b997052010-11-21 22:47:22 +0000257 if (bist == 0)
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000258 enable_lapic();
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000259
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000260 /* Force PCIRST# */
261 pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, SBR);
Stefan Reinauerbc8613e2010-08-25 18:35:42 +0000262 udelay(200 * 1000);
263 pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, 0);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000264
Stefan Reinauerbc8613e2010-08-25 18:35:42 +0000265 ich7_enable_lpc();
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000266 early_superio_config();
267
268 /* Set up the console */
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000269 console_init();
270
271 /* Halt if there was a built in self test failure */
272 report_bist_failure(bist);
273
274 if (MCHBAR16(SSKPD) == 0xCAFE) {
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000275 printk(BIOS_DEBUG, "soft reset detected, rebooting properly\n");
276 outb(0x6, 0xcf9);
Patrick Georgi546953c2014-11-29 10:38:17 +0100277 halt();
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000278 }
279
280 /* Perform some early chipset initialization required
281 * before RAM initialization can work
282 */
283 i945_early_initialization();
284
285 /* This has to happen after i945_early_initialization() */
286 init_artec_dongle();
287
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200288 s3resume = southbridge_detect_s3_resume();
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000289
290 /* Enable SPD ROMs and DDR-II DRAM */
291 enable_smbus();
Stefan Reinauer14e22772010-04-27 06:56:47 +0000292
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000293#if CONFIG_DEFAULT_CONSOLE_LOGLEVEL > 8
294 dump_spd_registers();
295#endif
296
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200297 sdram_initialize(s3resume ? 2 : 0, NULL);
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000298
299 /* Perform some initialization that must run before stage2 */
300 early_ich7_init();
301
Stefan Reinauer14e22772010-04-27 06:56:47 +0000302 /* This should probably go away. Until now it is required
303 * and mainboard specific
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000304 */
305 rcba_config();
306
307 /* Chipset Errata! */
308 fixup_i945_errata();
309
310 /* Initialize the internal PCIe links before we go into stage2 */
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200311 i945_late_initialization(s3resume);
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000312}