2 * (C) 2003 Linux Networx, SuSE Linux AG
3 * (C) 2004 Tyan Computer
5 #include <console/console.h>
6 #include <device/device.h>
7 #include <device/pci.h>
8 #include <device/pci_ids.h>
9 #include <device/pci_ops.h>
10 #include <pc80/mc146818rtc.h>
11 #include <pc80/isa-dma.h>
13 #include "i82801dbm.h"
19 void i82801dbm_enable_ioapic( struct device *dev)
22 volatile uint32_t *ioapic_sba = (volatile uint32_t *)0xfec00000;
23 volatile uint32_t *ioapic_sbd = (volatile uint32_t *)0xfec00010;
25 dword = pci_read_config32(dev, GEN_CNTL);
26 dword |= (3 << 7); /* enable ioapic */
27 dword |= (1 <<13); /* coprocessor error enable */
28 dword |= (1 << 1); /* delay transaction enable */
29 dword |= (1 << 2); /* DMA collection buf enable */
30 pci_write_config32(dev, GEN_CNTL, dword);
31 printk_debug("ioapic southbridge enabled %x\n",dword);
38 printk_debug("Southbridge apic id = %x\n",dword);
42 //lyh dword=*ioapic_sbd;
43 //lyh printk_debug("Southbridge apic DT = %x\n",dword);
49 void i82801dbm_enable_serial_irqs( struct device *dev)
51 pci_write_config8(dev, SERIRQ_CNTL, (1 << 7)|(1 << 6)|((21 - 17) << 2)|(0<< 0));
53 void i82801dbm_lpc_route_dma( struct device *dev, uint8_t mask)
57 word = pci_read_config16(dev, PCI_DMA_CFG);
58 word &= ((1 << 10) - (1 << 8));
59 for(i = 0; i < 8; i++) {
62 word |= ((mask & (1 << i))? 3:1) << (i*2);
64 pci_write_config16(dev, PCI_DMA_CFG, word);
66 void i82801dbm_rtc_init(struct device *dev)
71 byte = pci_read_config8(dev, GEN_PMCON_3);
72 rtc_failed = byte & RTC_FAILED;
74 byte &= ~(1 << 1); /* preserve the power fail state */
75 pci_write_config8(dev, GEN_PMCON_3, byte);
77 dword = pci_read_config32(dev, GEN_STS);
78 rtc_failed |= dword & (1 << 2);
83 void i82801dbm_1f0_misc(struct device *dev)
85 pci_write_config16(dev, PCICMD, 0x014f);
86 pci_write_config32(dev, PMBASE, 0x00001001);
87 pci_write_config8(dev, ACPI_CNTL, 0x10);
88 pci_write_config32(dev, GPIO_BASE, 0x00001181);
89 pci_write_config8(dev, GPIO_CNTL, 0x10);
90 pci_write_config32(dev, PIRQA_ROUT, 0x0A05030B);
91 pci_write_config8(dev, PIRQE_ROUT, 0x07);
92 pci_write_config8(dev, RTC_CONF, 0x04);
93 pci_write_config8(dev, COM_DEC, 0x10); //lyh E0->
94 pci_write_config16(dev, LPC_EN, 0x000F); //LYH 000D->
97 static void enable_hpet(struct device *dev)
99 const unsigned long hpet_address = 0xfed0000;
102 uint32_t code = (0 & 0x3);
104 dword = pci_read_config32(dev, GEN_CNTL);
105 dword |= (1 << 17); /* enable hpet */
106 /*Bits [16:15]Memory Address Range
107 00 FED0_0000h - FED0_03FFh
108 01 FED0_1000h - FED0_13FFh
109 10 FED0_2000h - FED0_23FFh
110 11 FED0_3000h - FED0_33FFh*/
112 dword &= ~(3 << 15); /* clear it */
115 printk_debug("enabling HPET @0x%x\n", hpet_address | (code <<12) );
118 static void lpc_init(struct device *dev)
124 /* IO APIC initialization */
125 i82801dbm_enable_ioapic(dev);
127 i82801dbm_enable_serial_irqs(dev);
129 #ifdef SUSPICIOUS_LOOKING_CODE
130 // The ICH-4 datasheet does not mention this configuration register.
131 // This code may have been inherited (incorrectly) from code for the AMD 766 southbridge,
132 // which *does* support this functionality.
134 /* posted memory write enable */
135 byte = pci_read_config8(dev, 0x46);
136 pci_write_config8(dev, 0x46, byte | (1<<0));
139 /* power after power fail */
140 /* FIXME this doesn't work! */
141 /* Which state do we want to goto after g3 (power restored)?
145 pci_write_config8(dev, GEN_PMCON_3, pwr_on?0:1);
146 printk_info("set power %s after power fail\n", pwr_on?"on":"off");
148 /* Enable Error reporting */
149 /* Set up sync flood detected */
150 byte = pci_read_config8(dev, 0x47);
152 pci_write_config8(dev, 0x47, byte);
155 /* Set up NMI on errors */
157 byte &= ~(1 << 3); /* IOCHK# NMI Enable */
158 byte &= ~(1 << 2); /* PCI SERR# Enable */
161 nmi_option = NMI_OFF;
162 get_option(&nmi_option, "nmi");
164 byte &= ~(1 << 7); /* set NMI */
168 /* Initialize the real time clock */
169 i82801dbm_rtc_init(dev);
171 i82801dbm_lpc_route_dma(dev, 0xff);
173 /* Initialize isa dma */
176 i82801dbm_1f0_misc(dev);
177 /* Initialize the High Precision Event Timers */
181 static void i82801dbm_lpc_read_resources(device_t dev)
183 struct resource *res;
185 /* Get the normal pci resources of this device */
186 pci_dev_read_resources(dev);
188 /* Add an extra subtractive resource for both memory and I/O */
189 res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0));
190 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
192 res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0));
193 res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
196 static void i82801dbm_lpc_enable_resources(device_t dev)
198 pci_dev_enable_resources(dev);
199 enable_childrens_resources(dev);
202 static struct device_operations lpc_ops = {
203 .read_resources = i82801dbm_lpc_read_resources,
204 .set_resources = pci_dev_set_resources,
205 .enable_resources = i82801dbm_lpc_enable_resources,
207 .scan_bus = scan_static_bus,
208 .enable = i82801dbm_enable,
211 static const struct pci_driver lpc_driver __pci_driver = {
213 .vendor = PCI_VENDOR_ID_INTEL,
214 .device = PCI_DEVICE_ID_INTEL_82801DBM_LPC,