| 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 <arch/smp/mpspec.h> |
| 19 |
#include <southbridge/intel/common/acpi_pirq_gen.h> |
| 20 |
#include <southbridge/intel/common/rcba_pirq.h> |
| 21 |
#include <southbridge/intel/common/hpet.h> |
| 22 |
#include <southbridge/intel/common/pmbase.h> |
| 23 |
#include <southbridge/intel/common/spi.h> |
| 24 |
|
| 25 |
#include "chip.h" |
| 26 |
#include "i82801gx.h" |
| 27 |
|
| 28 |
#define NMI_OFF 0 |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
static void i82801gx_enable_ioapic(struct device *dev) |
| 36 |
{ |
| 37 |
register_new_ioapic_gsi0(IO_APIC_ADDR); |
| 38 |
} |
| 39 |
|
| 40 |
static void i82801gx_enable_serial_irqs(struct device *dev) |
| 41 |
{ |
| 42 |
|
| 43 |
pci_write_config8(dev, SERIRQ_CNTL, (1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0)); |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
static void i82801gx_pirq_init(struct device *dev) |
| 68 |
{ |
| 69 |
struct device *irq_dev; |
| 70 |
|
| 71 |
const struct southbridge_intel_i82801gx_config *config = dev->chip_info; |
| 72 |
|
| 73 |
pci_write_config8(dev, PIRQA_ROUT, config->pirqa_routing); |
| 74 |
pci_write_config8(dev, PIRQB_ROUT, config->pirqb_routing); |
| 75 |
pci_write_config8(dev, PIRQC_ROUT, config->pirqc_routing); |
| 76 |
pci_write_config8(dev, PIRQD_ROUT, config->pirqd_routing); |
| 77 |
|
| 78 |
pci_write_config8(dev, PIRQE_ROUT, config->pirqe_routing); |
| 79 |
pci_write_config8(dev, PIRQF_ROUT, config->pirqf_routing); |
| 80 |
pci_write_config8(dev, PIRQG_ROUT, config->pirqg_routing); |
| 81 |
pci_write_config8(dev, PIRQH_ROUT, config->pirqh_routing); |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) { |
| 88 |
u8 int_pin = 0, int_line = 0; |
| 89 |
|
| 90 |
if (!is_enabled_pci(irq_dev)) |
| 91 |
continue; |
| 92 |
|
| 93 |
int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN); |
| 94 |
|
| 95 |
switch (int_pin) { |
| 96 |
case 1: |
| 97 |
int_line = config->pirqa_routing; break; |
| 98 |
case 2: |
| 99 |
int_line = config->pirqb_routing; break; |
| 100 |
case 3: |
| 101 |
int_line = config->pirqc_routing; break; |
| 102 |
case 4: |
| 103 |
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 i82801gx_gpi_routing(struct device *dev) |
| 114 |
{ |
| 115 |
|
| 116 |
const struct southbridge_intel_i82801gx_config *config = dev->chip_info; |
| 117 |
u32 reg32 = 0; |
| 118 |
|
| 119 |
|
| 120 |
reg32 |= (config->gpi0_routing & 0x03) << 0; |
| 121 |
reg32 |= (config->gpi1_routing & 0x03) << 2; |
| 122 |
reg32 |= (config->gpi2_routing & 0x03) << 4; |
| 123 |
reg32 |= (config->gpi3_routing & 0x03) << 6; |
| 124 |
reg32 |= (config->gpi4_routing & 0x03) << 8; |
| 125 |
reg32 |= (config->gpi5_routing & 0x03) << 10; |
| 126 |
reg32 |= (config->gpi6_routing & 0x03) << 12; |
| 127 |
reg32 |= (config->gpi7_routing & 0x03) << 14; |
| 128 |
reg32 |= (config->gpi8_routing & 0x03) << 16; |
| 129 |
reg32 |= (config->gpi9_routing & 0x03) << 18; |
| 130 |
reg32 |= (config->gpi10_routing & 0x03) << 20; |
| 131 |
reg32 |= (config->gpi11_routing & 0x03) << 22; |
| 132 |
reg32 |= (config->gpi12_routing & 0x03) << 24; |
| 133 |
reg32 |= (config->gpi13_routing & 0x03) << 26; |
| 134 |
reg32 |= (config->gpi14_routing & 0x03) << 28; |
| 135 |
reg32 |= (config->gpi15_routing & 0x03) << 30; |
| 136 |
|
| 137 |
pci_write_config32(dev, GPIO_ROUT, reg32); |
| 138 |
} |
| 139 |
|
| 140 |
static void i82801gx_power_options(struct device *dev) |
| 141 |
{ |
| 142 |
u8 reg8; |
| 143 |
u16 reg16; |
| 144 |
u32 reg32; |
| 145 |
const char *state; |
| 146 |
|
| 147 |
const struct southbridge_intel_i82801gx_config *config = dev->chip_info; |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
const unsigned int pwr_on = get_uint_option("power_on_after_fail", MAINBOARD_POWER_ON); |
| 156 |
|
| 157 |
reg8 = pci_read_config8(dev, GEN_PMCON_3); |
| 158 |
reg8 &= 0xfe; |
| 159 |
switch (pwr_on) { |
| 160 |
case MAINBOARD_POWER_OFF: |
| 161 |
reg8 |= 1; |
| 162 |
state = "off"; |
| 163 |
break; |
| 164 |
case MAINBOARD_POWER_ON: |
| 165 |
reg8 &= ~1; |
| 166 |
state = "on"; |
| 167 |
break; |
| 168 |
case MAINBOARD_POWER_KEEP: |
| 169 |
reg8 &= ~1; |
| 170 |
state = "state keep"; |
| 171 |
break; |
| 172 |
default: |
| 173 |
state = "undefined"; |
| 174 |
} |
| 175 |
|
| 176 |
reg8 |= (3 << 4); |
| 177 |
reg8 &= ~(1 << 3); |
| 178 |
|
| 179 |
pci_write_config8(dev, GEN_PMCON_3, reg8); |
| 180 |
printk(BIOS_INFO, "Set power %s after power failure.\n", state); |
| 181 |
|
| 182 |
|
| 183 |
reg8 = inb(0x61); |
| 184 |
reg8 &= 0x0f; |
| 185 |
reg8 &= ~(1 << 3); |
| 186 |
|
| 187 |
reg8 |= (1 << 2); |
| 188 |
outb(reg8, 0x61); |
| 189 |
|
| 190 |
reg8 = inb(0x70); |
| 191 |
const unsigned int nmi_option = get_uint_option("nmi", NMI_OFF); |
| 192 |
if (nmi_option) { |
| 193 |
printk(BIOS_INFO, "NMI sources enabled.\n"); |
| 194 |
reg8 &= ~(1 << 7); |
| 195 |
} else { |
| 196 |
printk(BIOS_INFO, "NMI sources disabled.\n"); |
| 197 |
reg8 |= (1 << 7); |
| 198 |
} |
| 199 |
outb(reg8, 0x70); |
| 200 |
|
| 201 |
|
| 202 |
reg16 = pci_read_config16(dev, GEN_PMCON_1); |
| 203 |
reg16 &= ~(3 << 0); |
| 204 |
reg16 |= (1 << 2); |
| 205 |
reg16 |= (1 << 3); |
| 206 |
reg16 |= (1 << 5); |
| 207 |
|
| 208 |
if (config->c4onc3_enable) |
| 209 |
reg16 |= (1 << 7); |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
reg16 |= (1 << 10); |
| 214 |
if (CONFIG(DEBUG_PERIODIC_SMI)) |
| 215 |
reg16 |= (3 << 0); |
| 216 |
pci_write_config16(dev, GEN_PMCON_1, reg16); |
| 217 |
|
| 218 |
|
| 219 |
i82801gx_gpi_routing(dev); |
| 220 |
|
| 221 |
write_pmbase32(GPE0_EN, config->gpe0_en); |
| 222 |
write_pmbase16(ALT_GP_SMI_EN, config->alt_gp_smi_en); |
| 223 |
|
| 224 |
|
| 225 |
reg32 = read_pmbase32(PM1_CNT); |
| 226 |
|
| 227 |
reg32 &= ~(7 << 10); |
| 228 |
reg32 |= (1 << 1); |
| 229 |
reg32 |= (1 << 0); |
| 230 |
write_pmbase32(PM1_CNT, reg32); |
| 231 |
} |
| 232 |
|
| 233 |
static void i82801gx_configure_cstates(struct device *dev) |
| 234 |
{ |
| 235 |
|
| 236 |
pci_or_config8(dev, 0xa9, (1 << 4) | (1 << 3) | (1 << 2)); |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
pci_update_config8(dev, 0xaa, 0xf0, (2 << 2) | (2 << 0)); |
| 242 |
} |
| 243 |
|
| 244 |
static void i82801gx_rtc_init(struct device *dev) |
| 245 |
{ |
| 246 |
u8 reg8; |
| 247 |
int rtc_failed; |
| 248 |
|
| 249 |
reg8 = pci_read_config8(dev, GEN_PMCON_3); |
| 250 |
rtc_failed = reg8 & RTC_BATTERY_DEAD; |
| 251 |
if (rtc_failed) { |
| 252 |
reg8 &= ~RTC_BATTERY_DEAD; |
| 253 |
pci_write_config8(dev, GEN_PMCON_3, reg8); |
| 254 |
} |
| 255 |
printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed); |
| 256 |
|
| 257 |
cmos_init(rtc_failed); |
| 258 |
} |
| 259 |
|
| 260 |
static void enable_clock_gating(void) |
| 261 |
{ |
| 262 |
u32 reg32; |
| 263 |
|
| 264 |
|
| 265 |
reg32 = RCBA32(CG); |
| 266 |
reg32 |= (1 << 31); |
| 267 |
reg32 |= (1 << 30); |
| 268 |
|
| 269 |
reg32 |= (1 << 27) | (1 << 26) | (1 << 25) | (1 << 24); |
| 270 |
reg32 |= (1 << 23); |
| 271 |
reg32 |= (1 << 19); |
| 272 |
reg32 |= (1 << 3) | (1 << 1); |
| 273 |
reg32 |= (1 << 2); |
| 274 |
reg32 &= ~(1 << 20); |
| 275 |
reg32 &= ~((1 << 29) | (1 << 28)); |
| 276 |
RCBA32(CG) = reg32; |
| 277 |
} |
| 278 |
|
| 279 |
static void i82801gx_set_acpi_mode(struct device *dev) |
| 280 |
{ |
| 281 |
if (!acpi_is_wakeup_s3()) { |
| 282 |
apm_control(APM_CNT_ACPI_DISABLE); |
| 283 |
} else { |
| 284 |
apm_control(APM_CNT_ACPI_ENABLE); |
| 285 |
} |
| 286 |
} |
| 287 |
|
| 288 |
static void i82801gx_spi_init(void) |
| 289 |
{ |
| 290 |
u16 spicontrol; |
| 291 |
|
| 292 |
spicontrol = RCBA16(SPIBASE + 2); |
| 293 |
spicontrol &= ~(1 << 0); |
| 294 |
RCBA16(SPIBASE + 2) = spicontrol; |
| 295 |
} |
| 296 |
|
| 297 |
static void i82801gx_fixups(struct device *dev) |
| 298 |
{ |
| 299 |
|
| 300 |
RCBA32(0x1d40) |= 1; |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
pci_write_config8(dev, 0xad, 0x3); |
| 307 |
} |
| 308 |
|
| 309 |
static void lpc_init(struct device *dev) |
| 310 |
{ |
| 311 |
printk(BIOS_DEBUG, "i82801gx: %s\n", __func__); |
| 312 |
|
| 313 |
|
| 314 |
i82801gx_enable_ioapic(dev); |
| 315 |
|
| 316 |
i82801gx_enable_serial_irqs(dev); |
| 317 |
|
| 318 |
|
| 319 |
i82801gx_pirq_init(dev); |
| 320 |
|
| 321 |
|
| 322 |
i82801gx_power_options(dev); |
| 323 |
|
| 324 |
|
| 325 |
i82801gx_configure_cstates(dev); |
| 326 |
|
| 327 |
|
| 328 |
i82801gx_rtc_init(dev); |
| 329 |
|
| 330 |
|
| 331 |
isa_dma_init(); |
| 332 |
|
| 333 |
|
| 334 |
enable_hpet(); |
| 335 |
|
| 336 |
|
| 337 |
enable_clock_gating(); |
| 338 |
|
| 339 |
setup_i8259(); |
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
i8259_configure_irq_trigger(9, 1); |
| 344 |
|
| 345 |
i82801gx_set_acpi_mode(dev); |
| 346 |
|
| 347 |
i82801gx_spi_init(); |
| 348 |
|
| 349 |
i82801gx_fixups(dev); |
| 350 |
} |
| 351 |
|
| 352 |
static void i82801gx_lpc_read_resources(struct device *dev) |
| 353 |
{ |
| 354 |
struct resource *res; |
| 355 |
u8 io_index = 0; |
| 356 |
int i; |
| 357 |
|
| 358 |
|
| 359 |
pci_dev_read_resources(dev); |
| 360 |
|
| 361 |
|
| 362 |
res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0)); |
| 363 |
res->base = 0; |
| 364 |
res->size = 0x1000; |
| 365 |
res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | |
| 366 |
IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 367 |
|
| 368 |
res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0)); |
| 369 |
res->base = 0xff800000; |
| 370 |
res->size = 0x00800000; |
| 371 |
res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | |
| 372 |
IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 373 |
|
| 374 |
res = new_resource(dev, 3); |
| 375 |
res->base = IO_APIC_ADDR; |
| 376 |
res->size = 0x00001000; |
| 377 |
res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 378 |
|
| 379 |
|
| 380 |
for (i = 0; i < 4; i++) { |
| 381 |
u32 gen_dec; |
| 382 |
gen_dec = pci_read_config32(dev, 0x84 + 4 * i); |
| 383 |
|
| 384 |
if ((gen_dec & 0xFFFC) > 0x1000) { |
| 385 |
res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0)); |
| 386 |
res->base = gen_dec & 0xFFFC; |
| 387 |
res->size = (gen_dec >> 16) & 0xFC; |
| 388 |
res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | |
| 389 |
IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 390 |
} |
| 391 |
} |
| 392 |
} |
| 393 |
|
| 394 |
static void lpc_final(struct device *dev) |
| 395 |
{ |
| 396 |
u16 tco1_cnt; |
| 397 |
|
| 398 |
if (!CONFIG(INTEL_CHIPSET_LOCKDOWN)) |
| 399 |
return; |
| 400 |
|
| 401 |
if (CONFIG(BOOT_DEVICE_SPI_FLASH)) |
| 402 |
spi_finalize_ops(); |
| 403 |
|
| 404 |
|
| 405 |
SPIBAR16(0) = SPIBAR16(0) | (1 << 15); |
| 406 |
|
| 407 |
|
| 408 |
RCBA32(0x3410) |= 1 << 0; |
| 409 |
|
| 410 |
|
| 411 |
pci_or_config16(dev, GEN_PMCON_1, 1 << 4); |
| 412 |
|
| 413 |
|
| 414 |
tco1_cnt = inw(DEFAULT_PMBASE + 0x60 + TCO1_CNT); |
| 415 |
tco1_cnt |= (1 << 12); |
| 416 |
outw(tco1_cnt, DEFAULT_PMBASE + 0x60 + TCO1_CNT); |
| 417 |
|
| 418 |
|
| 419 |
post_code(POSTCODE_OS_BOOT); |
| 420 |
} |
| 421 |
|
| 422 |
static const char *lpc_acpi_name(const struct device *dev) |
| 423 |
{ |
| 424 |
return "LPCB"; |
| 425 |
} |
| 426 |
|
| 427 |
static void southbridge_fill_ssdt(const struct device *device) |
| 428 |
{ |
| 429 |
intel_acpi_gen_def_acpi_pirq(device); |
| 430 |
} |
| 431 |
|
| 432 |
static struct device_operations device_ops = { |
| 433 |
.read_resources = i82801gx_lpc_read_resources, |
| 434 |
.set_resources = pci_dev_set_resources, |
| 435 |
.enable_resources = pci_dev_enable_resources, |
| 436 |
.write_acpi_tables = acpi_write_hpet, |
| 437 |
.acpi_fill_ssdt = southbridge_fill_ssdt, |
| 438 |
.acpi_name = lpc_acpi_name, |
| 439 |
.init = lpc_init, |
| 440 |
.scan_bus = scan_static_bus, |
| 441 |
.enable = i82801gx_enable, |
| 442 |
.ops_pci = &pci_dev_ops_pci, |
| 443 |
.final = lpc_final, |
| 444 |
}; |
| 445 |
|
| 446 |
static const unsigned short pci_device_ids[] = { |
| 447 |
0x27b0, |
| 448 |
0x27b8, |
| 449 |
0x27b9, |
| 450 |
0x27bc, |
| 451 |
0x27bd, |
| 452 |
0 |
| 453 |
}; |
| 454 |
|
| 455 |
static const struct pci_driver ich7_lpc __pci_driver = { |
| 456 |
.ops = &device_ops, |
| 457 |
.vendor = PCI_VID_INTEL, |
| 458 |
.devices = pci_device_ids, |
| 459 |
}; |
| 460 |
|
| 461 |
bool southbridge_support_c5(void) |
| 462 |
{ |
| 463 |
return false; |
| 464 |
} |
| 465 |
|
| 466 |
bool southbridge_support_c6(void) |
| 467 |
{ |
| 468 |
return false; |
| 469 |
} |