diff options
author | Jerome Forissier <jerome.forissier@linaro.org> | 2017-02-17 17:39:06 +0100 |
---|---|---|
committer | Jerome Forissier <jerome.forissier@linaro.org> | 2017-03-17 18:23:51 +0100 |
commit | 2e5aa31ba0454b74d619671061093ebfcf913aec (patch) | |
tree | 9d61c8081467be3ab46add3827de88e04aa1f93b /core/drivers/ns16550.c | |
parent | ab806dc30280e7fd735d85cb53e334244da295f7 (diff) |
drivers: convert ns16550 driver to use struct serial_chip
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
Diffstat (limited to 'core/drivers/ns16550.c')
-rw-r--r-- | core/drivers/ns16550.c | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/core/drivers/ns16550.c b/core/drivers/ns16550.c index 710b351e..eea430a0 100644 --- a/core/drivers/ns16550.c +++ b/core/drivers/ns16550.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2015 Freescale Semiconductor, Inc. + * Copyright (c) 2017, Linaro Limited * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,6 +28,7 @@ #include <drivers/ns16550.h> #include <io.h> +#include <util.h> /* uart register defines */ #define UART_RBR 0x0 @@ -42,16 +44,44 @@ /* uart status register bits */ #define UART_LSR_THRE 0x20 /* Transmit-hold-register empty */ -void ns16550_flush(vaddr_t base) +static vaddr_t chip_to_base(struct serial_chip *chip) { + struct ns16550_data *pd = + container_of(chip, struct ns16550_data, chip); + + return io_pa_or_va(&pd->base); +} + +static void ns16550_flush(struct serial_chip *chip) +{ + vaddr_t base = chip_to_base(chip); + while ((read8(base + UART_LSR) & UART_LSR_THRE) == 0) ; } -void ns16550_putc(int ch, vaddr_t base) +static void ns16550_putc(struct serial_chip *chip, int ch) { - ns16550_flush(base); + vaddr_t base = chip_to_base(chip); + + ns16550_flush(chip); /* write out charset to Transmit-hold-register */ write8(ch, base + UART_THR); } + +static const struct serial_ops ns16550_ops = { + .flush = ns16550_flush, + .putc = ns16550_putc, +}; + +void ns16550_init(struct ns16550_data *pd, paddr_t base) +{ + pd->base.pa = base; + pd->chip.ops = &ns16550_ops; + + /* + * Do nothing, uart driver shared with normal world, + * everything for uart driver initialization is done in bootloader. + */ +} |