| 1 |
|
| 2 |
|
| 3 |
#include <cpu/intel/speedstep.h> |
| 4 |
#include <console/console.h> |
| 5 |
#include <device/device.h> |
| 6 |
#include <device/pci.h> |
| 7 |
#include <device/pci_ids.h> |
| 8 |
#include <option.h> |
| 9 |
#include <pc80/mc146818rtc.h> |
| 10 |
#include <pc80/isa-dma.h> |
| 11 |
#include <pc80/i8259.h> |
| 12 |
#include <arch/io.h> |
| 13 |
#include <device/pci_ops.h> |
| 14 |
#include <arch/ioapic.h> |
| 15 |
#include <acpi/acpi.h> |
| 16 |
#include <cpu/x86/smm.h> |
| 17 |
#include <acpi/acpigen.h> |
| 18 |
#include "chip.h" |
| 19 |
#include "i82801ix.h" |
| 20 |
#include <southbridge/intel/common/pciehp.h> |
| 21 |
#include <southbridge/intel/common/pmutil.h> |
| 22 |
#include <southbridge/intel/common/acpi_pirq_gen.h> |
| 23 |
#include <southbridge/intel/common/rcba_pirq.h> |
| 24 |
#include <static.h> |
| 25 |
|
| 26 |
#define NMI_OFF 0 |
| 27 |
|
| 28 |
typedef struct southbridge_intel_i82801ix_config config_t; |
| 29 |
|
| 30 |
static void i82801ix_enable_apic(struct device *dev) |
| 31 |
{ |
| 32 |
|
| 33 |
RCBA8(0x31ff) = 0x03; |
| 34 |
|
| 35 |
RCBA8(0x31ff); |
| 36 |
|
| 37 |
|
| 38 |
ioapic_lock_max_vectors(IO_APIC_ADDR); |
| 39 |
|
| 40 |
register_new_ioapic_gsi0(IO_APIC_ADDR); |
| 41 |
} |
| 42 |
|
| 43 |
static void i82801ix_enable_serial_irqs(struct device *dev) |
| 44 |
{ |
| 45 |
|
| 46 |
pci_write_config8(dev, D31F0_SERIRQ_CNTL, |
| 47 |
(1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0)); |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
static void i82801ix_pirq_init(struct device *dev) |
| 72 |
{ |
| 73 |
struct device *irq_dev; |
| 74 |
|
| 75 |
config_t *config = dev->chip_info; |
| 76 |
|
| 77 |
pci_write_config8(dev, D31F0_PIRQA_ROUT, config->pirqa_routing); |
| 78 |
pci_write_config8(dev, D31F0_PIRQB_ROUT, config->pirqb_routing); |
| 79 |
pci_write_config8(dev, D31F0_PIRQC_ROUT, config->pirqc_routing); |
| 80 |
pci_write_config8(dev, D31F0_PIRQD_ROUT, config->pirqd_routing); |
| 81 |
|
| 82 |
pci_write_config8(dev, D31F0_PIRQE_ROUT, config->pirqe_routing); |
| 83 |
pci_write_config8(dev, D31F0_PIRQF_ROUT, config->pirqf_routing); |
| 84 |
pci_write_config8(dev, D31F0_PIRQG_ROUT, config->pirqg_routing); |
| 85 |
pci_write_config8(dev, D31F0_PIRQH_ROUT, config->pirqh_routing); |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) { |
| 92 |
u8 int_pin = 0, int_line = 0; |
| 93 |
|
| 94 |
if (!is_enabled_pci(irq_dev)) |
| 95 |
continue; |
| 96 |
|
| 97 |
int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN); |
| 98 |
|
| 99 |
switch (int_pin) { |
| 100 |
case 1: int_line = config->pirqa_routing; break; |
| 101 |
case 2: int_line = config->pirqb_routing; break; |
| 102 |
case 3: int_line = config->pirqc_routing; break; |
| 103 |
case 4: int_line = config->pirqd_routing; break; |
| 104 |
} |
| 105 |
|
| 106 |
if (!int_line) |
| 107 |
continue; |
| 108 |
|
| 109 |
pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line); |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
static void i82801ix_gpi_routing(struct device *dev) |
| 114 |
{ |
| 115 |
|
| 116 |
config_t *config = dev->chip_info; |
| 117 |
u32 reg32 = 0; |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
reg32 |= (config->gpi0_routing & 0x03) << 0; |
| 123 |
reg32 |= (config->gpi1_routing & 0x03) << 2; |
| 124 |
reg32 |= (config->gpi2_routing & 0x03) << 4; |
| 125 |
reg32 |= (config->gpi3_routing & 0x03) << 6; |
| 126 |
reg32 |= (config->gpi4_routing & 0x03) << 8; |
| 127 |
reg32 |= (config->gpi5_routing & 0x03) << 10; |
| 128 |
reg32 |= (config->gpi6_routing & 0x03) << 12; |
| 129 |
reg32 |= (config->gpi7_routing & 0x03) << 14; |
| 130 |
reg32 |= (config->gpi8_routing & 0x03) << 16; |
| 131 |
reg32 |= (config->gpi9_routing & 0x03) << 18; |
| 132 |
reg32 |= (config->gpi10_routing & 0x03) << 20; |
| 133 |
reg32 |= (config->gpi11_routing & 0x03) << 22; |
| 134 |
reg32 |= (config->gpi12_routing & 0x03) << 24; |
| 135 |
reg32 |= (config->gpi13_routing & 0x03) << 26; |
| 136 |
reg32 |= (config->gpi14_routing & 0x03) << 28; |
| 137 |
reg32 |= (config->gpi15_routing & 0x03) << 30; |
| 138 |
|
| 139 |
pci_write_config32(dev, D31F0_GPIO_ROUT, reg32); |
| 140 |
} |
| 141 |
|
| 142 |
bool southbridge_support_c5(void) |
| 143 |
{ |
| 144 |
struct device *lpc_dev = __pci_0_1f_0; |
| 145 |
struct southbridge_intel_i82801ix_config *config = lpc_dev->chip_info; |
| 146 |
return config->c5_enable; |
| 147 |
} |
| 148 |
|
| 149 |
bool southbridge_support_c6(void) |
| 150 |
{ |
| 151 |
struct device *lpc_dev = __pci_0_1f_0; |
| 152 |
struct southbridge_intel_i82801ix_config *config = lpc_dev->chip_info; |
| 153 |
return config->c6_enable; |
| 154 |
} |
| 155 |
|
| 156 |
static void i82801ix_power_options(struct device *dev) |
| 157 |
{ |
| 158 |
u8 reg8; |
| 159 |
u16 reg16, pmbase; |
| 160 |
u32 reg32; |
| 161 |
const char *state; |
| 162 |
|
| 163 |
config_t *config = dev->chip_info; |
| 164 |
|
| 165 |
|
| 166 |
pci_or_config32(dev, 0xac, (1 << 30) | (3 << 8)); |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
const unsigned int pwr_on = get_uint_option("power_on_after_fail", MAINBOARD_POWER_ON); |
| 175 |
|
| 176 |
reg8 = pci_read_config8(dev, D31F0_GEN_PMCON_3); |
| 177 |
reg8 &= 0xfe; |
| 178 |
switch (pwr_on) { |
| 179 |
case MAINBOARD_POWER_OFF: |
| 180 |
reg8 |= 1; |
| 181 |
state = "off"; |
| 182 |
break; |
| 183 |
case MAINBOARD_POWER_ON: |
| 184 |
reg8 &= ~1; |
| 185 |
state = "on"; |
| 186 |
break; |
| 187 |
case MAINBOARD_POWER_KEEP: |
| 188 |
reg8 &= ~1; |
| 189 |
state = "state keep"; |
| 190 |
break; |
| 191 |
default: |
| 192 |
state = "undefined"; |
| 193 |
} |
| 194 |
|
| 195 |
reg8 |= (3 << 4); |
| 196 |
reg8 &= ~(1 << 3); |
| 197 |
|
| 198 |
pci_write_config8(dev, D31F0_GEN_PMCON_3, reg8); |
| 199 |
printk(BIOS_INFO, "Set power %s after power failure.\n", state); |
| 200 |
|
| 201 |
|
| 202 |
reg8 = inb(0x61); |
| 203 |
reg8 &= 0x0f; |
| 204 |
reg8 &= ~(1 << 3); |
| 205 |
|
| 206 |
reg8 |= (1 << 2); |
| 207 |
outb(reg8, 0x61); |
| 208 |
|
| 209 |
reg8 = inb(0x74); |
| 210 |
const unsigned int nmi_option = get_uint_option("nmi", NMI_OFF); |
| 211 |
if (nmi_option) { |
| 212 |
printk(BIOS_INFO, "NMI sources enabled.\n"); |
| 213 |
reg8 &= ~(1 << 7); |
| 214 |
} else { |
| 215 |
printk(BIOS_INFO, "NMI sources disabled.\n"); |
| 216 |
reg8 |= (1 << 7); |
| 217 |
} |
| 218 |
outb(reg8, 0x70); |
| 219 |
|
| 220 |
|
| 221 |
reg16 = pci_read_config16(dev, D31F0_GEN_PMCON_1); |
| 222 |
reg16 &= ~(3 << 0); |
| 223 |
reg16 |= (1 << 2); |
| 224 |
reg16 |= (1 << 3); |
| 225 |
reg16 |= (1 << 5); |
| 226 |
|
| 227 |
if (config->c4onc3_enable) |
| 228 |
reg16 |= (1 << 7); |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
reg16 |= (1 << 10); |
| 233 |
if (CONFIG(DEBUG_PERIODIC_SMI)) |
| 234 |
reg16 |= (3 << 0); |
| 235 |
if (southbridge_support_c5()) |
| 236 |
reg16 |= (1 << 11); |
| 237 |
pci_write_config16(dev, D31F0_GEN_PMCON_1, reg16); |
| 238 |
|
| 239 |
|
| 240 |
if (southbridge_support_c5()) { |
| 241 |
reg8 = pci_read_config8(dev, D31F0_C5_EXIT_TIMING); |
| 242 |
reg8 &= ~((7 << 3) | (7 << 0)); |
| 243 |
if (southbridge_support_c6()) |
| 244 |
reg8 |= (5 << 3) | (3 << 0); |
| 245 |
|
| 246 |
else |
| 247 |
reg8 |= (0 << 3) | (1 << 0); |
| 248 |
|
| 249 |
pci_write_config8(dev, D31F0_C5_EXIT_TIMING, reg8); |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
i82801ix_gpi_routing(dev); |
| 254 |
|
| 255 |
pmbase = pci_read_config16(dev, 0x40) & 0xfffe; |
| 256 |
|
| 257 |
outl(config->gpe0_en, pmbase + 0x28); |
| 258 |
outw(config->alt_gp_smi_en, pmbase + 0x38); |
| 259 |
|
| 260 |
|
| 261 |
reg16 = inw(pmbase + 0x00); |
| 262 |
outw(reg16, pmbase + 0x00); |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
reg32 = inl(pmbase + 0x10); |
| 270 |
reg32 &= ~(7 << 5); |
| 271 |
reg32 |= (config->throttle_duty & 7) << 5; |
| 272 |
outl(reg32, pmbase + 0x10); |
| 273 |
} |
| 274 |
|
| 275 |
static void i82801ix_configure_cstates(struct device *dev) |
| 276 |
{ |
| 277 |
|
| 278 |
pci_or_config8(dev, D31F0_CxSTATE_CNF, (1 << 4) | (1 << 3) | (1 << 2)); |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
pci_update_config8(dev, D31F0_C4TIMING_CNT, ~0x0f, (2 << 2) | (2 << 0)); |
| 284 |
|
| 285 |
|
| 286 |
} |
| 287 |
|
| 288 |
static void i82801ix_rtc_init(struct device *dev) |
| 289 |
{ |
| 290 |
u8 reg8; |
| 291 |
int rtc_failed; |
| 292 |
|
| 293 |
reg8 = pci_read_config8(dev, D31F0_GEN_PMCON_3); |
| 294 |
rtc_failed = reg8 & RTC_BATTERY_DEAD; |
| 295 |
if (rtc_failed) { |
| 296 |
reg8 &= ~RTC_BATTERY_DEAD; |
| 297 |
pci_write_config8(dev, D31F0_GEN_PMCON_3, reg8); |
| 298 |
} |
| 299 |
printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed); |
| 300 |
|
| 301 |
cmos_init(rtc_failed); |
| 302 |
} |
| 303 |
|
| 304 |
static void enable_hpet(void) |
| 305 |
{ |
| 306 |
u32 reg32; |
| 307 |
|
| 308 |
|
| 309 |
reg32 = RCBA32(RCBA_HPTC); |
| 310 |
reg32 |= (1 << 7); |
| 311 |
reg32 &= ~(3 << 0); |
| 312 |
RCBA32(RCBA_HPTC) = reg32; |
| 313 |
} |
| 314 |
|
| 315 |
static void enable_clock_gating(void) |
| 316 |
{ |
| 317 |
u32 reg32; |
| 318 |
|
| 319 |
|
| 320 |
RCBA32(RCBA_DMIC) |= 3; |
| 321 |
|
| 322 |
|
| 323 |
reg32 = RCBA32(RCBA_CG); |
| 324 |
reg32 |= (1 << 31); |
| 325 |
|
| 326 |
reg32 |= (1 << 29) | (1 << 28); |
| 327 |
|
| 328 |
reg32 |= (1 << 27) | (1 << 26) | (1 << 25) | (1 << 24); |
| 329 |
reg32 |= (1 << 23); |
| 330 |
reg32 |= (1 << 22); |
| 331 |
reg32 &= ~(1 << 21); |
| 332 |
reg32 &= ~(1 << 20); |
| 333 |
reg32 |= (1 << 19); |
| 334 |
|
| 335 |
reg32 |= (1 << 18) | (1 << 17); |
| 336 |
reg32 |= (1 << 16); |
| 337 |
|
| 338 |
reg32 |= (1 << 4) | (1 << 3) | (1 << 2) | (1 << 1); |
| 339 |
reg32 |= (1 << 0); |
| 340 |
RCBA32(RCBA_CG) = reg32; |
| 341 |
|
| 342 |
|
| 343 |
RCBA32(0x38c0) |= 7; |
| 344 |
} |
| 345 |
|
| 346 |
static void i82801ix_set_acpi_mode(struct device *dev) |
| 347 |
{ |
| 348 |
if (!acpi_is_wakeup_s3()) { |
| 349 |
apm_control(APM_CNT_ACPI_DISABLE); |
| 350 |
} else { |
| 351 |
apm_control(APM_CNT_ACPI_ENABLE); |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
static void lpc_init(struct device *dev) |
| 356 |
{ |
| 357 |
printk(BIOS_DEBUG, "i82801ix: %s\n", __func__); |
| 358 |
|
| 359 |
|
| 360 |
i82801ix_enable_apic(dev); |
| 361 |
|
| 362 |
i82801ix_enable_serial_irqs(dev); |
| 363 |
|
| 364 |
|
| 365 |
i82801ix_pirq_init(dev); |
| 366 |
|
| 367 |
|
| 368 |
i82801ix_power_options(dev); |
| 369 |
|
| 370 |
|
| 371 |
if (LPC_IS_MOBILE(dev)) |
| 372 |
i82801ix_configure_cstates(dev); |
| 373 |
|
| 374 |
|
| 375 |
i82801ix_rtc_init(dev); |
| 376 |
|
| 377 |
|
| 378 |
isa_dma_init(); |
| 379 |
|
| 380 |
|
| 381 |
enable_hpet(); |
| 382 |
|
| 383 |
|
| 384 |
enable_clock_gating(); |
| 385 |
|
| 386 |
setup_i8259(); |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
i8259_configure_irq_trigger(9, 1); |
| 391 |
|
| 392 |
i82801ix_set_acpi_mode(dev); |
| 393 |
} |
| 394 |
|
| 395 |
static void i82801ix_lpc_read_resources(struct device *dev) |
| 396 |
{ |
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
struct resource *res; |
| 428 |
|
| 429 |
|
| 430 |
pci_dev_read_resources(dev); |
| 431 |
|
| 432 |
|
| 433 |
res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); |
| 434 |
res->base = 0; |
| 435 |
res->size = 0x1000; |
| 436 |
res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | |
| 437 |
IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 438 |
|
| 439 |
res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); |
| 440 |
res->base = 0xff800000; |
| 441 |
res->size = 0x00800000; |
| 442 |
res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | |
| 443 |
IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 444 |
|
| 445 |
res = new_resource(dev, 3); |
| 446 |
res->base = IO_APIC_ADDR; |
| 447 |
res->size = 0x00001000; |
| 448 |
res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 449 |
} |
| 450 |
|
| 451 |
static const char *lpc_acpi_name(const struct device *dev) |
| 452 |
{ |
| 453 |
return "LPCB"; |
| 454 |
} |
| 455 |
|
| 456 |
static void southbridge_fill_ssdt(const struct device *device) |
| 457 |
{ |
| 458 |
struct device *dev = pcidev_on_root(0x1f, 0); |
| 459 |
config_t *chip = dev->chip_info; |
| 460 |
|
| 461 |
intel_acpi_pcie_hotplug_generator(chip->pcie_hotplug_map, 8); |
| 462 |
intel_acpi_gen_def_acpi_pirq(device); |
| 463 |
} |
| 464 |
|
| 465 |
static struct device_operations device_ops = { |
| 466 |
.read_resources = i82801ix_lpc_read_resources, |
| 467 |
.set_resources = pci_dev_set_resources, |
| 468 |
.enable_resources = pci_dev_enable_resources, |
| 469 |
.write_acpi_tables = acpi_write_hpet, |
| 470 |
.acpi_fill_ssdt = southbridge_fill_ssdt, |
| 471 |
.acpi_name = lpc_acpi_name, |
| 472 |
.init = lpc_init, |
| 473 |
.scan_bus = scan_static_bus, |
| 474 |
.ops_pci = &pci_dev_ops_pci, |
| 475 |
}; |
| 476 |
|
| 477 |
static const unsigned short pci_device_ids[] = { |
| 478 |
PCI_DID_INTEL_82801IH_LPC, |
| 479 |
PCI_DID_INTEL_82801IO_LPC, |
| 480 |
PCI_DID_INTEL_82801IR_LPC, |
| 481 |
PCI_DID_INTEL_82801IEM_LPC, |
| 482 |
PCI_DID_INTEL_82801IB_LPC, |
| 483 |
PCI_DID_INTEL_82801IBM_LPC, |
| 484 |
0 |
| 485 |
}; |
| 486 |
|
| 487 |
static const struct pci_driver ich9_lpc __pci_driver = { |
| 488 |
.ops = &device_ops, |
| 489 |
.vendor = PCI_VID_INTEL, |
| 490 |
.devices = pci_device_ids, |
| 491 |
}; |