blob: b85bd6883dc06619896b354c8a5e3d184dbf38a8 [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>
Kyösti Mälkkibdaec072019-03-02 23:18:29 +020019#include <arch/io.h>
Elyes HAOUASd07048a2019-04-21 20:17:11 +020020#include <cf9_reset.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>
Patrick Rudolph425e75a2019-03-24 15:06:17 +010033#include <southbridge/intel/common/pmclib.h>
Elyes HAOUAS5d4cf362018-08-06 09:58:28 +020034#include <superio/winbond/common/winbond.h>
35#include <superio/winbond/w83627thg/w83627thg.h>
36
37#include "option_table.h"
Patrick Georgid0835952010-10-05 09:07:10 +000038
Uwe Hermann57b2ff82010-11-21 17:29:59 +000039#define SERIAL_DEV PNP_DEV(0x2e, W83627THG_SP1)
40
Stefan Reinauer36a22682008-10-29 04:52:57 +000041static void ich7_enable_lpc(void)
42{
Patrick Georgia4700192011-01-27 07:39:38 +000043 int lpt_en = 0;
Arthur Heymansb451df22017-08-15 20:59:09 +020044 if (read_option(lpt, 0) != 0)
45 lpt_en = LPT_LPC_EN; /* enable LPT */
46
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020047 /* Enable Serial IRQ */
Arthur Heymansb451df22017-08-15 20:59:09 +020048 pci_write_config8(PCI_DEV(0, 0x1f, 0), SERIRQ_CNTL, 0xd0);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020049 /* Set COM1/COM2 decode range */
Arthur Heymansb451df22017-08-15 20:59:09 +020050 pci_write_config16(PCI_DEV(0, 0x1f, 0), LPC_IO_DEC, 0x0010);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020051 /* Enable COM1/COM2/KBD/SuperIO1+2 */
Arthur Heymansb451df22017-08-15 20:59:09 +020052 pci_write_config16(PCI_DEV(0, 0x1f, 0), LPC_EN, CNF2_LPC_EN
53 | CNF1_LPC_EN | KBC_LPC_EN | FDD_LPC_EN | COMA_LPC_EN
54 | COMB_LPC_EN | lpt_en);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020055 /* Enable HWM at 0xa00 */
Arthur Heymansb451df22017-08-15 20:59:09 +020056 pci_write_config32(PCI_DEV(0, 0x1f, 0), GEN1_DEC, 0x00fc0a01);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020057 /* COM3 decode */
Arthur Heymansb451df22017-08-15 20:59:09 +020058 pci_write_config32(PCI_DEV(0, 0x1f, 0), GEN2_DEC, 0x000403e9);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020059 /* COM4 decode */
Arthur Heymansb451df22017-08-15 20:59:09 +020060 pci_write_config32(PCI_DEV(0, 0x1f, 0), GEN3_DEC, 0x000402e9);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020061 /* io 0x300 decode */
Arthur Heymansb451df22017-08-15 20:59:09 +020062 pci_write_config32(PCI_DEV(0, 0x1f, 0), GEN4_DEC, 0x00000301);
Stefan Reinauer36a22682008-10-29 04:52:57 +000063}
64
Stefan Reinauer36a22682008-10-29 04:52:57 +000065/* This box has two superios, so enabling serial becomes slightly excessive.
66 * We disable a lot of stuff to make sure that there are no conflicts between
67 * the two. Also set up the GPIOs from the beginning. This is the "no schematic
68 * but safe anyways" method.
69 */
70static void early_superio_config_w83627thg(void)
71{
Antonello Dettori9ec11232016-11-08 18:44:46 +010072 pnp_devfn_t dev;
Stefan Reinauer14e22772010-04-27 06:56:47 +000073
Elyes HAOUAS531b87a2016-09-19 09:46:33 -060074 dev = PNP_DEV(0x2e, W83627THG_SP1);
Elyes HAOUAS5d4cf362018-08-06 09:58:28 +020075 pnp_enter_conf_state(dev);
Stefan Reinauer36a22682008-10-29 04:52:57 +000076
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020077 pnp_write_config(dev, 0x24, 0xc6); /* PNPCSV */
Stefan Reinaueraca6ec62009-10-26 17:12:21 +000078
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020079 pnp_write_config(dev, 0x29, 0x43); /* GPIO settings */
80 pnp_write_config(dev, 0x2a, 0x40); /* GPIO settings */
Stefan Reinaueraca6ec62009-10-26 17:12:21 +000081
Elyes HAOUAS531b87a2016-09-19 09:46:33 -060082 dev = PNP_DEV(0x2e, W83627THG_SP1);
Stefan Reinauer36a22682008-10-29 04:52:57 +000083 pnp_set_logical_device(dev);
84 pnp_set_enable(dev, 0);
85 pnp_set_iobase(dev, PNP_IDX_IO0, 0x3f8);
86 pnp_set_irq(dev, PNP_IDX_IRQ0, 4);
87 pnp_set_enable(dev, 1);
88
Elyes HAOUAS531b87a2016-09-19 09:46:33 -060089 dev = PNP_DEV(0x2e, W83627THG_SP2);
Stefan Reinauer36a22682008-10-29 04:52:57 +000090 pnp_set_logical_device(dev);
91 pnp_set_enable(dev, 0);
92 pnp_set_iobase(dev, PNP_IDX_IO0, 0x2f8);
93 pnp_set_irq(dev, PNP_IDX_IRQ0, 3);
Stefan Reinauer36a22682008-10-29 04:52:57 +000094 pnp_set_enable(dev, 1);
95
Elyes HAOUAS531b87a2016-09-19 09:46:33 -060096 dev = PNP_DEV(0x2e, W83627THG_KBC);
Stefan Reinauer36a22682008-10-29 04:52:57 +000097 pnp_set_logical_device(dev);
98 pnp_set_enable(dev, 0);
99 pnp_set_iobase(dev, PNP_IDX_IO0, 0x60);
100 pnp_set_iobase(dev, PNP_IDX_IO1, 0x64);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000101 pnp_set_enable(dev, 1);
102
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600103 dev = PNP_DEV(0x2e, W83627THG_GAME_MIDI_GPIO1);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000104 pnp_set_logical_device(dev);
105 pnp_set_enable(dev, 0);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200106 pnp_write_config(dev, 0xf5, 0xff); /* invert all GPIOs */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000107 pnp_set_enable(dev, 1);
108
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600109 dev = PNP_DEV(0x2e, W83627THG_GPIO2);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000110 pnp_set_logical_device(dev);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200111 pnp_set_enable(dev, 1); /* Just enable it */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000112
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600113 dev = PNP_DEV(0x2e, W83627THG_GPIO3);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000114 pnp_set_logical_device(dev);
115 pnp_set_enable(dev, 0);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200116 pnp_write_config(dev, 0xf0, 0xfb); /* GPIO bit 2 is output */
117 pnp_write_config(dev, 0xf1, 0x00); /* GPIO bit 2 is 0 */
118 pnp_write_config(dev, 0x30, 0x03); /* Enable GPIO3+4. pnp_set_enable is not sufficient */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000119
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600120 dev = PNP_DEV(0x2e, W83627THG_FDC);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000121 pnp_set_logical_device(dev);
122 pnp_set_enable(dev, 0);
123
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600124 dev = PNP_DEV(0x2e, W83627THG_PP);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000125 pnp_set_logical_device(dev);
126 pnp_set_enable(dev, 0);
127
Stefan Reinauer54309d62009-01-20 22:53:10 +0000128 /* Enable HWM */
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600129 dev = PNP_DEV(0x2e, W83627THG_HWM);
Stefan Reinauer54309d62009-01-20 22:53:10 +0000130 pnp_set_logical_device(dev);
131 pnp_set_enable(dev, 0);
132 pnp_set_iobase(dev, PNP_IDX_IO0, 0xa00);
133 pnp_set_enable(dev, 1);
134
Elyes HAOUAS5d4cf362018-08-06 09:58:28 +0200135 pnp_exit_conf_state(dev);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000136
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600137 dev = PNP_DEV(0x4e, W83627THG_SP1);
Elyes HAOUAS5d4cf362018-08-06 09:58:28 +0200138 pnp_enter_conf_state(dev);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000139
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200140 pnp_set_logical_device(dev); /* Set COM3 to sane non-conflicting values */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000141 pnp_set_enable(dev, 0);
142 pnp_set_iobase(dev, PNP_IDX_IO0, 0x3e8);
143 pnp_set_irq(dev, PNP_IDX_IRQ0, 11);
144 pnp_set_enable(dev, 1);
145
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600146 dev = PNP_DEV(0x4e, W83627THG_SP2);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200147 pnp_set_logical_device(dev); /* Set COM4 to sane non-conflicting values */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000148 pnp_set_enable(dev, 0);
149 pnp_set_iobase(dev, PNP_IDX_IO0, 0x2e8);
150 pnp_set_irq(dev, PNP_IDX_IRQ0, 10);
151 pnp_set_enable(dev, 1);
152
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600153 dev = PNP_DEV(0x4e, W83627THG_FDC);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000154 pnp_set_logical_device(dev);
155 pnp_set_enable(dev, 0);
156
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600157 dev = PNP_DEV(0x4e, W83627THG_PP);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000158 pnp_set_logical_device(dev);
159 pnp_set_enable(dev, 0);
160
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600161 dev = PNP_DEV(0x4e, W83627THG_KBC);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000162 pnp_set_logical_device(dev);
163 pnp_set_enable(dev, 0);
164 pnp_set_iobase(dev, PNP_IDX_IO0, 0x00);
165 pnp_set_iobase(dev, PNP_IDX_IO1, 0x00);
166
Elyes HAOUAS5d4cf362018-08-06 09:58:28 +0200167 pnp_exit_conf_state(dev);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000168}
169
170static void rcba_config(void)
171{
172 /* Set up virtual channel 0 */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000173
174 /* Device 1f interrupt pin register */
Arthur Heymansb451df22017-08-15 20:59:09 +0200175 RCBA32(D31IP) = 0x00042210;
Stefan Reinauer36a22682008-10-29 04:52:57 +0000176 /* Device 1d interrupt pin register */
Arthur Heymansb451df22017-08-15 20:59:09 +0200177 RCBA32(D28IP) = 0x00214321;
Stefan Reinauer36a22682008-10-29 04:52:57 +0000178
179 /* dev irq route register */
Arthur Heymansb451df22017-08-15 20:59:09 +0200180 RCBA16(D31IR) = 0x0132;
181 RCBA16(D30IR) = 0x3241;
182 RCBA16(D29IR) = 0x0237;
183 RCBA16(D28IR) = 0x3210;
184 RCBA16(D27IR) = 0x3210;
Stefan Reinauer36a22682008-10-29 04:52:57 +0000185
186 /* Enable IOAPIC */
Arthur Heymansb451df22017-08-15 20:59:09 +0200187 RCBA8(OIC) = 0x03;
Stefan Reinauer36a22682008-10-29 04:52:57 +0000188
Stefan Reinauer36a22682008-10-29 04:52:57 +0000189 /* Enable PCIe Root Port Clock Gate */
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200190
Stefan Reinauer36a22682008-10-29 04:52:57 +0000191}
192
193static void early_ich7_init(void)
194{
195 uint8_t reg8;
196 uint32_t reg32;
197
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200198 /* program secondary mlt XXX byte? */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000199 pci_write_config8(PCI_DEV(0, 0x1e, 0), 0x1b, 0x20);
200
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200201 /* reset rtc power status */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000202 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xa4);
203 reg8 &= ~(1 << 2);
204 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa4, reg8);
205
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200206 /* usb transient disconnect */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000207 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xad);
208 reg8 |= (3 << 0);
209 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xad, reg8);
210
211 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xfc);
212 reg32 |= (1 << 29) | (1 << 17);
213 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xfc, reg32);
214
215 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xdc);
216 reg32 |= (1 << 31) | (1 << 27);
217 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xdc, reg32);
218
219 RCBA32(0x0088) = 0x0011d000;
220 RCBA16(0x01fc) = 0x060f;
221 RCBA32(0x01f4) = 0x86000040;
222 RCBA32(0x0214) = 0x10030549;
223 RCBA32(0x0218) = 0x00020504;
224 RCBA8(0x0220) = 0xc5;
Arthur Heymansb451df22017-08-15 20:59:09 +0200225 reg32 = RCBA32(GCS);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000226 reg32 |= (1 << 6);
Arthur Heymansb451df22017-08-15 20:59:09 +0200227 RCBA32(GCS) = reg32;
Stefan Reinauer36a22682008-10-29 04:52:57 +0000228 reg32 = RCBA32(0x3430);
229 reg32 &= ~(3 << 0);
230 reg32 |= (1 << 0);
231 RCBA32(0x3430) = reg32;
Stefan Reinauer36a22682008-10-29 04:52:57 +0000232 RCBA16(0x0200) = 0x2008;
233 RCBA8(0x2027) = 0x0d;
234 RCBA16(0x3e08) |= (1 << 7);
235 RCBA16(0x3e48) |= (1 << 7);
236 RCBA32(0x3e0e) |= (1 << 7);
237 RCBA32(0x3e4e) |= (1 << 7);
238
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +0200239 /* next step only on ich7m b0 and later: */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000240 reg32 = RCBA32(0x2034);
241 reg32 &= ~(0x0f << 16);
242 reg32 |= (5 << 16);
243 RCBA32(0x2034) = reg32;
244}
245
Kyösti Mälkki15fa9922016-06-17 10:00:28 +0300246void mainboard_romstage_entry(unsigned long bist)
Stefan Reinauer36a22682008-10-29 04:52:57 +0000247{
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200248 int s3resume = 0;
Stefan Reinauer36a22682008-10-29 04:52:57 +0000249
Uwe Hermann7b997052010-11-21 22:47:22 +0000250 if (bist == 0)
Stefan Reinauer36a22682008-10-29 04:52:57 +0000251 enable_lapic();
Stefan Reinauer36a22682008-10-29 04:52:57 +0000252
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000253 /* Force PCIRST# */
254 pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, SBR);
Stefan Reinauerbc8613e2010-08-25 18:35:42 +0000255 udelay(200 * 1000);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000256 pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, 0);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000257
Stefan Reinauerbc8613e2010-08-25 18:35:42 +0000258 ich7_enable_lpc();
Stefan Reinauer36a22682008-10-29 04:52:57 +0000259 early_superio_config_w83627thg();
260
261 /* Set up the console */
Stefan Reinauer36a22682008-10-29 04:52:57 +0000262 console_init();
263
264 /* Halt if there was a built in self test failure */
265 report_bist_failure(bist);
266
267 if (MCHBAR16(SSKPD) == 0xCAFE) {
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000268 printk(BIOS_DEBUG, "soft reset detected, rebooting properly\n");
Elyes HAOUASd07048a2019-04-21 20:17:11 +0200269 system_reset();
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
Kyösti Mälkki346d2012019-03-23 10:07:16 +0200282 if (CONFIG(DEBUG_RAM_SETUP))
283 dump_spd_registers();
Stefan Reinauer36a22682008-10-29 04:52:57 +0000284
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200285 sdram_initialize(s3resume ? 2 : 0, NULL);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000286
287 /* Perform some initialization that must run before stage2 */
288 early_ich7_init();
289
Stefan Reinauer14e22772010-04-27 06:56:47 +0000290 /* This should probably go away. Until now it is required
291 * and mainboard specific
Stefan Reinauer36a22682008-10-29 04:52:57 +0000292 */
293 rcba_config();
294
295 /* Chipset Errata! */
296 fixup_i945_errata();
297
298 /* Initialize the internal PCIe links before we go into stage2 */
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200299 i945_late_initialization(s3resume);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000300}