Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 coresystems GmbH |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame^] | 5 | * Copyright 2013 Google Inc. |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 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, MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | #include <console/console.h> |
| 23 | #include <device/device.h> |
| 24 | #include <device/pci.h> |
| 25 | #include <device/pci_ids.h> |
| 26 | #include <pc80/mc146818rtc.h> |
| 27 | #include <pc80/isa-dma.h> |
| 28 | #include <pc80/i8259.h> |
| 29 | #include <arch/io.h> |
| 30 | #include <arch/ioapic.h> |
| 31 | #include <arch/acpi.h> |
| 32 | #include <cpu/cpu.h> |
Aaron Durbin | 29ffa54 | 2012-12-21 21:21:48 -0600 | [diff] [blame] | 33 | #include <cpu/x86/smm.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 34 | #include <elog.h> |
| 35 | #include "pch.h" |
| 36 | |
| 37 | #define NMI_OFF 0 |
| 38 | |
| 39 | #define ENABLE_ACPI_MODE_IN_COREBOOT 0 |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 40 | |
| 41 | typedef struct southbridge_intel_lynxpoint_config config_t; |
| 42 | |
| 43 | static void pch_enable_apic(struct device *dev) |
| 44 | { |
| 45 | int i; |
| 46 | u32 reg32; |
| 47 | volatile u32 *ioapic_index = (volatile u32 *)(IO_APIC_ADDR); |
| 48 | volatile u32 *ioapic_data = (volatile u32 *)(IO_APIC_ADDR + 0x10); |
| 49 | |
| 50 | /* Enable ACPI I/O and power management. |
| 51 | * Set SCI IRQ to IRQ9 |
| 52 | */ |
| 53 | pci_write_config8(dev, ACPI_CNTL, 0x80); |
| 54 | |
| 55 | *ioapic_index = 0; |
| 56 | *ioapic_data = (1 << 25); |
| 57 | |
| 58 | /* affirm full set of redirection table entries ("write once") */ |
| 59 | *ioapic_index = 1; |
| 60 | reg32 = *ioapic_data; |
| 61 | *ioapic_index = 1; |
| 62 | *ioapic_data = reg32; |
| 63 | |
| 64 | *ioapic_index = 0; |
| 65 | reg32 = *ioapic_data; |
| 66 | printk(BIOS_DEBUG, "Southbridge APIC ID = %x\n", (reg32 >> 24) & 0x0f); |
| 67 | if (reg32 != (1 << 25)) |
| 68 | die("APIC Error\n"); |
| 69 | |
| 70 | printk(BIOS_SPEW, "Dumping IOAPIC registers\n"); |
| 71 | for (i=0; i<3; i++) { |
| 72 | *ioapic_index = i; |
| 73 | printk(BIOS_SPEW, " reg 0x%04x:", i); |
| 74 | reg32 = *ioapic_data; |
| 75 | printk(BIOS_SPEW, " 0x%08x\n", reg32); |
| 76 | } |
| 77 | |
| 78 | *ioapic_index = 3; /* Select Boot Configuration register. */ |
| 79 | *ioapic_data = 1; /* Use Processor System Bus to deliver interrupts. */ |
| 80 | } |
| 81 | |
| 82 | static void pch_enable_serial_irqs(struct device *dev) |
| 83 | { |
| 84 | /* Set packet length and toggle silent mode bit for one frame. */ |
| 85 | pci_write_config8(dev, SERIRQ_CNTL, |
| 86 | (1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0)); |
| 87 | #if !CONFIG_SERIRQ_CONTINUOUS_MODE |
| 88 | pci_write_config8(dev, SERIRQ_CNTL, |
| 89 | (1 << 7) | (0 << 6) | ((21 - 17) << 2) | (0 << 0)); |
| 90 | #endif |
| 91 | } |
| 92 | |
| 93 | /* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control |
| 94 | * 0x00 - 0000 = Reserved |
| 95 | * 0x01 - 0001 = Reserved |
| 96 | * 0x02 - 0010 = Reserved |
| 97 | * 0x03 - 0011 = IRQ3 |
| 98 | * 0x04 - 0100 = IRQ4 |
| 99 | * 0x05 - 0101 = IRQ5 |
| 100 | * 0x06 - 0110 = IRQ6 |
| 101 | * 0x07 - 0111 = IRQ7 |
| 102 | * 0x08 - 1000 = Reserved |
| 103 | * 0x09 - 1001 = IRQ9 |
| 104 | * 0x0A - 1010 = IRQ10 |
| 105 | * 0x0B - 1011 = IRQ11 |
| 106 | * 0x0C - 1100 = IRQ12 |
| 107 | * 0x0D - 1101 = Reserved |
| 108 | * 0x0E - 1110 = IRQ14 |
| 109 | * 0x0F - 1111 = IRQ15 |
| 110 | * PIRQ[n]_ROUT[7] - PIRQ Routing Control |
| 111 | * 0x80 - The PIRQ is not routed. |
| 112 | */ |
| 113 | |
| 114 | static void pch_pirq_init(device_t dev) |
| 115 | { |
| 116 | device_t irq_dev; |
| 117 | /* Get the chip configuration */ |
| 118 | config_t *config = dev->chip_info; |
| 119 | |
| 120 | pci_write_config8(dev, PIRQA_ROUT, config->pirqa_routing); |
| 121 | pci_write_config8(dev, PIRQB_ROUT, config->pirqb_routing); |
| 122 | pci_write_config8(dev, PIRQC_ROUT, config->pirqc_routing); |
| 123 | pci_write_config8(dev, PIRQD_ROUT, config->pirqd_routing); |
| 124 | |
| 125 | pci_write_config8(dev, PIRQE_ROUT, config->pirqe_routing); |
| 126 | pci_write_config8(dev, PIRQF_ROUT, config->pirqf_routing); |
| 127 | pci_write_config8(dev, PIRQG_ROUT, config->pirqg_routing); |
| 128 | pci_write_config8(dev, PIRQH_ROUT, config->pirqh_routing); |
| 129 | |
| 130 | /* Eric Biederman once said we should let the OS do this. |
| 131 | * I am not so sure anymore he was right. |
| 132 | */ |
| 133 | |
| 134 | for(irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) { |
| 135 | u8 int_pin=0, int_line=0; |
| 136 | |
| 137 | if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI) |
| 138 | continue; |
| 139 | |
| 140 | int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN); |
| 141 | |
| 142 | switch (int_pin) { |
| 143 | case 1: /* INTA# */ int_line = config->pirqa_routing; break; |
| 144 | case 2: /* INTB# */ int_line = config->pirqb_routing; break; |
| 145 | case 3: /* INTC# */ int_line = config->pirqc_routing; break; |
| 146 | case 4: /* INTD# */ int_line = config->pirqd_routing; break; |
| 147 | } |
| 148 | |
| 149 | if (!int_line) |
| 150 | continue; |
| 151 | |
| 152 | pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | static void pch_gpi_routing(device_t dev) |
| 157 | { |
| 158 | /* Get the chip configuration */ |
| 159 | config_t *config = dev->chip_info; |
| 160 | u32 reg32 = 0; |
| 161 | |
| 162 | /* An array would be much nicer here, or some |
| 163 | * other method of doing this. |
| 164 | */ |
| 165 | reg32 |= (config->gpi0_routing & 0x03) << 0; |
| 166 | reg32 |= (config->gpi1_routing & 0x03) << 2; |
| 167 | reg32 |= (config->gpi2_routing & 0x03) << 4; |
| 168 | reg32 |= (config->gpi3_routing & 0x03) << 6; |
| 169 | reg32 |= (config->gpi4_routing & 0x03) << 8; |
| 170 | reg32 |= (config->gpi5_routing & 0x03) << 10; |
| 171 | reg32 |= (config->gpi6_routing & 0x03) << 12; |
| 172 | reg32 |= (config->gpi7_routing & 0x03) << 14; |
| 173 | reg32 |= (config->gpi8_routing & 0x03) << 16; |
| 174 | reg32 |= (config->gpi9_routing & 0x03) << 18; |
| 175 | reg32 |= (config->gpi10_routing & 0x03) << 20; |
| 176 | reg32 |= (config->gpi11_routing & 0x03) << 22; |
| 177 | reg32 |= (config->gpi12_routing & 0x03) << 24; |
| 178 | reg32 |= (config->gpi13_routing & 0x03) << 26; |
| 179 | reg32 |= (config->gpi14_routing & 0x03) << 28; |
| 180 | reg32 |= (config->gpi15_routing & 0x03) << 30; |
| 181 | |
| 182 | pci_write_config32(dev, 0xb8, reg32); |
| 183 | } |
| 184 | |
| 185 | static void pch_power_options(device_t dev) |
| 186 | { |
| 187 | u8 reg8; |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame^] | 188 | u16 reg16; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 189 | u32 reg32; |
| 190 | const char *state; |
| 191 | /* Get the chip configuration */ |
| 192 | config_t *config = dev->chip_info; |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame^] | 193 | u16 pmbase = get_pmbase(); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 194 | int pwr_on=CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL; |
| 195 | int nmi_option; |
| 196 | |
| 197 | /* Which state do we want to goto after g3 (power restored)? |
| 198 | * 0 == S0 Full On |
| 199 | * 1 == S5 Soft Off |
| 200 | * |
| 201 | * If the option is not existent (Laptops), use Kconfig setting. |
| 202 | */ |
| 203 | get_option(&pwr_on, "power_on_after_fail"); |
| 204 | |
| 205 | reg16 = pci_read_config16(dev, GEN_PMCON_3); |
| 206 | reg16 &= 0xfffe; |
| 207 | switch (pwr_on) { |
| 208 | case MAINBOARD_POWER_OFF: |
| 209 | reg16 |= 1; |
| 210 | state = "off"; |
| 211 | break; |
| 212 | case MAINBOARD_POWER_ON: |
| 213 | reg16 &= ~1; |
| 214 | state = "on"; |
| 215 | break; |
| 216 | case MAINBOARD_POWER_KEEP: |
| 217 | reg16 &= ~1; |
| 218 | state = "state keep"; |
| 219 | break; |
| 220 | default: |
| 221 | state = "undefined"; |
| 222 | } |
| 223 | |
| 224 | reg16 &= ~(3 << 4); /* SLP_S4# Assertion Stretch 4s */ |
| 225 | reg16 |= (1 << 3); /* SLP_S4# Assertion Stretch Enable */ |
| 226 | |
| 227 | reg16 &= ~(1 << 10); |
| 228 | reg16 |= (1 << 11); /* SLP_S3# Min Assertion Width 50ms */ |
| 229 | |
| 230 | reg16 |= (1 << 12); /* Disable SLP stretch after SUS well */ |
| 231 | |
| 232 | pci_write_config16(dev, GEN_PMCON_3, reg16); |
| 233 | printk(BIOS_INFO, "Set power %s after power failure.\n", state); |
| 234 | |
| 235 | /* Set up NMI on errors. */ |
| 236 | reg8 = inb(0x61); |
| 237 | reg8 &= 0x0f; /* Higher Nibble must be 0 */ |
| 238 | reg8 &= ~(1 << 3); /* IOCHK# NMI Enable */ |
| 239 | // reg8 &= ~(1 << 2); /* PCI SERR# Enable */ |
| 240 | reg8 |= (1 << 2); /* PCI SERR# Disable for now */ |
| 241 | outb(reg8, 0x61); |
| 242 | |
| 243 | reg8 = inb(0x70); |
| 244 | nmi_option = NMI_OFF; |
| 245 | get_option(&nmi_option, "nmi"); |
| 246 | if (nmi_option) { |
| 247 | printk(BIOS_INFO, "NMI sources enabled.\n"); |
| 248 | reg8 &= ~(1 << 7); /* Set NMI. */ |
| 249 | } else { |
| 250 | printk(BIOS_INFO, "NMI sources disabled.\n"); |
| 251 | reg8 |= ( 1 << 7); /* Can't mask NMI from PCI-E and NMI_NOW */ |
| 252 | } |
| 253 | outb(reg8, 0x70); |
| 254 | |
| 255 | /* Enable CPU_SLP# and Intel Speedstep, set SMI# rate down */ |
| 256 | reg16 = pci_read_config16(dev, GEN_PMCON_1); |
| 257 | reg16 &= ~(3 << 0); // SMI# rate 1 minute |
| 258 | reg16 &= ~(1 << 10); // Disable BIOS_PCI_EXP_EN for native PME |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 259 | pci_write_config16(dev, GEN_PMCON_1, reg16); |
| 260 | |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame^] | 261 | /* |
| 262 | * Set the board's GPI routing on LynxPoint-H. |
| 263 | * This is done as part of GPIO configuration on LynxPoint-LP. |
| 264 | */ |
| 265 | if (pch_is_lp()) |
| 266 | pch_gpi_routing(dev); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 267 | |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame^] | 268 | /* GPE setup based on device tree configuration */ |
| 269 | enable_all_gpe(config->gpe0_en_1, config->gpe0_en_2, |
| 270 | config->gpe0_en_3, config->gpe0_en_4); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 271 | |
Duncan Laurie | 467f31d | 2013-03-08 17:00:37 -0800 | [diff] [blame^] | 272 | /* SMI setup based on device tree configuration */ |
| 273 | enable_alt_smi(config->alt_gp_smi_en); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 274 | |
| 275 | /* Set up power management block and determine sleep mode */ |
| 276 | reg32 = inl(pmbase + 0x04); // PM1_CNT |
| 277 | reg32 &= ~(7 << 10); // SLP_TYP |
| 278 | reg32 |= (1 << 0); // SCI_EN |
| 279 | outl(reg32, pmbase + 0x04); |
| 280 | |
| 281 | /* Clear magic status bits to prevent unexpected wake */ |
| 282 | reg32 = RCBA32(0x3310); |
| 283 | reg32 |= (1 << 4)|(1 << 5)|(1 << 0); |
| 284 | RCBA32(0x3310) = reg32; |
| 285 | |
| 286 | reg32 = RCBA32(0x3f02); |
| 287 | reg32 &= ~0xf; |
| 288 | RCBA32(0x3f02) = reg32; |
| 289 | } |
| 290 | |
| 291 | static void pch_rtc_init(struct device *dev) |
| 292 | { |
| 293 | u8 reg8; |
| 294 | int rtc_failed; |
| 295 | |
| 296 | reg8 = pci_read_config8(dev, GEN_PMCON_3); |
| 297 | rtc_failed = reg8 & RTC_BATTERY_DEAD; |
| 298 | if (rtc_failed) { |
| 299 | reg8 &= ~RTC_BATTERY_DEAD; |
| 300 | pci_write_config8(dev, GEN_PMCON_3, reg8); |
| 301 | #if CONFIG_ELOG |
| 302 | elog_add_event(ELOG_TYPE_RTC_RESET); |
| 303 | #endif |
| 304 | } |
| 305 | printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed); |
| 306 | |
| 307 | rtc_init(rtc_failed); |
| 308 | } |
| 309 | |
| 310 | /* CougarPoint PCH Power Management init */ |
| 311 | #if 0 |
| 312 | static void cpt_pm_init(struct device *dev) |
| 313 | { |
| 314 | printk(BIOS_DEBUG, "CougarPoint PM init\n"); |
| 315 | pci_write_config8(dev, 0xa9, 0x47); |
| 316 | RCBA32_AND_OR(0x2238, ~0UL, (1 << 6)|(1 << 0)); |
| 317 | RCBA32_AND_OR(0x228c, ~0UL, (1 << 0)); |
| 318 | RCBA16_AND_OR(0x1100, ~0UL, (1 << 13)|(1 << 14)); |
| 319 | RCBA16_AND_OR(0x0900, ~0UL, (1 << 14)); |
| 320 | RCBA32(0x2304) = 0xc0388400; |
| 321 | RCBA32_AND_OR(0x2314, ~0UL, (1 << 5)|(1 << 18)); |
| 322 | RCBA32_AND_OR(0x2320, ~0UL, (1 << 15)|(1 << 1)); |
| 323 | RCBA32_AND_OR(0x3314, ~0x1f, 0xf); |
| 324 | RCBA32(0x3318) = 0x050f0000; |
| 325 | RCBA32(0x3324) = 0x04000000; |
| 326 | RCBA32_AND_OR(0x3340, ~0UL, 0xfffff); |
| 327 | RCBA32_AND_OR(0x3344, ~0UL, (1 << 1)); |
| 328 | RCBA32(0x3360) = 0x0001c000; |
| 329 | RCBA32(0x3368) = 0x00061100; |
| 330 | RCBA32(0x3378) = 0x7f8fdfff; |
| 331 | RCBA32(0x337c) = 0x000003fc; |
| 332 | RCBA32(0x3388) = 0x00001000; |
| 333 | RCBA32(0x3390) = 0x0001c000; |
| 334 | RCBA32(0x33a0) = 0x00000800; |
| 335 | RCBA32(0x33b0) = 0x00001000; |
| 336 | RCBA32(0x33c0) = 0x00093900; |
| 337 | RCBA32(0x33cc) = 0x24653002; |
| 338 | RCBA32(0x33d0) = 0x062108fe; |
| 339 | RCBA32_AND_OR(0x33d4, 0xf000f000, 0x00670060); |
| 340 | RCBA32(0x3a28) = 0x01010000; |
| 341 | RCBA32(0x3a2c) = 0x01010404; |
| 342 | RCBA32(0x3a80) = 0x01041041; |
| 343 | RCBA32_AND_OR(0x3a84, ~0x0000ffff, 0x00001001); |
| 344 | RCBA32_AND_OR(0x3a84, ~0UL, (1 << 24)); /* SATA 2/3 disabled */ |
| 345 | RCBA32_AND_OR(0x3a88, ~0UL, (1 << 0)); /* SATA 4/5 disabled */ |
| 346 | RCBA32(0x3a6c) = 0x00000001; |
| 347 | RCBA32_AND_OR(0x2344, 0x00ffff00, 0xff00000c); |
| 348 | RCBA32_AND_OR(0x80c, ~(0xff << 20), 0x11 << 20); |
| 349 | RCBA32(0x33c8) = 0; |
| 350 | RCBA32_AND_OR(0x21b0, ~0UL, 0xf); |
| 351 | } |
| 352 | #endif |
| 353 | |
| 354 | static void enable_hpet(void) |
| 355 | { |
| 356 | u32 reg32; |
| 357 | |
| 358 | /* Move HPET to default address 0xfed00000 and enable it */ |
| 359 | reg32 = RCBA32(HPTC); |
| 360 | reg32 |= (1 << 7); // HPET Address Enable |
| 361 | reg32 &= ~(3 << 0); |
| 362 | RCBA32(HPTC) = reg32; |
| 363 | /* Read it back to stick. It's affected by posted write syndrome. */ |
| 364 | reg32 = RCBA32(HPTC); |
| 365 | } |
| 366 | |
| 367 | static void enable_clock_gating(device_t dev) |
| 368 | { |
Duncan Laurie | 74c0d05 | 2012-12-17 11:31:40 -0800 | [diff] [blame] | 369 | #if CONFIG_INTEL_LYNXPOINT_LP |
| 370 | /* LynxPoint LP */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 371 | u32 reg32; |
| 372 | u16 reg16; |
| 373 | |
Duncan Laurie | 74c0d05 | 2012-12-17 11:31:40 -0800 | [diff] [blame] | 374 | /* DMI */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 375 | RCBA32_AND_OR(0x2234, ~0UL, 0xf); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 376 | reg16 = pci_read_config16(dev, GEN_PMCON_1); |
Duncan Laurie | 74c0d05 | 2012-12-17 11:31:40 -0800 | [diff] [blame] | 377 | reg16 &= ~((1 << 11) | (1 << 14)); |
| 378 | reg16 |= (1 << 5) | (1 << 6) | (1 << 7) | (1 << 12) | (1 << 13); |
| 379 | reg16 |= (1 << 2); // PCI CLKRUN# Enable |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 380 | pci_write_config16(dev, GEN_PMCON_1, reg16); |
| 381 | |
Duncan Laurie | 74c0d05 | 2012-12-17 11:31:40 -0800 | [diff] [blame] | 382 | reg32 = pci_read_config32(dev, 0x64); |
| 383 | reg32 |= (1 << 6); |
| 384 | pci_write_config32(dev, 0x64, reg32); |
| 385 | |
| 386 | RCBA32_AND_OR(0x2614, 0x8fffffff, 0x0f006500); |
| 387 | RCBA32_OR(0x900, 0x0000031f); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 388 | |
| 389 | reg32 = RCBA32(CG); |
Duncan Laurie | 74c0d05 | 2012-12-17 11:31:40 -0800 | [diff] [blame] | 390 | reg32 |= (1 << 31); // LPC Dynamic |
| 391 | reg32 |= (1 << 30); // LP LPC |
| 392 | reg32 |= (1 << 28); // GPIO Dynamic |
| 393 | reg32 |= (1 << 27); // HPET Dynamic |
| 394 | reg32 |= (1 << 26); // LP LPC |
| 395 | reg32 |= (1 << 22); // HDA Dynamic |
| 396 | reg32 |= (1 << 16); // PCIe Dynamic |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 397 | RCBA32(CG) = reg32; |
| 398 | |
Duncan Laurie | 74c0d05 | 2012-12-17 11:31:40 -0800 | [diff] [blame] | 399 | RCBA32_OR(0x3434, 0x7); // LP LPC |
| 400 | |
| 401 | RCBA32_AND_OR(0x333c, 0xff0fffff, 0x00800000); // SATA |
| 402 | |
| 403 | RCBA32_OR(0x38c0, 0x3c07); // SPI Dynamic |
| 404 | |
| 405 | pch_iobp_update(0xCF000000, ~0UL, 0x00007001); |
| 406 | pch_iobp_update(0xCE00C000, ~0UL, 0x00000001); |
| 407 | #else |
| 408 | /* LynxPoint Mobile */ |
| 409 | u32 reg32; |
| 410 | u16 reg16; |
| 411 | |
| 412 | /* DMI */ |
| 413 | RCBA32_AND_OR(0x2234, ~0UL, 0xf); |
| 414 | reg16 = pci_read_config16(dev, GEN_PMCON_1); |
| 415 | reg16 |= (1 << 11) | (1 << 12) | (1 << 14); |
| 416 | reg16 |= (1 << 2); // PCI CLKRUN# Enable |
| 417 | pci_write_config16(dev, GEN_PMCON_1, reg16); |
| 418 | RCBA32_OR(0x900, (1 << 14)); |
| 419 | |
| 420 | reg32 = RCBA32(CG); |
| 421 | reg32 |= (1 << 22); // HDA Dynamic |
| 422 | reg32 |= (1 << 31); // LPC Dynamic |
| 423 | reg32 |= (1 << 16); // PCIe Dynamic |
| 424 | reg32 |= (1 << 27); // HPET Dynamic |
| 425 | reg32 |= (1 << 28); // GPIO Dynamic |
| 426 | RCBA32(CG) = reg32; |
| 427 | |
| 428 | RCBA32_OR(0x38c0, 0x7); // SPI Dynamic |
| 429 | #endif |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 430 | } |
| 431 | |
Aaron Durbin | 29ffa54 | 2012-12-21 21:21:48 -0600 | [diff] [blame] | 432 | static void pch_set_acpi_mode(void) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 433 | { |
Aaron Durbin | 29ffa54 | 2012-12-21 21:21:48 -0600 | [diff] [blame] | 434 | #if CONFIG_HAVE_SMI_HANDLER |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 435 | if (acpi_slp_type != 3) { |
| 436 | #if ENABLE_ACPI_MODE_IN_COREBOOT |
| 437 | printk(BIOS_DEBUG, "Enabling ACPI via APMC:\n"); |
Aaron Durbin | 29ffa54 | 2012-12-21 21:21:48 -0600 | [diff] [blame] | 438 | outb(APM_CNT_ACPI_ENABLE, APM_CNT); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 439 | printk(BIOS_DEBUG, "done.\n"); |
| 440 | #else |
| 441 | printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n"); |
Aaron Durbin | 29ffa54 | 2012-12-21 21:21:48 -0600 | [diff] [blame] | 442 | outb(APM_CNT_ACPI_DISABLE, APM_CNT); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 443 | printk(BIOS_DEBUG, "done.\n"); |
| 444 | #endif |
| 445 | } |
Aaron Durbin | 29ffa54 | 2012-12-21 21:21:48 -0600 | [diff] [blame] | 446 | #endif /* CONFIG_HAVE_SMI_HANDLER */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 447 | } |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 448 | |
| 449 | static void pch_disable_smm_only_flashing(struct device *dev) |
| 450 | { |
| 451 | u8 reg8; |
| 452 | |
| 453 | printk(BIOS_SPEW, "Enabling BIOS updates outside of SMM... "); |
| 454 | reg8 = pci_read_config8(dev, 0xdc); /* BIOS_CNTL */ |
| 455 | reg8 &= ~(1 << 5); |
| 456 | pci_write_config8(dev, 0xdc, reg8); |
| 457 | } |
| 458 | |
| 459 | static void pch_fixups(struct device *dev) |
| 460 | { |
| 461 | u8 gen_pmcon_2; |
| 462 | |
| 463 | /* Indicate DRAM init done for MRC S3 to know it can resume */ |
| 464 | gen_pmcon_2 = pci_read_config8(dev, GEN_PMCON_2); |
| 465 | gen_pmcon_2 |= (1 << 7); |
| 466 | pci_write_config8(dev, GEN_PMCON_2, gen_pmcon_2); |
| 467 | |
| 468 | /* |
| 469 | * Enable DMI ASPM in the PCH |
| 470 | */ |
| 471 | RCBA32_AND_OR(0x2304, ~(1 << 10), 0); |
| 472 | RCBA32_OR(0x21a4, (1 << 11)|(1 << 10)); |
| 473 | RCBA32_OR(0x21a8, 0x3); |
| 474 | } |
| 475 | |
| 476 | static void pch_decode_init(struct device *dev) |
| 477 | { |
| 478 | config_t *config = dev->chip_info; |
| 479 | |
| 480 | printk(BIOS_DEBUG, "pch_decode_init\n"); |
| 481 | |
| 482 | pci_write_config32(dev, LPC_GEN1_DEC, config->gen1_dec); |
| 483 | pci_write_config32(dev, LPC_GEN2_DEC, config->gen2_dec); |
| 484 | pci_write_config32(dev, LPC_GEN3_DEC, config->gen3_dec); |
| 485 | pci_write_config32(dev, LPC_GEN4_DEC, config->gen4_dec); |
| 486 | } |
| 487 | |
| 488 | static void lpc_init(struct device *dev) |
| 489 | { |
| 490 | printk(BIOS_DEBUG, "pch: lpc_init\n"); |
| 491 | |
| 492 | /* Set the value for PCI command register. */ |
| 493 | pci_write_config16(dev, PCI_COMMAND, 0x000f); |
| 494 | |
| 495 | /* IO APIC initialization. */ |
| 496 | pch_enable_apic(dev); |
| 497 | |
| 498 | pch_enable_serial_irqs(dev); |
| 499 | |
| 500 | /* Setup the PIRQ. */ |
| 501 | pch_pirq_init(dev); |
| 502 | |
| 503 | /* Setup power options. */ |
| 504 | pch_power_options(dev); |
| 505 | |
| 506 | /* Initialize power management */ |
| 507 | switch (pch_silicon_type()) { |
| 508 | default: |
| 509 | printk(BIOS_ERR, "Unknown Chipset: 0x%04x\n", dev->device); |
| 510 | } |
| 511 | |
| 512 | /* Set the state of the GPIO lines. */ |
| 513 | //gpio_init(dev); |
| 514 | |
| 515 | /* Initialize the real time clock. */ |
| 516 | pch_rtc_init(dev); |
| 517 | |
| 518 | /* Initialize ISA DMA. */ |
| 519 | isa_dma_init(); |
| 520 | |
| 521 | /* Initialize the High Precision Event Timers, if present. */ |
| 522 | enable_hpet(); |
| 523 | |
| 524 | /* Initialize Clock Gating */ |
| 525 | enable_clock_gating(dev); |
| 526 | |
| 527 | setup_i8259(); |
| 528 | |
| 529 | /* The OS should do this? */ |
| 530 | /* Interrupt 9 should be level triggered (SCI) */ |
| 531 | i8259_configure_irq_trigger(9, 1); |
| 532 | |
| 533 | pch_disable_smm_only_flashing(dev); |
| 534 | |
Aaron Durbin | 29ffa54 | 2012-12-21 21:21:48 -0600 | [diff] [blame] | 535 | pch_set_acpi_mode(); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 536 | |
| 537 | pch_fixups(dev); |
| 538 | } |
| 539 | |
Aaron Durbin | 6f561af | 2012-12-19 14:38:01 -0600 | [diff] [blame] | 540 | static void pch_lpc_add_mmio_resources(device_t dev) |
| 541 | { |
| 542 | u32 reg; |
| 543 | struct resource *res; |
| 544 | const u32 default_decode_base = IO_APIC_ADDR; |
| 545 | |
| 546 | /* |
| 547 | * Just report all resources from IO-APIC base to 4GiB. Don't mark |
| 548 | * them reserved as that may upset the OS if this range is marked |
| 549 | * as reserved in the e820. |
| 550 | */ |
| 551 | res = new_resource(dev, OIC); |
| 552 | res->base = default_decode_base; |
| 553 | res->size = 0 - default_decode_base; |
| 554 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 555 | |
| 556 | /* RCBA */ |
| 557 | if (DEFAULT_RCBA < default_decode_base) { |
| 558 | res = new_resource(dev, RCBA); |
| 559 | res->base = DEFAULT_RCBA; |
| 560 | res->size = 16 * 1024; |
| 561 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | |
| 562 | IORESOURCE_FIXED | IORESOURCE_RESERVE; |
| 563 | } |
| 564 | |
| 565 | /* Check LPC Memory Decode register. */ |
| 566 | reg = pci_read_config32(dev, LGMR); |
| 567 | if (reg & 1) { |
| 568 | reg &= ~0xffff; |
| 569 | if (reg < default_decode_base) { |
| 570 | res = new_resource(dev, LGMR); |
| 571 | res->base = reg; |
| 572 | res->size = 16 * 1024; |
| 573 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | |
| 574 | IORESOURCE_FIXED | IORESOURCE_RESERVE; |
| 575 | } |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | /* Default IO range claimed by the LPC device. The upper bound is exclusive. */ |
| 580 | #define LPC_DEFAULT_IO_RANGE_LOWER 0 |
| 581 | #define LPC_DEFAULT_IO_RANGE_UPPER 0x1000 |
| 582 | |
| 583 | static inline int pch_io_range_in_default(u16 base, u16 size) |
| 584 | { |
| 585 | /* Does it start above the range? */ |
| 586 | if (base >= LPC_DEFAULT_IO_RANGE_UPPER) |
| 587 | return 0; |
| 588 | |
| 589 | /* Is it entirely contained? */ |
| 590 | if (base >= LPC_DEFAULT_IO_RANGE_LOWER && |
| 591 | (base + size) < LPC_DEFAULT_IO_RANGE_UPPER) |
| 592 | return 1; |
| 593 | |
| 594 | /* This will return not in range for partial overlaps. */ |
| 595 | return 0; |
| 596 | } |
| 597 | |
| 598 | /* |
| 599 | * Note: this function assumes there is no overlap with the default LPC device's |
| 600 | * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER. |
| 601 | */ |
| 602 | static void pch_lpc_add_io_resource(device_t dev, u16 base, u16 size, int index) |
| 603 | { |
| 604 | struct resource *res; |
| 605 | |
| 606 | if (pch_io_range_in_default(base, size)) |
| 607 | return; |
| 608 | |
| 609 | res = new_resource(dev, index); |
| 610 | res->base = base; |
| 611 | res->size = size; |
| 612 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 613 | } |
| 614 | |
| 615 | static void pch_lpc_add_gen_io_resources(device_t dev, int reg_value, int index) |
| 616 | { |
| 617 | /* |
| 618 | * Check if the register is enabled. If so and the base exceeds the |
| 619 | * device's deafult claim range add the resoure. |
| 620 | */ |
| 621 | if (reg_value & 1) { |
| 622 | u16 base = reg_value & 0xfffc; |
| 623 | u16 size = (0x3 | ((reg_value >> 16) & 0xfc)) + 1; |
| 624 | pch_lpc_add_io_resource(dev, base, size, index); |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | static void pch_lpc_add_io_resources(device_t dev) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 629 | { |
| 630 | struct resource *res; |
| 631 | config_t *config = dev->chip_info; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 632 | |
Aaron Durbin | 6f561af | 2012-12-19 14:38:01 -0600 | [diff] [blame] | 633 | /* Add the default claimed IO range for the LPC device. */ |
| 634 | res = new_resource(dev, 0); |
| 635 | res->base = LPC_DEFAULT_IO_RANGE_LOWER; |
| 636 | res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER; |
| 637 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 638 | |
| 639 | /* GPIOBASE */ |
Duncan Laurie | 7922b46 | 2013-03-08 16:34:33 -0800 | [diff] [blame] | 640 | pch_lpc_add_io_resource(dev, get_gpiobase(), DEFAULT_GPIOSIZE, |
Aaron Durbin | 6f561af | 2012-12-19 14:38:01 -0600 | [diff] [blame] | 641 | GPIO_BASE); |
| 642 | |
| 643 | /* PMBASE */ |
Duncan Laurie | 7922b46 | 2013-03-08 16:34:33 -0800 | [diff] [blame] | 644 | pch_lpc_add_io_resource(dev, get_pmbase(), 256, PMBASE); |
Aaron Durbin | 6f561af | 2012-12-19 14:38:01 -0600 | [diff] [blame] | 645 | |
| 646 | /* LPC Generic IO Decode range. */ |
| 647 | pch_lpc_add_gen_io_resources(dev, config->gen1_dec, LPC_GEN1_DEC); |
| 648 | pch_lpc_add_gen_io_resources(dev, config->gen2_dec, LPC_GEN2_DEC); |
| 649 | pch_lpc_add_gen_io_resources(dev, config->gen3_dec, LPC_GEN3_DEC); |
| 650 | pch_lpc_add_gen_io_resources(dev, config->gen4_dec, LPC_GEN4_DEC); |
| 651 | } |
| 652 | |
| 653 | static void pch_lpc_read_resources(device_t dev) |
| 654 | { |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 655 | /* Get the normal PCI resources of this device. */ |
| 656 | pci_dev_read_resources(dev); |
| 657 | |
Aaron Durbin | 6f561af | 2012-12-19 14:38:01 -0600 | [diff] [blame] | 658 | /* Add non-standard MMIO resources. */ |
| 659 | pch_lpc_add_mmio_resources(dev); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 660 | |
Aaron Durbin | 6f561af | 2012-12-19 14:38:01 -0600 | [diff] [blame] | 661 | /* Add IO resources. */ |
| 662 | pch_lpc_add_io_resources(dev); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | static void pch_lpc_enable_resources(device_t dev) |
| 666 | { |
| 667 | pch_decode_init(dev); |
| 668 | return pci_dev_enable_resources(dev); |
| 669 | } |
| 670 | |
| 671 | static void pch_lpc_enable(device_t dev) |
| 672 | { |
| 673 | /* Enable PCH Display Port */ |
| 674 | RCBA16(DISPBDF) = 0x0010; |
| 675 | RCBA32_OR(FD2, PCH_ENABLE_DBDF); |
| 676 | |
| 677 | pch_enable(dev); |
| 678 | } |
| 679 | |
| 680 | static void set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 681 | { |
| 682 | if (!vendor || !device) { |
| 683 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 684 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 685 | } else { |
| 686 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 687 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | static struct pci_operations pci_ops = { |
| 692 | .set_subsystem = set_subsystem, |
| 693 | }; |
| 694 | |
| 695 | static struct device_operations device_ops = { |
| 696 | .read_resources = pch_lpc_read_resources, |
| 697 | .set_resources = pci_dev_set_resources, |
| 698 | .enable_resources = pch_lpc_enable_resources, |
| 699 | .init = lpc_init, |
| 700 | .enable = pch_lpc_enable, |
| 701 | .scan_bus = scan_static_bus, |
| 702 | .ops_pci = &pci_ops, |
| 703 | }; |
| 704 | |
| 705 | |
Aaron Durbin | c1989c4 | 2012-12-11 17:13:17 -0600 | [diff] [blame] | 706 | /* IDs for LPC device of Intel 8 Series Chipset (Lynx Point) */ |
| 707 | static const unsigned short pci_device_ids[] = { |
| 708 | 0x8c41, /* Mobile Full Featured Engineering Sample. */ |
| 709 | 0x8c42, /* Desktop Full Featured Engineering Sample. */ |
| 710 | 0x8c44, /* Z87 SKU */ |
| 711 | 0x8c46, /* Z85 SKU */ |
| 712 | 0x8c49, /* HM86 SKU */ |
| 713 | 0x8c4a, /* H87 SKU */ |
| 714 | 0x8c4b, /* HM87 SKU */ |
| 715 | 0x8c4c, /* Q85 SKU */ |
| 716 | 0x8c4e, /* Q87 SKU */ |
| 717 | 0x8c4f, /* QM87 SKU */ |
Duncan Laurie | 74c0d05 | 2012-12-17 11:31:40 -0800 | [diff] [blame] | 718 | 0x9c41, /* LP Full Featured Engineering Sample */ |
| 719 | 0x9c43, /* LP Premium SKU */ |
| 720 | 0x9c45, /* LP Mainstream SKU */ |
| 721 | 0x9c47, /* LP Value SKU */ |
Aaron Durbin | c1989c4 | 2012-12-11 17:13:17 -0600 | [diff] [blame] | 722 | 0 }; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 723 | |
| 724 | static const struct pci_driver pch_lpc __pci_driver = { |
| 725 | .ops = &device_ops, |
| 726 | .vendor = PCI_VENDOR_ID_INTEL, |
| 727 | .devices = pci_device_ids, |
| 728 | }; |
| 729 | |
| 730 | |