blob: e72c3dcceb997ce41055f1505735aacde31f2589 [file] [log] [blame]
Stefan Reinauer36a22682008-10-29 04:52:57 +00001/*
2 * This file is part of the coreboot project.
Stefan Reinauer14e22772010-04-27 06:56:47 +00003 *
Stefan Reinauerde3206a2010-02-22 06:09:43 +00004 * Copyright (C) 2007-2010 coresystems GmbH
Stefan Reinauer36a22682008-10-29 04:52:57 +00005 *
Uwe Hermann2bb4acf2010-03-01 17:19:55 +00006 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
Stefan Reinauer36a22682008-10-29 04:52:57 +00009 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Uwe Hermann2bb4acf2010-03-01 17:19:55 +000017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Stefan Reinauer36a22682008-10-29 04:52:57 +000018 */
19
Myles Watson1d6d45e2009-11-06 17:02:51 +000020// __PRE_RAM__ means: use "unsigned" for device, not a struct.
Stefan Reinauer5e328232010-03-29 19:19:16 +000021
Stefan Reinauer36a22682008-10-29 04:52:57 +000022#include <stdint.h>
Patrick Georgi12aba822009-04-30 07:07:22 +000023#include <string.h>
Patrick Georgid0835952010-10-05 09:07:10 +000024#include <lib.h>
Kyösti Mälkki12d681b2014-06-14 18:51:34 +030025#include <arch/acpi.h>
Kyösti Mälkkia7c96112013-10-13 20:41:57 +030026#include <cbmem.h>
Stefan Reinauer36a22682008-10-29 04:52:57 +000027#include <arch/io.h>
Stefan Reinauer36a22682008-10-29 04:52:57 +000028#include <device/pci_def.h>
29#include <device/pnp_def.h>
30#include <cpu/x86/lapic.h>
Edwin Beasanteb50c7d2010-07-06 21:05:04 +000031#include <pc80/mc146818rtc.h>
Stefan Reinauer10ec0fe2010-09-25 10:40:47 +000032#include "option_table.h"
Stefan Reinauerde3206a2010-02-22 06:09:43 +000033#include <console/console.h>
Stefan Reinauer36a22682008-10-29 04:52:57 +000034#include <cpu/x86/bist.h>
Patrick Georgi546953c2014-11-29 10:38:17 +010035#include <halt.h>
Edward O'Callaghan4f5a5252014-04-03 14:40:24 +110036#include <superio/winbond/w83627thg/w83627thg.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 Georgid0835952010-10-05 09:07:10 +000040
Uwe Hermann57b2ff82010-11-21 17:29:59 +000041#define SERIAL_DEV PNP_DEV(0x2e, W83627THG_SP1)
42
Patrick Georgid0835952010-10-05 09:07:10 +000043void setup_ich7_gpios(void)
Stefan Reinauer36a22682008-10-29 04:52:57 +000044{
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000045 printk(BIOS_DEBUG, " GPIOS...");
Stefan Reinauer36a22682008-10-29 04:52:57 +000046 /* General Registers */
47 outl(0x1f1ff7c0, DEFAULT_GPIOBASE + 0x00); /* GPIO_USE_SEL */
48 outl(0xe0e8efc3, DEFAULT_GPIOBASE + 0x04); /* GP_IO_SEL */
49 outl(0xebffeeff, DEFAULT_GPIOBASE + 0x0c); /* GP_LVL */
50 /* Output Control Registers */
51 outl(0x00000000, DEFAULT_GPIOBASE + 0x18); /* GPO_BLINK */
52 /* Input Control Registers */
53 outl(0x00002180, DEFAULT_GPIOBASE + 0x2c); /* GPI_INV */
Stefan Reinauere1025d02009-03-11 15:20:36 +000054 outl(0x000100ff, DEFAULT_GPIOBASE + 0x30); /* GPIO_USE_SEL2 */
Stefan Reinauer36a22682008-10-29 04:52:57 +000055 outl(0x00000030, DEFAULT_GPIOBASE + 0x34); /* GP_IO_SEL2 */
56 outl(0x00010035, DEFAULT_GPIOBASE + 0x38); /* GP_LVL */
57}
58
Stefan Reinauer36a22682008-10-29 04:52:57 +000059static void ich7_enable_lpc(void)
60{
Patrick Georgia4700192011-01-27 07:39:38 +000061 int lpt_en = 0;
Patrick Georgib2517532011-05-10 21:53:13 +000062 if (read_option(lpt, 0) != 0) {
Patrick Georgia4700192011-01-27 07:39:38 +000063 lpt_en = 1<<2; // enable LPT
64 }
Stefan Reinauer36a22682008-10-29 04:52:57 +000065 // Enable Serial IRQ
66 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x64, 0xd0);
67 // Set COM1/COM2 decode range
68 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x80, 0x0010);
69 // Enable COM1/COM2/KBD/SuperIO1+2
Patrick Georgia4700192011-01-27 07:39:38 +000070 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x82, 0x340b | lpt_en);
Stefan Reinauer36a22682008-10-29 04:52:57 +000071 // Enable HWM at 0xa00
Stefan Reinauere1025d02009-03-11 15:20:36 +000072 pci_write_config32(PCI_DEV(0, 0x1f, 0), 0x84, 0x00fc0a01);
Stefan Reinauer36a22682008-10-29 04:52:57 +000073 // COM3 decode
74 pci_write_config32(PCI_DEV(0, 0x1f, 0), 0x88, 0x000403e9);
75 // COM4 decode
76 pci_write_config32(PCI_DEV(0, 0x1f, 0), 0x8c, 0x000402e9);
Stefan Reinauer14e22772010-04-27 06:56:47 +000077 // io 0x300 decode
Stefan Reinauer36a22682008-10-29 04:52:57 +000078 pci_write_config32(PCI_DEV(0, 0x1f, 0), 0x90, 0x00000301);
79}
80
Edward O'Callaghan2c55b702014-05-13 23:29:22 +100081/* TODO: superio code should really not be in mainboard */
82static void pnp_enter_func_mode(device_t dev)
83{
84 u16 port = dev >> 8;
85 outb(0x87, port);
86 outb(0x87, port);
87}
88
89static void pnp_exit_func_mode(device_t dev)
90{
91 u16 port = dev >> 8;
92 outb(0xaa, port);
93}
94
Stefan Reinauer36a22682008-10-29 04:52:57 +000095/* This box has two superios, so enabling serial becomes slightly excessive.
96 * We disable a lot of stuff to make sure that there are no conflicts between
97 * the two. Also set up the GPIOs from the beginning. This is the "no schematic
98 * but safe anyways" method.
99 */
100static void early_superio_config_w83627thg(void)
101{
102 device_t dev;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000103
Stefan Reinauer36a22682008-10-29 04:52:57 +0000104 dev=PNP_DEV(0x2e, W83627THG_SP1);
Edward O'Callaghan2c55b702014-05-13 23:29:22 +1000105 pnp_enter_func_mode(dev);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000106
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000107 pnp_write_config(dev, 0x24, 0xc6); // PNPCSV
108
109 pnp_write_config(dev, 0x29, 0x43); // GPIO settings
110 pnp_write_config(dev, 0x2a, 0x40); // GPIO settings
111
112 dev=PNP_DEV(0x2e, W83627THG_SP1);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000113 pnp_set_logical_device(dev);
114 pnp_set_enable(dev, 0);
115 pnp_set_iobase(dev, PNP_IDX_IO0, 0x3f8);
116 pnp_set_irq(dev, PNP_IDX_IRQ0, 4);
117 pnp_set_enable(dev, 1);
118
119 dev=PNP_DEV(0x2e, W83627THG_SP2);
120 pnp_set_logical_device(dev);
121 pnp_set_enable(dev, 0);
122 pnp_set_iobase(dev, PNP_IDX_IO0, 0x2f8);
123 pnp_set_irq(dev, PNP_IDX_IRQ0, 3);
124 // pnp_write_config(dev, 0xf1, 4); // IRMODE0
125 pnp_set_enable(dev, 1);
126
127 dev=PNP_DEV(0x2e, W83627THG_KBC);
128 pnp_set_logical_device(dev);
129 pnp_set_enable(dev, 0);
130 pnp_set_iobase(dev, PNP_IDX_IO0, 0x60);
131 pnp_set_iobase(dev, PNP_IDX_IO1, 0x64);
132 // pnp_write_config(dev, 0xf0, 0x82);
133 pnp_set_enable(dev, 1);
134
135 dev=PNP_DEV(0x2e, W83627THG_GAME_MIDI_GPIO1);
136 pnp_set_logical_device(dev);
137 pnp_set_enable(dev, 0);
138 pnp_write_config(dev, 0xf5, 0xff); // invert all GPIOs
139 pnp_set_enable(dev, 1);
140
141 dev=PNP_DEV(0x2e, W83627THG_GPIO2);
142 pnp_set_logical_device(dev);
143 pnp_set_enable(dev, 1); // Just enable it
144
145 dev=PNP_DEV(0x2e, W83627THG_GPIO3);
146 pnp_set_logical_device(dev);
147 pnp_set_enable(dev, 0);
148 pnp_write_config(dev, 0xf0, 0xfb); // GPIO bit 2 is output
149 pnp_write_config(dev, 0xf1, 0x00); // GPIO bit 2 is 0
150 pnp_write_config(dev, 0x30, 0x03); // Enable GPIO3+4. pnp_set_enable is not sufficient
151
152 dev=PNP_DEV(0x2e, W83627THG_FDC);
153 pnp_set_logical_device(dev);
154 pnp_set_enable(dev, 0);
155
156 dev=PNP_DEV(0x2e, W83627THG_PP);
157 pnp_set_logical_device(dev);
158 pnp_set_enable(dev, 0);
159
Stefan Reinauer54309d62009-01-20 22:53:10 +0000160 /* Enable HWM */
161 dev=PNP_DEV(0x2e, W83627THG_HWM);
162 pnp_set_logical_device(dev);
163 pnp_set_enable(dev, 0);
164 pnp_set_iobase(dev, PNP_IDX_IO0, 0xa00);
165 pnp_set_enable(dev, 1);
166
Edward O'Callaghan2c55b702014-05-13 23:29:22 +1000167 pnp_exit_func_mode(dev);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000168
169 dev=PNP_DEV(0x4e, W83627THG_SP1);
Edward O'Callaghan2c55b702014-05-13 23:29:22 +1000170 pnp_enter_func_mode(dev);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000171
172 pnp_set_logical_device(dev); // Set COM3 to sane non-conflicting values
173 pnp_set_enable(dev, 0);
174 pnp_set_iobase(dev, PNP_IDX_IO0, 0x3e8);
175 pnp_set_irq(dev, PNP_IDX_IRQ0, 11);
176 pnp_set_enable(dev, 1);
177
Stefan Reinauer14e22772010-04-27 06:56:47 +0000178 dev=PNP_DEV(0x4e, W83627THG_SP2);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000179 pnp_set_logical_device(dev); // Set COM4 to sane non-conflicting values
180 pnp_set_enable(dev, 0);
181 pnp_set_iobase(dev, PNP_IDX_IO0, 0x2e8);
182 pnp_set_irq(dev, PNP_IDX_IRQ0, 10);
183 pnp_set_enable(dev, 1);
184
185 dev=PNP_DEV(0x4e, W83627THG_FDC);
186 pnp_set_logical_device(dev);
187 pnp_set_enable(dev, 0);
188
189 dev=PNP_DEV(0x4e, W83627THG_PP);
190 pnp_set_logical_device(dev);
191 pnp_set_enable(dev, 0);
192
193 dev=PNP_DEV(0x4e, W83627THG_KBC);
194 pnp_set_logical_device(dev);
195 pnp_set_enable(dev, 0);
196 pnp_set_iobase(dev, PNP_IDX_IO0, 0x00);
197 pnp_set_iobase(dev, PNP_IDX_IO1, 0x00);
198
Edward O'Callaghan2c55b702014-05-13 23:29:22 +1000199 pnp_exit_func_mode(dev);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000200}
201
202static void rcba_config(void)
203{
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000204 u32 reg32;
205
Stefan Reinauer36a22682008-10-29 04:52:57 +0000206 /* Set up virtual channel 0 */
207 //RCBA32(0x0014) = 0x80000001;
208 //RCBA32(0x001c) = 0x03128010;
209
210 /* Device 1f interrupt pin register */
211 RCBA32(0x3100) = 0x00042210;
212 /* Device 1d interrupt pin register */
213 RCBA32(0x310c) = 0x00214321;
214
215 /* dev irq route register */
216 RCBA16(0x3140) = 0x0132;
217 RCBA16(0x3142) = 0x3241;
218 RCBA16(0x3144) = 0x0237;
219 RCBA16(0x3146) = 0x3210;
220 RCBA16(0x3148) = 0x3210;
221
222 /* Enable IOAPIC */
223 RCBA8(0x31ff) = 0x03;
224
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000225 /* Now, this is a bit ugly. As per PCI specification, function 0 of a
226 * device always has to be implemented. So disabling ethernet port 1
227 * would essentially disable all three ethernet ports of the mainboard.
228 * It's possible to rename the ports to achieve compatibility to the
229 * PCI spec but this will confuse all (static!) tables containing
Stefan Reinauer14e22772010-04-27 06:56:47 +0000230 * interrupt routing information.
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000231 * To avoid this, we enable (unused) port 6 and swap it with port 1
232 * in the case that ethernet port 1 is disabled. Since no devices
233 * are connected to that port, we don't have to worry about interrupt
234 * routing.
235 */
236 int port_shuffle = 0;
237
Stefan Reinauer36a22682008-10-29 04:52:57 +0000238 /* Disable unused devices */
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000239 reg32 = FD_ACMOD|FD_ACAUD|FD_PATA;
240 reg32 |= FD_PCIE6|FD_PCIE5|FD_PCIE4;
241
Patrick Georgib2517532011-05-10 21:53:13 +0000242 if (read_option(ethernet1, 0) != 0) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000243 printk(BIOS_DEBUG, "Disabling ethernet adapter 1.\n");
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000244 reg32 |= FD_PCIE1;
245 }
Patrick Georgib2517532011-05-10 21:53:13 +0000246 if (read_option(ethernet2, 0) != 0) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000247 printk(BIOS_DEBUG, "Disabling ethernet adapter 2.\n");
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000248 reg32 |= FD_PCIE2;
249 } else {
250 if (reg32 & FD_PCIE1)
251 port_shuffle = 1;
252 }
Patrick Georgib2517532011-05-10 21:53:13 +0000253 if (read_option(ethernet3, 0) != 0) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000254 printk(BIOS_DEBUG, "Disabling ethernet adapter 3.\n");
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000255 reg32 |= FD_PCIE3;
256 } else {
257 if (reg32 & FD_PCIE1)
258 port_shuffle = 1;
259 }
260
261 if (port_shuffle) {
262 /* Enable PCIE6 again */
263 reg32 &= ~FD_PCIE6;
264 /* Swap PCIE6 and PCIE1 */
265 RCBA32(RPFN) = 0x00043215;
266 }
267
268 reg32 |= 1;
269
270 RCBA32(0x3418) = reg32;
Stefan Reinauer36a22682008-10-29 04:52:57 +0000271
272 /* Enable PCIe Root Port Clock Gate */
273 // RCBA32(0x341c) = 0x00000001;
274}
275
276static void early_ich7_init(void)
277{
278 uint8_t reg8;
279 uint32_t reg32;
280
281 // program secondary mlt XXX byte?
282 pci_write_config8(PCI_DEV(0, 0x1e, 0), 0x1b, 0x20);
283
284 // reset rtc power status
285 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xa4);
286 reg8 &= ~(1 << 2);
287 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa4, reg8);
288
289 // usb transient disconnect
290 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xad);
291 reg8 |= (3 << 0);
292 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xad, reg8);
293
294 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xfc);
295 reg32 |= (1 << 29) | (1 << 17);
296 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xfc, reg32);
297
298 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xdc);
299 reg32 |= (1 << 31) | (1 << 27);
300 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xdc, reg32);
301
302 RCBA32(0x0088) = 0x0011d000;
303 RCBA16(0x01fc) = 0x060f;
304 RCBA32(0x01f4) = 0x86000040;
305 RCBA32(0x0214) = 0x10030549;
306 RCBA32(0x0218) = 0x00020504;
307 RCBA8(0x0220) = 0xc5;
308 reg32 = RCBA32(0x3410);
309 reg32 |= (1 << 6);
310 RCBA32(0x3410) = reg32;
311 reg32 = RCBA32(0x3430);
312 reg32 &= ~(3 << 0);
313 reg32 |= (1 << 0);
314 RCBA32(0x3430) = reg32;
315 RCBA32(0x3418) |= (1 << 0);
316 RCBA16(0x0200) = 0x2008;
317 RCBA8(0x2027) = 0x0d;
318 RCBA16(0x3e08) |= (1 << 7);
319 RCBA16(0x3e48) |= (1 << 7);
320 RCBA32(0x3e0e) |= (1 << 7);
321 RCBA32(0x3e4e) |= (1 << 7);
322
323 // next step only on ich7m b0 and later:
324 reg32 = RCBA32(0x2034);
325 reg32 &= ~(0x0f << 16);
326 reg32 |= (5 << 16);
327 RCBA32(0x2034) = reg32;
328}
329
Aaron Durbina0a37272014-08-14 08:35:11 -0500330#include <cpu/intel/romstage.h>
Stefan Reinauer3e1f5242010-04-12 23:04:29 +0000331void main(unsigned long bist)
Stefan Reinauer36a22682008-10-29 04:52:57 +0000332{
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200333 int s3resume = 0;
Stefan Reinauer36a22682008-10-29 04:52:57 +0000334
Uwe Hermann7b997052010-11-21 22:47:22 +0000335 if (bist == 0)
Stefan Reinauer36a22682008-10-29 04:52:57 +0000336 enable_lapic();
Stefan Reinauer36a22682008-10-29 04:52:57 +0000337
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000338 /* Force PCIRST# */
339 pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, SBR);
Stefan Reinauerbc8613e2010-08-25 18:35:42 +0000340 udelay(200 * 1000);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000341 pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, 0);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000342
Stefan Reinauerbc8613e2010-08-25 18:35:42 +0000343 ich7_enable_lpc();
Stefan Reinauer36a22682008-10-29 04:52:57 +0000344 early_superio_config_w83627thg();
345
346 /* Set up the console */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000347 console_init();
348
349 /* Halt if there was a built in self test failure */
350 report_bist_failure(bist);
351
352 if (MCHBAR16(SSKPD) == 0xCAFE) {
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000353 printk(BIOS_DEBUG, "soft reset detected, rebooting properly\n");
354 outb(0x6, 0xcf9);
Patrick Georgi546953c2014-11-29 10:38:17 +0100355 halt();
Stefan Reinauer36a22682008-10-29 04:52:57 +0000356 }
357
358 /* Perform some early chipset initialization required
359 * before RAM initialization can work
360 */
361 i945_early_initialization();
362
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200363 s3resume = southbridge_detect_s3_resume();
Stefan Reinauera5fdadf2009-07-21 21:58:20 +0000364
Stefan Reinauer36a22682008-10-29 04:52:57 +0000365 /* Enable SPD ROMs and DDR-II DRAM */
366 enable_smbus();
Stefan Reinauer14e22772010-04-27 06:56:47 +0000367
Stefan Reinauer08670622009-06-30 15:17:49 +0000368#if CONFIG_DEFAULT_CONSOLE_LOGLEVEL > 8
Stefan Reinauer36a22682008-10-29 04:52:57 +0000369 dump_spd_registers();
370#endif
371
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200372 sdram_initialize(s3resume ? 2 : 0, NULL);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000373
374 /* Perform some initialization that must run before stage2 */
375 early_ich7_init();
376
Stefan Reinauer14e22772010-04-27 06:56:47 +0000377 /* This should probably go away. Until now it is required
378 * and mainboard specific
Stefan Reinauer36a22682008-10-29 04:52:57 +0000379 */
380 rcba_config();
381
382 /* Chipset Errata! */
383 fixup_i945_errata();
384
385 /* Initialize the internal PCIe links before we go into stage2 */
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200386 i945_late_initialization(s3resume);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000387}