dfc5c3e235ff4e14fcae0af6e049f07f3ded9553
[coreboot.git] / src / northbridge / via / vx800 / vx800_early_serial.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2009 One Laptop per Child, Association, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
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.
14  *
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
18 */
19
20 /*
21  * Enable the serial devices on the VIA
22  */
23 #include <arch/romcc_io.h>
24
25 /* The base address is 0x15c, 0x2e, depending on config bytes */
26
27 #define SIO_BASE 0x3f0
28 #define SIO_DATA  SIO_BASE+1
29
30 static void vx800_writesuper(uint8_t reg, uint8_t val) 
31 {
32         outb(reg, SIO_BASE);
33         outb(val, SIO_DATA);
34 }
35
36 static void vx800_writepnpaddr(uint8_t val) 
37 {
38         outb(val, 0x2e);
39         outb(val, 0xeb);
40 }
41
42 static void vx800_writepnpdata(uint8_t val) 
43 {
44         outb(val, 0x2f);
45         outb(val, 0xeb);
46 }
47
48 static void vx800_writesiobyte(uint16_t reg, uint8_t val) 
49 {
50         outb(val, reg);
51 }
52
53 static void vx800_writesioword(uint16_t reg, uint16_t val) 
54 {
55         outw(val, reg);
56 }
57
58
59 /* regs we use: 85, and the southbridge devfn is defined by the
60    mainboard
61  */
62
63 static void enable_vx800_serial(void) 
64 {
65         outb(6, 0x80);
66         outb(0x03, 0x22);
67
68
69         //pci_write_config8(PCI_DEV(0,17,0),0xb4,0x7e);
70         //pci_write_config8(PCI_DEV(0,17,0),0xb0,0x10);
71         
72         // turn on pnp
73         vx800_writepnpaddr(0x87);
74         vx800_writepnpaddr(0x87);
75         // now go ahead and set up com1. 
76         // set address
77         vx800_writepnpaddr(0x7);
78         vx800_writepnpdata(0x2);
79         // enable serial out
80         vx800_writepnpaddr(0x30);
81         vx800_writepnpdata(0x1);
82         // serial port 1 base address (FEh)
83         vx800_writepnpaddr(0x60);
84         vx800_writepnpdata(0xfe);
85         // serial port 1 IRQ (04h)
86         vx800_writepnpaddr(0x70);
87         vx800_writepnpdata(0x4);
88         // serial port 1 control
89         vx800_writepnpaddr(0xf0);
90         vx800_writepnpdata(0x2);
91         // turn of pnp
92         vx800_writepnpaddr(0xaa);
93
94         // set up reg to set baud rate.
95         vx800_writesiobyte(0x3fb, 0x80);
96         // Set 115 kb
97         vx800_writesioword(0x3f8, 1);
98         // Set 9.6 kb
99         //      WRITESIOWORD(0x3f8, 12)
100         // now set no parity, one stop, 8 bits
101         vx800_writesiobyte(0x3fb, 3);
102         // now turn on RTS, DRT
103         vx800_writesiobyte(0x3fc, 3);
104         // Enable interrupts
105         vx800_writesiobyte(0x3f9, 0xf);
106         // should be done. Dump a char for fun.
107         vx800_writesiobyte(0x3f8, 48);
108         outb(7, 0x80);
109 }
110