uart8250io: Unify calls with generic UART

Change-Id: I6d56648e56f2177e1d5332497321e718df18300c
Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-on: http://review.coreboot.org/5234
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
This commit is contained in:
Kyösti Mälkki 2014-02-15 07:53:18 +02:00
parent 1d7541feeb
commit 4770749edc
7 changed files with 47 additions and 44 deletions

View File

@ -20,6 +20,7 @@
#include <stdint.h> #include <stdint.h>
#include <console/loglevel.h> #include <console/loglevel.h>
#include <console/post_codes.h> #include <console/post_codes.h>
#include <console/uart.h>
#include <console/ne2k.h> #include <console/ne2k.h>
/* __PRE_RAM__ */ /* __PRE_RAM__ */
@ -28,9 +29,6 @@
* we could use the same code on all architectures. * we could use the same code on all architectures.
*/ */
#define console_loglevel CONFIG_DEFAULT_CONSOLE_LOGLEVEL #define console_loglevel CONFIG_DEFAULT_CONSOLE_LOGLEVEL
#if CONFIG_CONSOLE_SERIAL8250
#include <uart8250.h>
#endif
#if CONFIG_CONSOLE_SERIAL8250 #if CONFIG_CONSOLE_SERIAL8250
#include "drivers/uart/util.c" #include "drivers/uart/util.c"
@ -43,7 +41,7 @@
static void __console_tx_byte(unsigned char byte) static void __console_tx_byte(unsigned char byte)
{ {
#if CONFIG_CONSOLE_SERIAL8250 #if CONFIG_CONSOLE_SERIAL8250
uart8250_tx_byte(CONFIG_TTYS0_BASE, byte); uart_tx_byte(byte);
#endif #endif
#if CONFIG_CONSOLE_NE2K #if CONFIG_CONSOLE_NE2K
ne2k_append_data_byte(byte, CONFIG_CONSOLE_NE2K_IO_PORT); ne2k_append_data_byte(byte, CONFIG_CONSOLE_NE2K_IO_PORT);
@ -64,7 +62,7 @@ static void __console_tx_char(int loglevel, unsigned char byte)
{ {
if (console_loglevel >= loglevel) { if (console_loglevel >= loglevel) {
#if CONFIG_CONSOLE_SERIAL8250 #if CONFIG_CONSOLE_SERIAL8250
uart8250_tx_byte(CONFIG_TTYS0_BASE, byte); uart_tx_byte(byte);
#endif #endif
#if CONFIG_CONSOLE_NE2K #if CONFIG_CONSOLE_NE2K
ne2k_append_data_byte(byte, CONFIG_CONSOLE_NE2K_IO_PORT); ne2k_append_data_byte(byte, CONFIG_CONSOLE_NE2K_IO_PORT);

View File

@ -26,7 +26,7 @@
#include <console/spkmodem.h> #include <console/spkmodem.h>
#include <console/vtxprintf.h> #include <console/vtxprintf.h>
#if CONFIG_CONSOLE_SERIAL8250 || CONFIG_CONSOLE_SERIAL8250MEM #if CONFIG_CONSOLE_SERIAL8250MEM
#include <uart8250.h> #include <uart8250.h>
#endif #endif
@ -42,7 +42,7 @@ void console_tx_byte(unsigned char byte)
} }
#endif #endif
#if CONFIG_CONSOLE_SERIAL8250 #if CONFIG_CONSOLE_SERIAL8250
uart8250_tx_byte(CONFIG_TTYS0_BASE, byte); uart_tx_byte(byte);
#endif #endif
#if CONFIG_USBDEBUG && (CONFIG_USBDEBUG_IN_ROMSTAGE || !defined(__PRE_RAM__)) #if CONFIG_USBDEBUG && (CONFIG_USBDEBUG_IN_ROMSTAGE || !defined(__PRE_RAM__))
usb_tx_byte(0, byte); usb_tx_byte(0, byte);
@ -64,7 +64,7 @@ void console_tx_flush(void)
uart8250_mem_tx_flush(CONFIG_OXFORD_OXPCIE_BASE_ADDRESS + 0x1000); uart8250_mem_tx_flush(CONFIG_OXFORD_OXPCIE_BASE_ADDRESS + 0x1000);
#endif #endif
#if CONFIG_CONSOLE_SERIAL8250 #if CONFIG_CONSOLE_SERIAL8250
uart8250_tx_flush(CONFIG_TTYS0_BASE); uart_tx_flush();
#endif #endif
#if CONFIG_CONSOLE_NE2K #if CONFIG_CONSOLE_NE2K
ne2k_transmit(CONFIG_CONSOLE_NE2K_IO_PORT); ne2k_transmit(CONFIG_CONSOLE_NE2K_IO_PORT);

View File

@ -19,7 +19,6 @@
#include <console/console.h> #include <console/console.h>
#include <console/uart.h> #include <console/uart.h>
#include <uart8250.h>
static void ttyS0_init(void) static void ttyS0_init(void)
{ {
@ -28,22 +27,22 @@ static void ttyS0_init(void)
static void ttyS0_tx_byte(unsigned char data) 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) static void ttyS0_tx_flush(void)
{ {
uart8250_tx_flush(CONFIG_TTYS0_BASE); uart_tx_flush();
} }
static unsigned char ttyS0_rx_byte(void) static unsigned char ttyS0_rx_byte(void)
{ {
return uart8250_rx_byte(CONFIG_TTYS0_BASE); return uart_rx_byte();
} }
static int ttyS0_tst_byte(void) 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 = { static const struct console_driver uart8250_console __console = {

View File

@ -45,7 +45,7 @@ void console_tx_byte(unsigned char byte)
uart8250_mem_tx_byte(serial8250mem_base_address, byte); uart8250_mem_tx_byte(serial8250mem_base_address, byte);
#endif #endif
#if CONFIG_CONSOLE_SERIAL8250 #if CONFIG_CONSOLE_SERIAL8250
uart8250_tx_byte(CONFIG_TTYS0_BASE, byte); uart_tx_byte(byte);
#endif #endif
} }

View File

@ -37,10 +37,11 @@ unsigned int uart_baudrate_divisor(unsigned int baudrate,
unsigned int refclk, unsigned int oversample); unsigned int refclk, unsigned int oversample);
unsigned char uart_rx_byte(void); void uart_init(void);
void uart_tx_byte(unsigned char data); void uart_tx_byte(unsigned char data);
void uart_tx_flush(void); void uart_tx_flush(void);
void uart_init(void); unsigned char uart_rx_byte(void);
int uart_can_rx_byte(void);
uint32_t uartmem_getbaseaddr(void); uint32_t uartmem_getbaseaddr(void);

View File

@ -105,16 +105,6 @@
#define UART_SCR 0x07 #define UART_SCR 0x07
#define UART_SPR 0x07 #define UART_SPR 0x07
#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 #if CONFIG_CONSOLE_SERIAL8250MEM
void uartmem_init(void); void uartmem_init(void);

View File

@ -40,40 +40,30 @@
#define SINGLE_CHAR_TIMEOUT (50 * 1000) #define SINGLE_CHAR_TIMEOUT (50 * 1000)
#define FIFO_TIMEOUT (16 * SINGLE_CHAR_TIMEOUT) #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; 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; unsigned long int i = SINGLE_CHAR_TIMEOUT;
while (i-- && !uart8250_can_tx_byte(base_port)); 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; unsigned long int i = FIFO_TIMEOUT;
while (i-- && !(inb(base_port + UART_LSR) & UART_LSR_TEMT)); while (i-- && !(inb(base_port + UART_LSR) & UART_LSR_TEMT));
} }
void uart8250_tx_byte(unsigned base_port, unsigned char data) static int uart8250_can_rx_byte(unsigned base_port)
{
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)
{ {
return inb(base_port + UART_LSR) & UART_LSR_DR; 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; unsigned long int i = SINGLE_CHAR_TIMEOUT;
while (i-- && !uart8250_can_rx_byte(base_port)); while (i-- && !uart8250_can_rx_byte(base_port));
@ -84,7 +74,7 @@ unsigned char uart8250_rx_byte(unsigned base_port)
return 0x0; return 0x0;
} }
void uart8250_init(unsigned base_port, unsigned divisor) static void uart8250_init(unsigned base_port, unsigned divisor)
{ {
DISABLE_TRACE; DISABLE_TRACE;
/* Disable interrupts */ /* Disable interrupts */
@ -107,10 +97,35 @@ void uart8250_init(unsigned base_port, unsigned divisor)
ENABLE_TRACE; ENABLE_TRACE;
} }
/* FIXME: Needs uart index from Kconfig.
* Already use array as a work-around for ROMCC.
*/
static const unsigned bases[1] = { CONFIG_TTYS0_BASE };
void uart_init(void) void uart_init(void)
{ {
unsigned int div; unsigned int div;
div = uart_baudrate_divisor(default_baudrate(), BAUDRATE_REFCLK, div = uart_baudrate_divisor(default_baudrate(), BAUDRATE_REFCLK,
BAUDRATE_OVERSAMPLE); BAUDRATE_OVERSAMPLE);
uart8250_init(CONFIG_TTYS0_BASE, div); uart8250_init(bases[0], div);
}
void uart_tx_byte(unsigned char data)
{
uart8250_tx_byte(bases[0], data);
}
unsigned char uart_rx_byte(void)
{
return uart8250_rx_byte(bases[0]);
}
int uart_can_rx_byte(void)
{
return uart8250_can_rx_byte(bases[0]);
}
void uart_tx_flush(void)
{
uart8250_tx_flush(bases[0]);
} }