]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
tty: serial: uartlite: Use read_poll_timeout for a polling loop
authorSean Anderson <sean.anderson@seco.com>
Thu, 26 Aug 2021 19:25:49 +0000 (15:25 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 27 Aug 2021 14:34:32 +0000 (16:34 +0200)
read_poll_timeout was recently introduced, and can be used to simplify
our console polling loop. This results in a slight reduction in code.
early_uartlite_putc can't get the same treatment, because it can be
called before udelay is set up.

Signed-off-by: Sean Anderson <sean.anderson@seco.com>
Link: https://lore.kernel.org/r/20210826192549.3203071-1-sean.anderson@seco.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/uartlite.c

index a1b9264498e2a610f9aa66527672235fd84fecef..dfc1ba4e1572427a04ccf3d86696e49b793d5ed1 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/interrupt.h>
 #include <linux/init.h>
 #include <linux/io.h>
+#include <linux/iopoll.h>
 #include <linux/of.h>
 #include <linux/of_address.h>
 #include <linux/of_device.h>
@@ -454,24 +455,15 @@ static const struct uart_ops ulite_ops = {
 static void ulite_console_wait_tx(struct uart_port *port)
 {
        u8 val;
-       unsigned long timeout;
 
        /*
         * Spin waiting for TX fifo to have space available.
         * When using the Microblaze Debug Module this can take up to 1s
         */
-       timeout = jiffies + msecs_to_jiffies(1000);
-       while (1) {
-               val = uart_in32(ULITE_STATUS, port);
-               if ((val & ULITE_STATUS_TXFULL) == 0)
-                       break;
-               if (time_after(jiffies, timeout)) {
-                       dev_warn(port->dev,
-                                "timeout waiting for TX buffer empty\n");
-                       break;
-               }
-               cpu_relax();
-       }
+       if (read_poll_timeout_atomic(uart_in32, val, !(val & ULITE_STATUS_TXFULL),
+                                    0, 1000000, false, ULITE_STATUS, port))
+               dev_warn(port->dev,
+                        "timeout waiting for TX buffer empty\n");
 }
 
 static void ulite_console_putchar(struct uart_port *port, int ch)