2004-08-24 18:20:46 +02:00
|
|
|
/*
|
2010-03-14 18:01:08 +01:00
|
|
|
* This file is part of the coreboot project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003 Linux Networx
|
|
|
|
* Copyright (C) 2004 SuSE Linux AG
|
|
|
|
* Copyright (C) 2004 Tyan Computer
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; version 2 of
|
|
|
|
* the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2004-08-24 18:20:46 +02:00
|
|
|
*/
|
2010-03-14 18:01:08 +01:00
|
|
|
|
2004-08-24 18:20:46 +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>
|
2005-09-21 15:53:44 +02:00
|
|
|
#include <pc80/isa-dma.h>
|
|
|
|
#include <arch/io.h>
|
2010-02-27 02:50:21 +01:00
|
|
|
#include "i82801dx.h"
|
2004-08-24 18:20:46 +02:00
|
|
|
|
|
|
|
#define NMI_OFF 0
|
|
|
|
|
2010-03-14 18:01:08 +01:00
|
|
|
void i82801dx_enable_ioapic(struct device *dev)
|
2004-08-24 18:20:46 +02:00
|
|
|
{
|
2010-03-14 18:01:08 +01:00
|
|
|
u32 dword;
|
|
|
|
volatile u32 *ioapic_sba = (volatile u32 *)0xfec00000;
|
|
|
|
volatile u32 *ioapic_sbd = (volatile u32 *)0xfec00010;
|
|
|
|
|
|
|
|
dword = pci_read_config32(dev, GEN_CNTL);
|
|
|
|
dword |= (3 << 7); /* enable ioapic */
|
|
|
|
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);
|
|
|
|
*ioapic_sba = 0;
|
|
|
|
*ioapic_sbd = (2 << 24);
|
|
|
|
//lyh *ioapic_sba=3;
|
|
|
|
//lyh *ioapic_sbd=1;
|
|
|
|
*ioapic_sba = 0;
|
|
|
|
dword = *ioapic_sbd;
|
|
|
|
printk_debug("Southbridge apic id = %x\n", dword);
|
|
|
|
if (dword != (2 << 24))
|
|
|
|
die("");
|
|
|
|
//lyh *ioapic_sba=3;
|
|
|
|
//lyh dword=*ioapic_sbd;
|
|
|
|
//lyh printk_debug("Southbridge apic DT = %x\n",dword);
|
|
|
|
//lyh if(dword!=1)
|
|
|
|
//lyh die("");
|
2004-08-24 18:20:46 +02:00
|
|
|
|
|
|
|
}
|
2010-03-14 18:01:08 +01:00
|
|
|
|
|
|
|
void i82801dx_enable_serial_irqs(struct device *dev)
|
2004-08-24 18:20:46 +02:00
|
|
|
{
|
2010-03-14 18:01:08 +01:00
|
|
|
pci_write_config8(dev, SERIRQ_CNTL,
|
|
|
|
(1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0));
|
2004-08-24 18:20:46 +02:00
|
|
|
}
|
2010-03-14 18:01:08 +01:00
|
|
|
|
|
|
|
void i82801dx_lpc_route_dma(struct device *dev, u8 mask)
|
2004-08-24 18:20:46 +02:00
|
|
|
{
|
2010-03-14 18:01:08 +01:00
|
|
|
u16 word;
|
|
|
|
int i;
|
|
|
|
word = pci_read_config16(dev, PCI_DMA_CFG);
|
|
|
|
word &= ((1 << 10) - (1 << 8));
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
if (i == 4)
|
|
|
|
continue;
|
|
|
|
word |= ((mask & (1 << i)) ? 3 : 1) << (i * 2);
|
|
|
|
}
|
|
|
|
pci_write_config16(dev, PCI_DMA_CFG, word);
|
2004-08-24 18:20:46 +02:00
|
|
|
}
|
2010-03-14 18:01:08 +01:00
|
|
|
|
2010-02-27 02:50:21 +01:00
|
|
|
void i82801dx_rtc_init(struct device *dev)
|
2004-08-24 18:20:46 +02:00
|
|
|
{
|
2010-03-14 18:01:08 +01:00
|
|
|
u8 byte;
|
|
|
|
u32 dword;
|
|
|
|
int rtc_failed;
|
|
|
|
byte = pci_read_config8(dev, GEN_PMCON_3);
|
|
|
|
rtc_failed = byte & RTC_FAILED;
|
|
|
|
if (rtc_failed) {
|
|
|
|
byte &= ~(1 << 1); /* preserve the power fail state */
|
|
|
|
pci_write_config8(dev, GEN_PMCON_3, byte);
|
|
|
|
}
|
|
|
|
dword = pci_read_config32(dev, GEN_STS);
|
|
|
|
rtc_failed |= dword & (1 << 2);
|
|
|
|
rtc_init(rtc_failed);
|
2004-08-24 18:20:46 +02:00
|
|
|
}
|
|
|
|
|
2010-02-27 02:50:21 +01:00
|
|
|
void i82801dx_1f0_misc(struct device *dev)
|
2004-08-24 18:20:46 +02:00
|
|
|
{
|
2010-03-14 18:01:08 +01:00
|
|
|
pci_write_config16(dev, PCICMD, 0x014f);
|
|
|
|
pci_write_config32(dev, PMBASE, 0x00001001);
|
|
|
|
pci_write_config8(dev, ACPI_CNTL, 0x10);
|
|
|
|
pci_write_config32(dev, GPIO_BASE, 0x00001181);
|
|
|
|
pci_write_config8(dev, GPIO_CNTL, 0x10);
|
|
|
|
pci_write_config32(dev, PIRQA_ROUT, 0x0A05030B);
|
|
|
|
pci_write_config8(dev, PIRQE_ROUT, 0x07);
|
|
|
|
pci_write_config8(dev, RTC_CONF, 0x04);
|
|
|
|
pci_write_config8(dev, COM_DEC, 0x10); //lyh E0->
|
|
|
|
pci_write_config16(dev, LPC_EN, 0x000F); //LYH 000D->
|
2004-08-24 18:20:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void enable_hpet(struct device *dev)
|
|
|
|
{
|
2010-03-17 04:14:28 +01:00
|
|
|
const unsigned long hpet_address = 0xfed00000;
|
2004-08-24 18:20:46 +02:00
|
|
|
|
2010-03-14 18:01:08 +01:00
|
|
|
u32 dword;
|
|
|
|
u32 code = (0 & 0x3);
|
|
|
|
|
|
|
|
dword = pci_read_config32(dev, GEN_CNTL);
|
|
|
|
dword |= (1 << 17); /* enable hpet */
|
2004-08-24 18:20:46 +02:00
|
|
|
/*Bits [16:15]Memory Address Range
|
2010-03-14 18:01:08 +01:00
|
|
|
00 FED0_0000h - FED0_03FFh
|
|
|
|
01 FED0_1000h - FED0_13FFh
|
|
|
|
10 FED0_2000h - FED0_23FFh
|
|
|
|
11 FED0_3000h - FED0_33FFh */
|
2004-08-24 18:20:46 +02:00
|
|
|
|
2010-03-14 18:01:08 +01:00
|
|
|
dword &= ~(3 << 15); /* clear it */
|
|
|
|
dword |= (code << 15);
|
2004-08-24 18:20:46 +02:00
|
|
|
|
2010-03-17 04:14:28 +01:00
|
|
|
printk_debug("enabling HPET @0x%lx\n", hpet_address | (code << 12));
|
2004-08-24 18:20:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void lpc_init(struct device *dev)
|
|
|
|
{
|
2010-03-14 18:01:08 +01:00
|
|
|
u8 byte;
|
|
|
|
int pwr_on = -1;
|
2009-06-03 16:19:33 +02:00
|
|
|
int nmi_option;
|
2004-08-24 18:20:46 +02:00
|
|
|
|
|
|
|
/* IO APIC initialization */
|
2010-02-27 02:50:21 +01:00
|
|
|
i82801dx_enable_ioapic(dev);
|
2004-08-24 18:20:46 +02:00
|
|
|
|
2010-02-27 02:50:21 +01:00
|
|
|
i82801dx_enable_serial_irqs(dev);
|
2005-09-21 15:53:44 +02:00
|
|
|
|
2010-03-14 18:01:08 +01:00
|
|
|
#ifdef SUSPICIOUS_LOOKING_CODE
|
2005-09-21 15:53:44 +02:00
|
|
|
// The ICH-4 datasheet does not mention this configuration register.
|
|
|
|
// This code may have been inherited (incorrectly) from code for the AMD 766 southbridge,
|
|
|
|
// which *does* support this functionality.
|
|
|
|
|
2004-08-24 18:20:46 +02:00
|
|
|
/* posted memory write enable */
|
|
|
|
byte = pci_read_config8(dev, 0x46);
|
2010-03-14 18:01:08 +01:00
|
|
|
pci_write_config8(dev, 0x46, byte | (1 << 0));
|
2005-09-21 15:53:44 +02:00
|
|
|
#endif
|
2004-08-24 18:20:46 +02:00
|
|
|
|
|
|
|
/* power after power fail */
|
2010-03-14 18:01:08 +01:00
|
|
|
/* FIXME this doesn't work! */
|
|
|
|
/* Which state do we want to goto after g3 (power restored)?
|
|
|
|
* 0 == S0 Full On
|
|
|
|
* 1 == S5 Soft Off
|
|
|
|
*/
|
|
|
|
pci_write_config8(dev, GEN_PMCON_3, pwr_on ? 0 : 1);
|
|
|
|
printk_info("set power %s after power fail\n", pwr_on ? "on" : "off");
|
2004-08-24 18:20:46 +02:00
|
|
|
#if 0
|
|
|
|
/* Enable Error reporting */
|
|
|
|
/* Set up sync flood detected */
|
|
|
|
byte = pci_read_config8(dev, 0x47);
|
|
|
|
byte |= (1 << 1);
|
|
|
|
pci_write_config8(dev, 0x47, byte);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Set up NMI on errors */
|
2010-03-14 18:01:08 +01:00
|
|
|
byte = inb(0x61);
|
|
|
|
byte &= ~(1 << 3); /* IOCHK# NMI Enable */
|
|
|
|
byte &= ~(1 << 2); /* PCI SERR# Enable */
|
|
|
|
outb(byte, 0x61);
|
|
|
|
byte = inb(0x70);
|
2004-08-24 18:20:46 +02:00
|
|
|
nmi_option = NMI_OFF;
|
2009-06-03 16:19:33 +02:00
|
|
|
get_option(&nmi_option, "nmi");
|
2010-03-14 18:01:08 +01:00
|
|
|
if (nmi_option) {
|
|
|
|
byte &= ~(1 << 7); /* set NMI */
|
|
|
|
outb(byte, 0x70);
|
2004-08-24 18:20:46 +02:00
|
|
|
}
|
2010-03-14 18:01:08 +01:00
|
|
|
|
2004-08-24 18:20:46 +02:00
|
|
|
/* Initialize the real time clock */
|
2010-02-27 02:50:21 +01:00
|
|
|
i82801dx_rtc_init(dev);
|
2004-08-24 18:20:46 +02:00
|
|
|
|
2010-02-27 02:50:21 +01:00
|
|
|
i82801dx_lpc_route_dma(dev, 0xff);
|
2004-08-24 18:20:46 +02:00
|
|
|
|
|
|
|
/* Initialize isa dma */
|
|
|
|
isa_dma_init();
|
|
|
|
|
2010-02-27 02:50:21 +01:00
|
|
|
i82801dx_1f0_misc(dev);
|
2004-08-24 18:20:46 +02:00
|
|
|
/* Initialize the High Precision Event Timers */
|
|
|
|
enable_hpet(dev);
|
|
|
|
}
|
|
|
|
|
2010-02-27 02:50:21 +01:00
|
|
|
static void i82801dx_lpc_read_resources(device_t dev)
|
2004-08-24 18:20:46 +02:00
|
|
|
{
|
2004-10-22 04:33:51 +02:00
|
|
|
struct resource *res;
|
2004-08-24 18:20:46 +02:00
|
|
|
|
2009-07-02 20:56:24 +02:00
|
|
|
/* Get the normal PCI resources of this device. */
|
2004-08-24 18:20:46 +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. */
|
2004-10-22 04:33:51 +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 |
|
2010-03-14 18:01:08 +01:00
|
|
|
IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
|
2004-10-22 04:33:51 +02:00
|
|
|
|
|
|
|
res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0));
|
2009-07-02 20:56:24 +02:00
|
|
|
res->base = 0xff800000;
|
2010-03-14 18:01:08 +01:00
|
|
|
res->size = 0x00800000; /* 8 MB for flash */
|
2009-07-02 20:56:24 +02:00
|
|
|
res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE |
|
2010-03-14 18:01:08 +01:00
|
|
|
IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
|
2009-07-02 20:56:24 +02:00
|
|
|
|
2010-03-14 18:01:08 +01:00
|
|
|
res = new_resource(dev, 3); /* IOAPIC */
|
2009-07-02 20:56:24 +02:00
|
|
|
res->base = 0xfec00000;
|
|
|
|
res->size = 0x00001000;
|
|
|
|
res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
|
2004-10-22 04:33:51 +02:00
|
|
|
}
|
|
|
|
|
2010-02-27 02:50:21 +01:00
|
|
|
static void i82801dx_lpc_enable_resources(device_t dev)
|
2004-10-22 04:33:51 +02:00
|
|
|
{
|
|
|
|
pci_dev_enable_resources(dev);
|
|
|
|
enable_childrens_resources(dev);
|
2004-08-24 18:20:46 +02:00
|
|
|
}
|
|
|
|
|
2010-03-14 18:01:08 +01:00
|
|
|
static struct device_operations lpc_ops = {
|
|
|
|
.read_resources = i82801dx_lpc_read_resources,
|
|
|
|
.set_resources = pci_dev_set_resources,
|
2010-02-27 02:50:21 +01:00
|
|
|
.enable_resources = i82801dx_lpc_enable_resources,
|
2010-03-14 18:01:08 +01:00
|
|
|
.init = lpc_init,
|
|
|
|
.scan_bus = scan_static_bus,
|
|
|
|
.enable = i82801dx_enable,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* 82801DB/DBL */
|
|
|
|
static const struct pci_driver lpc_driver_db __pci_driver = {
|
|
|
|
.ops = &lpc_ops,
|
|
|
|
.vendor = PCI_VENDOR_ID_INTEL,
|
|
|
|
.device = PCI_DEVICE_ID_INTEL_82801DB_LPC,
|
2004-08-24 18:20:46 +02:00
|
|
|
};
|
|
|
|
|
2010-03-14 18:01:08 +01:00
|
|
|
/* 82801DBM */
|
|
|
|
static const struct pci_driver lpc_driver_dbm __pci_driver = {
|
|
|
|
.ops = &lpc_ops,
|
2004-08-24 18:20:46 +02:00
|
|
|
.vendor = PCI_VENDOR_ID_INTEL,
|
2007-11-04 04:21:37 +01:00
|
|
|
.device = PCI_DEVICE_ID_INTEL_82801DBM_LPC,
|
2004-08-24 18:20:46 +02:00
|
|
|
};
|