This patch unifies the use of config options in v2 to all start with CONFIG_
[coreboot.git] / src / lib / uart8250.c
index 778919b7ff5ddf89a38f94638a69fb3ae042a90c..79eb1c51c19987610043480e43e6fdf57af3ab80 100644 (file)
@@ -1,7 +1,3 @@
-#ifndef lint
-static char rcsid[] = "$Id$";
-#endif
-
 /* Should support 8250, 16450, 16550, 16550A type uarts */
 #include <arch/io.h>
 #include <uart8250.h>
@@ -49,6 +45,18 @@ void uart8250_tx_byte(unsigned base_port, unsigned char data)
        uart8250_wait_until_sent(base_port);
 }
 
+int uart8250_can_rx_byte(unsigned base_port)
+{
+       return inb(base_port + UART_LSR) & 0x01;
+}
+
+unsigned char uart8250_rx_byte(unsigned base_port)
+{
+       while(!uart8250_can_rx_byte(base_port))
+               ;
+       return inb(base_port + UART_RBR);
+}
+
 void uart8250_init(unsigned base_port, unsigned divisor, unsigned lcs)
 {
        lcs &= 0x7f;
@@ -56,9 +64,27 @@ void uart8250_init(unsigned base_port, unsigned divisor, unsigned lcs)
        outb(0x0, base_port + UART_IER);
        /* enable fifo's */
        outb(0x01, base_port + UART_FCR);
+       /* assert DTR and RTS so the other end is happy */
+       outb(0x03, base_port + UART_MCR);
        /* Set Baud Rate Divisor to 12 ==> 115200 Baud */
        outb(0x80 | lcs, base_port + UART_LCR);
        outb(divisor & 0xFF,   base_port + UART_DLL);
        outb((divisor >> 8) & 0xFF,    base_port + UART_DLM);
        outb(lcs, base_port + UART_LCR);
 }
+
+/* Initialize a generic uart */
+void init_uart8250(unsigned base_port, struct uart8250 *uart)
+{
+       int divisor;
+       int lcs;
+       divisor = 115200/(uart->baud ? uart->baud: 1);
+       lcs = 3;
+       if (base_port == CONFIG_TTYS0_BASE) {
+               /* Don't reinitialize the console serial port,
+                * This is espeically nasty in SMP.
+                */
+               return;
+       }
+       uart8250_init(base_port, divisor, lcs);
+}