Since some people disapprove of white space cleanups mixed in regular commits
[coreboot.git] / src / console / uart8250_console.c
1 #include <console/console.h>
2 #include <uart8250.h>
3 #include <pc80/mc146818rtc.h>
4
5 /* Base Address */
6 #ifndef CONFIG_TTYS0_BASE
7 #define CONFIG_TTYS0_BASE 0x3f8
8 #endif
9
10 #ifndef CONFIG_TTYS0_BAUD
11 #define CONFIG_TTYS0_BAUD 115200
12 #endif
13
14 #ifndef CONFIG_TTYS0_DIV
15 #if ((115200%CONFIG_TTYS0_BAUD) != 0)
16 #error Bad ttys0 baud rate
17 #endif
18 #define CONFIG_TTYS0_DIV        (115200/CONFIG_TTYS0_BAUD)
19 #endif
20
21 /* Line Control Settings */
22 #ifndef CONFIG_TTYS0_LCS
23 /* Set 8bit, 1 stop bit, no parity */
24 #define CONFIG_TTYS0_LCS        0x3
25 #endif
26
27 #define UART_LCS        CONFIG_TTYS0_LCS
28
29 static void ttyS0_init(void)
30 {
31         static const unsigned char div[8]={1,2,3,6,12,24,48,96};
32         int b_index=0;
33         unsigned int divisor=CONFIG_TTYS0_DIV;
34
35         if(get_option(&b_index,"baud_rate")==0) {
36                 divisor=div[b_index];
37         }
38         uart8250_init(CONFIG_TTYS0_BASE, divisor, CONFIG_TTYS0_LCS);
39 }
40
41 static void ttyS0_tx_byte(unsigned char data)
42 {
43         uart8250_tx_byte(CONFIG_TTYS0_BASE, data);
44 }
45
46 static unsigned char ttyS0_rx_byte(void)
47 {
48         return uart8250_rx_byte(CONFIG_TTYS0_BASE);
49 }
50
51 static int ttyS0_tst_byte(void)
52 {
53         return uart8250_can_rx_byte(CONFIG_TTYS0_BASE);
54 }
55
56 static const struct console_driver uart8250_console __console = {
57         .init    = ttyS0_init,
58         .tx_byte = ttyS0_tx_byte,
59         .rx_byte = ttyS0_rx_byte,
60         .tst_byte = ttyS0_tst_byte,
61 };
62