blob: 52432a0cbee5d35618b2cf1ddab5d12e77a31674 [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>
Kyösti Mälkkibdaec072019-03-02 23:18:29 +020020#include <arch/io.h>
Elyes HAOUAS5d4cf362018-08-06 09:58:28 +020021#include <console/console.h>
22#include <cpu/intel/romstage.h>
23#include <cpu/x86/bist.h>
24#include <cpu/x86/lapic.h>
Stefan Reinauer36a22682008-10-29 04:52:57 +000025#include <device/pci_def.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020026#include <device/pci_ops.h>
Kyösti Mälkki3855c012019-03-03 08:45:19 +020027#include <device/pnp_ops.h>
Stefan Reinauer36a22682008-10-29 04:52:57 +000028#include <device/pnp_def.h>
Edwin Beasanteb50c7d2010-07-06 21:05:04 +000029#include <pc80/mc146818rtc.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110030#include <northbridge/intel/i945/i945.h>
31#include <northbridge/intel/i945/raminit.h>
32#include <southbridge/intel/i82801gx/i82801gx.h>
Elyes HAOUAS5d4cf362018-08-06 09:58:28 +020033#include <superio/winbond/common/winbond.h>
34#include <superio/winbond/w83627thg/w83627thg.h>
35
36#include "option_table.h"
Patrick Georgid0835952010-10-05 09:07:10 +000037
Uwe Hermann57b2ff82010-11-21 17:29:59 +000038#define SERIAL_DEV PNP_DEV(0x2e, W83627THG_SP1)
39
Stefan Reinauer36a22682008-10-29 04:52:57 +000040static void ich7_enable_lpc(void)
41{
Patrick Georgia4700192011-01-27 07:39:38 +000042 int lpt_en = 0;
Arthur Heymansb451df22017-08-15 20:59:09 +020043 if (read_option(lpt, 0) != 0)
44 lpt_en = LPT_LPC_EN; /* enable LPT */
45
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020046 /* Enable Serial IRQ */
Arthur Heymansb451df22017-08-15 20:59:09 +020047 pci_write_config8(PCI_DEV(0, 0x1f, 0), SERIRQ_CNTL, 0xd0);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020048 /* Set COM1/COM2 decode range */
Arthur Heymansb451df22017-08-15 20:59:09 +020049 pci_write_config16(PCI_DEV(0, 0x1f, 0), LPC_IO_DEC, 0x0010);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020050 /* Enable COM1/COM2/KBD/SuperIO1+2 */
Arthur Heymansb451df22017-08-15 20:59:09 +020051 pci_write_config16(PCI_DEV(0, 0x1f, 0), LPC_EN, CNF2_LPC_EN
52 | CNF1_LPC_EN | KBC_LPC_EN | FDD_LPC_EN | COMA_LPC_EN
53 | COMB_LPC_EN | lpt_en);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020054 /* Enable HWM at 0xa00 */
Arthur Heymansb451df22017-08-15 20:59:09 +020055 pci_write_config32(PCI_DEV(0, 0x1f, 0), GEN1_DEC, 0x00fc0a01);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020056 /* COM3 decode */
Arthur Heymansb451df22017-08-15 20:59:09 +020057 pci_write_config32(PCI_DEV(0, 0x1f, 0), GEN2_DEC, 0x000403e9);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020058 /* COM4 decode */
Arthur Heymansb451df22017-08-15 20:59:09 +020059 pci_write_config32(PCI_DEV(0, 0x1f, 0), GEN3_DEC, 0x000402e9);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020060 /* io 0x300 decode */
Arthur Heymansb451df22017-08-15 20:59:09 +020061 pci_write_config32(PCI_DEV(0, 0x1f, 0), GEN4_DEC, 0x00000301);
Stefan Reinauer36a22682008-10-29 04:52:57 +000062}
63
Stefan Reinauer36a22682008-10-29 04:52:57 +000064/* This box has two superios, so enabling serial becomes slightly excessive.
65 * We disable a lot of stuff to make sure that there are no conflicts between
66 * the two. Also set up the GPIOs from the beginning. This is the "no schematic
67 * but safe anyways" method.
68 */
69static void early_superio_config_w83627thg(void)
70{
Antonello Dettori9ec11232016-11-08 18:44:46 +010071 pnp_devfn_t dev;
Stefan Reinauer14e22772010-04-27 06:56:47 +000072
Elyes HAOUAS531b87a2016-09-19 09:46:33 -060073 dev = PNP_DEV(0x2e, W83627THG_SP1);
Elyes HAOUAS5d4cf362018-08-06 09:58:28 +020074 pnp_enter_conf_state(dev);
Stefan Reinauer36a22682008-10-29 04:52:57 +000075
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020076 pnp_write_config(dev, 0x24, 0xc6); /* PNPCSV */
Stefan Reinaueraca6ec62009-10-26 17:12:21 +000077
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020078 pnp_write_config(dev, 0x29, 0x43); /* GPIO settings */
79 pnp_write_config(dev, 0x2a, 0x40); /* GPIO settings */
Stefan Reinaueraca6ec62009-10-26 17:12:21 +000080
Elyes HAOUAS531b87a2016-09-19 09:46:33 -060081 dev = PNP_DEV(0x2e, W83627THG_SP1);
Stefan Reinauer36a22682008-10-29 04:52:57 +000082 pnp_set_logical_device(dev);
83 pnp_set_enable(dev, 0);
84 pnp_set_iobase(dev, PNP_IDX_IO0, 0x3f8);
85 pnp_set_irq(dev, PNP_IDX_IRQ0, 4);
86 pnp_set_enable(dev, 1);
87
Elyes HAOUAS531b87a2016-09-19 09:46:33 -060088 dev = PNP_DEV(0x2e, W83627THG_SP2);
Stefan Reinauer36a22682008-10-29 04:52:57 +000089 pnp_set_logical_device(dev);
90 pnp_set_enable(dev, 0);
91 pnp_set_iobase(dev, PNP_IDX_IO0, 0x2f8);
92 pnp_set_irq(dev, PNP_IDX_IRQ0, 3);
Stefan Reinauer36a22682008-10-29 04:52:57 +000093 pnp_set_enable(dev, 1);
94
Elyes HAOUAS531b87a2016-09-19 09:46:33 -060095 dev = PNP_DEV(0x2e, W83627THG_KBC);
Stefan Reinauer36a22682008-10-29 04:52:57 +000096 pnp_set_logical_device(dev);
97 pnp_set_enable(dev, 0);
98 pnp_set_iobase(dev, PNP_IDX_IO0, 0x60);
99 pnp_set_iobase(dev, PNP_IDX_IO1, 0x64);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000100 pnp_set_enable(dev, 1);
101
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600102 dev = PNP_DEV(0x2e, W83627THG_GAME_MIDI_GPIO1);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000103 pnp_set_logical_device(dev);
104 pnp_set_enable(dev, 0);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200105 pnp_write_config(dev, 0xf5, 0xff); /* invert all GPIOs */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000106 pnp_set_enable(dev, 1);
107
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600108 dev = PNP_DEV(0x2e, W83627THG_GPIO2);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000109 pnp_set_logical_device(dev);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200110 pnp_set_enable(dev, 1); /* Just enable it */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000111
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600112 dev = PNP_DEV(0x2e, W83627THG_GPIO3);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000113 pnp_set_logical_device(dev);
114 pnp_set_enable(dev, 0);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200115 pnp_write_config(dev, 0xf0, 0xfb); /* GPIO bit 2 is output */
116 pnp_write_config(dev, 0xf1, 0x00); /* GPIO bit 2 is 0 */
117 pnp_write_config(dev, 0x30, 0x03); /* Enable GPIO3+4. pnp_set_enable is not sufficient */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000118
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600119 dev = PNP_DEV(0x2e, W83627THG_FDC);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000120 pnp_set_logical_device(dev);
121 pnp_set_enable(dev, 0);
122
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600123 dev = PNP_DEV(0x2e, W83627THG_PP);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000124 pnp_set_logical_device(dev);
125 pnp_set_enable(dev, 0);
126
Stefan Reinauer54309d62009-01-20 22:53:10 +0000127 /* Enable HWM */
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600128 dev = PNP_DEV(0x2e, W83627THG_HWM);
Stefan Reinauer54309d62009-01-20 22:53:10 +0000129 pnp_set_logical_device(dev);
130 pnp_set_enable(dev, 0);
131 pnp_set_iobase(dev, PNP_IDX_IO0, 0xa00);
132 pnp_set_enable(dev, 1);
133
Elyes HAOUAS5d4cf362018-08-06 09:58:28 +0200134 pnp_exit_conf_state(dev);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000135
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600136 dev = PNP_DEV(0x4e, W83627THG_SP1);
Elyes HAOUAS5d4cf362018-08-06 09:58:28 +0200137 pnp_enter_conf_state(dev);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000138
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200139 pnp_set_logical_device(dev); /* Set COM3 to sane non-conflicting values */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000140 pnp_set_enable(dev, 0);
141 pnp_set_iobase(dev, PNP_IDX_IO0, 0x3e8);
142 pnp_set_irq(dev, PNP_IDX_IRQ0, 11);
143 pnp_set_enable(dev, 1);
144
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600145 dev = PNP_DEV(0x4e, W83627THG_SP2);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200146 pnp_set_logical_device(dev); /* Set COM4 to sane non-conflicting values */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000147 pnp_set_enable(dev, 0);
148 pnp_set_iobase(dev, PNP_IDX_IO0, 0x2e8);
149 pnp_set_irq(dev, PNP_IDX_IRQ0, 10);
150 pnp_set_enable(dev, 1);
151
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600152 dev = PNP_DEV(0x4e, W83627THG_FDC);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000153 pnp_set_logical_device(dev);
154 pnp_set_enable(dev, 0);
155
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600156 dev = PNP_DEV(0x4e, W83627THG_PP);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000157 pnp_set_logical_device(dev);
158 pnp_set_enable(dev, 0);
159
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600160 dev = PNP_DEV(0x4e, W83627THG_KBC);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000161 pnp_set_logical_device(dev);
162 pnp_set_enable(dev, 0);
163 pnp_set_iobase(dev, PNP_IDX_IO0, 0x00);
164 pnp_set_iobase(dev, PNP_IDX_IO1, 0x00);
165
Elyes HAOUAS5d4cf362018-08-06 09:58:28 +0200166 pnp_exit_conf_state(dev);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000167}
168
169static void rcba_config(void)
170{
171 /* Set up virtual channel 0 */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000172
173 /* Device 1f interrupt pin register */
Arthur Heymansb451df22017-08-15 20:59:09 +0200174 RCBA32(D31IP) = 0x00042210;
Stefan Reinauer36a22682008-10-29 04:52:57 +0000175 /* Device 1d interrupt pin register */
Arthur Heymansb451df22017-08-15 20:59:09 +0200176 RCBA32(D28IP) = 0x00214321;
Stefan Reinauer36a22682008-10-29 04:52:57 +0000177
178 /* dev irq route register */
Arthur Heymansb451df22017-08-15 20:59:09 +0200179 RCBA16(D31IR) = 0x0132;
180 RCBA16(D30IR) = 0x3241;
181 RCBA16(D29IR) = 0x0237;
182 RCBA16(D28IR) = 0x3210;
183 RCBA16(D27IR) = 0x3210;
Stefan Reinauer36a22682008-10-29 04:52:57 +0000184
185 /* Enable IOAPIC */
Arthur Heymansb451df22017-08-15 20:59:09 +0200186 RCBA8(OIC) = 0x03;
Stefan Reinauer36a22682008-10-29 04:52:57 +0000187
Stefan Reinauer36a22682008-10-29 04:52:57 +0000188 /* Enable PCIe Root Port Clock Gate */
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200189
Stefan Reinauer36a22682008-10-29 04:52:57 +0000190}
191
192static void early_ich7_init(void)
193{
194 uint8_t reg8;
195 uint32_t reg32;
196
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200197 /* program secondary mlt XXX byte? */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000198 pci_write_config8(PCI_DEV(0, 0x1e, 0), 0x1b, 0x20);
199
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200200 /* reset rtc power status */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000201 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xa4);
202 reg8 &= ~(1 << 2);
203 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa4, reg8);
204
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200205 /* usb transient disconnect */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000206 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xad);
207 reg8 |= (3 << 0);
208 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xad, reg8);
209
210 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xfc);
211 reg32 |= (1 << 29) | (1 << 17);
212 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xfc, reg32);
213
214 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xdc);
215 reg32 |= (1 << 31) | (1 << 27);
216 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xdc, reg32);
217
218 RCBA32(0x0088) = 0x0011d000;
219 RCBA16(0x01fc) = 0x060f;
220 RCBA32(0x01f4) = 0x86000040;
221 RCBA32(0x0214) = 0x10030549;
222 RCBA32(0x0218) = 0x00020504;
223 RCBA8(0x0220) = 0xc5;
Arthur Heymansb451df22017-08-15 20:59:09 +0200224 reg32 = RCBA32(GCS);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000225 reg32 |= (1 << 6);
Arthur Heymansb451df22017-08-15 20:59:09 +0200226 RCBA32(GCS) = reg32;
Stefan Reinauer36a22682008-10-29 04:52:57 +0000227 reg32 = RCBA32(0x3430);
228 reg32 &= ~(3 << 0);
229 reg32 |= (1 << 0);
230 RCBA32(0x3430) = reg32;
Stefan Reinauer36a22682008-10-29 04:52:57 +0000231 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
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200238 /* next step only on ich7m b0 and later: */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000239 reg32 = RCBA32(0x2034);
240 reg32 &= ~(0x0f << 16);
241 reg32 |= (5 << 16);
242 RCBA32(0x2034) = reg32;
243}
244
Kyösti Mälkki15fa9922016-06-17 10:00:28 +0300245void mainboard_romstage_entry(unsigned long bist)
Stefan Reinauer36a22682008-10-29 04:52:57 +0000246{
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200247 int s3resume = 0;
Stefan Reinauer36a22682008-10-29 04:52:57 +0000248
Uwe Hermann7b997052010-11-21 22:47:22 +0000249 if (bist == 0)
Stefan Reinauer36a22682008-10-29 04:52:57 +0000250 enable_lapic();
Stefan Reinauer36a22682008-10-29 04:52:57 +0000251
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000252 /* Force PCIRST# */
253 pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, SBR);
Stefan Reinauerbc8613e2010-08-25 18:35:42 +0000254 udelay(200 * 1000);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000255 pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, 0);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000256
Stefan Reinauerbc8613e2010-08-25 18:35:42 +0000257 ich7_enable_lpc();
Stefan Reinauer36a22682008-10-29 04:52:57 +0000258 early_superio_config_w83627thg();
259
260 /* Set up the console */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000261 console_init();
262
263 /* Halt if there was a built in self test failure */
264 report_bist_failure(bist);
265
266 if (MCHBAR16(SSKPD) == 0xCAFE) {
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000267 printk(BIOS_DEBUG, "soft reset detected, rebooting properly\n");
268 outb(0x6, 0xcf9);
Patrick Georgi546953c2014-11-29 10:38:17 +0100269 halt();
Stefan Reinauer36a22682008-10-29 04:52:57 +0000270 }
271
272 /* Perform some early chipset initialization required
273 * before RAM initialization can work
274 */
275 i945_early_initialization();
276
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200277 s3resume = southbridge_detect_s3_resume();
Stefan Reinauera5fdadf2009-07-21 21:58:20 +0000278
Stefan Reinauer36a22682008-10-29 04:52:57 +0000279 /* Enable SPD ROMs and DDR-II DRAM */
280 enable_smbus();
Stefan Reinauer14e22772010-04-27 06:56:47 +0000281
Stefan Reinauer08670622009-06-30 15:17:49 +0000282#if CONFIG_DEFAULT_CONSOLE_LOGLEVEL > 8
Stefan Reinauer36a22682008-10-29 04:52:57 +0000283 dump_spd_registers();
284#endif
285
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200286 sdram_initialize(s3resume ? 2 : 0, NULL);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000287
288 /* Perform some initialization that must run before stage2 */
289 early_ich7_init();
290
Stefan Reinauer14e22772010-04-27 06:56:47 +0000291 /* This should probably go away. Until now it is required
292 * and mainboard specific
Stefan Reinauer36a22682008-10-29 04:52:57 +0000293 */
294 rcba_config();
295
296 /* Chipset Errata! */
297 fixup_i945_errata();
298
299 /* Initialize the internal PCIe links before we go into stage2 */
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200300 i945_late_initialization(s3resume);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000301}