1 #include <part/fallback_boot.h>
5 #define TTYS0_BASE 0x3f8
9 #define TTYS0_BAUD 115200
12 #if ((115200%TTYS0_BAUD) != 0)
13 #error Bad ttys0 baud rate
16 #define TTYS0_DIV (115200/TTYS0_BAUD)
18 /* Line Control Settings */
20 /* Set 8bit, 1 stop bit, no parity */
24 #define UART_LCS TTYS0_LCS
27 #if CONFIG_USE_PRINTK_IN_CAR == 0
47 static int uart_can_tx_byte(void)
49 return inb(TTYS0_BASE + UART_LSR) & 0x20;
52 static void uart_wait_to_tx_byte(void)
54 while(!uart_can_tx_byte())
58 static void uart_wait_until_sent(void)
60 while(!(inb(TTYS0_BASE + UART_LSR) & 0x40))
64 static void uart_tx_byte(unsigned char data)
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();
72 static void uart_init(void)
74 /* disable interrupts */
75 outb(0x0, TTYS0_BASE + UART_IER);
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);
85 ttys0_div = divisor[ttys0_index];
86 outb(ttys0_div & 0xff, TTYS0_BASE + UART_DLL);
87 outb(0, TTYS0_BASE + UART_DLM);
89 outb(TTYS0_DIV & 0xFF, TTYS0_BASE + UART_DLL);
90 outb((TTYS0_DIV >> 8) & 0xFF, TTYS0_BASE + UART_DLM);
92 outb(UART_LCS, TTYS0_BASE + UART_LCR);
96 /* CONFIG_USE_PRINTK_IN_CAR == 1 */
97 #if CONFIG_USE_INIT == 0
98 #include "../lib/uart8250.c"
101 extern void uart8250_init(unsigned base_port, unsigned divisor, unsigned lcs);
102 static void uart_init(void)
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);
109 ttys0_div = divisor[ttys0_index];
110 uart8250_init(TTYS0_BASE, ttys0_div, UART_LCS);
112 uart8250_init(TTYS0_BASE, TTYS0_DIV, UART_LCS);