1 /* Should support 8250, 16450, 16550, 16550A type uarts */
23 static inline int uart8250_can_tx_byte(unsigned base_port)
25 return inb(base_port + UART_LSR) & 0x20;
28 static inline void uart8250_wait_to_tx_byte(unsigned base_port)
30 while(!uart8250_can_tx_byte(base_port))
34 static inline void uart8250_wait_until_sent(unsigned base_port)
36 while(!(inb(base_port + UART_LSR) & 0x40))
40 void uart8250_tx_byte(unsigned base_port, unsigned char data)
42 uart8250_wait_to_tx_byte(base_port);
43 outb(data, base_port + UART_TBR);
44 /* Make certain the data clears the fifos */
45 uart8250_wait_until_sent(base_port);
48 int uart8250_can_rx_byte(unsigned base_port)
50 return inb(base_port + UART_LSR) & 0x01;
53 unsigned char uart8250_rx_byte(unsigned base_port)
55 while(!uart8250_can_rx_byte(base_port))
57 return inb(base_port + UART_RBR);
60 void uart8250_init(unsigned base_port, unsigned divisor, unsigned lcs)
63 /* disable interrupts */
64 outb(0x0, base_port + UART_IER);
66 outb(0x01, base_port + UART_FCR);
67 /* Set Baud Rate Divisor to 12 ==> 115200 Baud */
68 outb(0x80 | lcs, base_port + UART_LCR);
69 outb(divisor & 0xFF, base_port + UART_DLL);
70 outb((divisor >> 8) & 0xFF, base_port + UART_DLM);
71 outb(lcs, base_port + UART_LCR);
74 /* Initialize a generic uart */
75 void init_uart8250(unsigned base_port, struct uart8250 *uart)
79 divisor = 115200/(uart->baud ? uart->baud: 1);
81 if (base_port == TTYS0_BASE) {
82 /* Don't reinitialize the console serial port,
83 * This is espeically nasty in SMP.
87 uart8250_init(base_port, divisor, lcs);