2 * This file is part of the LinuxBIOS project.
4 * Copyright (C) 2003 Linux Networx
5 * Copyright (C) 2003 SuSE Linux AG
6 * Copyright (C) 2005 Tyan Computer
7 * (Written by Yinghai Lu <yinghailu@gmail.com> for Tyan Computer)
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 /* From 82801DBM, needs to be fixed to support everything the 82801ER does. */
26 #include <console/console.h>
27 #include <device/device.h>
28 #include <device/pci.h>
29 #include <device/pci_ids.h>
30 #include <pc80/mc146818rtc.h>
31 #include <pc80/isa-dma.h>
35 #define PMBASE_ADDR 0x00000400 /* ACPI Base Address Register */
36 #define GPIO_BASE_ADDR 0x00000500 /* GPIO Base Address Register */
40 /* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control
41 * 0x00 - 0000 = Reserved
42 * 0x01 - 0001 = Reserved
43 * 0x02 - 0010 = Reserved
49 * 0x08 - 1000 = Reserved
54 * 0x0D - 1101 = Reserved
57 * PIRQ[n]_ROUT[7] - PIRQ Routing Control
58 * 0x80 - The PIRQ is not routed.
70 void i82801xx_enable_apic(struct device *dev)
73 volatile uint32_t *ioapic_index = (volatile uint32_t *)0xfec00000;
74 volatile uint32_t *ioapic_data = (volatile uint32_t *)0xfec00010;
76 /* Set ACPI base address (I/O space). */
77 pci_write_config32(dev, PMBASE, (PMBASE_ADDR | 1));
79 /* Enable ACPI I/O and power management. */
80 pci_write_config8(dev, ACPI_CNTL, 0x10);
82 reg32 = pci_read_config32(dev, GEN_CNTL);
83 reg32 |= (3 << 7); /* Enable IOAPIC */
84 reg32 |= (1 << 13); /* Coprocessor error enable */
85 reg32 |= (1 << 1); /* Delayed transaction enable */
86 reg32 |= (1 << 2); /* DMA collection buffer enable */
87 pci_write_config32(dev, GEN_CNTL, reg32);
88 printk_debug("IOAPIC Southbridge enabled %x\n", reg32);
91 *ioapic_data = (1 << 25);
95 printk_debug("Southbridge APIC ID = %x\n", reg32);
96 if (reg32 != (1 << 25))
99 /* TODO: From i82801ca, needed/useful on other ICH? */
100 *ioapic_index = 3; /* Select Boot Configuration register. */
101 *ioapic_data = 1; /* Use Processor System Bus to deliver interrupts. */
104 void i82801xx_enable_serial_irqs(struct device *dev)
106 /* Set packet length and toggle silent mode bit. */
107 pci_write_config8(dev, SERIRQ_CNTL,
108 (1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0));
109 pci_write_config8(dev, SERIRQ_CNTL,
110 (1 << 7) | (0 << 6) | ((21 - 17) << 2) | (0 << 0));
111 /* TODO: Explain/#define the real meaning of these magic numbers. */
114 static void i82801xx_pirq_init(device_t dev, uint16_t ich_model)
116 /* Route PIRQA - PIRQD. */
117 pci_write_config8(dev, PIRQA_ROUT, PIRQA);
118 pci_write_config8(dev, PIRQB_ROUT, PIRQB);
119 pci_write_config8(dev, PIRQC_ROUT, PIRQC);
120 pci_write_config8(dev, PIRQD_ROUT, PIRQD);
122 /* Route PIRQE - PIRQH (for ICH2-ICH9). */
123 if (ich_model >= 0x2440) {
124 pci_write_config8(dev, PIRQE_ROUT, PIRQE);
125 pci_write_config8(dev, PIRQF_ROUT, PIRQF);
126 pci_write_config8(dev, PIRQG_ROUT, PIRQG);
127 pci_write_config8(dev, PIRQH_ROUT, PIRQH);
131 static void i82801xx_power_options(device_t dev)
137 /* power after power fail */
138 /* FIXME this doesn't work! */
139 /* Which state do we want to goto after g3 (power restored)?
143 pci_write_config8(dev, GEN_PMCON_3, pwr_on ? 0 : 1);
144 printk_info("Set power %s if power fails\n", pwr_on ? "on" : "off");
146 /* Set up NMI on errors. */
148 byte &= ~(1 << 3); /* IOCHK# NMI Enable */
149 byte &= ~(1 << 2); /* PCI SERR# Enable */
153 nmi_option = NMI_OFF;
154 get_option(&nmi_option, "nmi");
156 byte &= ~(1 << 7); /* Set NMI. */
161 static void gpio_init(device_t dev, uint16_t ich_model)
163 /* Set the value for GPIO base address register and enable GPIO.
164 * Note: ICH-ICH5 registers differ from ICH6-ICH9.
166 if (ich_model <= 0x24D0) {
167 pci_write_config32(dev, GPIO_BASE_ICH0_5, (GPIO_BASE_ADDR | 1));
168 pci_write_config8(dev, GPIO_CNTL_ICH0_5, 0x10);
169 } else if (ich_model >= 0x2640) {
170 pci_write_config32(dev, GPIO_BASE_ICH6_9, (GPIO_BASE_ADDR | 1));
171 pci_write_config8(dev, GPIO_CNTL_ICH6_9, 0x10);
175 void i82801xx_rtc_init(struct device *dev)
181 reg8 = pci_read_config8(dev, GEN_PMCON_3);
182 rtc_failed = reg8 & RTC_BATTERY_DEAD;
184 reg8 &= ~(1 << 1); /* Preserve the power fail state. */
185 pci_write_config8(dev, GEN_PMCON_3, reg8);
187 reg32 = pci_read_config32(dev, GEN_STS);
188 rtc_failed |= reg32 & (1 << 2);
189 rtc_init(rtc_failed);
191 /* Enable access to the upper 128 byte bank of CMOS RAM. */
192 pci_write_config8(dev, RTC_CONF, 0x04);
195 void i82801xx_lpc_route_dma(struct device *dev, uint8_t mask)
200 reg16 = pci_read_config16(dev, PCI_DMA_CFG);
202 for (i = 0; i < 8; i++) {
205 reg16 |= ((mask & (1 << i)) ? 3 : 1) << (i * 2);
207 pci_write_config16(dev, PCI_DMA_CFG, reg16);
210 static void i82801xx_lpc_decode_en(device_t dev, uint16_t ich_model)
212 /* Decode 0x3F8-0x3FF (COM1) for COMA port, 0x2F8-0x2FF (COM2) for COMB.
213 * LPT decode defaults to 0x378-0x37F and 0x778-0x77F.
214 * Floppy decode defaults to 0x3F0-0x3F5, 0x3F7.
215 * We also need to set the value for LPC I/F Enables Register.
216 * Note: ICH-ICH5 registers differ from ICH6-ICH9.
218 if (ich_model <= 0x24D0) {
219 pci_write_config8(dev, COM_DEC, 0x10);
220 pci_write_config16(dev, LPC_EN_ICH0_5, 0x300F);
221 } else if (ich_model >= 0x2640) {
222 pci_write_config8(dev, LPC_IO_DEC, 0x10);
223 pci_write_config16(dev, LPC_EN_ICH6_9, 0x300F);
227 static void enable_hpet(struct device *dev)
231 uint32_t code = (0 & 0x3);
233 reg32 = pci_read_config32(dev, GEN_CNTL);
234 reg32 |= (1 << 17); /* Enable HPET. */
236 * Bits [16:15] Memory Address Range
237 * 00 FED0_0000h - FED0_03FFh
238 * 01 FED0_1000h - FED0_13FFh
239 * 10 FED0_2000h - FED0_23FFh
240 * 11 FED0_3000h - FED0_33FFh
242 reg32 &= ~(3 << 15); /* Clear it */
243 reg32 |= (code << 15);
244 /* TODO: reg32 is never written to anywhere? */
245 printk_debug("Enabling HPET @0x%x\n", HPET_ADDR | (code << 12));
249 static void lpc_init(struct device *dev)
251 uint16_t ich_model = pci_read_config16(dev, PCI_DEVICE_ID);
253 /* Set the value for PCI command register. */
254 pci_write_config16(dev, PCI_COMMAND, 0x000f);
256 /* IO APIC initialization. */
257 i82801xx_enable_apic(dev);
259 i82801xx_enable_serial_irqs(dev);
261 /* Setup the PIRQ. */
262 i82801xx_pirq_init(dev, ich_model);
264 /* Setup power options. */
265 i82801xx_power_options(dev);
267 /* Set the state of the GPIO lines. */
268 gpio_init(dev, ich_model);
270 /* Initialize the real time clock. */
271 i82801xx_rtc_init(dev);
274 i82801xx_lpc_route_dma(dev, 0xff);
276 /* Initialize ISA DMA. */
279 /* Setup decode ports and LPC I/F enables. */
280 i82801xx_lpc_decode_en(dev, ich_model);
282 /* Initialize the High Precision Event Timers, if present. */
286 static void i82801xx_lpc_read_resources(device_t dev)
288 struct resource *res;
290 /* Get the normal PCI resources of this device. */
291 pci_dev_read_resources(dev);
293 /* Add an extra subtractive resource for both memory and I/O. */
294 res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0));
296 IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
298 res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0));
300 IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
303 static void i82801xx_lpc_enable_resources(device_t dev)
305 pci_dev_enable_resources(dev);
306 enable_childrens_resources(dev);
309 static struct device_operations lpc_ops = {
310 .read_resources = i82801xx_lpc_read_resources,
311 .set_resources = pci_dev_set_resources,
312 .enable_resources = i82801xx_lpc_enable_resources,
314 .scan_bus = scan_static_bus,
315 .enable = i82801xx_enable,
318 static const struct pci_driver i82801aa_lpc __pci_driver = {
320 .vendor = PCI_VENDOR_ID_INTEL,
324 static const struct pci_driver i82801ab_lpc __pci_driver = {
326 .vendor = PCI_VENDOR_ID_INTEL,
330 static const struct pci_driver i82801ba_lpc __pci_driver = {
332 .vendor = PCI_VENDOR_ID_INTEL,
336 static const struct pci_driver i82801ca_lpc __pci_driver = {
338 .vendor = PCI_VENDOR_ID_INTEL,
342 static const struct pci_driver i82801db_lpc __pci_driver = {
344 .vendor = PCI_VENDOR_ID_INTEL,
348 static const struct pci_driver i82801dbm_lpc __pci_driver = {
350 .vendor = PCI_VENDOR_ID_INTEL,
354 /* 82801EB and 82801ER */
355 static const struct pci_driver i82801ex_lpc __pci_driver = {
357 .vendor = PCI_VENDOR_ID_INTEL,