[U-Boot] [PATCH 2/6] serial: add UniPhier serial driver

Marek Vasut
2014-07-04T14:40:29Z

On Friday, July 04, 2014 at 12:19:14 PM, Masahiro Yamada wrote:
> The driver for on-chip UART used on Panasonic UniPhier platform.
>
> Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>

[...]

> +static void uniphier_serial_init(struct uniphier_serial *port)
> +{
> + writeb(UART_LCR_WLS_8, &port->lcr);
> +
> +#define MODE_X_DIV 16

You can use just const unsigned here instead of #define.

> +
> + /* Compute divisor value. Normally, we should simply return:
> + * CONFIG_SYS_NS16550_CLK) / MODE_X_DIV / gd->baudrate
> + * but we need to round that value by adding 0.5.
> + * Rounding is especially important at high baud rates.
> + */
> + writew((CONFIG_SYS_UNIPHIER_UART_CLK + (gd->baudrate *
> + (MODE_X_DIV / 2))) / (MODE_X_DIV * gd->baudrate), &port->dlr);
> +}
> +
> +static void uniphier_serial_setbrg(struct uniphier_serial *port)
> +{
> + uniphier_serial_init(port);
> +}
> +
> +static int uniphier_serial_tstc(struct uniphier_serial *port)
> +{
> + return (readb(&port->lsr) & UART_LSR_DR) != 0;
> +}
> +
> +static int uniphier_serial_getc(struct uniphier_serial *port)
> +{
> + while (!uniphier_serial_tstc(port))
> + ;
> +
> + return readb(&port->rbr);
> +}
> +
> +static void uniphier_serial_putc(struct uniphier_serial *port, const char
> c) +{
> + if (c == '\n')
> + uniphier_serial_putc(port, '\r');
> +
> + while (!(readb(&port->lsr) & UART_LSR_THRE))
> + ;

I think in this function, you can avoid such completely unbounded loop.

[...]

Best regard,
Marek Vasut