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>
  • Loading branch information
gagachang committed Sep 26, 2023
1 parent 5a5aeb1 commit b2eba8d
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(struct serial_chip *chip)
Expand Down Expand Up @@ -73,9 +74,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 = container_of(chip, struct ns16550_data, chip);
vaddr_t base = chip_to_base(chip);

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 = container_of(chip, struct ns16550_data, chip);
vaddr_t base = chip_to_base(chip);

while (!ns16550_have_rx_data(chip)) {
/* Transmit FIFO is empty, 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 b2eba8d

Please sign in to comment.