diff mbox series

[v4,05/10] tty: serial: extract tx_ready() from __serial_lpc32xx_tx()

Message ID 20220920052049.20507-6-jslaby@suse.cz (mailing list archive)
State New, archived
Headers show
Series [v4,01/10] tty: serial: move and cleanup vt8500_tx_empty() | expand

Commit Message

Jiri Slaby Sept. 20, 2022, 5:20 a.m. UTC
The condition in __serial_lpc32xx_tx()'s loop is barely readable.
Extract it to a separate function. This will make the cleanup in the
next patches easier too.

Cc: Vladimir Zapolskiy <vz@mleia.com>
Cc: <linux-arm-kernel@lists.infradead.org>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---

Notes:
    [v4] this is new in v4 -- extracted as a separate change

 drivers/tty/serial/lpc32xx_hs.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Ilpo Järvinen Sept. 20, 2022, 8:11 a.m. UTC | #1
On Tue, 20 Sep 2022, Jiri Slaby wrote:

> The condition in __serial_lpc32xx_tx()'s loop is barely readable.
> Extract it to a separate function. This will make the cleanup in the
> next patches easier too.
> 
> Cc: Vladimir Zapolskiy <vz@mleia.com>
> Cc: <linux-arm-kernel@lists.infradead.org>
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

I noticed that wait_for_xmit_ready() uses < 32 for the similar check 
which seems fishy...
diff mbox series

Patch

diff --git a/drivers/tty/serial/lpc32xx_hs.c b/drivers/tty/serial/lpc32xx_hs.c
index 0d5ef7df27d0..ed47f4768338 100644
--- a/drivers/tty/serial/lpc32xx_hs.c
+++ b/drivers/tty/serial/lpc32xx_hs.c
@@ -278,6 +278,13 @@  static void __serial_lpc32xx_rx(struct uart_port *port)
 
 static void serial_lpc32xx_stop_tx(struct uart_port *port);
 
+static bool serial_lpc32xx_tx_ready(struct uart_port *port)
+{
+	u32 level = readl(LPC32XX_HSUART_LEVEL(port->membase));
+
+	return LPC32XX_HSU_TX_LEV(level) < 64;
+}
+
 static void __serial_lpc32xx_tx(struct uart_port *port)
 {
 	struct circ_buf *xmit = &port->state->xmit;
@@ -293,8 +300,7 @@  static void __serial_lpc32xx_tx(struct uart_port *port)
 		goto exit_tx;
 
 	/* Transfer data */
-	while (LPC32XX_HSU_TX_LEV(readl(
-		LPC32XX_HSUART_LEVEL(port->membase))) < 64) {
+	while (serial_lpc32xx_tx_ready(port)) {
 		writel((u32) xmit->buf[xmit->tail],
 		       LPC32XX_HSUART_FIFO(port->membase));
 		xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);