Skip to content

Commit 2e5f3a6

Browse files
sean-anderson-secogregkh
authored andcommitted
tty: serial: uartlite: Use read_poll_timeout for a polling loop
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 3620a89 commit 2e5f3a6

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

drivers/tty/serial/uartlite.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/interrupt.h>
1818
#include <linux/init.h>
1919
#include <linux/io.h>
20+
#include <linux/iopoll.h>
2021
#include <linux/of.h>
2122
#include <linux/of_address.h>
2223
#include <linux/of_device.h>
@@ -454,24 +455,15 @@ static const struct uart_ops ulite_ops = {
454455
static void ulite_console_wait_tx(struct uart_port *port)
455456
{
456457
u8 val;
457-
unsigned long timeout;
458458

459459
/*
460460
* Spin waiting for TX fifo to have space available.
461461
* When using the Microblaze Debug Module this can take up to 1s
462462
*/
463-
timeout = jiffies + msecs_to_jiffies(1000);
464-
while (1) {
465-
val = uart_in32(ULITE_STATUS, port);
466-
if ((val & ULITE_STATUS_TXFULL) == 0)
467-
break;
468-
if (time_after(jiffies, timeout)) {
469-
dev_warn(port->dev,
470-
"timeout waiting for TX buffer empty\n");
471-
break;
472-
}
473-
cpu_relax();
474-
}
463+
if (read_poll_timeout_atomic(uart_in32, val, !(val & ULITE_STATUS_TXFULL),
464+
0, 1000000, false, ULITE_STATUS, port))
465+
dev_warn(port->dev,
466+
"timeout waiting for TX buffer empty\n");
475467
}
476468

477469
static void ulite_console_putchar(struct uart_port *port, int ch)

0 commit comments

Comments
 (0)