blob: 67b0a95cfb30f81a669a3733b3cce8fee5637f18 [file] [log] [blame]
Eric Biederman8ca8d762003-04-22 19:02:15 +00001/* Should support 8250, 16450, 16550, 16550A type uarts */
2#include <arch/io.h>
3#include <uart8250.h>
4
5/* Data */
6#define UART_RBR 0x00
7#define UART_TBR 0x00
8
9/* Control */
10#define UART_IER 0x01
11#define UART_IIR 0x02
12#define UART_FCR 0x02
13#define UART_LCR 0x03
14#define UART_MCR 0x04
15#define UART_DLL 0x00
16#define UART_DLM 0x01
17
18/* Status */
19#define UART_LSR 0x05
20#define UART_MSR 0x06
21#define UART_SCR 0x07
22
23static inline int uart8250_can_tx_byte(unsigned base_port)
24{
25 return inb(base_port + UART_LSR) & 0x20;
26}
27
28static inline void uart8250_wait_to_tx_byte(unsigned base_port)
29{
30 while(!uart8250_can_tx_byte(base_port))
31 ;
32}
33
34static inline void uart8250_wait_until_sent(unsigned base_port)
35{
36 while(!(inb(base_port + UART_LSR) & 0x40))
37 ;
38}
39
40void uart8250_tx_byte(unsigned base_port, unsigned char data)
41{
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);
46}
47
48void uart8250_init(unsigned base_port, unsigned divisor, unsigned lcs)
49{
50 lcs &= 0x7f;
51 /* disable interrupts */
52 outb(0x0, base_port + UART_IER);
53 /* enable fifo's */
54 outb(0x01, base_port + UART_FCR);
55 /* Set Baud Rate Divisor to 12 ==> 115200 Baud */
56 outb(0x80 | lcs, base_port + UART_LCR);
57 outb(divisor & 0xFF, base_port + UART_DLL);
58 outb((divisor >> 8) & 0xFF, base_port + UART_DLM);
59 outb(lcs, base_port + UART_LCR);
60}
Eric Biederman5cd81732004-03-11 15:01:31 +000061
62/* Initialize a generic uart */
63void init_uart8250(unsigned base_port, struct uart8250 *uart)
64{
65 int divisor;
66 int lcs;
67 divisor = 115200/(uart->baud ? uart->baud: 1);
68 lcs = 3;
69 if (base_port == TTYS0_BASE) {
70 /* Don't reinitialize the console serial port,
71 * This is espeically nasty in SMP.
72 */
73 return;
74 }
75 uart8250_init(base_port, divisor, lcs);
76}