2005-09-14 17:34:03 +02:00
|
|
|
/*
|
|
|
|
* (C) 2003 Linux Networx, SuSE Linux AG
|
|
|
|
* (C) 2004 Tyan Computer
|
2006-08-23 16:28:37 +02:00
|
|
|
* (c) 2005 Digital Design Corporation
|
2005-09-14 17:34:03 +02:00
|
|
|
*/
|
|
|
|
#include <console/console.h>
|
|
|
|
#include <device/device.h>
|
|
|
|
#include <device/pci.h>
|
|
|
|
#include <device/pci_ids.h>
|
|
|
|
#include <device/pci_ops.h>
|
|
|
|
#include <pc80/mc146818rtc.h>
|
|
|
|
#include <pc80/isa-dma.h>
|
|
|
|
#include <arch/io.h>
|
2010-02-27 02:50:21 +01:00
|
|
|
#include "i82801cx.h"
|
2005-09-14 17:34:03 +02:00
|
|
|
|
|
|
|
#define NMI_OFF 0
|
2006-08-23 16:28:37 +02:00
|
|
|
|
2009-06-30 17:17:49 +02:00
|
|
|
#ifndef CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL
|
|
|
|
#define CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL MAINBOARD_POWER_ON
|
2006-08-23 16:28:37 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define MAINBOARD_POWER_OFF 0
|
|
|
|
#define MAINBOARD_POWER_ON 1
|
|
|
|
|
2005-09-14 17:34:03 +02:00
|
|
|
|
2010-02-27 02:50:21 +01:00
|
|
|
void i82801cx_enable_ioapic( struct device *dev)
|
2005-09-14 17:34:03 +02:00
|
|
|
{
|
|
|
|
uint32_t dword;
|
|
|
|
volatile uint32_t* ioapic_index = (volatile uint32_t*)0xfec00000;
|
|
|
|
volatile uint32_t* ioapic_data = (volatile uint32_t*)0xfec00010;
|
|
|
|
|
|
|
|
dword = pci_read_config32(dev, GEN_CNTL);
|
|
|
|
dword |= (3 << 7); /* enable ioapic & disable SMBus interrupts */
|
|
|
|
dword |= (1 <<13); /* coprocessor error enable */
|
|
|
|
dword |= (1 << 1); /* delay transaction enable */
|
|
|
|
dword |= (1 << 2); /* DMA collection buf enable */
|
|
|
|
pci_write_config32(dev, GEN_CNTL, dword);
|
|
|
|
printk_debug("ioapic southbridge enabled %x\n",dword);
|
|
|
|
|
|
|
|
// Must program the APIC's ID before using it
|
|
|
|
|
|
|
|
*ioapic_index = 0; // Select APIC ID register
|
|
|
|
*ioapic_data = (2<<24);
|
|
|
|
|
|
|
|
// Hang if the ID didn't take (chip not present?)
|
|
|
|
*ioapic_index = 0;
|
|
|
|
dword = *ioapic_data;
|
|
|
|
printk_debug("Southbridge apic id = %x\n", (dword>>24) & 0xF);
|
|
|
|
if(dword != (2<<24))
|
|
|
|
die("");
|
|
|
|
|
|
|
|
*ioapic_index = 3; // Select Boot Configuration register
|
|
|
|
*ioapic_data = 1; // Use Processor System Bus to deliver interrupts
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is how interrupts are received from the Super I/O chip
|
2010-02-27 02:50:21 +01:00
|
|
|
void i82801cx_enable_serial_irqs( struct device *dev)
|
2005-09-14 17:34:03 +02:00
|
|
|
{
|
|
|
|
// Recognize serial IRQs, continuous mode, frame size 21, 4 clock start frame pulse width
|
|
|
|
pci_write_config8(dev, SERIRQ_CNTL, (1 << 7)|(1 << 6)|((21 - 17) << 2)|(0<< 0));
|
|
|
|
}
|
|
|
|
|
2006-08-23 16:28:37 +02:00
|
|
|
//----------------------------------------------------------------------------------
|
2010-02-27 02:50:21 +01:00
|
|
|
// Function: i82801cx_lpc_route_dma
|
2005-09-14 17:34:03 +02:00
|
|
|
// Parameters: dev
|
|
|
|
// mask - identifies whether each channel should be used for PCI DMA
|
|
|
|
// (bit = 0) or LPC DMA (bit = 1). The LSb controls channel 0.
|
2006-08-23 16:28:37 +02:00
|
|
|
// Channel 4 is not used (reserved).
|
|
|
|
// Return Value: None
|
|
|
|
// Description: Route all DMA channels to either PCI or LPC.
|
|
|
|
//
|
2010-02-27 02:50:21 +01:00
|
|
|
void i82801cx_lpc_route_dma( struct device *dev, uint8_t mask)
|
2005-09-14 17:34:03 +02:00
|
|
|
{
|
|
|
|
uint16_t dmaConfig;
|
|
|
|
int channelIndex;
|
2006-08-23 16:28:37 +02:00
|
|
|
|
2005-09-14 17:34:03 +02:00
|
|
|
dmaConfig = pci_read_config16(dev, PCI_DMA_CFG);
|
|
|
|
dmaConfig &= 0x300; // Preserve reserved bits
|
|
|
|
for(channelIndex = 0; channelIndex < 8; channelIndex++) {
|
|
|
|
if (channelIndex == 4)
|
|
|
|
continue; // Register doesn't support channel 4
|
|
|
|
dmaConfig |= ((mask & (1 << channelIndex))? 3:1) << (channelIndex*2);
|
|
|
|
}
|
|
|
|
pci_write_config16(dev, PCI_DMA_CFG, dmaConfig);
|
|
|
|
}
|
|
|
|
|
2010-02-27 02:50:21 +01:00
|
|
|
void i82801cx_rtc_init(struct device *dev)
|
2005-09-14 17:34:03 +02:00
|
|
|
{
|
|
|
|
uint32_t dword;
|
2006-08-23 16:28:37 +02:00
|
|
|
int rtc_failed;
|
2009-06-30 17:17:49 +02:00
|
|
|
int pwr_on = CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL;
|
2006-08-23 16:28:37 +02:00
|
|
|
uint8_t pmcon3 = pci_read_config8(dev, GEN_PMCON_3);
|
2005-09-14 17:34:03 +02:00
|
|
|
|
|
|
|
rtc_failed = pmcon3 & RTC_BATTERY_DEAD;
|
|
|
|
if (rtc_failed) {
|
|
|
|
// Clear the RTC_BATTERY_DEAD bit, but preserve
|
2006-08-23 16:28:37 +02:00
|
|
|
// the RTC_POWER_FAILED, G3 state, and reserved bits
|
2005-09-14 17:34:03 +02:00
|
|
|
// NOTE: RTC_BATTERY_DEAD and RTC_POWER_FAILED are "write-1-clear" bits
|
|
|
|
pmcon3 &= ~RTC_POWER_FAILED;
|
2006-08-23 16:28:37 +02:00
|
|
|
}
|
|
|
|
|
2009-06-03 16:19:33 +02:00
|
|
|
get_option(&pwr_on, "power_on_after_fail");
|
2006-08-23 16:28:37 +02:00
|
|
|
pmcon3 &= ~SLEEP_AFTER_POWER_FAIL;
|
|
|
|
if (!pwr_on) {
|
|
|
|
pmcon3 |= SLEEP_AFTER_POWER_FAIL;
|
|
|
|
}
|
|
|
|
pci_write_config8(dev, GEN_PMCON_3, pmcon3);
|
|
|
|
printk_info("set power %s after power fail\n",
|
|
|
|
pwr_on ? "on" : "off");
|
2005-09-14 17:34:03 +02:00
|
|
|
|
|
|
|
// See if the Safe Mode jumper is set
|
|
|
|
dword = pci_read_config32(dev, GEN_STS);
|
|
|
|
rtc_failed |= dword & (1 << 2);
|
|
|
|
|
|
|
|
rtc_init(rtc_failed);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-27 02:50:21 +01:00
|
|
|
void i82801cx_1f0_misc(struct device *dev)
|
2005-09-14 17:34:03 +02:00
|
|
|
{
|
|
|
|
// Prevent LPC disabling, enable parity errors, and SERR# (System Error)
|
|
|
|
pci_write_config16(dev, PCI_COMMAND, 0x014f);
|
|
|
|
|
2006-12-14 01:43:50 +01:00
|
|
|
// Set ACPI base address to 0x1100 (I/O space)
|
|
|
|
pci_write_config32(dev, PMBASE, 0x00001101);
|
2005-09-14 17:34:03 +02:00
|
|
|
|
|
|
|
// Enable ACPI I/O and power management
|
|
|
|
pci_write_config8(dev, ACPI_CNTL, 0x10);
|
|
|
|
|
|
|
|
// Set GPIO base address to 0x1180 (I/O space)
|
|
|
|
pci_write_config32(dev, GPIO_BASE, 0x00001181);
|
|
|
|
|
|
|
|
// Enable GPIO
|
|
|
|
pci_write_config8(dev, GPIO_CNTL, 0x10);
|
|
|
|
|
|
|
|
// Route PIRQA to IRQ11, PIRQB to IRQ3, PIRQC to IRQ5, PIRQD to IRQ10
|
|
|
|
pci_write_config32(dev, PIRQA_ROUT, 0x0A05030B);
|
|
|
|
|
|
|
|
// Route PIRQE to IRQ7. Leave PIRQF - PIRQH unrouted.
|
|
|
|
pci_write_config8(dev, PIRQE_ROUT, 0x07);
|
|
|
|
|
|
|
|
// Enable access to the upper 128 byte bank of CMOS RAM
|
|
|
|
pci_write_config8(dev, RTC_CONF, 0x04);
|
|
|
|
|
2006-08-23 16:28:37 +02:00
|
|
|
// Decode 0x3F8-0x3FF (COM1) for COMA port,
|
2005-09-14 17:34:03 +02:00
|
|
|
// 0x2F8-0x2FF (COM2) for COMB
|
|
|
|
pci_write_config8(dev, COM_DEC, 0x10);
|
|
|
|
|
2006-08-23 16:28:37 +02:00
|
|
|
// LPT decode defaults to 0x378-0x37F and 0x778-0x77F
|
|
|
|
// Floppy decode defaults to 0x3F0-0x3F5, 0x3F7
|
|
|
|
|
|
|
|
// Enable COMA, COMB, LPT, floppy;
|
2005-09-14 17:34:03 +02:00
|
|
|
// disable microcontroller, Super I/O, sound, gameport
|
|
|
|
pci_write_config16(dev, LPC_EN, 0x000F);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lpc_init(struct device *dev)
|
|
|
|
{
|
|
|
|
uint8_t byte;
|
|
|
|
int pwr_on=-1;
|
2009-06-03 16:19:33 +02:00
|
|
|
int nmi_option;
|
2005-09-14 17:34:03 +02:00
|
|
|
|
|
|
|
/* IO APIC initialization */
|
2010-02-27 02:50:21 +01:00
|
|
|
i82801cx_enable_ioapic(dev);
|
2005-09-14 17:34:03 +02:00
|
|
|
|
2010-02-27 02:50:21 +01:00
|
|
|
i82801cx_enable_serial_irqs(dev);
|
2005-09-14 17:34:03 +02:00
|
|
|
|
|
|
|
/* power after power fail */
|
|
|
|
/* FIXME this doesn't work! */
|
|
|
|
/* Which state do we want to goto after g3 (power restored)?
|
|
|
|
* 0 == S0 Full On
|
|
|
|
* 1 == S5 Soft Off
|
|
|
|
*/
|
|
|
|
byte = pci_read_config8(dev, GEN_PMCON_3);
|
|
|
|
if (pwr_on)
|
|
|
|
byte &= ~1; // Return to S0 (boot) after power is re-applied
|
|
|
|
else
|
|
|
|
byte |= 1; // Return to S5
|
|
|
|
pci_write_config8(dev, GEN_PMCON_3, byte);
|
|
|
|
printk_info("set power %s after power fail\n", pwr_on?"on":"off");
|
|
|
|
|
2006-08-23 16:28:37 +02:00
|
|
|
/* Set up NMI on errors */
|
|
|
|
byte = inb(0x61);
|
|
|
|
byte &= ~(1 << 3); /* IOCHK# NMI Enable */
|
|
|
|
byte &= ~(1 << 2); /* PCI SERR# Enable */
|
|
|
|
outb(byte, 0x61);
|
|
|
|
byte = inb(0x70);
|
|
|
|
nmi_option = NMI_OFF;
|
2009-06-03 16:19:33 +02:00
|
|
|
get_option(&nmi_option, "nmi");
|
2006-08-23 16:28:37 +02:00
|
|
|
if (nmi_option) {
|
|
|
|
byte &= ~(1 << 7); /* set NMI */
|
|
|
|
outb(byte, 0x70);
|
|
|
|
}
|
2005-09-14 17:34:03 +02:00
|
|
|
|
|
|
|
/* Initialize the real time clock */
|
2010-02-27 02:50:21 +01:00
|
|
|
i82801cx_rtc_init(dev);
|
2005-09-14 17:34:03 +02:00
|
|
|
|
2010-02-27 02:50:21 +01:00
|
|
|
i82801cx_lpc_route_dma(dev, 0xff);
|
2005-09-14 17:34:03 +02:00
|
|
|
|
|
|
|
/* Initialize isa dma */
|
|
|
|
isa_dma_init();
|
|
|
|
|
2010-02-27 02:50:21 +01:00
|
|
|
i82801cx_1f0_misc(dev);
|
2005-09-14 17:34:03 +02:00
|
|
|
}
|
|
|
|
|
2010-02-27 02:50:21 +01:00
|
|
|
static void i82801cx_lpc_read_resources(device_t dev)
|
2005-09-14 17:34:03 +02:00
|
|
|
{
|
|
|
|
struct resource *res;
|
|
|
|
|
2009-07-02 20:56:24 +02:00
|
|
|
/* Get the normal PCI resources of this device. */
|
2005-09-14 17:34:03 +02:00
|
|
|
pci_dev_read_resources(dev);
|
|
|
|
|
2009-07-02 20:56:24 +02:00
|
|
|
/* Add an extra subtractive resource for both memory and I/O. */
|
2005-09-14 17:34:03 +02:00
|
|
|
res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0));
|
2009-07-02 20:56:24 +02:00
|
|
|
res->base = 0;
|
|
|
|
res->size = 0x1000;
|
|
|
|
res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
|
|
|
|
IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
|
2005-09-14 17:34:03 +02:00
|
|
|
|
|
|
|
res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0));
|
2009-07-02 20:56:24 +02:00
|
|
|
res->base = 0xff800000;
|
|
|
|
res->size = 0x00800000; /* 8 MB for flash */
|
|
|
|
res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE |
|
|
|
|
IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
|
|
|
|
|
|
|
|
res = new_resource(dev, 3); /* IOAPIC */
|
|
|
|
res->base = 0xfec00000;
|
|
|
|
res->size = 0x00001000;
|
|
|
|
res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
|
2005-09-14 17:34:03 +02:00
|
|
|
}
|
|
|
|
|
2010-02-27 02:50:21 +01:00
|
|
|
static void i82801cx_lpc_enable_resources(device_t dev)
|
2005-09-14 17:34:03 +02:00
|
|
|
{
|
|
|
|
pci_dev_enable_resources(dev);
|
|
|
|
enable_childrens_resources(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct device_operations lpc_ops = {
|
2010-02-27 02:50:21 +01:00
|
|
|
.read_resources = i82801cx_lpc_read_resources,
|
2005-09-14 17:34:03 +02:00
|
|
|
.set_resources = pci_dev_set_resources,
|
2010-02-27 02:50:21 +01:00
|
|
|
.enable_resources = i82801cx_lpc_enable_resources,
|
2005-09-14 17:34:03 +02:00
|
|
|
.init = lpc_init,
|
|
|
|
.scan_bus = scan_static_bus,
|
|
|
|
.enable = 0,
|
|
|
|
};
|
|
|
|
|
2007-10-24 11:08:58 +02:00
|
|
|
static const struct pci_driver lpc_driver __pci_driver = {
|
2005-09-14 17:34:03 +02:00
|
|
|
.ops = &lpc_ops,
|
|
|
|
.vendor = PCI_VENDOR_ID_INTEL,
|
|
|
|
.device = PCI_DEVICE_ID_INTEL_82801CA_LPC,
|
|
|
|
};
|