Add constants for fast path resume copying
[coreboot.git] / src / southbridge / via / vt8237r / lpc.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007, 2008 Rudolf Marek <r.marek@assembler.cz>
5  * Copyright (C) 2009 Jon Harrison <bothlyn@blueyonder.co.uk>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; version 2 of the License.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20
21 /* Inspiration from other VIA SB code. */
22
23 #include <arch/io.h>
24 #include <console/console.h>
25 #include <device/device.h>
26 #include <device/pci.h>
27 #include <device/pci_ids.h>
28 #include <pc80/mc146818rtc.h>
29 #include <arch/ioapic.h>
30 #include <cpu/x86/lapic.h>
31 #include <cpu/cpu.h>
32 #include <pc80/keyboard.h>
33 #include <pc80/i8259.h>
34 #include <stdlib.h>
35 #include <arch/acpi.h>
36 #include "vt8237r.h"
37 #include "chip.h"
38
39 static void southbridge_init_common(struct device *dev);
40
41 #if CONFIG_EPIA_VT8237R_INIT
42                    /* Interrupts for  INT# A   B   C   D */
43 static const unsigned char pciIrqs[4]  = { 10, 11, 12, 0};
44
45             /* Interrupt Assignments for Pins   1   2   3   4  */
46 static const unsigned char sataPins[4] =     { 'A','B','C','D'};
47 static const unsigned char vgaPins[4] =      { 'A','B','C','D'};
48 static const unsigned char usbPins[4] =      { 'A','B','C','D'};
49 static const unsigned char enetPins[4] =     { 'A','B','C','D'};
50 static const unsigned char vt8237Pins[4] =   { 'A','B','C','D'};
51 static const unsigned char slotPins[4] =     { 'C','D','A','B'};
52 static const unsigned char riserPins[4] =    { 'D','C','B','A'};
53
54 static unsigned char *pin_to_irq(const unsigned char *pin)
55 {
56         static unsigned char Irqs[4];
57         int i;
58         for (i = 0 ; i < 4 ; i++)
59                 Irqs[i] = pciIrqs[ pin[i] - 'A' ];
60
61         return Irqs;
62 }
63 #endif
64
65 /** Set up PCI IRQ routing, route everything through APIC. */
66 static void pci_routing_fixup(struct device *dev)
67 {
68 #if CONFIG_EPIA_VT8237R_INIT
69         device_t pdev;
70 #endif
71
72         /* PCI PNP Interrupt Routing INTE/F - disable */
73         pci_write_config8(dev, 0x44, 0x00);
74
75         /* PCI PNP Interrupt Routing INTG/H - disable */
76         pci_write_config8(dev, 0x45, 0x00);
77
78         /* Gate Interrupts until RAM Writes are flushed */
79         pci_write_config8(dev, 0x49, 0x20);
80
81 #if CONFIG_EPIA_VT8237R_INIT
82
83         /* Share INTE-INTH with INTA-INTD as per stock BIOS. */
84         pci_write_config8(dev, 0x46, 0x00);
85
86         /* setup PCI IRQ routing (For PCI Slot)*/
87         pci_write_config8(dev, 0x55, pciIrqs[0] << 4);
88         pci_write_config8(dev, 0x56, pciIrqs[1] | (pciIrqs[2] << 4) );
89         pci_write_config8(dev, 0x57, pciIrqs[3] << 4);
90
91         /* PCI Routing Fixup */
92
93         //Setup MiniPCI Slot
94         pci_assign_irqs(0, 0x14, pin_to_irq(slotPins));
95
96         // Via 2 slot riser card 2nd slot
97         pci_assign_irqs(0, 0x13, pin_to_irq(riserPins));
98
99         //Setup USB
100         pci_assign_irqs(0, 0x10, pin_to_irq(usbPins));
101
102         //Setup VT8237R Sound
103         pci_assign_irqs(0, 0x11, pin_to_irq(vt8237Pins));
104
105         //Setup Ethernet
106         pci_assign_irqs(0, 0x12, pin_to_irq(enetPins));
107
108         //Setup VGA
109         pci_assign_irqs(1, 0x00, pin_to_irq(vgaPins));
110
111         /* APIC Routing Fixup */
112
113         // Setup SATA
114         pdev = dev_find_device(PCI_VENDOR_ID_VIA,
115                                 PCI_DEVICE_ID_VIA_VT6420_SATA, 0);
116         pci_write_config8(pdev, PCI_INTERRUPT_PIN, 0x02);
117         pci_assign_irqs(0, 0x0f, pin_to_irq(sataPins));
118
119
120         // Setup PATA Override
121         pdev = dev_find_device(PCI_VENDOR_ID_VIA,
122                                 PCI_DEVICE_ID_VIA_82C586_1, 0);
123         pci_write_config8(pdev, PCI_INTERRUPT_PIN, 0x01);
124         pci_write_config8(pdev, PCI_INTERRUPT_LINE, 0xFF);
125
126 #else
127         /* Route INTE-INTH through registers above, no map to INTA-INTD. */
128         pci_write_config8(dev, 0x46, 0x10);
129
130         /* PCI Interrupt Polarity */
131         pci_write_config8(dev, 0x54, 0x00);
132
133         /* PCI INTA# Routing */
134         pci_write_config8(dev, 0x55, 0x00);
135
136         /* PCI INTB#/C# Routing */
137         pci_write_config8(dev, 0x56, 0x00);
138
139         /* PCI INTD# Routing */
140         pci_write_config8(dev, 0x57, 0x00);
141 #endif
142 }
143
144
145
146 /**
147  * Set up the power management capabilities directly into ACPI mode.
148  * This avoids having to handle any System Management Interrupts (SMIs).
149  */
150
151 static void setup_pm(device_t dev)
152 {
153         u16 tmp;
154         struct southbridge_via_vt8237r_config *cfg;
155
156         cfg = dev->chip_info;
157
158         /* Debounce LID and PWRBTN# Inputs for 16ms. */
159         pci_write_config8(dev, 0x80, 0x20);
160
161         /* Set ACPI base address to I/O VT8237R_ACPI_IO_BASE. */
162         pci_write_config16(dev, 0x88, VT8237R_ACPI_IO_BASE | 0x1);
163
164         /* Set ACPI to 9, must set IRQ 9 override to level! Set PSON gating. */
165         pci_write_config8(dev, 0x82, 0x40 | VT8237R_ACPI_IRQ);
166
167 #if CONFIG_EPIA_VT8237R_INIT
168         /* Primary interupt channel, define wake events 0=IRQ0 15=IRQ15 1=en. */
169         pci_write_config16(dev, 0x84, 0x3052);
170 #else
171         /* Primary interupt channel, define wake events 0=IRQ0 15=IRQ15 1=en. */
172         pci_write_config16(dev, 0x84, 0x30b2);
173
174 #endif
175         /* SMI output level to low, 7.5us throttle clock */
176         pci_write_config8(dev, 0x8d, 0x18);
177
178         /* GP Timer Control 1s */
179         pci_write_config8(dev, 0x93, 0x88);
180
181         /*
182          * 7 = SMBus clock from RTC 32.768KHz
183          * 5 = Internal PLL reset from susp disabled
184          * 2 = GPO2 is SUSA#
185          */
186         tmp = 0xa0;
187         if (cfg && cfg->enable_gpo3)
188                 tmp |= 0x10;
189         pci_write_config8(dev, 0x94, tmp);
190
191         /*
192          * 7 = stp to sust delay 1msec
193          * 6 = SUSST# Deasserted Before PWRGD for STD
194          * 5 = Keyboard/Mouse Swap
195          * 4 = PWRGOOD reset on VT8237A/S
196          * 3 = GPO26/GPO27 is GPO
197          * 2 = Disable Alert on Lan
198          * 1 = SUSCLK/GPO4
199          * 0 = USB Wakeup
200          */
201
202 #if CONFIG_EPIA_VT8237R_INIT
203         pci_write_config8(dev, 0x95, 0xc2);
204 #else
205         tmp = 0xcc;
206         if (cfg) {
207                 if (cfg->disable_gpo26_gpo27)
208                         tmp &= ~0x08;
209                 if (cfg->enable_aol_2_smb_slave)
210                         tmp &= ~0x04;
211         }
212         pci_write_config8(dev, 0x95, tmp);
213 #endif
214
215         /* Disable GP3 timer. */
216         pci_write_config8(dev, 0x98, 0);
217
218         /* Enable ACPI accessm RTC signal gated with PSON. */
219         pci_write_config8(dev, 0x81, 0x84);
220
221         /* Clear status events. */
222         outw(0xffff, VT8237R_ACPI_IO_BASE + 0x00);
223         outw(0xffff, VT8237R_ACPI_IO_BASE + 0x20);
224         outw(0xffff, VT8237R_ACPI_IO_BASE + 0x28);
225         outl(0xffffffff, VT8237R_ACPI_IO_BASE + 0x30);
226
227         /* Disable SCI on GPIO. */
228         outw(0x0, VT8237R_ACPI_IO_BASE + 0x22);
229
230         /* Disable SMI on GPIO. */
231         outw(0x0, VT8237R_ACPI_IO_BASE + 0x24);
232
233         /* Disable all global enable SMIs, except SW SMI */
234         outw(0x40, VT8237R_ACPI_IO_BASE + 0x2a);
235
236         /* Primary activity SMI disable. */
237         outl(0x0, VT8237R_ACPI_IO_BASE + 0x34);
238
239         /* GP timer reload on none. */
240         outl(0x0, VT8237R_ACPI_IO_BASE + 0x38);
241
242         /* Disable extended IO traps. */
243         outb(0x0, VT8237R_ACPI_IO_BASE + 0x42);
244
245         /* SCI is generated for RTC/pwrBtn/slpBtn. */
246         tmp = inw(VT8237R_ACPI_IO_BASE + 0x04);
247 #if CONFIG_HAVE_ACPI_RESUME == 1
248         acpi_slp_type = ((tmp & (7 << 10)) >> 10) == 1 ? 3 : 0 ;
249         printk(BIOS_DEBUG, "SLP_TYP type was %x %x\n", tmp, acpi_slp_type);
250 #endif
251
252         /* All SMI on, both IDE buses ON, PSON rising edge. */
253         outw(0x1, VT8237R_ACPI_IO_BASE + 0x2c);
254
255         /* clear sleep */
256         tmp &= ~(7 << 10);
257         tmp |= 1;
258         outw(tmp, VT8237R_ACPI_IO_BASE + 0x04);
259 }
260
261 static void vt8237r_init(struct device *dev)
262 {
263         u8 enables;
264         struct southbridge_via_vt8237r_config *cfg;
265
266         cfg = dev->chip_info;
267
268 #if CONFIG_EPIA_VT8237R_INIT
269         printk(BIOS_SPEW, "Entering vt8237r_init, for EPIA.\n");
270         /*
271          * TODO: Looks like stock BIOS can do this but causes a hang
272          * Enable SATA LED, disable special CPU Frequency Change -
273          * GPIO28 GPIO22 GPIO29 GPIO23 are GPIOs.
274          * Setup to match EPIA default
275          * PCS0# on Pin U1
276          */
277         enables = pci_read_config8(dev, 0xe5);
278         enables |= 0x23;
279         pci_write_config8(dev, 0xe5, enables);
280
281         /*
282          * Enable Flash Write Access.
283          * Note EPIA-N Does not use REQ5 or PCISTP#(Hang)
284          */
285         enables = pci_read_config8(dev, 0xe4);
286         enables |= 0x2B;
287         pci_write_config8(dev, 0xe4, enables);
288
289         /* Enables Extra RTC Ports */
290         enables = pci_read_config8(dev, 0x4E);
291         enables |= 0x80;
292         pci_write_config8(dev, 0x4E, enables);
293
294 #else
295         printk(BIOS_SPEW, "Entering vt8237r_init.\n");
296         /*
297          * Enable SATA LED, disable special CPU Frequency Change -
298          * GPIO28 GPIO22 GPIO29 GPIO23 are GPIOs.
299          */
300         pci_write_config8(dev, 0xe5, 0x09);
301
302         enables = 0x4;
303         if (cfg) {
304                 if (cfg->enable_gpo5)
305                         enables |= 0x01;
306                 if (cfg->gpio15_12_dir_output)
307                         enables |= 0x10;
308         }
309         /* REQ5 as PCI request input - should be together with INTE-INTH. */
310         pci_write_config8(dev, 0xe4, enables);
311 #endif
312
313         /* Set bit 3 of 0x4f (use INIT# as CPU reset). */
314         enables = pci_read_config8(dev, 0x4f);
315         enables |= 0x08;
316         pci_write_config8(dev, 0x4f, enables);
317
318 #if CONFIG_EPIA_VT8237R_INIT
319         /*
320          * Set Read Pass Write Control Enable
321          */
322         pci_write_config8(dev, 0x48, 0x0c);
323 #else
324
325   #if CONFIG_SOUTHBRIDGE_VIA_SUBTYPE_K8T800 || CONFIG_SOUTHBRIDGE_VIA_SUBTYPE_K8T800_OLD
326         /* It seems that when we pair with the K8T800, we need to disable
327          * the A2 mask
328          */
329         pci_write_config8(dev, 0x48, 0x0c);
330   #else
331         /*
332          * Set Read Pass Write Control Enable
333          * (force A2 from APIC FSB to low).
334          */
335         pci_write_config8(dev, 0x48, 0x8c);
336   #endif
337
338 #endif
339
340         southbridge_init_common(dev);
341
342 #if !CONFIG_EPIA_VT8237R_INIT
343         /* FIXME: Intel needs more bit set for C2/C3. */
344
345         /*
346          * Allow SLP# signal to assert LDTSTOP_L.
347          * Will work for C3 and for FID/VID change.
348          */
349         outb(0x1, VT8237R_ACPI_IO_BASE + 0x11);
350 #endif
351
352         printk(BIOS_SPEW, "Leaving %s.\n", __func__);
353         printk(BIOS_SPEW, "And taking a dump:\n");
354         dump_south(dev);
355 }
356
357 static void vt8237a_init(struct device *dev)
358 {
359         /*
360          * FIXME: This is based on vt8237s_init() and the values the AMI
361          *        BIOS on my M2V wrote to these registers (by loking
362          *        at lspci -nxxx output).
363          *        Works for me.
364          */
365         u32 tmp;
366
367         /* Set bit 3 of 0x4f (use INIT# as CPU reset). */
368         tmp = pci_read_config8(dev, 0x4f);
369         tmp |= 0x08;
370         pci_write_config8(dev, 0x4f, tmp);
371
372         /*
373          * bit2: REQ5 as PCI request input - should be together with INTE-INTH.
374          * bit5: usb power control lines as gpio
375          */
376         pci_write_config8(dev, 0xe4, 0x24);
377         /*
378          * Enable APIC wakeup from INTH
379          * Enable SATA LED, disable special CPU Frequency Change -
380          * GPIO28 GPIO22 GPIO29 GPIO23 are GPIOs.
381          */
382         pci_write_config8(dev, 0xe5, 0x69);
383
384         /* Reduce further the STPCLK/LDTSTP signal to 5us. */
385         pci_write_config8(dev, 0xec, 0x4);
386
387         /* Host Bus Power Management Control, maybe not needed */
388         pci_write_config8(dev, 0x8c, 0x5);
389
390         /* Enable HPET at VT8237R_HPET_ADDR. */
391         pci_write_config32(dev, 0x68, (VT8237R_HPET_ADDR | 0x80));
392
393         southbridge_init_common(dev);
394
395         /* Share INTE-INTH with INTA-INTD for simplicity */
396         pci_write_config8(dev, 0x46, 0x00);
397
398         /* FIXME: Intel needs more bit set for C2/C3. */
399
400         /*
401          * Allow SLP# signal to assert LDTSTOP_L.
402          * Will work for C3 and for FID/VID change.
403          */
404         outb(0x1, VT8237R_ACPI_IO_BASE + 0x11);
405
406         dump_south(dev);
407 }
408
409 static void vt8237s_init(struct device *dev)
410 {
411         u32 tmp;
412
413         /* Put SPI base VT8237S_SPI_MEM_BASE. */
414         tmp = pci_read_config32(dev, 0xbc);
415         pci_write_config32(dev, 0xbc,
416                            (VT8237S_SPI_MEM_BASE >> 8) | (tmp & 0xFF000000));
417
418         /*
419          * REQ5 as PCI request input - should be together with INTE-INTH.
420          */
421         pci_write_config8(dev, 0xe4, 0x04);
422
423         /* Reduce further the STPCLK/LDTSTP signal to 5us. */
424         pci_write_config8(dev, 0xec, 0x4);
425
426         /* Host Bus Power Management Control, maybe not needed */
427         pci_write_config8(dev, 0x8c, 0x5);
428
429         /* Enable HPET at VT8237R_HPET_ADDR., does not work correctly on R. */
430         pci_write_config32(dev, 0x68, (VT8237R_HPET_ADDR | 0x80));
431
432         southbridge_init_common(dev);
433
434         /* FIXME: Intel needs more bit set for C2/C3. */
435
436         /*
437          * Allow SLP# signal to assert LDTSTOP_L.
438          * Will work for C3 and for FID/VID change. FIXME FIXME, pre rev A2.
439          */
440         outb(0xff, VT8237R_ACPI_IO_BASE + 0x50);
441
442         dump_south(dev);
443 }
444
445 static void vt8237_common_init(struct device *dev)
446 {
447         u8 enables, byte;
448         struct southbridge_via_vt8237r_config *cfg;
449 #if !CONFIG_EPIA_VT8237R_INIT
450         unsigned char pwr_on;
451 #endif
452
453         cfg = dev->chip_info;
454
455         /* Enable addr/data stepping. */
456         byte = pci_read_config8(dev, PCI_COMMAND);
457         byte |= PCI_COMMAND_WAIT;
458         pci_write_config8(dev, PCI_COMMAND, byte);
459
460 /* EPIA-N(L) Uses CN400 for BIOS Access */
461 #if !CONFIG_EPIA_VT8237R_INIT
462         /* Enable the internal I/O decode. */
463         enables = pci_read_config8(dev, 0x6C);
464         enables |= 0x80;
465         pci_write_config8(dev, 0x6C, enables);
466
467         /*
468          * ROM decode
469          * bit range
470          *   7 000E0000h-000EFFFFh
471          *   6 FFF00000h-FFF7FFFFh
472          *   5 FFE80000h-FFEFFFFFh
473          *   4 FFE00000h-FFE7FFFFh
474          *   3 FFD80000h-FFDFFFFFh
475          *   2 FFD00000h-FFD7FFFFh
476          *   1 FFC80000h-FFCFFFFFh
477          *   0 FFC00000h-FFC7FFFFh
478          * So 0x7f here sets ROM decode to FFC00000-FFFFFFFF or 4Mbyte.
479          */
480         pci_write_config8(dev, 0x41, 0x7f);
481 #endif
482
483         /*
484          * Set bit 6 of 0x40 (I/O recovery time).
485          * IMPORTANT FIX - EISA = ECLR reg at 0x4d0! Decoding must be on so
486          * that PCI interrupts can be properly marked as level triggered.
487          */
488         enables = pci_read_config8(dev, 0x40);
489         enables |= 0x44;
490         pci_write_config8(dev, 0x40, enables);
491
492         /* Line buffer control */
493         enables = pci_read_config8(dev, 0x42);
494         enables |= 0xf8;
495         pci_write_config8(dev, 0x42, enables);
496
497         /* Delay transaction control */
498         pci_write_config8(dev, 0x43, 0xb);
499
500 #if CONFIG_EPIA_VT8237R_INIT
501         /* I/O recovery time, default IDE routing */
502         pci_write_config8(dev, 0x4c, 0x04);
503
504         /* ROM memory cycles go to LPC. */
505         pci_write_config8(dev, 0x59, 0x80);
506
507         /*
508          * Bit | Meaning
509          * -------------
510          *   3 | Bypass APIC De-Assert Message (1=Enable)
511          *   2 | APIC HyperTransport Mode (1=Enable)
512          *   1 | possibly "INTE#, INTF#, INTG#, INTH# as PCI"
513          *     | bit 1=1 works for Aaron at VIA, bit 1=0 works for jakllsch
514          *   0 | Dynamic Clock Gating Main Switch (1=Enable)
515          */
516         pci_write_config8(dev, 0x5b, 0x9);
517
518         /* Set 0x58 to 0x42 APIC On and RTC Write Protect.*/
519         pci_write_config8(dev, 0x58, 0x42);
520
521         /* Enable serial IRQ, 6PCI clocks. */
522         pci_write_config8(dev, 0x52, 0x9);
523 #else
524         /* I/O recovery time, default IDE routing */
525         pci_write_config8(dev, 0x4c, 0x44);
526
527         /* ROM memory cycles go to LPC. */
528         pci_write_config8(dev, 0x59, 0x80);
529
530         /*
531          * Bit | Meaning
532          * -------------
533          *   3 | Bypass APIC De-Assert Message (1=Enable)
534          *   2 | APIC HyperTransport Mode (1=Enable)
535          *   1 | possibly "INTE#, INTF#, INTG#, INTH# as PCI"
536          *     | bit 1=1 works for Aaron at VIA, bit 1=0 works for jakllsch
537          *   0 | Dynamic Clock Gating Main Switch (1=Enable)
538          */
539         if (cfg && cfg->int_efgh_as_gpio) {
540                 pci_write_config8(dev, 0x5b, 0x9);
541         } else {
542                 pci_write_config8(dev, 0x5b, 0xb);
543         }
544
545         /* configure power state of the board after loss of power */
546         if (get_option(&pwr_on, "power_on_after_fail") < 0)
547                 pwr_on = 1;
548         enables = pci_read_config8(dev, 0x58);
549         pci_write_config8(dev, 0x58, enables & ~0x02);
550         outb(0x0d, 0x70);
551         outb(pwr_on ? 0x00 : 0x80, 0x71);
552         pci_write_config8(dev, 0x58, enables);
553
554         /* Set 0x58 to 0x43 APIC and RTC. */
555         pci_write_config8(dev, 0x58, 0x43);
556
557         /* Enable serial IRQ, 6PCI clocks. */
558         pci_write_config8(dev, 0x52, 0x9);
559 #endif
560 #if CONFIG_HAVE_SMI_HANDLER
561         smm_lock();
562 #endif
563
564         /* Power management setup */
565         setup_pm(dev);
566
567         /* Start the RTC. */
568         rtc_init(0);
569 }
570
571 static void vt8237r_read_resources(device_t dev)
572 {
573         struct resource *res;
574
575         pci_dev_read_resources(dev);
576
577         /* Fixed ACPI Base IO Base*/
578         res = new_resource(dev, 0x88);
579         res->base = VT8237R_ACPI_IO_BASE;
580         res->size = 128;
581         res->limit = 0xffffUL;
582         res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE |
583                      IORESOURCE_STORED | IORESOURCE_ASSIGNED;
584
585         /* Fixed EISA ECLR I/O Regs     */
586         res = new_resource(dev, 3);
587         res->base = 0x4d0;
588         res->size = 2;
589         res->limit = 0xffffUL;
590         res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE |
591                      IORESOURCE_STORED | IORESOURCE_ASSIGNED;
592
593         /* Fixed System Management Bus I/O Resource */
594         res = new_resource(dev, 0xD0);
595         res->base = VT8237R_SMBUS_IO_BASE;
596         res->size = 16;
597         res->limit = 0xffffUL;
598         res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE |
599                      IORESOURCE_STORED | IORESOURCE_ASSIGNED;
600
601         /* Fixed APIC resource */
602         res = new_resource(dev, 0x44);
603         res->base = IO_APIC_ADDR;
604         res->size = 256;
605         res->limit = 0xffffffffUL;
606         res->align = 8;
607         res->gran = 8;
608         res->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_RESERVE |
609                      IORESOURCE_STORED | IORESOURCE_ASSIGNED;
610
611         /* Fixed flashrom resource */
612         res = new_resource(dev, 4);
613         res->base = 0xff000000UL;
614         res->size = 0x01000000UL; /* 16MB */
615         res->limit = 0xffffffffUL;
616         res->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_RESERVE |
617                      IORESOURCE_STORED | IORESOURCE_ASSIGNED;
618
619         res = new_resource(dev, 1);
620         res->base = 0x0UL;
621         res->size = 0x1000UL;
622         res->limit = 0xffffUL;
623         res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
624 }
625
626 static void init_keyboard(struct device *dev)
627 {
628         u8 regval = pci_read_config8(dev, 0x51);
629         if (regval & 0x1)
630                 pc_keyboard_init(0);
631 }
632
633 static void southbridge_init_common(struct device *dev)
634 {
635         vt8237_common_init(dev);
636         pci_routing_fixup(dev);
637         setup_ioapic(IO_APIC_ADDR, VT8237R_APIC_ID);
638         setup_i8259();
639         init_keyboard(dev);
640 }
641
642
643 static void vt8237_set_subsystem(device_t dev, unsigned vendor, unsigned device)
644 {
645         pci_write_config16(dev, 0x70, vendor);
646         pci_write_config16(dev, 0x72, device);
647 }
648
649 static struct pci_operations lops_pci = {
650         .set_subsystem = vt8237_set_subsystem,
651 };
652
653 static const struct device_operations vt8237r_lpc_ops_s = {
654         .read_resources         = vt8237r_read_resources,
655         .set_resources          = pci_dev_set_resources,
656         .enable_resources       = pci_dev_enable_resources,
657         .init                   = vt8237s_init,
658         .scan_bus               = scan_static_bus,
659         .ops_pci                = &lops_pci,
660 };
661
662 static const struct device_operations vt8237r_lpc_ops_r = {
663         .read_resources         = vt8237r_read_resources,
664         .set_resources          = pci_dev_set_resources,
665         .enable_resources       = pci_dev_enable_resources,
666         .init                   = vt8237r_init,
667         .scan_bus               = scan_static_bus,
668         .ops_pci                = &lops_pci,
669 };
670
671 static const struct device_operations vt8237r_lpc_ops_a = {
672         .read_resources         = vt8237r_read_resources,
673         .set_resources          = pci_dev_set_resources,
674         .enable_resources       = pci_dev_enable_resources,
675         .init                   = vt8237a_init,
676         .scan_bus               = scan_static_bus,
677         .ops_pci                = &lops_pci,
678 };
679
680 static const struct pci_driver lpc_driver_r __pci_driver = {
681         .ops    = &vt8237r_lpc_ops_r,
682         .vendor = PCI_VENDOR_ID_VIA,
683         .device = PCI_DEVICE_ID_VIA_VT8237R_LPC,
684 };
685
686 static const struct pci_driver lpc_driver_a __pci_driver = {
687         .ops    = &vt8237r_lpc_ops_a,
688         .vendor = PCI_VENDOR_ID_VIA,
689         .device = PCI_DEVICE_ID_VIA_VT8237A_LPC,
690 };
691
692 static const struct pci_driver lpc_driver_s __pci_driver = {
693         .ops    = &vt8237r_lpc_ops_s,
694         .vendor = PCI_VENDOR_ID_VIA,
695         .device = PCI_DEVICE_ID_VIA_VT8237S_LPC,
696 };