blob: 0777412a0fecfab0a0293b60f6e18085a5732e19 [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.
Stefan Reinauer36a22682008-10-29 04:52:57 +000014 */
15
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020016/* __PRE_RAM__ means: use "unsigned" for device, not a struct. */
Stefan Reinauer5e328232010-03-29 19:19:16 +000017
Stefan Reinauer36a22682008-10-29 04:52:57 +000018#include <stdint.h>
Elyes HAOUAS5d4cf362018-08-06 09:58:28 +020019#include <halt.h>
Elyes HAOUAS5d4cf362018-08-06 09:58:28 +020020#include <console/console.h>
21#include <cpu/intel/romstage.h>
22#include <cpu/x86/bist.h>
23#include <cpu/x86/lapic.h>
Stefan Reinauer36a22682008-10-29 04:52:57 +000024#include <device/pci_def.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020025#include <device/pci_ops.h>
Stefan Reinauer36a22682008-10-29 04:52:57 +000026#include <device/pnp_def.h>
Edwin Beasanteb50c7d2010-07-06 21:05:04 +000027#include <pc80/mc146818rtc.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110028#include <northbridge/intel/i945/i945.h>
29#include <northbridge/intel/i945/raminit.h>
30#include <southbridge/intel/i82801gx/i82801gx.h>
Elyes HAOUAS5d4cf362018-08-06 09:58:28 +020031#include <superio/winbond/common/winbond.h>
32#include <superio/winbond/w83627thg/w83627thg.h>
33
34#include "option_table.h"
Patrick Georgid0835952010-10-05 09:07:10 +000035
Uwe Hermann57b2ff82010-11-21 17:29:59 +000036#define SERIAL_DEV PNP_DEV(0x2e, W83627THG_SP1)
37
Stefan Reinauer36a22682008-10-29 04:52:57 +000038static void ich7_enable_lpc(void)
39{
Patrick Georgia4700192011-01-27 07:39:38 +000040 int lpt_en = 0;
Arthur Heymansb451df22017-08-15 20:59:09 +020041 if (read_option(lpt, 0) != 0)
42 lpt_en = LPT_LPC_EN; /* enable LPT */
43
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020044 /* Enable Serial IRQ */
Arthur Heymansb451df22017-08-15 20:59:09 +020045 pci_write_config8(PCI_DEV(0, 0x1f, 0), SERIRQ_CNTL, 0xd0);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020046 /* Set COM1/COM2 decode range */
Arthur Heymansb451df22017-08-15 20:59:09 +020047 pci_write_config16(PCI_DEV(0, 0x1f, 0), LPC_IO_DEC, 0x0010);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020048 /* Enable COM1/COM2/KBD/SuperIO1+2 */
Arthur Heymansb451df22017-08-15 20:59:09 +020049 pci_write_config16(PCI_DEV(0, 0x1f, 0), LPC_EN, CNF2_LPC_EN
50 | CNF1_LPC_EN | KBC_LPC_EN | FDD_LPC_EN | COMA_LPC_EN
51 | COMB_LPC_EN | lpt_en);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020052 /* Enable HWM at 0xa00 */
Arthur Heymansb451df22017-08-15 20:59:09 +020053 pci_write_config32(PCI_DEV(0, 0x1f, 0), GEN1_DEC, 0x00fc0a01);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020054 /* COM3 decode */
Arthur Heymansb451df22017-08-15 20:59:09 +020055 pci_write_config32(PCI_DEV(0, 0x1f, 0), GEN2_DEC, 0x000403e9);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020056 /* COM4 decode */
Arthur Heymansb451df22017-08-15 20:59:09 +020057 pci_write_config32(PCI_DEV(0, 0x1f, 0), GEN3_DEC, 0x000402e9);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020058 /* io 0x300 decode */
Arthur Heymansb451df22017-08-15 20:59:09 +020059 pci_write_config32(PCI_DEV(0, 0x1f, 0), GEN4_DEC, 0x00000301);
Stefan Reinauer36a22682008-10-29 04:52:57 +000060}
61
Stefan Reinauer36a22682008-10-29 04:52:57 +000062/* This box has two superios, so enabling serial becomes slightly excessive.
63 * We disable a lot of stuff to make sure that there are no conflicts between
64 * the two. Also set up the GPIOs from the beginning. This is the "no schematic
65 * but safe anyways" method.
66 */
67static void early_superio_config_w83627thg(void)
68{
Antonello Dettori9ec11232016-11-08 18:44:46 +010069 pnp_devfn_t dev;
Stefan Reinauer14e22772010-04-27 06:56:47 +000070
Elyes HAOUAS531b87a2016-09-19 09:46:33 -060071 dev = PNP_DEV(0x2e, W83627THG_SP1);
Elyes HAOUAS5d4cf362018-08-06 09:58:28 +020072 pnp_enter_conf_state(dev);
Stefan Reinauer36a22682008-10-29 04:52:57 +000073
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020074 pnp_write_config(dev, 0x24, 0xc6); /* PNPCSV */
Stefan Reinaueraca6ec62009-10-26 17:12:21 +000075
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020076 pnp_write_config(dev, 0x29, 0x43); /* GPIO settings */
77 pnp_write_config(dev, 0x2a, 0x40); /* GPIO settings */
Stefan Reinaueraca6ec62009-10-26 17:12:21 +000078
Elyes HAOUAS531b87a2016-09-19 09:46:33 -060079 dev = PNP_DEV(0x2e, W83627THG_SP1);
Stefan Reinauer36a22682008-10-29 04:52:57 +000080 pnp_set_logical_device(dev);
81 pnp_set_enable(dev, 0);
82 pnp_set_iobase(dev, PNP_IDX_IO0, 0x3f8);
83 pnp_set_irq(dev, PNP_IDX_IRQ0, 4);
84 pnp_set_enable(dev, 1);
85
Elyes HAOUAS531b87a2016-09-19 09:46:33 -060086 dev = PNP_DEV(0x2e, W83627THG_SP2);
Stefan Reinauer36a22682008-10-29 04:52:57 +000087 pnp_set_logical_device(dev);
88 pnp_set_enable(dev, 0);
89 pnp_set_iobase(dev, PNP_IDX_IO0, 0x2f8);
90 pnp_set_irq(dev, PNP_IDX_IRQ0, 3);
Stefan Reinauer36a22682008-10-29 04:52:57 +000091 pnp_set_enable(dev, 1);
92
Elyes HAOUAS531b87a2016-09-19 09:46:33 -060093 dev = PNP_DEV(0x2e, W83627THG_KBC);
Stefan Reinauer36a22682008-10-29 04:52:57 +000094 pnp_set_logical_device(dev);
95 pnp_set_enable(dev, 0);
96 pnp_set_iobase(dev, PNP_IDX_IO0, 0x60);
97 pnp_set_iobase(dev, PNP_IDX_IO1, 0x64);
Stefan Reinauer36a22682008-10-29 04:52:57 +000098 pnp_set_enable(dev, 1);
99
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600100 dev = PNP_DEV(0x2e, W83627THG_GAME_MIDI_GPIO1);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000101 pnp_set_logical_device(dev);
102 pnp_set_enable(dev, 0);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200103 pnp_write_config(dev, 0xf5, 0xff); /* invert all GPIOs */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000104 pnp_set_enable(dev, 1);
105
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600106 dev = PNP_DEV(0x2e, W83627THG_GPIO2);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000107 pnp_set_logical_device(dev);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200108 pnp_set_enable(dev, 1); /* Just enable it */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000109
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600110 dev = PNP_DEV(0x2e, W83627THG_GPIO3);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000111 pnp_set_logical_device(dev);
112 pnp_set_enable(dev, 0);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200113 pnp_write_config(dev, 0xf0, 0xfb); /* GPIO bit 2 is output */
114 pnp_write_config(dev, 0xf1, 0x00); /* GPIO bit 2 is 0 */
115 pnp_write_config(dev, 0x30, 0x03); /* Enable GPIO3+4. pnp_set_enable is not sufficient */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000116
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600117 dev = PNP_DEV(0x2e, W83627THG_FDC);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000118 pnp_set_logical_device(dev);
119 pnp_set_enable(dev, 0);
120
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600121 dev = PNP_DEV(0x2e, W83627THG_PP);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000122 pnp_set_logical_device(dev);
123 pnp_set_enable(dev, 0);
124
Stefan Reinauer54309d62009-01-20 22:53:10 +0000125 /* Enable HWM */
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600126 dev = PNP_DEV(0x2e, W83627THG_HWM);
Stefan Reinauer54309d62009-01-20 22:53:10 +0000127 pnp_set_logical_device(dev);
128 pnp_set_enable(dev, 0);
129 pnp_set_iobase(dev, PNP_IDX_IO0, 0xa00);
130 pnp_set_enable(dev, 1);
131
Elyes HAOUAS5d4cf362018-08-06 09:58:28 +0200132 pnp_exit_conf_state(dev);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000133
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600134 dev = PNP_DEV(0x4e, W83627THG_SP1);
Elyes HAOUAS5d4cf362018-08-06 09:58:28 +0200135 pnp_enter_conf_state(dev);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000136
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200137 pnp_set_logical_device(dev); /* Set COM3 to sane non-conflicting values */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000138 pnp_set_enable(dev, 0);
139 pnp_set_iobase(dev, PNP_IDX_IO0, 0x3e8);
140 pnp_set_irq(dev, PNP_IDX_IRQ0, 11);
141 pnp_set_enable(dev, 1);
142
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600143 dev = PNP_DEV(0x4e, W83627THG_SP2);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200144 pnp_set_logical_device(dev); /* Set COM4 to sane non-conflicting values */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000145 pnp_set_enable(dev, 0);
146 pnp_set_iobase(dev, PNP_IDX_IO0, 0x2e8);
147 pnp_set_irq(dev, PNP_IDX_IRQ0, 10);
148 pnp_set_enable(dev, 1);
149
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600150 dev = PNP_DEV(0x4e, W83627THG_FDC);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000151 pnp_set_logical_device(dev);
152 pnp_set_enable(dev, 0);
153
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600154 dev = PNP_DEV(0x4e, W83627THG_PP);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000155 pnp_set_logical_device(dev);
156 pnp_set_enable(dev, 0);
157
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600158 dev = PNP_DEV(0x4e, W83627THG_KBC);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000159 pnp_set_logical_device(dev);
160 pnp_set_enable(dev, 0);
161 pnp_set_iobase(dev, PNP_IDX_IO0, 0x00);
162 pnp_set_iobase(dev, PNP_IDX_IO1, 0x00);
163
Elyes HAOUAS5d4cf362018-08-06 09:58:28 +0200164 pnp_exit_conf_state(dev);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000165}
166
167static void rcba_config(void)
168{
169 /* Set up virtual channel 0 */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000170
171 /* Device 1f interrupt pin register */
Arthur Heymansb451df22017-08-15 20:59:09 +0200172 RCBA32(D31IP) = 0x00042210;
Stefan Reinauer36a22682008-10-29 04:52:57 +0000173 /* Device 1d interrupt pin register */
Arthur Heymansb451df22017-08-15 20:59:09 +0200174 RCBA32(D28IP) = 0x00214321;
Stefan Reinauer36a22682008-10-29 04:52:57 +0000175
176 /* dev irq route register */
Arthur Heymansb451df22017-08-15 20:59:09 +0200177 RCBA16(D31IR) = 0x0132;
178 RCBA16(D30IR) = 0x3241;
179 RCBA16(D29IR) = 0x0237;
180 RCBA16(D28IR) = 0x3210;
181 RCBA16(D27IR) = 0x3210;
Stefan Reinauer36a22682008-10-29 04:52:57 +0000182
183 /* Enable IOAPIC */
Arthur Heymansb451df22017-08-15 20:59:09 +0200184 RCBA8(OIC) = 0x03;
Stefan Reinauer36a22682008-10-29 04:52:57 +0000185
Stefan Reinauer36a22682008-10-29 04:52:57 +0000186 /* Enable PCIe Root Port Clock Gate */
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200187
Stefan Reinauer36a22682008-10-29 04:52:57 +0000188}
189
190static void early_ich7_init(void)
191{
192 uint8_t reg8;
193 uint32_t reg32;
194
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200195 /* program secondary mlt XXX byte? */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000196 pci_write_config8(PCI_DEV(0, 0x1e, 0), 0x1b, 0x20);
197
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200198 /* reset rtc power status */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000199 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xa4);
200 reg8 &= ~(1 << 2);
201 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa4, reg8);
202
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200203 /* usb transient disconnect */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000204 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xad);
205 reg8 |= (3 << 0);
206 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xad, reg8);
207
208 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xfc);
209 reg32 |= (1 << 29) | (1 << 17);
210 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xfc, reg32);
211
212 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xdc);
213 reg32 |= (1 << 31) | (1 << 27);
214 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xdc, reg32);
215
216 RCBA32(0x0088) = 0x0011d000;
217 RCBA16(0x01fc) = 0x060f;
218 RCBA32(0x01f4) = 0x86000040;
219 RCBA32(0x0214) = 0x10030549;
220 RCBA32(0x0218) = 0x00020504;
221 RCBA8(0x0220) = 0xc5;
Arthur Heymansb451df22017-08-15 20:59:09 +0200222 reg32 = RCBA32(GCS);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000223 reg32 |= (1 << 6);
Arthur Heymansb451df22017-08-15 20:59:09 +0200224 RCBA32(GCS) = reg32;
Stefan Reinauer36a22682008-10-29 04:52:57 +0000225 reg32 = RCBA32(0x3430);
226 reg32 &= ~(3 << 0);
227 reg32 |= (1 << 0);
228 RCBA32(0x3430) = reg32;
Stefan Reinauer36a22682008-10-29 04:52:57 +0000229 RCBA16(0x0200) = 0x2008;
230 RCBA8(0x2027) = 0x0d;
231 RCBA16(0x3e08) |= (1 << 7);
232 RCBA16(0x3e48) |= (1 << 7);
233 RCBA32(0x3e0e) |= (1 << 7);
234 RCBA32(0x3e4e) |= (1 << 7);
235
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200236 /* next step only on ich7m b0 and later: */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000237 reg32 = RCBA32(0x2034);
238 reg32 &= ~(0x0f << 16);
239 reg32 |= (5 << 16);
240 RCBA32(0x2034) = reg32;
241}
242
Kyösti Mälkki15fa9922016-06-17 10:00:28 +0300243void mainboard_romstage_entry(unsigned long bist)
Stefan Reinauer36a22682008-10-29 04:52:57 +0000244{
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200245 int s3resume = 0;
Stefan Reinauer36a22682008-10-29 04:52:57 +0000246
Uwe Hermann7b997052010-11-21 22:47:22 +0000247 if (bist == 0)
Stefan Reinauer36a22682008-10-29 04:52:57 +0000248 enable_lapic();
Stefan Reinauer36a22682008-10-29 04:52:57 +0000249
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000250 /* Force PCIRST# */
251 pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, SBR);
Stefan Reinauerbc8613e2010-08-25 18:35:42 +0000252 udelay(200 * 1000);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000253 pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, 0);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000254
Stefan Reinauerbc8613e2010-08-25 18:35:42 +0000255 ich7_enable_lpc();
Stefan Reinauer36a22682008-10-29 04:52:57 +0000256 early_superio_config_w83627thg();
257
258 /* Set up the console */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000259 console_init();
260
261 /* Halt if there was a built in self test failure */
262 report_bist_failure(bist);
263
264 if (MCHBAR16(SSKPD) == 0xCAFE) {
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000265 printk(BIOS_DEBUG, "soft reset detected, rebooting properly\n");
266 outb(0x6, 0xcf9);
Patrick Georgi546953c2014-11-29 10:38:17 +0100267 halt();
Stefan Reinauer36a22682008-10-29 04:52:57 +0000268 }
269
270 /* Perform some early chipset initialization required
271 * before RAM initialization can work
272 */
273 i945_early_initialization();
274
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200275 s3resume = southbridge_detect_s3_resume();
Stefan Reinauera5fdadf2009-07-21 21:58:20 +0000276
Stefan Reinauer36a22682008-10-29 04:52:57 +0000277 /* Enable SPD ROMs and DDR-II DRAM */
278 enable_smbus();
Stefan Reinauer14e22772010-04-27 06:56:47 +0000279
Stefan Reinauer08670622009-06-30 15:17:49 +0000280#if CONFIG_DEFAULT_CONSOLE_LOGLEVEL > 8
Stefan Reinauer36a22682008-10-29 04:52:57 +0000281 dump_spd_registers();
282#endif
283
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200284 sdram_initialize(s3resume ? 2 : 0, NULL);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000285
286 /* Perform some initialization that must run before stage2 */
287 early_ich7_init();
288
Stefan Reinauer14e22772010-04-27 06:56:47 +0000289 /* This should probably go away. Until now it is required
290 * and mainboard specific
Stefan Reinauer36a22682008-10-29 04:52:57 +0000291 */
292 rcba_config();
293
294 /* Chipset Errata! */
295 fixup_i945_errata();
296
297 /* Initialize the internal PCIe links before we go into stage2 */
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200298 i945_late_initialization(s3resume);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000299}