Kyösti Mälkki (kyosti.malkki@gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/5234
-gerrit
commit 60193d2d271557aeca8b1949753240b1dd12767b Author: Kyösti Mälkki kyosti.malkki@gmail.com Date: Sat Feb 15 07:53:18 2014 +0200
uart8250io: Unify calls with generic UART
Change-Id: I6d56648e56f2177e1d5332497321e718df18300c Signed-off-by: Kyösti Mälkki kyosti.malkki@gmail.com --- src/arch/x86/lib/romcc_console.c | 8 +++--- src/arch/x86/lib/romstage_console.c | 6 ++--- src/console/uart8250_console.c | 10 ++++---- src/include/console/uart.h | 1 + src/include/uart8250.h | 10 -------- src/lib/uart8250.c | 50 +++++++++++++++++++++++-------------- 6 files changed, 43 insertions(+), 42 deletions(-)
diff --git a/src/arch/x86/lib/romcc_console.c b/src/arch/x86/lib/romcc_console.c index 0f0e017..5a88146 100644 --- a/src/arch/x86/lib/romcc_console.c +++ b/src/arch/x86/lib/romcc_console.c @@ -20,6 +20,7 @@ #include <stdint.h> #include <console/loglevel.h> #include <console/post_codes.h> +#include <console/uart.h> #include <console/ne2k.h>
/* __PRE_RAM__ */ @@ -28,9 +29,6 @@ * we could use the same code on all architectures. */ #define console_loglevel CONFIG_DEFAULT_CONSOLE_LOGLEVEL -#if CONFIG_CONSOLE_SERIAL8250 -#include <uart8250.h> -#endif
#include <console/util.c>
@@ -44,7 +42,7 @@ static void __console_tx_byte(unsigned char byte) { #if CONFIG_CONSOLE_SERIAL8250 - uart8250_tx_byte(CONFIG_TTYS0_BASE, byte); + uart_tx_byte(byte); #endif #if CONFIG_CONSOLE_NE2K ne2k_append_data_byte(byte, CONFIG_CONSOLE_NE2K_IO_PORT); @@ -65,7 +63,7 @@ static void __console_tx_char(int loglevel, unsigned char byte) { if (console_loglevel >= loglevel) { #if CONFIG_CONSOLE_SERIAL8250 - uart8250_tx_byte(CONFIG_TTYS0_BASE, byte); + uart_tx_byte(byte); #endif #if CONFIG_CONSOLE_NE2K ne2k_append_data_byte(byte, CONFIG_CONSOLE_NE2K_IO_PORT); diff --git a/src/arch/x86/lib/romstage_console.c b/src/arch/x86/lib/romstage_console.c index 4981f39..89d7f82 100644 --- a/src/arch/x86/lib/romstage_console.c +++ b/src/arch/x86/lib/romstage_console.c @@ -26,7 +26,7 @@ #include <console/spkmodem.h> #include <console/vtxprintf.h>
-#if CONFIG_CONSOLE_SERIAL8250 || CONFIG_CONSOLE_SERIAL8250MEM +#if CONFIG_CONSOLE_SERIAL8250MEM #include <uart8250.h> #endif
@@ -42,7 +42,7 @@ void console_tx_byte(unsigned char byte) } #endif #if CONFIG_CONSOLE_SERIAL8250 - uart8250_tx_byte(CONFIG_TTYS0_BASE, byte); + uart_tx_byte(byte); #endif #if CONFIG_USBDEBUG && (CONFIG_USBDEBUG_IN_ROMSTAGE || !defined(__PRE_RAM__)) usb_tx_byte(0, byte); @@ -64,7 +64,7 @@ void console_tx_flush(void) uart8250_mem_tx_flush(CONFIG_OXFORD_OXPCIE_BASE_ADDRESS + 0x1000); #endif #if CONFIG_CONSOLE_SERIAL8250 - uart8250_tx_flush(CONFIG_TTYS0_BASE); + uart_tx_flush(); #endif #if CONFIG_CONSOLE_NE2K ne2k_transmit(CONFIG_CONSOLE_NE2K_IO_PORT); diff --git a/src/console/uart8250_console.c b/src/console/uart8250_console.c index 196412c..52f59f6 100644 --- a/src/console/uart8250_console.c +++ b/src/console/uart8250_console.c @@ -18,7 +18,7 @@ */
#include <console/console.h> -#include <uart8250.h> +#include <console/uart.h>
static void ttyS0_init(void) { @@ -27,22 +27,22 @@ static void ttyS0_init(void)
static void ttyS0_tx_byte(unsigned char data) { - uart8250_tx_byte(CONFIG_TTYS0_BASE, data); + uart_tx_byte(data); }
static void ttyS0_tx_flush(void) { - uart8250_tx_flush(CONFIG_TTYS0_BASE); + uart_tx_flush(); }
static unsigned char ttyS0_rx_byte(void) { - return uart8250_rx_byte(CONFIG_TTYS0_BASE); + return uart_rx_byte(); }
static int ttyS0_tst_byte(void) { - return uart8250_can_rx_byte(CONFIG_TTYS0_BASE); + return uart_can_rx_byte(); }
static const struct console_driver uart8250_console __console = { diff --git a/src/include/console/uart.h b/src/include/console/uart.h index 6cd3beb..ac4455a 100644 --- a/src/include/console/uart.h +++ b/src/include/console/uart.h @@ -24,6 +24,7 @@ void uart_init(void); void uart_tx_byte(unsigned char data); void uart_tx_flush(void); unsigned char uart_rx_byte(void); +int uart_can_rx_byte(void);
unsigned uart_divisor(unsigned basefreq); diff --git a/src/include/uart8250.h b/src/include/uart8250.h index a214ce1..4d7ebcc 100644 --- a/src/include/uart8250.h +++ b/src/include/uart8250.h @@ -26,16 +26,6 @@ #error Bad ttyS0 baud rate #endif
-#if CONFIG_CONSOLE_SERIAL8250 -unsigned char uart8250_rx_byte(unsigned base_port); -int uart8250_can_rx_byte(unsigned base_port); -void uart8250_tx_byte(unsigned base_port, unsigned char data); -void uart8250_tx_flush(unsigned base_port); -/* Yes it is silly to have three different uart init functions. But we used to - * have three different sets of uart code, so it's an improvement. - */ -void uart8250_init(unsigned base_port, unsigned divisor); -#endif #if CONFIG_CONSOLE_SERIAL8250MEM void uartmem_init(void);
diff --git a/src/lib/uart8250.c b/src/lib/uart8250.c index 4d2cb63..bf51cc6 100644 --- a/src/lib/uart8250.c +++ b/src/lib/uart8250.c @@ -19,7 +19,7 @@ */
#include <arch/io.h> -#include <uart8250.h> +#include <console/uart.h> #include <trace.h> #include "drivers/uart/uart8250reg.h"
@@ -34,40 +34,30 @@ #define SINGLE_CHAR_TIMEOUT (50 * 1000) #define FIFO_TIMEOUT (16 * SINGLE_CHAR_TIMEOUT)
-static inline int uart8250_can_tx_byte(unsigned base_port) +static int uart8250_can_tx_byte(unsigned base_port) { return inb(base_port + UART_LSR) & UART_LSR_THRE; }
-static inline void uart8250_wait_to_tx_byte(unsigned base_port) +static void uart8250_tx_byte(unsigned base_port, unsigned char data) { unsigned long int i = SINGLE_CHAR_TIMEOUT; while (i-- && !uart8250_can_tx_byte(base_port)); + outb(data, base_port + UART_TBR); }
-static inline void uart8250_wait_until_sent(unsigned base_port) +static void uart8250_tx_flush(unsigned base_port) { unsigned long int i = FIFO_TIMEOUT; while (i-- && !(inb(base_port + UART_LSR) & UART_LSR_TEMT)); }
-void uart8250_tx_byte(unsigned base_port, unsigned char data) -{ - uart8250_wait_to_tx_byte(base_port); - outb(data, base_port + UART_TBR); -} - -void uart8250_tx_flush(unsigned base_port) -{ - uart8250_wait_until_sent(base_port); -} - -int uart8250_can_rx_byte(unsigned base_port) +static int uart8250_can_rx_byte(unsigned base_port) { return inb(base_port + UART_LSR) & UART_LSR_DR; }
-unsigned char uart8250_rx_byte(unsigned base_port) +static unsigned char uart8250_rx_byte(unsigned base_port) { unsigned long int i = SINGLE_CHAR_TIMEOUT; while (i-- && !uart8250_can_rx_byte(base_port)); @@ -78,7 +68,7 @@ unsigned char uart8250_rx_byte(unsigned base_port) return 0x0; }
-void uart8250_init(unsigned base_port, unsigned divisor) +static void uart8250_init(unsigned base_port, unsigned divisor) { DISABLE_TRACE; /* Disable interrupts */ @@ -101,8 +91,30 @@ void uart8250_init(unsigned base_port, unsigned divisor) ENABLE_TRACE; }
+static const unsigned base = CONFIG_TTYS0_BASE; + void uart_init(void) { unsigned int div = uart_divisor(115200); - uart8250_init(CONFIG_TTYS0_BASE, div); + uart8250_init(base, div); +} + +void uart_tx_byte(unsigned char data) +{ + uart8250_tx_byte(base, data); +} + +unsigned char uart_rx_byte(void) +{ + return uart8250_rx_byte(base); +} + +int uart_can_rx_byte(void) +{ + return uart8250_can_rx_byte(base); +} + +void uart_tx_flush(void) +{ + uart8250_tx_flush(base); }