fix lots of warnings for cache as ram builds (trivial)
[coreboot.git] / src / pc80 / serial.c
1 #include <part/fallback_boot.h>
2
3 /* Base Address */
4 #ifndef TTYS0_BASE
5 #define TTYS0_BASE 0x3f8
6 #endif
7
8 #ifndef TTYS0_BAUD
9 #define TTYS0_BAUD 115200
10 #endif
11
12 #if ((115200%TTYS0_BAUD) != 0)
13 #error Bad ttys0 baud rate
14 #endif
15
16 #define TTYS0_DIV       (115200/TTYS0_BAUD)
17
18 /* Line Control Settings */
19 #ifndef TTYS0_LCS
20 /* Set 8bit, 1 stop bit, no parity */
21 #define TTYS0_LCS       0x3
22 #endif
23
24 #define UART_LCS        TTYS0_LCS
25
26
27 #if CONFIG_USE_PRINTK_IN_CAR == 0
28
29 /* Data */
30 #define UART_RBR 0x00
31 #define UART_TBR 0x00
32
33 /* Control */
34 #define UART_IER 0x01
35 #define UART_IIR 0x02
36 #define UART_FCR 0x02
37 #define UART_LCR 0x03
38 #define UART_MCR 0x04
39 #define UART_DLL 0x00
40 #define UART_DLM 0x01
41
42 /* Status */
43 #define UART_LSR 0x05
44 #define UART_MSR 0x06
45 #define UART_SCR 0x07
46
47 static int uart_can_tx_byte(void)
48 {
49         return inb(TTYS0_BASE + UART_LSR) & 0x20;
50 }
51
52 static void uart_wait_to_tx_byte(void)
53 {
54         while(!uart_can_tx_byte()) 
55         ;
56 }
57
58 static void uart_wait_until_sent(void)
59 {
60         while(!(inb(TTYS0_BASE + UART_LSR) & 0x40))
61         ; 
62 }
63
64 static void uart_tx_byte(unsigned char data)
65 {
66         uart_wait_to_tx_byte();
67         outb(data, TTYS0_BASE + UART_TBR);
68         /* Make certain the data clears the fifos */
69         uart_wait_until_sent();
70 }
71
72 static void uart_init(void)
73 {
74         /* disable interrupts */
75         outb(0x0, TTYS0_BASE + UART_IER);
76         /* enable fifo's */
77         outb(0x01, TTYS0_BASE + UART_FCR);
78         /* Set Baud Rate Divisor to 12 ==> 115200 Baud */
79         outb(0x80 | UART_LCS, TTYS0_BASE + UART_LCR);
80 #if USE_OPTION_TABLE == 1
81         static const unsigned char divisor[] = { 1,2,3,6,12,24,48,96 };
82         unsigned ttys0_div, ttys0_index;
83         ttys0_index = read_option(CMOS_VSTART_baud_rate, CMOS_VLEN_baud_rate, 0);
84         ttys0_index &= 7;
85         ttys0_div = divisor[ttys0_index];
86         outb(ttys0_div & 0xff, TTYS0_BASE + UART_DLL);
87         outb(0, TTYS0_BASE + UART_DLM);
88 #else
89         outb(TTYS0_DIV & 0xFF,   TTYS0_BASE + UART_DLL);
90         outb((TTYS0_DIV >> 8) & 0xFF,    TTYS0_BASE + UART_DLM);
91 #endif
92         outb(UART_LCS, TTYS0_BASE + UART_LCR);
93 }
94
95 #else
96 /* CONFIG_USE_PRINTK_IN_CAR == 1 */
97 #if CONFIG_USE_INIT == 0
98 #include "../lib/uart8250.c"
99 #endif
100
101 extern void uart8250_init(unsigned base_port, unsigned divisor, unsigned lcs);
102 static void uart_init(void)
103 {
104 #if USE_OPTION_TABLE == 1
105         static const unsigned char divisor[] = { 1,2,3,6,12,24,48,96 };
106         unsigned ttys0_div, ttys0_index;
107         ttys0_index = read_option(CMOS_VSTART_baud_rate, CMOS_VLEN_baud_rate, 0);
108         ttys0_index &= 7;
109         ttys0_div = divisor[ttys0_index];
110         uart8250_init(TTYS0_BASE, ttys0_div, UART_LCS);
111 #else
112         uart8250_init(TTYS0_BASE, TTYS0_DIV, UART_LCS);
113 #endif  
114 }
115 #endif