1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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 "vt8237r.h"
36#include "chip.h"
37
38static void southbridge_init_common(struct device *dev);
39
40#if CONFIG_EPIA_VT8237R_INIT
41
42static const unsigned char pciIrqs[4] = { 10, 11, 12, 0};
43
44
45static const unsigned char sataPins[4] = { 'A','B','C','D'};
46static const unsigned char vgaPins[4] = { 'A','B','C','D'};
47static const unsigned char usbPins[4] = { 'A','B','C','D'};
48static const unsigned char enetPins[4] = { 'A','B','C','D'};
49static const unsigned char vt8237Pins[4] = { 'A','B','C','D'};
50static const unsigned char slotPins[4] = { 'C','D','A','B'};
51static const unsigned char riserPins[4] = { 'D','C','B','A'};
52
53static unsigned char *pin_to_irq(const unsigned char *pin)
54{
55 static unsigned char Irqs[4];
56 int i;
57 for (i = 0 ; i < 4 ; i++)
58 Irqs[i] = pciIrqs[ pin[i] - 'A' ];
59
60 return Irqs;
61}
62#endif
63
64
65static void pci_routing_fixup(struct device *dev)
66{
67#if CONFIG_EPIA_VT8237R_INIT
68 device_t pdev;
69#endif
70
71
72 pci_write_config8(dev, 0x44, 0x00);
73
74
75 pci_write_config8(dev, 0x45, 0x00);
76
77
78 pci_write_config8(dev, 0x49, 0x20);
79
80#if CONFIG_EPIA_VT8237R_INIT
81
82
83 pci_write_config8(dev, 0x46, 0x00);
84
85
86 pci_write_config8(dev, 0x55, pciIrqs[0] << 4);
87 pci_write_config8(dev, 0x56, pciIrqs[1] | (pciIrqs[2] << 4) );
88 pci_write_config8(dev, 0x57, pciIrqs[3] << 4);
89
90
91
92
93 pci_assign_irqs(0, 0x14, pin_to_irq(slotPins));
94
95
96 pci_assign_irqs(0, 0x13, pin_to_irq(riserPins));
97
98
99 pci_assign_irqs(0, 0x10, pin_to_irq(usbPins));
100
101
102 pci_assign_irqs(0, 0x11, pin_to_irq(vt8237Pins));
103
104
105 pci_assign_irqs(0, 0x12, pin_to_irq(enetPins));
106
107
108 pci_assign_irqs(1, 0x00, pin_to_irq(vgaPins));
109
110
111
112
113 pdev = dev_find_device(PCI_VENDOR_ID_VIA,
114 PCI_DEVICE_ID_VIA_VT6420_SATA, 0);
115 pci_write_config8(pdev, PCI_INTERRUPT_PIN, 0x02);
116 pci_assign_irqs(0, 0x0f, pin_to_irq(sataPins));
117
118
119
120 pdev = dev_find_device(PCI_VENDOR_ID_VIA,
121 PCI_DEVICE_ID_VIA_82C586_1, 0);
122 pci_write_config8(pdev, PCI_INTERRUPT_PIN, 0x01);
123 pci_write_config8(pdev, PCI_INTERRUPT_LINE, 0xFF);
124
125#else
126
127 pci_write_config8(dev, 0x46, 0x10);
128
129
130 pci_write_config8(dev, 0x54, 0x00);
131
132
133 pci_write_config8(dev, 0x55, 0x00);
134
135
136 pci_write_config8(dev, 0x56, 0x00);
137
138
139 pci_write_config8(dev, 0x57, 0x00);
140#endif
141}
142
143
144
145
146
147
148
149
150extern u8 acpi_slp_type;
151
152
153static void setup_pm(device_t dev)
154{
155 u16 tmp;
156
157 pci_write_config8(dev, 0x80, 0x20);
158
159
160 pci_write_config16(dev, 0x88, VT8237R_ACPI_IO_BASE | 0x1);
161
162
163 pci_write_config8(dev, 0x82, 0x40 | VT8237R_ACPI_IRQ);
164
165#if CONFIG_EPIA_VT8237R_INIT
166
167 pci_write_config16(dev, 0x84, 0x3052);
168#else
169
170 pci_write_config16(dev, 0x84, 0x30b2);
171
172#endif
173
174 pci_write_config8(dev, 0x8d, 0x18);
175
176
177 pci_write_config8(dev, 0x93, 0x88);
178
179
180
181
182
183
184 pci_write_config8(dev, 0x94, 0xa0);
185
186
187
188
189
190
191
192
193
194
195
196
197#if CONFIG_EPIA_VT8237R_INIT
198 pci_write_config8(dev, 0x95, 0xc2);
199#else
200 pci_write_config8(dev, 0x95, 0xcc);
201#endif
202
203
204 pci_write_config8(dev, 0x98, 0);
205
206
207 pci_write_config8(dev, 0x81, 0x84);
208
209
210 outw(0xffff, VT8237R_ACPI_IO_BASE + 0x00);
211 outw(0xffff, VT8237R_ACPI_IO_BASE + 0x20);
212 outw(0xffff, VT8237R_ACPI_IO_BASE + 0x28);
213 outl(0xffffffff, VT8237R_ACPI_IO_BASE + 0x30);
214
215
216 outw(0x0, VT8237R_ACPI_IO_BASE + 0x22);
217
218
219 outw(0x0, VT8237R_ACPI_IO_BASE + 0x24);
220
221
222 outw(0x40, VT8237R_ACPI_IO_BASE + 0x2a);
223
224
225 outl(0x0, VT8237R_ACPI_IO_BASE + 0x34);
226
227
228 outl(0x0, VT8237R_ACPI_IO_BASE + 0x38);
229
230
231 outb(0x0, VT8237R_ACPI_IO_BASE + 0x42);
232
233
234 tmp = inw(VT8237R_ACPI_IO_BASE + 0x04);
235#if CONFIG_HAVE_ACPI_RESUME == 1
236 acpi_slp_type = ((tmp & (7 << 10)) >> 10) == 1 ? 3 : 0 ;
237 printk(BIOS_DEBUG, "SLP_TYP type was %x %x\n", tmp, acpi_slp_type);
238#endif
239
240
241 outw(0x1, VT8237R_ACPI_IO_BASE + 0x2c);
242
243
244 tmp &= ~(7 << 10);
245 tmp |= 1;
246 outw(tmp, VT8237R_ACPI_IO_BASE + 0x04);
247}
248
249static void vt8237r_init(struct device *dev)
250{
251 u8 enables;
252
253#if CONFIG_EPIA_VT8237R_INIT
254 printk(BIOS_SPEW, "Entering vt8237r_init, for EPIA.\n");
255
256
257
258
259
260
261
262 enables = pci_read_config8(dev, 0xe5);
263 enables |= 0x23;
264 pci_write_config8(dev, 0xe5, enables);
265
266
267
268
269
270 enables = pci_read_config8(dev, 0xe4);
271 enables |= 0x2B;
272 pci_write_config8(dev, 0xe4, enables);
273
274
275 enables = pci_read_config8(dev, 0x4E);
276 enables |= 0x80;
277 pci_write_config8(dev, 0x4E, enables);
278
279#else
280 printk(BIOS_SPEW, "Entering vt8237r_init.\n");
281
282
283
284
285 pci_write_config8(dev, 0xe5, 0x09);
286
287
288 pci_write_config8(dev, 0xe4, 0x4);
289#endif
290
291
292 enables = pci_read_config8(dev, 0x4f);
293 enables |= 0x08;
294 pci_write_config8(dev, 0x4f, enables);
295
296#if CONFIG_EPIA_VT8237R_INIT
297
298
299
300 pci_write_config8(dev, 0x48, 0x0c);
301#else
302
303 #if CONFIG_SOUTHBRIDGE_VIA_K8T800
304
305
306
307 pci_write_config8(dev, 0x48, 0x0c);
308 #else
309
310
311
312
313 pci_write_config8(dev, 0x48, 0x8c);
314 #endif
315
316#endif
317
318 southbridge_init_common(dev);
319
320#if !CONFIG_EPIA_VT8237R_INIT
321
322
323
324
325
326
327 outb(0x1, VT8237R_ACPI_IO_BASE + 0x11);
328#endif
329
330 printk(BIOS_SPEW, "Leaving %s.\n", __func__);
331 printk(BIOS_SPEW, "And taking a dump:\n");
332 dump_south(dev);
333}
334
335static void vt8237a_init(struct device *dev)
336{
337
338
339
340
341
342
343 u32 tmp;
344
345
346 tmp = pci_read_config8(dev, 0x4f);
347 tmp |= 0x08;
348 pci_write_config8(dev, 0x4f, tmp);
349
350
351
352
353
354 pci_write_config8(dev, 0xe4, 0x24);
355
356
357
358
359
360 pci_write_config8(dev, 0xe5, 0x69);
361
362
363 pci_write_config8(dev, 0xec, 0x4);
364
365
366 pci_write_config8(dev, 0x8c, 0x5);
367
368
369 pci_write_config32(dev, 0x68, (VT8237R_HPET_ADDR | 0x80));
370
371 southbridge_init_common(dev);
372
373
374 pci_write_config8(dev, 0x46, 0x00);
375
376
377
378
379
380
381
382 outb(0x1, VT8237R_ACPI_IO_BASE + 0x11);
383
384 dump_south(dev);
385}
386
387static void vt8237s_init(struct device *dev)
388{
389 u32 tmp;
390
391
392 tmp = pci_read_config32(dev, 0xbc);
393 pci_write_config32(dev, 0xbc,
394 (VT8237S_SPI_MEM_BASE >> 8) | (tmp & 0xFF000000));
395
396
397
398
399 pci_write_config8(dev, 0xe4, 0x04);
400
401
402 pci_write_config8(dev, 0xec, 0x4);
403
404
405 pci_write_config8(dev, 0x8c, 0x5);
406
407
408 pci_write_config32(dev, 0x68, (VT8237R_HPET_ADDR | 0x80));
409
410 southbridge_init_common(dev);
411
412
413
414
415
416
417
418 outb(0xff, VT8237R_ACPI_IO_BASE + 0x50);
419
420 dump_south(dev);
421}
422
423static void vt8237_common_init(struct device *dev)
424{
425 u8 enables, byte;
426
427
428 byte = pci_read_config8(dev, PCI_COMMAND);
429 byte |= PCI_COMMAND_WAIT;
430 pci_write_config8(dev, PCI_COMMAND, byte);
431
432
433#if !CONFIG_EPIA_VT8237R_INIT
434
435 enables = pci_read_config8(dev, 0x6C);
436 enables |= 0x80;
437 pci_write_config8(dev, 0x6C, enables);
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452 pci_write_config8(dev, 0x41, 0x7f);
453#endif
454
455
456
457
458
459
460 enables = pci_read_config8(dev, 0x40);
461 enables |= 0x44;
462 pci_write_config8(dev, 0x40, enables);
463
464
465 enables = pci_read_config8(dev, 0x42);
466 enables |= 0xf8;
467 pci_write_config8(dev, 0x42, enables);
468
469
470 pci_write_config8(dev, 0x43, 0xb);
471
472#if CONFIG_EPIA_VT8237R_INIT
473
474 pci_write_config8(dev, 0x4c, 0x04);
475
476
477 pci_write_config8(dev, 0x59, 0x80);
478
479
480
481
482
483
484
485
486
487
488 pci_write_config8(dev, 0x5b, 0x9);
489
490
491 pci_write_config8(dev, 0x58, 0x42);
492
493
494 pci_write_config8(dev, 0x52, 0x9);
495#else
496
497 pci_write_config8(dev, 0x4c, 0x44);
498
499
500 pci_write_config8(dev, 0x59, 0x80);
501
502
503
504
505
506
507
508
509
510
511 pci_write_config8(dev, 0x5b, 0xb);
512
513
514 pci_write_config8(dev, 0x58, 0x43);
515
516
517 pci_write_config8(dev, 0x52, 0x9);
518#endif
519#if CONFIG_HAVE_SMI_HANDLER
520 smm_lock();
521#endif
522
523
524 setup_pm(dev);
525
526
527 rtc_init(0);
528}
529
530static void vt8237r_read_resources(device_t dev)
531{
532 struct resource *res;
533
534 pci_dev_read_resources(dev);
535
536
537 res = new_resource(dev, 0x88);
538 res->base = VT8237R_ACPI_IO_BASE;
539 res->size = 128;
540 res->limit = 0xffffUL;
541 res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE |
542 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
543
544
545 res = new_resource(dev, 3);
546 res->base = 0x4d0;
547 res->size = 2;
548 res->limit = 0xffffUL;
549 res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE |
550 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
551
552
553 res = new_resource(dev, 0xD0);
554 res->base = VT8237R_SMBUS_IO_BASE;
555 res->size = 16;
556 res->limit = 0xffffUL;
557 res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE |
558 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
559
560
561 res = new_resource(dev, 0x44);
562 res->base = IO_APIC_ADDR;
563 res->size = 256;
564 res->limit = 0xffffffffUL;
565 res->align = 8;
566 res->gran = 8;
567 res->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_RESERVE |
568 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
569
570
571 res = new_resource(dev, 4);
572 res->base = 0xff000000UL;
573 res->size = 0x01000000UL;
574 res->limit = 0xffffffffUL;
575 res->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_RESERVE |
576 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
577
578 res = new_resource(dev, 1);
579 res->base = 0x0UL;
580 res->size = 0x1000UL;
581 res->limit = 0xffffUL;
582 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
583}
584
585static void init_keyboard(struct device *dev)
586{
587 u8 regval = pci_read_config8(dev, 0x51);
588 if (regval & 0x1)
589 pc_keyboard_init(0);
590}
591
592static void southbridge_init_common(struct device *dev)
593{
594 vt8237_common_init(dev);
595 pci_routing_fixup(dev);
596 setup_ioapic(IO_APIC_ADDR, VT8237R_APIC_ID);
597 setup_i8259();
598 init_keyboard(dev);
599}
600
601static const struct device_operations vt8237r_lpc_ops_s = {
602 .read_resources = vt8237r_read_resources,
603 .set_resources = pci_dev_set_resources,
604 .enable_resources = pci_dev_enable_resources,
605 .init = vt8237s_init,
606 .scan_bus = scan_static_bus,
607};
608
609static const struct device_operations vt8237r_lpc_ops_r = {
610 .read_resources = vt8237r_read_resources,
611 .set_resources = pci_dev_set_resources,
612 .enable_resources = pci_dev_enable_resources,
613 .init = vt8237r_init,
614 .scan_bus = scan_static_bus,
615};
616
617static const struct device_operations vt8237r_lpc_ops_a = {
618 .read_resources = vt8237r_read_resources,
619 .set_resources = pci_dev_set_resources,
620 .enable_resources = pci_dev_enable_resources,
621 .init = vt8237a_init,
622 .scan_bus = scan_static_bus,
623};
624
625static const struct pci_driver lpc_driver_r __pci_driver = {
626 .ops = &vt8237r_lpc_ops_r,
627 .vendor = PCI_VENDOR_ID_VIA,
628 .device = PCI_DEVICE_ID_VIA_VT8237R_LPC,
629};
630
631static const struct pci_driver lpc_driver_a __pci_driver = {
632 .ops = &vt8237r_lpc_ops_a,
633 .vendor = PCI_VENDOR_ID_VIA,
634 .device = PCI_DEVICE_ID_VIA_VT8237A_LPC,
635};
636
637static const struct pci_driver lpc_driver_s __pci_driver = {
638 .ops = &vt8237r_lpc_ops_s,
639 .vendor = PCI_VENDOR_ID_VIA,
640 .device = PCI_DEVICE_ID_VIA_VT8237S_LPC,
641};
642