Skip to content

Commit

Permalink
drivers: ns16550: Implement RX related features
Browse files Browse the repository at this point in the history
Implement ns16550_getchar() and ns16550_have_rx_data() for RX related
serial operations into ns16550 UART driver.

Signed-off-by: Alvin Chang <alvinga@andestech.com>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
  • Loading branch information
gagachang committed Oct 9, 2023
1 parent df576bc commit b59efe6
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions core/drivers/ns16550.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#define UART_SPR 0x7

/* uart status register bits */
#define UART_LSR_DR 0x01 /* DATA Ready */
#define UART_LSR_THRE 0x20 /* Transmit-hold-register empty */

static vaddr_t chip_to_base_and_data(struct serial_chip *chip,
Expand Down Expand Up @@ -74,9 +75,34 @@ static void ns16550_putc(struct serial_chip *chip, int ch)
serial_out(base + (UART_THR << pd->reg_shift), pd->io_width, ch);
}

static bool ns16550_have_rx_data(struct serial_chip *chip)
{
struct ns16550_data *pd = NULL;
vaddr_t base = chip_to_base_and_data(chip, &pd);

return serial_in(base + (UART_LSR << pd->reg_shift), pd->io_width) &
UART_LSR_DR;
}

static int ns16550_getchar(struct serial_chip *chip)
{
struct ns16550_data *pd = NULL;
vaddr_t base = chip_to_base_and_data(chip, &pd);

while (!ns16550_have_rx_data(chip)) {
/* Data is not ready, waiting again */
;
}

return serial_in(base + (UART_RBR << pd->reg_shift), pd->io_width) &
0xFF;
}

static const struct serial_ops ns16550_ops = {
.flush = ns16550_flush,
.putc = ns16550_putc,
.getchar = ns16550_getchar,
.have_rx_data = ns16550_have_rx_data,
};
DECLARE_KEEP_PAGER(ns16550_ops);

Expand Down

0 comments on commit b59efe6

Please sign in to comment.