From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marek Vasut Date: Fri, 4 Jul 2014 16:40:29 +0200 Subject: [U-Boot] [PATCH 2/6] serial: add UniPhier serial driver In-Reply-To: <1404469158-22703-3-git-send-email-yamada.m@jp.panasonic.com> References: <1404469158-22703-1-git-send-email-yamada.m@jp.panasonic.com> <1404469158-22703-3-git-send-email-yamada.m@jp.panasonic.com> Message-ID: <201407041640.29293.marex@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 [...] > +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