diff options
author | Anup Patel <anup.patel@wdc.com> | 2021-04-21 18:03:50 +0530 |
---|---|---|
committer | Anup Patel <anup@brainfault.org> | 2021-04-28 16:58:23 +0530 |
commit | 068ca086af2312d56efe51a724d78d84e1339ab4 (patch) | |
tree | 0e90c1a9e7a03254ff5dcb33507c5c9a06f9de3e /lib/utils/serial | |
parent | a3689db92a0e83ef25c52887aa686e4527e35a22 (diff) |
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>
Diffstat (limited to 'lib/utils/serial')
-rw-r--r-- | lib/utils/serial/fdt_serial.c | 21 | ||||
-rw-r--r-- | lib/utils/serial/fdt_serial_htif.c | 10 | ||||
-rw-r--r-- | lib/utils/serial/fdt_serial_shakti.c | 4 | ||||
-rw-r--r-- | lib/utils/serial/fdt_serial_sifive.c | 4 | ||||
-rw-r--r-- | lib/utils/serial/fdt_serial_uart8250.c | 2 | ||||
-rw-r--r-- | lib/utils/serial/shakti-uart.c | 12 | ||||
-rw-r--r-- | lib/utils/serial/sifive-uart.c | 12 | ||||
-rw-r--r-- | lib/utils/serial/uart8250.c | 13 |
8 files changed, 40 insertions, 38 deletions
diff --git a/lib/utils/serial/fdt_serial.c b/lib/utils/serial/fdt_serial.c index b9ce67e..43c55e8 100644 --- a/lib/utils/serial/fdt_serial.c +++ b/lib/utils/serial/fdt_serial.c @@ -24,34 +24,13 @@ static struct fdt_serial *serial_drivers[] = { &fdt_serial_shakti, }; -static void dummy_putc(char ch) -{ -} - -static int dummy_getc(void) -{ - return -1; -} - static struct fdt_serial dummy = { .match_table = NULL, .init = NULL, - .putc = dummy_putc, - .getc = dummy_getc, }; static struct fdt_serial *current_driver = &dummy; -void fdt_serial_putc(char ch) -{ - current_driver->putc(ch); -} - -int fdt_serial_getc(void) -{ - return current_driver->getc(); -} - int fdt_serial_init(void) { const void *prop; diff --git a/lib/utils/serial/fdt_serial_htif.c b/lib/utils/serial/fdt_serial_htif.c index 32d6953..fae55b8 100644 --- a/lib/utils/serial/fdt_serial_htif.c +++ b/lib/utils/serial/fdt_serial_htif.c @@ -16,9 +16,13 @@ static const struct fdt_match serial_htif_match[] = { { }, }; +static int serial_htif_init(void *fdt, int nodeoff, + const struct fdt_match *match) +{ + return htif_serial_init(); +} + struct fdt_serial fdt_serial_htif = { .match_table = serial_htif_match, - .init = NULL, - .getc = htif_getc, - .putc = htif_putc + .init = serial_htif_init }; diff --git a/lib/utils/serial/fdt_serial_shakti.c b/lib/utils/serial/fdt_serial_shakti.c index c6385a5..4f91419 100644 --- a/lib/utils/serial/fdt_serial_shakti.c +++ b/lib/utils/serial/fdt_serial_shakti.c @@ -29,7 +29,5 @@ static const struct fdt_match serial_shakti_match[] = { struct fdt_serial fdt_serial_shakti = { .match_table = serial_shakti_match, - .init = serial_shakti_init, - .getc = shakti_uart_getc, - .putc = shakti_uart_putc + .init = serial_shakti_init }; diff --git a/lib/utils/serial/fdt_serial_sifive.c b/lib/utils/serial/fdt_serial_sifive.c index 9e487a2..f4c833c 100644 --- a/lib/utils/serial/fdt_serial_sifive.c +++ b/lib/utils/serial/fdt_serial_sifive.c @@ -32,7 +32,5 @@ static const struct fdt_match serial_sifive_match[] = { struct fdt_serial fdt_serial_sifive = { .match_table = serial_sifive_match, - .init = serial_sifive_init, - .getc = sifive_uart_getc, - .putc = sifive_uart_putc + .init = serial_sifive_init }; diff --git a/lib/utils/serial/fdt_serial_uart8250.c b/lib/utils/serial/fdt_serial_uart8250.c index 5030b82..918193a 100644 --- a/lib/utils/serial/fdt_serial_uart8250.c +++ b/lib/utils/serial/fdt_serial_uart8250.c @@ -34,6 +34,4 @@ static const struct fdt_match serial_uart8250_match[] = { struct fdt_serial fdt_serial_uart8250 = { .match_table = serial_uart8250_match, .init = serial_uart8250_init, - .getc = uart8250_getc, - .putc = uart8250_putc }; diff --git a/lib/utils/serial/shakti-uart.c b/lib/utils/serial/shakti-uart.c index 7c1148e..e77a985 100644 --- a/lib/utils/serial/shakti-uart.c +++ b/lib/utils/serial/shakti-uart.c @@ -23,14 +23,14 @@ static volatile void *uart_base; -void shakti_uart_putc(char ch) +static void shakti_uart_putc(char ch) { while((readw(uart_base + REG_STATUS) & UART_TX_FULL)) ; writeb(ch, uart_base + REG_TX); } -int shakti_uart_getc(void) +static int shakti_uart_getc(void) { u16 status = readw(uart_base + REG_STATUS); if (status & UART_RX_FULL) @@ -38,11 +38,19 @@ int shakti_uart_getc(void) return -1; } +static struct sbi_console_device shakti_console = { + .name = "shakti_uart", + .console_putc = shakti_uart_putc, + .console_getc = shakti_uart_getc +}; + int shakti_uart_init(unsigned long base, u32 in_freq, u32 baudrate) { uart_base = (volatile void *)base; u16 baud = (u16)(in_freq/(16 * baudrate)); writew(baud, uart_base + REG_BAUD); + sbi_console_set_device(&shakti_console); + return 0; } diff --git a/lib/utils/serial/sifive-uart.c b/lib/utils/serial/sifive-uart.c index 72c8a62..57d80fa 100644 --- a/lib/utils/serial/sifive-uart.c +++ b/lib/utils/serial/sifive-uart.c @@ -66,7 +66,7 @@ static void set_reg(u32 num, u32 val) writel(val, uart_base + (num * 0x4)); } -void sifive_uart_putc(char ch) +static void sifive_uart_putc(char ch) { while (get_reg(UART_REG_TXFIFO) & UART_TXFIFO_FULL) ; @@ -74,7 +74,7 @@ void sifive_uart_putc(char ch) set_reg(UART_REG_TXFIFO, ch); } -int sifive_uart_getc(void) +static int sifive_uart_getc(void) { u32 ret = get_reg(UART_REG_RXFIFO); if (!(ret & UART_RXFIFO_EMPTY)) @@ -82,6 +82,12 @@ int sifive_uart_getc(void) return -1; } +static struct sbi_console_device sifive_console = { + .name = "sifive_uart", + .console_putc = sifive_uart_putc, + .console_getc = sifive_uart_getc +}; + int sifive_uart_init(unsigned long base, u32 in_freq, u32 baudrate) { uart_base = (volatile void *)base; @@ -98,5 +104,7 @@ int sifive_uart_init(unsigned long base, u32 in_freq, u32 baudrate) /* Enable Rx */ set_reg(UART_REG_RXCTRL, UART_RXCTRL_RXEN); + sbi_console_set_device(&sifive_console); + return 0; } diff --git a/lib/utils/serial/uart8250.c b/lib/utils/serial/uart8250.c index 9635ba8..1cf6624 100644 --- a/lib/utils/serial/uart8250.c +++ b/lib/utils/serial/uart8250.c @@ -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; } |