Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2007-2009 coresystems GmbH |
| 5 | * Copyright (C) 2011 Sven Schnelle <svens@stackframe.org> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; version 2 of |
| 10 | * the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
| 20 | * MA 02110-1301 USA |
| 21 | */ |
| 22 | |
| 23 | // __PRE_RAM__ means: use "unsigned" for device, not a struct. |
| 24 | |
| 25 | #include <stdint.h> |
| 26 | #include <string.h> |
| 27 | #include <arch/io.h> |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 28 | #include <device/pci_def.h> |
| 29 | #include <device/pnp_def.h> |
| 30 | #include <cpu/x86/lapic.h> |
| 31 | #include <lib.h> |
Kyösti Mälkki | 12d681b | 2014-06-14 18:51:34 +0300 | [diff] [blame] | 32 | #include <arch/acpi.h> |
Paul Menzel | ac6ea04 | 2013-04-29 23:21:07 +0200 | [diff] [blame] | 33 | #include <cbmem.h> |
Nico Huber | 44c392f | 2013-05-26 19:37:47 +0200 | [diff] [blame] | 34 | #include <timestamp.h> |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 35 | #include <pc80/mc146818rtc.h> |
| 36 | #include <console/console.h> |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 37 | #include <cpu/x86/bist.h> |
Patrick Georgi | 546953c | 2014-11-29 10:38:17 +0100 | [diff] [blame^] | 38 | #include <halt.h> |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 39 | #include "northbridge/intel/i945/i945.h" |
| 40 | #include "northbridge/intel/i945/raminit.h" |
| 41 | #include "southbridge/intel/i82801gx/i82801gx.h" |
| 42 | #include "dock.h" |
| 43 | |
| 44 | void setup_ich7_gpios(void) |
| 45 | { |
| 46 | printk(BIOS_DEBUG, " GPIOS..."); |
| 47 | |
| 48 | /* T60 GPIO: |
| 49 | 6: LEGACYIO# |
| 50 | 7: BDC_PRESENCE# |
| 51 | 8: H8_WAKE# |
| 52 | 10: MDI_DETECT |
| 53 | 12: H8SCI# |
| 54 | 14: CPUSB# |
| 55 | 15: CPPE# |
| 56 | 25: MDC_KILL# |
| 57 | 27: EXC_PWR_CTRL |
| 58 | 28: EXC_AUX_CTRL |
| 59 | 35: CLKREQ_SATA# |
| 60 | 36: PLANARID0 |
| 61 | 37: PLANARID1 |
| 62 | 38: PLANARID2 |
| 63 | 39: PLANARID3 |
| 64 | */ |
| 65 | outl(0x1f48f7c2, DEFAULT_GPIOBASE + 0x00); /* GPIO_USE_SEL */ |
| 66 | outl(0xe0e0ffc3, DEFAULT_GPIOBASE + 0x04); /* GP_IO_SEL */ |
| 67 | outl(0xfbfefb7d, DEFAULT_GPIOBASE + 0x0c); /* GP_LVL */ |
| 68 | /* Output Control Registers */ |
| 69 | outl(0x00040000, DEFAULT_GPIOBASE + 0x18); /* GPO_BLINK */ |
| 70 | /* Input Control Registers */ |
| 71 | outl(0x000039ff, DEFAULT_GPIOBASE + 0x2c); /* GPI_INV */ |
| 72 | outl(0x000100f0, DEFAULT_GPIOBASE + 0x30); /* GPIO_USE_SEL2 */ |
| 73 | outl(0x000000f1, DEFAULT_GPIOBASE + 0x34); /* GP_IO_SEL2 */ |
| 74 | outl(0x000300a3, DEFAULT_GPIOBASE + 0x38); /* GP_LVL2 */ |
| 75 | } |
| 76 | |
| 77 | static void ich7_enable_lpc(void) |
| 78 | { |
| 79 | // Enable Serial IRQ |
| 80 | pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x64, 0xd0); |
| 81 | // decode range |
| 82 | pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x80, 0x0210); |
| 83 | // decode range |
| 84 | pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x82, 0x1f0d); |
| 85 | |
| 86 | /* range 0x1600 - 0x167f */ |
| 87 | pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x84, 0x1601); |
| 88 | pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x86, 0x007c); |
| 89 | |
| 90 | /* range 0x15e0 - 0x10ef */ |
| 91 | pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x88, 0x15e1); |
| 92 | pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x8a, 0x000c); |
| 93 | |
| 94 | /* range 0x1680 - 0x169f */ |
| 95 | pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x8c, 0x1681); |
| 96 | pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x8e, 0x001c); |
| 97 | } |
| 98 | |
| 99 | static void early_superio_config(void) |
| 100 | { |
| 101 | int timeout = 100000; |
| 102 | device_t dev = PNP_DEV(0x2e, 3); |
| 103 | |
| 104 | pnp_write_config(dev, 0x29, 0xa0); |
| 105 | |
| 106 | while(!(pnp_read_config(dev, 0x29) & 0x10) && timeout--) |
| 107 | udelay(1000); |
| 108 | |
| 109 | /* Enable COM1 */ |
| 110 | pnp_set_logical_device(dev); |
| 111 | pnp_set_iobase(dev, PNP_IDX_IO0, 0x3f8); |
| 112 | pnp_set_enable(dev, 1); |
| 113 | } |
| 114 | |
| 115 | static void rcba_config(void) |
| 116 | { |
| 117 | /* Set up virtual channel 0 */ |
| 118 | RCBA32(0x0014) = 0x80000001; |
| 119 | RCBA32(0x001c) = 0x03128010; |
| 120 | |
| 121 | /* Device 1f interrupt pin register */ |
| 122 | RCBA32(0x3100) = 0x00001230; |
| 123 | RCBA32(0x3108) = 0x40004321; |
| 124 | |
| 125 | /* PCIe Interrupts */ |
| 126 | RCBA32(0x310c) = 0x00004321; |
| 127 | /* HD Audio Interrupt */ |
| 128 | RCBA32(0x3110) = 0x00000002; |
| 129 | |
| 130 | /* dev irq route register */ |
| 131 | RCBA16(0x3140) = 0x1007; |
| 132 | RCBA16(0x3142) = 0x0076; |
| 133 | RCBA16(0x3144) = 0x3210; |
| 134 | RCBA16(0x3146) = 0x7654; |
| 135 | RCBA16(0x3148) = 0x0010; |
| 136 | |
| 137 | /* Enable IOAPIC */ |
| 138 | RCBA8(0x31ff) = 0x03; |
| 139 | |
| 140 | /* Enable upper 128bytes of CMOS */ |
| 141 | RCBA32(0x3400) = (1 << 2); |
| 142 | |
| 143 | /* Disable unused devices */ |
| 144 | RCBA32(0x3418) = FD_PCIE6 | FD_PCIE5 | FD_INTLAN | FD_ACMOD | FD_ACAUD; |
| 145 | RCBA32(0x3418) |= (1 << 0); // Required. |
| 146 | |
| 147 | /* Set up I/O Trap #0 for 0xfe00 (SMIC) */ |
| 148 | RCBA32(0x1e84) = 0x00020001; |
| 149 | RCBA32(0x1e80) = 0x0000fe01; |
| 150 | |
| 151 | /* Set up I/O Trap #3 for 0x800-0x80c (Trap) */ |
| 152 | RCBA32(0x1e9c) = 0x000200f0; |
| 153 | RCBA32(0x1e98) = 0x000c0801; |
| 154 | } |
| 155 | |
| 156 | static void early_ich7_init(void) |
| 157 | { |
| 158 | uint8_t reg8; |
| 159 | uint32_t reg32; |
| 160 | |
| 161 | // program secondary mlt XXX byte? |
| 162 | pci_write_config8(PCI_DEV(0, 0x1e, 0), 0x1b, 0x20); |
| 163 | |
| 164 | // reset rtc power status |
| 165 | reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xa4); |
| 166 | reg8 &= ~(1 << 2); |
| 167 | pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa4, reg8); |
| 168 | |
| 169 | // usb transient disconnect |
| 170 | reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xad); |
| 171 | reg8 |= (3 << 0); |
| 172 | pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xad, reg8); |
| 173 | |
| 174 | reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xfc); |
| 175 | reg32 |= (1 << 29) | (1 << 17); |
| 176 | pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xfc, reg32); |
| 177 | |
| 178 | reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xdc); |
| 179 | reg32 |= (1 << 31) | (1 << 27); |
| 180 | pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xdc, reg32); |
| 181 | |
| 182 | RCBA32(0x0088) = 0x0011d000; |
| 183 | RCBA16(0x01fc) = 0x060f; |
| 184 | RCBA32(0x01f4) = 0x86000040; |
| 185 | RCBA32(0x0214) = 0x10030549; |
| 186 | RCBA32(0x0218) = 0x00020504; |
| 187 | RCBA8(0x0220) = 0xc5; |
| 188 | reg32 = RCBA32(0x3410); |
| 189 | reg32 |= (1 << 6); |
| 190 | RCBA32(0x3410) = reg32; |
| 191 | reg32 = RCBA32(0x3430); |
| 192 | reg32 &= ~(3 << 0); |
| 193 | reg32 |= (1 << 0); |
| 194 | RCBA32(0x3430) = reg32; |
| 195 | RCBA32(0x3418) |= (1 << 0); |
| 196 | RCBA16(0x0200) = 0x2008; |
| 197 | RCBA8(0x2027) = 0x0d; |
| 198 | RCBA16(0x3e08) |= (1 << 7); |
| 199 | RCBA16(0x3e48) |= (1 << 7); |
| 200 | RCBA32(0x3e0e) |= (1 << 7); |
| 201 | RCBA32(0x3e4e) |= (1 << 7); |
| 202 | |
| 203 | // next step only on ich7m b0 and later: |
| 204 | reg32 = RCBA32(0x2034); |
| 205 | reg32 &= ~(0x0f << 16); |
| 206 | reg32 |= (5 << 16); |
| 207 | RCBA32(0x2034) = reg32; |
| 208 | } |
| 209 | |
Aaron Durbin | a0a3727 | 2014-08-14 08:35:11 -0500 | [diff] [blame] | 210 | #include <cpu/intel/romstage.h> |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 211 | void main(unsigned long bist) |
| 212 | { |
Vladimir Serbinenko | 5560188 | 2014-10-15 20:17:51 +0200 | [diff] [blame] | 213 | int s3resume = 0; |
| 214 | int dock_err; |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 215 | const u8 spd_addrmap[2 * DIMM_SOCKETS] = { 0x50, 0x52, 0x51, 0x53 }; |
| 216 | |
Nico Huber | 44c392f | 2013-05-26 19:37:47 +0200 | [diff] [blame] | 217 | |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 218 | timestamp_init(get_initial_timestamp()); |
| 219 | timestamp_add_now(TS_START_ROMSTAGE); |
Nico Huber | 44c392f | 2013-05-26 19:37:47 +0200 | [diff] [blame] | 220 | |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 221 | if (bist == 0) |
| 222 | enable_lapic(); |
| 223 | |
| 224 | /* Force PCIRST# */ |
| 225 | pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, SBR); |
| 226 | udelay(200 * 1000); |
| 227 | pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, 0); |
| 228 | |
| 229 | ich7_enable_lpc(); |
| 230 | |
Sven Schnelle | b538110 | 2011-10-15 17:31:01 +0200 | [diff] [blame] | 231 | /* We want early GPIO setup, to be able to detect legacy I/O module */ |
| 232 | pci_write_config32(PCI_DEV(0, 0x1f, 0), GPIOBASE, DEFAULT_GPIOBASE | 1); |
| 233 | /* Enable GPIOs */ |
| 234 | pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x4c /* GC */ , 0x10); |
| 235 | setup_ich7_gpios(); |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 236 | |
Sven Schnelle | b538110 | 2011-10-15 17:31:01 +0200 | [diff] [blame] | 237 | dock_err = dlpc_init(); |
| 238 | |
| 239 | /* We prefer Legacy I/O module over docking */ |
| 240 | if (legacy_io_present()) { |
| 241 | legacy_io_init(); |
| 242 | early_superio_config(); |
| 243 | } else if (!dock_err && dock_present()) { |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 244 | dock_connect(); |
| 245 | early_superio_config(); |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 246 | } |
| 247 | |
Sven Schnelle | b538110 | 2011-10-15 17:31:01 +0200 | [diff] [blame] | 248 | /* Setup the console */ |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 249 | console_init(); |
| 250 | |
| 251 | /* Halt if there was a built in self test failure */ |
| 252 | report_bist_failure(bist); |
| 253 | |
| 254 | if (MCHBAR16(SSKPD) == 0xCAFE) { |
| 255 | printk(BIOS_DEBUG, "soft reset detected, rebooting properly\n"); |
| 256 | outb(0x6, 0xcf9); |
Patrick Georgi | 546953c | 2014-11-29 10:38:17 +0100 | [diff] [blame^] | 257 | halt(); |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | /* Perform some early chipset initialization required |
| 261 | * before RAM initialization can work |
| 262 | */ |
| 263 | i945_early_initialization(); |
| 264 | |
Vladimir Serbinenko | 5560188 | 2014-10-15 20:17:51 +0200 | [diff] [blame] | 265 | s3resume = southbridge_detect_s3_resume(); |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 266 | |
| 267 | /* Enable SPD ROMs and DDR-II DRAM */ |
| 268 | enable_smbus(); |
| 269 | |
| 270 | #if CONFIG_DEFAULT_CONSOLE_LOGLEVEL > 8 |
| 271 | dump_spd_registers(); |
| 272 | #endif |
| 273 | |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 274 | timestamp_add_now(TS_BEFORE_INITRAM); |
Vladimir Serbinenko | 5560188 | 2014-10-15 20:17:51 +0200 | [diff] [blame] | 275 | sdram_initialize(s3resume ? 2 : 0, spd_addrmap); |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 276 | timestamp_add_now(TS_AFTER_INITRAM); |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 277 | |
| 278 | /* Perform some initialization that must run before stage2 */ |
| 279 | early_ich7_init(); |
| 280 | |
| 281 | /* This should probably go away. Until now it is required |
| 282 | * and mainboard specific |
| 283 | */ |
| 284 | rcba_config(); |
| 285 | |
| 286 | /* Chipset Errata! */ |
| 287 | fixup_i945_errata(); |
| 288 | |
| 289 | /* Initialize the internal PCIe links before we go into stage2 */ |
Vladimir Serbinenko | 5560188 | 2014-10-15 20:17:51 +0200 | [diff] [blame] | 290 | i945_late_initialization(s3resume); |
Paul Menzel | ac6ea04 | 2013-04-29 23:21:07 +0200 | [diff] [blame] | 291 | |
Nico Huber | 44c392f | 2013-05-26 19:37:47 +0200 | [diff] [blame] | 292 | timestamp_add_now(TS_END_ROMSTAGE); |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 293 | } |