[PATCH] libchip/ns16550: Allow user calculate baud divisor
Christian Mauderer
list at c-mauderer.de
Thu Jan 16 19:48:00 UTC 2020
On 15/01/2020 12:50, G S Niteesh wrote:
> This patch will allow the user to pass a function to calculate
> the baud divisor.
> This is will allow for more flexibility, since for some BSP's
> like raspberrypi, the calculate of baud divisor is different
> from what is in the current driver.
> ---
> bsps/include/libchip/ns16550.h | 11 ++++++++---
> bsps/shared/dev/serial/ns16550-context.c | 6 ++++--
> 2 files changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/bsps/include/libchip/ns16550.h b/bsps/include/libchip/ns16550.h
> index f053c8767f9..ab7992fd30b 100644
> --- a/bsps/include/libchip/ns16550.h
> +++ b/bsps/include/libchip/ns16550.h
> @@ -1,6 +1,6 @@
> /**
> * @file
> - *
> + *
Please don't change lines that don't concern the target of your patch.
If you want to fix the white space please do so in an extra patch.
By the way: You can also send patch sets. Just pass all patches to "git
send-email". Then git will number patches that belong together (like
this and the AUX uart driver). That makes it easier to apply all in the
right order.
> */
>
> /*
> @@ -60,7 +60,11 @@ typedef uint8_t (*ns16550_get_reg)(uintptr_t port, uint8_t reg);
>
> typedef void (*ns16550_set_reg)(uintptr_t port, uint8_t reg, uint8_t value);
>
> -typedef struct {
> +typedef struct ns16550_context ns16550_context;
> +
> +typedef uint32_t (*ns16550_calculate_baud_divisor)(ns16550_context *ctx, uint32_t baud);
> +
> +struct ns16550_context{
> rtems_termios_device_context base;
> ns16550_get_reg get_reg;
> ns16550_set_reg set_reg;
> @@ -70,6 +74,7 @@ typedef struct {
> uint32_t initial_baud;
> bool has_fractional_divider_register;
> bool has_precision_clock_synthesizer;
> + ns16550_calculate_baud_divisor calculate_baud_divisor;
> uint8_t modem_control;
> uint8_t line_control;
> uint32_t baud_divisor;
> @@ -78,7 +83,7 @@ typedef struct {
> size_t out_current;
> const char *out_buf;
> rtems_termios_tty *tty;
> -} ns16550_context;
> +};
>
> extern const rtems_termios_device_handler ns16550_handler_interrupt;
> extern const rtems_termios_device_handler ns16550_handler_polled;
> diff --git a/bsps/shared/dev/serial/ns16550-context.c b/bsps/shared/dev/serial/ns16550-context.c
> index ce55b8309cc..70e73fc8c93 100644
> --- a/bsps/shared/dev/serial/ns16550-context.c
> +++ b/bsps/shared/dev/serial/ns16550-context.c
> @@ -1,6 +1,6 @@
> /**
> * @file
> - *
> + *
Again: Please only change if it is necessary for your patch.
> * This file contains the TTY driver for the National Semiconductor NS16550.
> *
> * This part is widely cloned and second sourced. It is found in a number
> @@ -112,6 +112,8 @@ static uint32_t NS16550_GetBaudDivisor(ns16550_context *ctx, uint32_t baud)
> NS16550_FRACTIONAL_DIVIDER,
> fractionalDivider
> );
> + } else if (ctx->calculate_baud_divisor != NULL) {
> + baudDivisor = ctx->calculate_baud_divisor(ctx, baud);
> }
>
> return baudDivisor;
> @@ -165,7 +167,7 @@ bool ns16550_probe(rtems_termios_device_context *base)
>
> ctx->modem_control = SP_MODEM_IRQ;
>
> - pNS16550 = ctx->port;
> + pNS16550 = ctx->port;
Again: Please only change if it is necessary for your patch.
> setReg = ctx->set_reg;
> getReg = ctx->get_reg;
>
>
More information about the devel
mailing list