2 * This file is part of the LinuxBIOS project.
4 * Copyright (C) 2007 Rudolf Marek <r.marek@assembler.cz>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License v2 as published by
8 * the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 /* Inspiration from other VIA SB code. */
23 #include <console/console.h>
24 #include <device/device.h>
25 #include <device/pci.h>
26 #include <device/pci_ops.h>
27 #include <device/pci_ids.h>
28 #include <pc80/mc146818rtc.h>
29 #include <cpu/x86/lapic.h>
34 #define ALL (0xff << 24)
36 #define DISABLED (1 << 16)
37 #define ENABLED (0 << 16)
38 #define TRIGGER_EDGE (0 << 15)
39 #define TRIGGER_LEVEL (1 << 15)
40 #define POLARITY_HIGH (0 << 13)
41 #define POLARITY_LOW (1 << 13)
42 #define PHYSICAL_DEST (0 << 11)
43 #define LOGICAL_DEST (1 << 11)
44 #define ExtINT (7 << 8)
49 extern void dump_south(device_t dev);
56 /* IO-APIC virtual wire mode configuration. */
57 /* mask, trigger, polarity, destination, delivery, vector */
58 {0, ENABLED | TRIGGER_EDGE | POLARITY_HIGH | PHYSICAL_DEST |
85 static void setup_ioapic(u32 ioapic_base)
87 u32 value_low, value_high, val;
91 /* All delivered to CPU0. */
92 ioapic_table[0].value_high = (lapicid()) << (56 - 32);
93 l = (unsigned long *)ioapic_base;
95 /* Set APIC to FSB message bus. */
98 l[4] = (val & 0xFFFFFE) | 1;
100 /* Set APIC ADDR - this will be VT8237R_APIC_ID. */
103 l[4] = (val & 0xF0FFFF) | (VT8237R_APIC_ID << 24);
105 for (i = 0; i < ARRAY_SIZE(ioapic_table); i++) {
106 l[0] = (ioapic_table[i].reg * 2) + 0x10;
107 l[4] = ioapic_table[i].value_low;
109 l[0] = (ioapic_table[i].reg * 2) + 0x11;
110 l[4] = ioapic_table[i].value_high;
113 if ((i == 0) && (value_low == 0xffffffff)) {
114 printk_warning("IO APIC not responding.\n");
120 /** Set up PCI IRQ routing, route everything through APIC. */
121 static void pci_routing_fixup(struct device *dev)
123 /* PCI PNP Interrupt Routing INTE/F - disable */
124 pci_write_config8(dev, 0x44, 0x00);
126 /* PCI PNP Interrupt Routing INTG/H - disable */
127 pci_write_config8(dev, 0x45, 0x00);
129 /* Route INTE-INTH through registers above, no map to INTA-INTD. */
130 pci_write_config8(dev, 0x46, 0x10);
132 /* PCI Interrupt Polarity */
133 pci_write_config8(dev, 0x54, 0x00);
135 /* PCI INTA# Routing */
136 pci_write_config8(dev, 0x55, 0x00);
138 /* PCI INTB#/C# Routing */
139 pci_write_config8(dev, 0x56, 0x00);
141 /* PCI INTD# Routing */
142 pci_write_config8(dev, 0x57, 0x00);
146 * Set up the power management capabilities directly into ACPI mode.
147 * This avoids having to handle any System Management Interrupts (SMIs).
149 void setup_pm(device_t dev)
151 /* Debounce LID and PWRBTN# Inputs for 16ms. */
152 pci_write_config8(dev, 0x80, 0x20);
154 /* Set ACPI base address to I/O VT8237R_ACPI_IO_BASE. */
155 pci_write_config16(dev, 0x88, VT8237R_ACPI_IO_BASE | 0x1);
157 /* Set ACPI to 9, must set IRQ 9 override to level! Set PSON gating. */
158 pci_write_config8(dev, 0x82, 0x40 | VT8237R_ACPI_IRQ);
160 /* Primary interupt channel, define wake events 0=IRQ0 15=IRQ15 1=en. */
161 pci_write_config16(dev, 0x84, 0x30b2);
163 /* SMI output level to low, 7.5us throttle clock */
164 pci_write_config8(dev, 0x8d, 0x18);
166 /* GP Timer Control 1s */
167 pci_write_config8(dev, 0x93, 0x88);
169 /* 7 = SMBus clock from RTC 32.768KHz
170 * 5 = Internal PLL reset from susp
173 pci_write_config8(dev, 0x94, 0xa4);
175 /* 7 = stp to sust delay 1msec
176 * 6 = SUSST# Deasserted Before PWRGD for STD
177 * 3 = GPO26/GPO27 is GPO
178 * 2 = Disable Alert on Lan
180 pci_write_config8(dev, 0x95, 0xcc);
182 /* Disable GP3 timer. */
183 pci_write_config8(dev, 0x98, 0);
185 /* Enable SATA LED, disable special CPU Frequency Change -
186 * GPIO28 GPIO22 GPIO29 GPIO23 are GPIOs.
188 pci_write_config8(dev, 0xe5, 0x9);
190 /* REQ5 as PCI request input - should be together with INTE-INTH. */
191 pci_write_config8(dev, 0xe4, 0x4);
193 /* Enable ACPI accessm RTC signal gated with PSON. */
194 pci_write_config8(dev, 0x81, 0x84);
196 /* Clear status events. */
197 outw(0xffff, VT8237R_ACPI_IO_BASE + 0x00);
198 outw(0xffff, VT8237R_ACPI_IO_BASE + 0x20);
199 outw(0xffff, VT8237R_ACPI_IO_BASE + 0x28);
200 outl(0xffffffff, VT8237R_ACPI_IO_BASE + 0x30);
202 /* Disable SCI on GPIO. */
203 outw(0x0, VT8237R_ACPI_IO_BASE + 0x22);
205 /* Disable SMI on GPIO. */
206 outw(0x0, VT8237R_ACPI_IO_BASE + 0x24);
208 /* Disable all global enable SMIs. */
209 outw(0x0, VT8237R_ACPI_IO_BASE + 0x2a);
211 /* All SMI off, both IDE buses ON, PSON rising edge. */
212 outw(0x0, VT8237R_ACPI_IO_BASE + 0x2c);
214 /* Primary activity SMI disable. */
215 outl(0x0, VT8237R_ACPI_IO_BASE + 0x34);
217 /* GP timer reload on none. */
218 outl(0x0, VT8237R_ACPI_IO_BASE + 0x38);
220 /* Disable extended IO traps. */
221 outb(0x0, VT8237R_ACPI_IO_BASE + 0x42);
223 /* SCI is generated for RTC/pwrBtn/slpBtn. */
224 outw(0x001, VT8237R_ACPI_IO_BASE + 0x04);
227 static void vt8237r_init(struct device *dev)
231 /* Enable addr/data stepping. */
232 byte = pci_read_config8(dev, PCI_COMMAND);
233 byte |= PCI_COMMAND_WAIT;
234 pci_write_config8(dev, PCI_COMMAND, byte);
236 /* Enable the internal I/O decode. */
237 enables = pci_read_config8(dev, 0x6C);
239 pci_write_config8(dev, 0x6C, enables);
241 /* FIXME: Map 4MB of flash into the address space,
242 * this should be in CAR call.
244 /* pci_write_config8(dev, 0x41, 0x7f); */
246 /* Set bit 6 of 0x40 (I/O recovery time).
247 * IMPORTANT FIX - EISA = ECLR reg at 0x4d0! Decoding must be on so
248 * that PCI interrupts can be properly marked as level triggered.
250 enables = pci_read_config8(dev, 0x40);
252 pci_write_config8(dev, 0x40, enables);
254 /* Line buffer control */
255 enables = pci_read_config8(dev, 0x42);
257 pci_write_config8(dev, 0x42, enables);
259 /* Delay transaction control */
260 pci_write_config8(dev, 0x43, 0xb);
262 /* I/O recovery time */
263 pci_write_config8(dev, 0x4c, 0x44);
265 /* ROM memory cycles go to LPC. */
266 pci_write_config8(dev, 0x59, 0x80);
268 /* Bypass APIC De-Assert Message, INTE#, INTF#, INTG#, INTH# as PCI. */
269 pci_write_config8(dev, 0x5B, 0xb);
271 /* Set Read Pass Write Control Enable (force A2 from APIC FSB to low). */
272 pci_write_config8(dev, 0x48, 0x8c);
274 /* Set 0x58 to 0x43 APIC and RTC. */
275 pci_write_config8(dev, 0x58, 0x43);
277 /* Set bit 3 of 0x4f (use INIT# as CPU reset). */
278 enables = pci_read_config8(dev, 0x4f);
280 pci_write_config8(dev, 0x4f, enables);
282 /* Enable serial IRQ, 6PCI clocks. */
283 pci_write_config8(dev, 0x52, 0x9);
285 /* Enable HPET at VT8237R_HPET_ADDR. */
286 pci_write_config32(dev, 0x68, (VT8237R_HPET_ADDR | 0x80));
288 /* Power management setup */
295 void vt8237r_read_resources(device_t dev)
297 struct resource *res;
299 pci_dev_read_resources(dev);
300 /* Fixed APIC resource */
301 res = new_resource(dev, 0x44);
302 res->base = VT8237R_APIC_BASE;
304 res->limit = res->base + res->size - 1;
307 res->flags = IORESOURCE_MEM | IORESOURCE_FIXED |
308 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
312 * The VT8237R is not a PCI bridge and has no resources of its own (other
313 * than standard PC I/O addresses), however it does control the ISA bus
314 * and so we need to manually call enable childrens resources on that bus.
316 void vt8237r_enable_resources(device_t dev)
318 pci_dev_enable_resources(dev);
319 enable_childrens_resources(dev);
322 static void init_keyboard(struct device *dev)
324 u8 regval = pci_read_config8(dev, 0x51);
326 init_pc_keyboard(0x60, 0x64, 0);
329 static void southbridge_init(struct device *dev)
332 pci_routing_fixup(dev);
333 setup_ioapic(VT8237R_APIC_BASE);
338 static const struct device_operations vt8237r_lpc_ops = {
339 .read_resources = vt8237r_read_resources,
340 .set_resources = pci_dev_set_resources,
341 .enable_resources = vt8237r_enable_resources,
342 .init = &southbridge_init,
343 .scan_bus = scan_static_bus,
346 static const struct pci_driver lpc_driver __pci_driver = {
347 .ops = &vt8237r_lpc_ops,
348 .vendor = PCI_VENDOR_ID_VIA,
349 .device = PCI_DEVICE_ID_VIA_VT8237R_LPC,