5b38b8e521a2a49d07ec4972cdc3321b83d9b1a2
[coreboot.git] / src / southbridge / via / vt8231 / vt8231_early_serial.c
1 /*
2  * Enable the serial evices on the VIA
3  */
4
5
6 /* The base address is 0x15c, 0x2e, depending on config bytes */
7
8 #define SIO_BASE 0x3f0
9 #define SIO_DATA  SIO_BASE+1
10
11 static void vt8231_writesuper(uint8_t reg, uint8_t val) 
12 {
13         outb(reg, SIO_BASE);
14         outb(val, SIO_DATA);
15 }
16
17 static void vt8231_writesiobyte(uint16_t reg, uint8_t val) 
18 {
19         outb(val, reg);
20 }
21
22 static void vt8231_writesioword(uint16_t reg, uint16_t val) 
23 {
24         outw(val, reg);
25 }
26
27
28 /* regs we use: 85, and the southbridge devfn is defined by the
29    mainboard
30  */
31
32 static void enable_vt8231_serial(void) 
33 {
34         uint8_t c;
35         device_t dev;
36         outb(6, 0x80);
37         dev = pci_locate_device(PCI_ID(0x1106,0x8231), 0);
38         
39         if (dev == PCI_DEV_INVALID) {
40                 outb(7, 0x80);
41                 die("Serial controller not found\n");
42         }
43         
44         /* first, you have to enable the superio and superio config. 
45            put a 6 reg 80
46         */
47         c = pci_read_config8(dev, 0x50);
48         c |= 6;
49         pci_write_config8(dev, 0x50, c);
50         outb(2, 0x80);
51         // now go ahead and set up com1. 
52         // set address
53         vt8231_writesuper(0xf4, 0xfe);
54         // enable serial out
55         vt8231_writesuper(0xf2, 7);
56         // That's it for the sio stuff.
57         //      movl    $SUPERIOCONFIG, %eax
58         //      movb    $9, %dl
59         //      PCI_WRITE_CONFIG_BYTE
60         // set up reg to set baud rate.
61         vt8231_writesiobyte(0x3fb, 0x80);
62         // Set 115 kb
63         vt8231_writesioword(0x3f8, 1);
64         // Set 9.6 kb
65         //      WRITESIOWORD(0x3f8, 12)
66         // now set no parity, one stop, 8 bits
67         vt8231_writesiobyte(0x3fb, 3);
68         // now turn on RTS, DRT
69         vt8231_writesiobyte(0x3fc, 3);
70         // Enable interrupts
71         vt8231_writesiobyte(0x3f9, 0xf);
72         // should be done. Dump a char for fun.
73         vt8231_writesiobyte(0x3f8, 48);
74 }