lib: sbi: Simplify console platform operations

Instead of having console_putc() and console_getc() callbacks in
platform operations, it will be much simpler for console driver to
directly register these operations as device to the sbi_console
implementation.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Xiang W <wxjstz@126.com>
This commit is contained in:
Anup Patel
2021-04-21 18:03:50 +05:30
committed by Anup Patel
parent a3689db92a
commit 068ca086af
25 changed files with 96 additions and 134 deletions

View File

@@ -8,6 +8,7 @@
*/
#include <sbi/riscv_io.h>
#include <sbi/sbi_console.h>
#include <sbi_utils/serial/uart8250.h>
/* clang-format off */
@@ -68,7 +69,7 @@ static void set_reg(u32 num, u32 val)
writel(val, uart8250_base + offset);
}
void uart8250_putc(char ch)
static void uart8250_putc(char ch)
{
while ((get_reg(UART_LSR_OFFSET) & UART_LSR_THRE) == 0)
;
@@ -76,13 +77,19 @@ void uart8250_putc(char ch)
set_reg(UART_THR_OFFSET, ch);
}
int uart8250_getc(void)
static int uart8250_getc(void)
{
if (get_reg(UART_LSR_OFFSET) & UART_LSR_DR)
return get_reg(UART_RBR_OFFSET);
return -1;
}
static struct sbi_console_device uart8250_console = {
.name = "uart8250",
.console_putc = uart8250_putc,
.console_getc = uart8250_getc
};
int uart8250_init(unsigned long base, u32 in_freq, u32 baudrate, u32 reg_shift,
u32 reg_width)
{
@@ -121,5 +128,7 @@ int uart8250_init(unsigned long base, u32 in_freq, u32 baudrate, u32 reg_shift,
/* Set scratchpad */
set_reg(UART_SCR_OFFSET, 0x00);
sbi_console_set_device(&uart8250_console);
return 0;
}