11f98fae3932565f8734b63955501f003b22b364
[coreboot.git] / src / southbridge / via / vt8235 / vt8235_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 vt8235_writepnpaddr(uint8_t val)
12 {
13         outb(val, 0x2e);
14         outb(val, 0xeb);
15 }
16
17 static void vt8235_writepnpdata(uint8_t val)
18 {
19         outb(val, 0x2f);
20         outb(val, 0xeb);
21 }
22
23
24 static void vt8235_writesiobyte(uint16_t reg, uint8_t val)
25 {
26         outb(val, reg);
27 }
28
29 static void vt8235_writesioword(uint16_t reg, uint16_t val)
30 {
31         outw(val, reg);
32 }
33
34
35 /* regs we use: 85, and the southbridge devfn is defined by the
36    mainboard
37  */
38
39 static void enable_vt8235_serial(void)
40 {
41         // turn on pnp
42         vt8235_writepnpaddr(0x87);
43         vt8235_writepnpaddr(0x87);
44         // now go ahead and set up com1.
45         // set address
46         vt8235_writepnpaddr(0x7);
47         vt8235_writepnpdata(0x2);
48         // enable serial out
49         vt8235_writepnpaddr(0x30);
50         vt8235_writepnpdata(0x1);
51         // serial port 1 base address (FEh)
52         vt8235_writepnpaddr(0x60);
53         vt8235_writepnpdata(0xfe);
54         // serial port 1 IRQ (04h)
55         vt8235_writepnpaddr(0x70);
56         vt8235_writepnpdata(0x4);
57         // serial port 1 control
58         vt8235_writepnpaddr(0xf0);
59         vt8235_writepnpdata(0x2);
60         // turn of pnp
61         vt8235_writepnpaddr(0xaa);
62
63         // set up reg to set baud rate.
64         vt8235_writesiobyte(0x3fb, 0x80);
65         // Set 115 kb
66         vt8235_writesioword(0x3f8, 1);
67         // Set 9.6 kb
68         //      WRITESIOWORD(0x3f8, 12)
69         // now set no parity, one stop, 8 bits
70         vt8235_writesiobyte(0x3fb, 3);
71         // now turn on RTS, DRT
72         vt8235_writesiobyte(0x3fc, 3);
73         // Enable interrupts
74         vt8235_writesiobyte(0x3f9, 0xf);
75         // should be done. Dump a char for fun.
76         vt8235_writesiobyte(0x3f8, 48);
77 }