Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Stefan Reinauer | 54309d6 | 2009-01-20 22:53:10 +0000 | [diff] [blame] | 4 | * Copyright (C) 2008-2009 coresystems GmbH |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 5 | * |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; version 2 of |
| 9 | * the License. |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
| 21 | #include <console/console.h> |
| 22 | #include <device/device.h> |
| 23 | #include <device/pci.h> |
| 24 | #include <device/pci_ids.h> |
| 25 | #include <pc80/mc146818rtc.h> |
| 26 | #include <pc80/isa-dma.h> |
Stefan Reinauer | 54309d6 | 2009-01-20 22:53:10 +0000 | [diff] [blame] | 27 | #include <pc80/i8259.h> |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 28 | #include <arch/io.h> |
Uwe Hermann | 74d1a6e | 2010-10-12 17:34:08 +0000 | [diff] [blame] | 29 | #include <arch/ioapic.h> |
Stefan Reinauer | ab87254 | 2011-10-14 15:18:29 -0700 | [diff] [blame^] | 30 | #include <arch/acpi.h> |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 31 | #include <cpu/cpu.h> |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 32 | #include "i82801gx.h" |
Sven Schnelle | f4dc1a7 | 2011-06-05 11:33:41 +0200 | [diff] [blame] | 33 | #include <cpu/x86/smm.h> |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 34 | |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 35 | #define NMI_OFF 0 |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 36 | |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 37 | #define ENABLE_ACPI_MODE_IN_COREBOOT 0 |
| 38 | #define TEST_SMM_FLASH_LOCKDOWN 0 |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 39 | |
Stefan Reinauer | 54309d6 | 2009-01-20 22:53:10 +0000 | [diff] [blame] | 40 | typedef struct southbridge_intel_i82801gx_config config_t; |
| 41 | |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 42 | static void i82801gx_enable_apic(struct device *dev) |
| 43 | { |
| 44 | int i; |
| 45 | u32 reg32; |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 46 | volatile u32 *ioapic_index = (volatile u32 *)(IO_APIC_ADDR); |
| 47 | volatile u32 *ioapic_data = (volatile u32 *)(IO_APIC_ADDR + 0x10); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 48 | |
Stefan Reinauer | 109ab31 | 2009-08-12 16:08:05 +0000 | [diff] [blame] | 49 | /* Enable ACPI I/O and power management. |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 50 | * Set SCI IRQ to IRQ9 |
| 51 | */ |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 52 | pci_write_config8(dev, ACPI_CNTL, 0x80); |
| 53 | |
| 54 | *ioapic_index = 0; |
| 55 | *ioapic_data = (1 << 25); |
| 56 | |
| 57 | *ioapic_index = 0; |
| 58 | reg32 = *ioapic_data; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 59 | printk(BIOS_DEBUG, "Southbridge APIC ID = %x\n", (reg32 >> 24) & 0x0f); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 60 | if (reg32 != (1 << 25)) |
| 61 | die("APIC Error\n"); |
| 62 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 63 | printk(BIOS_SPEW, "Dumping IOAPIC registers\n"); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 64 | for (i=0; i<3; i++) { |
| 65 | *ioapic_index = i; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 66 | printk(BIOS_SPEW, " reg 0x%04x:", i); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 67 | reg32 = *ioapic_data; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 68 | printk(BIOS_SPEW, " 0x%08x\n", reg32); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | *ioapic_index = 3; /* Select Boot Configuration register. */ |
| 72 | *ioapic_data = 1; /* Use Processor System Bus to deliver interrupts. */ |
| 73 | } |
| 74 | |
| 75 | static void i82801gx_enable_serial_irqs(struct device *dev) |
| 76 | { |
| 77 | /* Set packet length and toggle silent mode bit for one frame. */ |
| 78 | pci_write_config8(dev, SERIRQ_CNTL, |
| 79 | (1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0)); |
| 80 | } |
| 81 | |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 82 | /* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control |
| 83 | * 0x00 - 0000 = Reserved |
| 84 | * 0x01 - 0001 = Reserved |
| 85 | * 0x02 - 0010 = Reserved |
| 86 | * 0x03 - 0011 = IRQ3 |
| 87 | * 0x04 - 0100 = IRQ4 |
| 88 | * 0x05 - 0101 = IRQ5 |
| 89 | * 0x06 - 0110 = IRQ6 |
| 90 | * 0x07 - 0111 = IRQ7 |
| 91 | * 0x08 - 1000 = Reserved |
| 92 | * 0x09 - 1001 = IRQ9 |
| 93 | * 0x0A - 1010 = IRQ10 |
| 94 | * 0x0B - 1011 = IRQ11 |
| 95 | * 0x0C - 1100 = IRQ12 |
| 96 | * 0x0D - 1101 = Reserved |
| 97 | * 0x0E - 1110 = IRQ14 |
| 98 | * 0x0F - 1111 = IRQ15 |
| 99 | * PIRQ[n]_ROUT[7] - PIRQ Routing Control |
| 100 | * 0x80 - The PIRQ is not routed. |
| 101 | */ |
| 102 | |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 103 | static void i82801gx_pirq_init(device_t dev) |
| 104 | { |
Stefan Reinauer | 54309d6 | 2009-01-20 22:53:10 +0000 | [diff] [blame] | 105 | device_t irq_dev; |
| 106 | /* Get the chip configuration */ |
| 107 | config_t *config = dev->chip_info; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 108 | |
Stefan Reinauer | 54309d6 | 2009-01-20 22:53:10 +0000 | [diff] [blame] | 109 | pci_write_config8(dev, PIRQA_ROUT, config->pirqa_routing); |
| 110 | pci_write_config8(dev, PIRQB_ROUT, config->pirqb_routing); |
| 111 | pci_write_config8(dev, PIRQC_ROUT, config->pirqc_routing); |
| 112 | pci_write_config8(dev, PIRQD_ROUT, config->pirqd_routing); |
| 113 | |
| 114 | pci_write_config8(dev, PIRQE_ROUT, config->pirqe_routing); |
| 115 | pci_write_config8(dev, PIRQF_ROUT, config->pirqf_routing); |
| 116 | pci_write_config8(dev, PIRQG_ROUT, config->pirqg_routing); |
| 117 | pci_write_config8(dev, PIRQH_ROUT, config->pirqh_routing); |
| 118 | |
| 119 | /* Eric Biederman once said we should let the OS do this. |
| 120 | * I am not so sure anymore he was right. |
| 121 | */ |
| 122 | |
| 123 | for(irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) { |
| 124 | u8 int_pin=0, int_line=0; |
| 125 | |
| 126 | if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI) |
| 127 | continue; |
| 128 | |
| 129 | int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN); |
| 130 | |
| 131 | switch (int_pin) { |
| 132 | case 1: /* INTA# */ int_line = config->pirqa_routing; break; |
| 133 | case 2: /* INTB# */ int_line = config->pirqb_routing; break; |
| 134 | case 3: /* INTC# */ int_line = config->pirqc_routing; break; |
| 135 | case 4: /* INTD# */ int_line = config->pirqd_routing; break; |
| 136 | } |
| 137 | |
| 138 | if (!int_line) |
| 139 | continue; |
| 140 | |
| 141 | pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line); |
| 142 | } |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 145 | static void i82801gx_gpi_routing(device_t dev) |
| 146 | { |
| 147 | /* Get the chip configuration */ |
| 148 | config_t *config = dev->chip_info; |
| 149 | u32 reg32 = 0; |
| 150 | |
| 151 | /* An array would be much nicer here, or some |
| 152 | * other method of doing this. |
| 153 | */ |
| 154 | reg32 |= (config->gpi0_routing & 0x03) << 0; |
| 155 | reg32 |= (config->gpi1_routing & 0x03) << 2; |
| 156 | reg32 |= (config->gpi2_routing & 0x03) << 4; |
| 157 | reg32 |= (config->gpi3_routing & 0x03) << 6; |
| 158 | reg32 |= (config->gpi4_routing & 0x03) << 8; |
| 159 | reg32 |= (config->gpi5_routing & 0x03) << 10; |
| 160 | reg32 |= (config->gpi6_routing & 0x03) << 12; |
| 161 | reg32 |= (config->gpi7_routing & 0x03) << 14; |
| 162 | reg32 |= (config->gpi8_routing & 0x03) << 16; |
| 163 | reg32 |= (config->gpi9_routing & 0x03) << 18; |
| 164 | reg32 |= (config->gpi10_routing & 0x03) << 20; |
| 165 | reg32 |= (config->gpi11_routing & 0x03) << 22; |
| 166 | reg32 |= (config->gpi12_routing & 0x03) << 24; |
| 167 | reg32 |= (config->gpi13_routing & 0x03) << 26; |
| 168 | reg32 |= (config->gpi14_routing & 0x03) << 28; |
| 169 | reg32 |= (config->gpi15_routing & 0x03) << 30; |
| 170 | |
| 171 | pci_write_config32(dev, 0xb8, reg32); |
| 172 | } |
| 173 | |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 174 | static void i82801gx_power_options(device_t dev) |
| 175 | { |
| 176 | u8 reg8; |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 177 | u16 reg16, pmbase; |
| 178 | u32 reg32; |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 179 | const char *state; |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 180 | /* Get the chip configuration */ |
| 181 | config_t *config = dev->chip_info; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 182 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 183 | int pwr_on=CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL; |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 184 | int nmi_option; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 185 | |
| 186 | /* Which state do we want to goto after g3 (power restored)? |
| 187 | * 0 == S0 Full On |
| 188 | * 1 == S5 Soft Off |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 189 | * |
| 190 | * If the option is not existent (Laptops), use MAINBOARD_POWER_ON. |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 191 | */ |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 192 | if (get_option(&pwr_on, "power_on_after_fail") < 0) |
| 193 | pwr_on = MAINBOARD_POWER_ON; |
| 194 | |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 195 | reg8 = pci_read_config8(dev, GEN_PMCON_3); |
| 196 | reg8 &= 0xfe; |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 197 | switch (pwr_on) { |
| 198 | case MAINBOARD_POWER_OFF: |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 199 | reg8 |= 1; |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 200 | state = "off"; |
| 201 | break; |
| 202 | case MAINBOARD_POWER_ON: |
| 203 | reg8 &= ~1; |
| 204 | state = "on"; |
| 205 | break; |
| 206 | case MAINBOARD_POWER_KEEP: |
| 207 | reg8 &= ~1; |
| 208 | state = "state keep"; |
| 209 | break; |
| 210 | default: |
| 211 | state = "undefined"; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 212 | } |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 213 | |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 214 | reg8 |= (3 << 4); /* avoid #S4 assertions */ |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 215 | reg8 &= ~(1 << 3); /* minimum asssertion is 1 to 2 RTCCLK */ |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 216 | |
| 217 | pci_write_config8(dev, GEN_PMCON_3, reg8); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 218 | printk(BIOS_INFO, "Set power %s after power failure.\n", state); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 219 | |
| 220 | /* Set up NMI on errors. */ |
| 221 | reg8 = inb(0x61); |
| 222 | reg8 &= 0x0f; /* Higher Nibble must be 0 */ |
| 223 | reg8 &= ~(1 << 3); /* IOCHK# NMI Enable */ |
| 224 | // reg8 &= ~(1 << 2); /* PCI SERR# Enable */ |
| 225 | reg8 |= (1 << 2); /* PCI SERR# Disable for now */ |
| 226 | outb(reg8, 0x61); |
| 227 | |
| 228 | reg8 = inb(0x70); |
| 229 | nmi_option = NMI_OFF; |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 230 | get_option(&nmi_option, "nmi"); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 231 | if (nmi_option) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 232 | printk(BIOS_INFO, "NMI sources enabled.\n"); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 233 | reg8 &= ~(1 << 7); /* Set NMI. */ |
| 234 | } else { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 235 | printk(BIOS_INFO, "NMI sources disabled.\n"); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 236 | reg8 |= ( 1 << 7); /* Can't mask NMI from PCI-E and NMI_NOW */ |
| 237 | } |
| 238 | outb(reg8, 0x70); |
| 239 | |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 240 | /* Enable CPU_SLP# and Intel Speedstep, set SMI# rate down */ |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 241 | reg16 = pci_read_config16(dev, GEN_PMCON_1); |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 242 | reg16 &= ~(3 << 0); // SMI# rate 1 minute |
| 243 | reg16 |= (1 << 2); // CLKRUN_EN - Mobile/Ultra only |
| 244 | reg16 |= (1 << 3); // Speedstep Enable - Mobile/Ultra only |
| 245 | reg16 |= (1 << 5); // CPUSLP_EN Desktop only |
| 246 | // another laptop wants this? |
| 247 | // reg16 &= ~(1 << 10); // BIOS_PCI_EXP_EN - Desktop/Mobile only |
| 248 | reg16 |= (1 << 10); // BIOS_PCI_EXP_EN - Desktop/Mobile only |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 249 | #if DEBUG_PERIODIC_SMIS |
| 250 | /* Set DEBUG_PERIODIC_SMIS in i82801gx.h to debug using |
| 251 | * periodic SMIs. |
| 252 | */ |
| 253 | reg16 |= (3 << 0); // Periodic SMI every 8s |
| 254 | #endif |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 255 | pci_write_config16(dev, GEN_PMCON_1, reg16); |
| 256 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 257 | // Set the board's GPI routing. |
| 258 | i82801gx_gpi_routing(dev); |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 259 | |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 260 | pmbase = pci_read_config16(dev, 0x40) & 0xfffe; |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 261 | |
| 262 | outl(config->gpe0_en, pmbase + GPE0_EN); |
| 263 | outw(config->alt_gp_smi_en, pmbase + ALT_GP_SMI_EN); |
| 264 | |
| 265 | /* Set up power management block and determine sleep mode */ |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 266 | reg32 = inl(pmbase + 0x04); // PM1_CNT |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 267 | |
| 268 | reg32 &= ~(7 << 10); // SLP_TYP |
| 269 | reg32 |= (1 << 1); // enable C3->C0 transition on bus master |
| 270 | reg32 |= (1 << 0); // SCI_EN |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 271 | outl(reg32, pmbase + 0x04); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 274 | static void i82801gx_configure_cstates(device_t dev) |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 275 | { |
| 276 | u8 reg8; |
Stefan Reinauer | 109ab31 | 2009-08-12 16:08:05 +0000 | [diff] [blame] | 277 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 278 | reg8 = pci_read_config8(dev, 0xa9); // Cx state configuration |
| 279 | reg8 |= (1 << 4) | (1 << 3) | (1 << 2); // Enable Popup & Popdown |
| 280 | pci_write_config8(dev, 0xa9, reg8); |
| 281 | |
| 282 | // Set Deeper Sleep configuration to recommended values |
| 283 | reg8 = pci_read_config8(dev, 0xaa); |
| 284 | reg8 &= 0xf0; |
| 285 | reg8 |= (2 << 2); // Deeper Sleep to Stop CPU: 34-40us |
| 286 | reg8 |= (2 << 0); // Deeper Sleep to Sleep: 15us |
| 287 | pci_write_config8(dev, 0xaa, reg8); |
| 288 | } |
| 289 | |
| 290 | static void i82801gx_rtc_init(struct device *dev) |
| 291 | { |
| 292 | u8 reg8; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 293 | int rtc_failed; |
| 294 | |
| 295 | reg8 = pci_read_config8(dev, GEN_PMCON_3); |
| 296 | rtc_failed = reg8 & RTC_BATTERY_DEAD; |
| 297 | if (rtc_failed) { |
| 298 | reg8 &= ~RTC_BATTERY_DEAD; |
| 299 | pci_write_config8(dev, GEN_PMCON_3, reg8); |
| 300 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 301 | printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 302 | |
| 303 | rtc_init(rtc_failed); |
| 304 | } |
| 305 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 306 | static void enable_hpet(void) |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 307 | { |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 308 | u32 reg32; |
Stefan Reinauer | 109ab31 | 2009-08-12 16:08:05 +0000 | [diff] [blame] | 309 | |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 310 | /* Move HPET to default address 0xfed00000 and enable it */ |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 311 | reg32 = RCBA32(HPTC); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 312 | reg32 |= (1 << 7); // HPET Address Enable |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 313 | reg32 &= ~(3 << 0); |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 314 | RCBA32(HPTC) = reg32; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 315 | } |
| 316 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 317 | static void enable_clock_gating(void) |
| 318 | { |
| 319 | u32 reg32; |
Stefan Reinauer | 109ab31 | 2009-08-12 16:08:05 +0000 | [diff] [blame] | 320 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 321 | /* Enable Clock Gating for most devices */ |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 322 | reg32 = RCBA32(CG); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 323 | reg32 |= (1 << 31); // LPC clock gating |
| 324 | reg32 |= (1 << 30); // PATA clock gating |
| 325 | // SATA clock gating |
| 326 | reg32 |= (1 << 27) | (1 << 26) | (1 << 25) | (1 << 24); |
| 327 | reg32 |= (1 << 23); // AC97 clock gating |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 328 | reg32 |= (1 << 19); // USB EHCI clock gating |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 329 | reg32 |= (1 << 3) | (1 << 1); // DMI clock gating |
| 330 | reg32 |= (1 << 2); // PCIe clock gating; |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 331 | reg32 &= ~(1 << 20); // No static clock gating for USB |
| 332 | reg32 &= ~( (1 << 29) | (1 << 28) ); // Disable UHCI clock gating |
| 333 | RCBA32(CG) = reg32; |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 334 | } |
Stefan Reinauer | 269563a | 2009-01-19 21:20:22 +0000 | [diff] [blame] | 335 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 336 | #if CONFIG_HAVE_SMI_HANDLER |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 337 | static void i82801gx_lock_smm(struct device *dev) |
| 338 | { |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 339 | #if TEST_SMM_FLASH_LOCKDOWN |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 340 | u8 reg8; |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 341 | #endif |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 342 | |
Sven Schnelle | e261807 | 2011-06-05 11:39:12 +0200 | [diff] [blame] | 343 | if (acpi_slp_type != 3) { |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 344 | #if ENABLE_ACPI_MODE_IN_COREBOOT |
Sven Schnelle | f4dc1a7 | 2011-06-05 11:33:41 +0200 | [diff] [blame] | 345 | printk(BIOS_DEBUG, "Enabling ACPI via APMC:\n"); |
| 346 | outb(APM_CNT_ACPI_ENABLE, APM_CNT); // Enable ACPI mode |
| 347 | printk(BIOS_DEBUG, "done.\n"); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 348 | #else |
Sven Schnelle | f4dc1a7 | 2011-06-05 11:33:41 +0200 | [diff] [blame] | 349 | printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n"); |
| 350 | outb(APM_CNT_ACPI_DISABLE, APM_CNT); // Disable ACPI mode |
| 351 | printk(BIOS_DEBUG, "done.\n"); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 352 | #endif |
Sven Schnelle | e261807 | 2011-06-05 11:39:12 +0200 | [diff] [blame] | 353 | } else { |
| 354 | printk(BIOS_DEBUG, "S3 wakeup, enabling ACPI via APMC\n"); |
| 355 | outb(APM_CNT_ACPI_ENABLE, APM_CNT); |
| 356 | } |
Stefan Reinauer | 109ab31 | 2009-08-12 16:08:05 +0000 | [diff] [blame] | 357 | /* Don't allow evil boot loaders, kernels, or |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 358 | * userspace applications to deceive us: |
| 359 | */ |
| 360 | smm_lock(); |
| 361 | |
| 362 | #if TEST_SMM_FLASH_LOCKDOWN |
| 363 | /* Now try this: */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 364 | printk(BIOS_DEBUG, "Locking BIOS to RO... "); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 365 | reg8 = pci_read_config8(dev, 0xdc); /* BIOS_CNTL */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 366 | printk(BIOS_DEBUG, " BLE: %s; BWE: %s\n", (reg8&2)?"on":"off", |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 367 | (reg8&1)?"rw":"ro"); |
| 368 | reg8 &= ~(1 << 0); /* clear BIOSWE */ |
| 369 | pci_write_config8(dev, 0xdc, reg8); |
| 370 | reg8 |= (1 << 1); /* set BLE */ |
| 371 | pci_write_config8(dev, 0xdc, reg8); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 372 | printk(BIOS_DEBUG, "ok.\n"); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 373 | reg8 = pci_read_config8(dev, 0xdc); /* BIOS_CNTL */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 374 | printk(BIOS_DEBUG, " BLE: %s; BWE: %s\n", (reg8&2)?"on":"off", |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 375 | (reg8&1)?"rw":"ro"); |
| 376 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 377 | printk(BIOS_DEBUG, "Writing:\n"); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 378 | *(volatile u8 *)0xfff00000 = 0x00; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 379 | printk(BIOS_DEBUG, "Testing:\n"); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 380 | reg8 |= (1 << 0); /* set BIOSWE */ |
| 381 | pci_write_config8(dev, 0xdc, reg8); |
| 382 | |
| 383 | reg8 = pci_read_config8(dev, 0xdc); /* BIOS_CNTL */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 384 | printk(BIOS_DEBUG, " BLE: %s; BWE: %s\n", (reg8&2)?"on":"off", |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 385 | (reg8&1)?"rw":"ro"); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 386 | printk(BIOS_DEBUG, "Done.\n"); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 387 | #endif |
| 388 | } |
Stefan Reinauer | 269563a | 2009-01-19 21:20:22 +0000 | [diff] [blame] | 389 | #endif |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 390 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 391 | #define SPIBASE 0x3020 |
| 392 | static void i82801gx_spi_init(void) |
| 393 | { |
| 394 | u16 spicontrol; |
| 395 | |
| 396 | spicontrol = RCBA16(SPIBASE + 2); |
| 397 | spicontrol &= ~(1 << 0); // SPI Access Request |
| 398 | RCBA16(SPIBASE + 2) = spicontrol; |
| 399 | } |
| 400 | |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 401 | static void i82801gx_fixups(struct device *dev) |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 402 | { |
| 403 | /* This needs to happen after PCI enumeration */ |
| 404 | RCBA32(0x1d40) |= 1; |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 405 | |
| 406 | /* USB Transient Disconnect Detect: |
| 407 | * Prevent a SE0 condition on the USB ports from being |
| 408 | * interpreted by the UHCI controller as a disconnect |
| 409 | */ |
| 410 | pci_write_config8(dev, 0xad, 0x3); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 411 | } |
| 412 | |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 413 | static void lpc_init(struct device *dev) |
| 414 | { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 415 | printk(BIOS_DEBUG, "i82801gx: lpc_init\n"); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 416 | |
| 417 | /* Set the value for PCI command register. */ |
| 418 | pci_write_config16(dev, PCI_COMMAND, 0x000f); |
| 419 | |
| 420 | /* IO APIC initialization. */ |
| 421 | i82801gx_enable_apic(dev); |
| 422 | |
| 423 | i82801gx_enable_serial_irqs(dev); |
| 424 | |
| 425 | /* Setup the PIRQ. */ |
| 426 | i82801gx_pirq_init(dev); |
| 427 | |
| 428 | /* Setup power options. */ |
| 429 | i82801gx_power_options(dev); |
| 430 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 431 | /* Configure Cx state registers */ |
| 432 | i82801gx_configure_cstates(dev); |
| 433 | |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 434 | /* Set the state of the GPIO lines. */ |
| 435 | //gpio_init(dev); |
| 436 | |
| 437 | /* Initialize the real time clock. */ |
| 438 | i82801gx_rtc_init(dev); |
| 439 | |
| 440 | /* Initialize ISA DMA. */ |
| 441 | isa_dma_init(); |
| 442 | |
| 443 | /* Initialize the High Precision Event Timers, if present. */ |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 444 | enable_hpet(); |
| 445 | |
| 446 | /* Initialize Clock Gating */ |
| 447 | enable_clock_gating(); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 448 | |
| 449 | setup_i8259(); |
| 450 | |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 451 | /* The OS should do this? */ |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 452 | /* Interrupt 9 should be level triggered (SCI) */ |
| 453 | i8259_configure_irq_trigger(9, 1); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 454 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 455 | #if CONFIG_HAVE_SMI_HANDLER |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 456 | i82801gx_lock_smm(dev); |
Stefan Reinauer | 269563a | 2009-01-19 21:20:22 +0000 | [diff] [blame] | 457 | #endif |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 458 | |
| 459 | i82801gx_spi_init(); |
| 460 | |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 461 | i82801gx_fixups(dev); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | static void i82801gx_lpc_read_resources(device_t dev) |
| 465 | { |
| 466 | struct resource *res; |
| 467 | |
| 468 | /* Get the normal PCI resources of this device. */ |
| 469 | pci_dev_read_resources(dev); |
| 470 | |
| 471 | /* Add an extra subtractive resource for both memory and I/O. */ |
| 472 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 473 | res->base = 0; |
| 474 | res->size = 0x1000; |
| 475 | res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | |
| 476 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 477 | |
| 478 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 479 | res->base = 0xff800000; |
| 480 | res->size = 0x00800000; /* 8 MB for flash */ |
| 481 | res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | |
| 482 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 483 | |
| 484 | res = new_resource(dev, 3); /* IOAPIC */ |
Uwe Hermann | 74d1a6e | 2010-10-12 17:34:08 +0000 | [diff] [blame] | 485 | res->base = IO_APIC_ADDR; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 486 | res->size = 0x00001000; |
| 487 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 488 | } |
| 489 | |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 490 | static void set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 491 | { |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 492 | if (!vendor || !device) { |
| 493 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 494 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 495 | } else { |
| 496 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 497 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 498 | } |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | static struct pci_operations pci_ops = { |
| 502 | .set_subsystem = set_subsystem, |
| 503 | }; |
| 504 | |
| 505 | static struct device_operations device_ops = { |
| 506 | .read_resources = i82801gx_lpc_read_resources, |
| 507 | .set_resources = pci_dev_set_resources, |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 508 | .enable_resources = pci_dev_enable_resources, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 509 | .init = lpc_init, |
| 510 | .scan_bus = scan_static_bus, |
| 511 | .enable = i82801gx_enable, |
| 512 | .ops_pci = &pci_ops, |
| 513 | }; |
| 514 | |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 515 | /* 82801GH (ICH7 DH) */ |
| 516 | static const struct pci_driver ich7_dh_lpc __pci_driver = { |
| 517 | .ops = &device_ops, |
| 518 | .vendor = PCI_VENDOR_ID_INTEL, |
| 519 | .device = 0x27b0, |
| 520 | }; |
| 521 | |
Stefan Reinauer | 54309d6 | 2009-01-20 22:53:10 +0000 | [diff] [blame] | 522 | /* 82801GB/GR (ICH7/ICH7R) */ |
| 523 | static const struct pci_driver ich7_ich7r_lpc __pci_driver = { |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 524 | .ops = &device_ops, |
| 525 | .vendor = PCI_VENDOR_ID_INTEL, |
Uwe Hermann | 5d7a1c8 | 2008-10-31 18:41:09 +0000 | [diff] [blame] | 526 | .device = 0x27b8, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 527 | }; |
| 528 | |
Uwe Hermann | bddc693 | 2008-10-29 13:51:31 +0000 | [diff] [blame] | 529 | /* 82801GBM/GU (ICH7-M/ICH7-U) */ |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 530 | static const struct pci_driver ich7m_ich7u_lpc __pci_driver = { |
| 531 | .ops = &device_ops, |
| 532 | .vendor = PCI_VENDOR_ID_INTEL, |
Uwe Hermann | 5d7a1c8 | 2008-10-31 18:41:09 +0000 | [diff] [blame] | 533 | .device = 0x27b9, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 534 | }; |
| 535 | |
Uwe Hermann | bddc693 | 2008-10-29 13:51:31 +0000 | [diff] [blame] | 536 | /* 82801GHM (ICH7-M DH) */ |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 537 | static const struct pci_driver ich7m_dh_lpc __pci_driver = { |
| 538 | .ops = &device_ops, |
| 539 | .vendor = PCI_VENDOR_ID_INTEL, |
Uwe Hermann | 5d7a1c8 | 2008-10-31 18:41:09 +0000 | [diff] [blame] | 540 | .device = 0x27bd, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 541 | }; |