All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tty: serial: uartlite: Use read_poll_timeout for a polling loop
@ 2021-07-23 21:52 Sean Anderson
  2021-07-23 21:55 ` Sean Anderson
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Sean Anderson @ 2021-07-23 21:52 UTC (permalink / raw)
  To: linux-serial, Peter Korsgaard
  Cc: Michal Simek, Greg Kroah-Hartman, Sean Anderson

This uses read_poll_timeout_atomic to spin while waiting on uart_in32.

Signed-off-by: Sean Anderson <sean.anderson@seco.com>
---

 drivers/tty/serial/uartlite.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/drivers/tty/serial/uartlite.c b/drivers/tty/serial/uartlite.c
index f42ccc40ffa6..106bbbc86c87 100644
--- a/drivers/tty/serial/uartlite.c
+++ b/drivers/tty/serial/uartlite.c
@@ -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>
@@ -448,24 +449,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)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] tty: serial: uartlite: Use read_poll_timeout for a polling loop
  2021-07-23 21:52 [PATCH] tty: serial: uartlite: Use read_poll_timeout for a polling loop Sean Anderson
@ 2021-07-23 21:55 ` Sean Anderson
  2021-07-26 14:19 ` Michal Simek
  2021-07-29 14:59 ` Greg Kroah-Hartman
  2 siblings, 0 replies; 5+ messages in thread
From: Sean Anderson @ 2021-07-23 21:55 UTC (permalink / raw)
  To: linux-serial, Peter Korsgaard
  Cc: Michal Simek, Greg Kroah-Hartman, Peter Korsgaard, Peter Korsgaard

Looks like Peter's email bounces.

+CC the other emails of "Peter Korsgaard" in MAINTAINERS

On 7/23/21 5:52 PM, Sean Anderson wrote:
> This uses read_poll_timeout_atomic to spin while waiting on uart_in32.
> 
> Signed-off-by: Sean Anderson <sean.anderson@seco.com>
> ---
> 
>   drivers/tty/serial/uartlite.c | 18 +++++-------------
>   1 file changed, 5 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/tty/serial/uartlite.c b/drivers/tty/serial/uartlite.c
> index f42ccc40ffa6..106bbbc86c87 100644
> --- a/drivers/tty/serial/uartlite.c
> +++ b/drivers/tty/serial/uartlite.c
> @@ -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>
> @@ -448,24 +449,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)
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tty: serial: uartlite: Use read_poll_timeout for a polling loop
  2021-07-23 21:52 [PATCH] tty: serial: uartlite: Use read_poll_timeout for a polling loop Sean Anderson
  2021-07-23 21:55 ` Sean Anderson
@ 2021-07-26 14:19 ` Michal Simek
  2021-07-29 14:59 ` Greg Kroah-Hartman
  2 siblings, 0 replies; 5+ messages in thread
From: Michal Simek @ 2021-07-26 14:19 UTC (permalink / raw)
  To: Sean Anderson, linux-serial, Peter Korsgaard, Shubhrajyoti Datta
  Cc: Michal Simek, Greg Kroah-Hartman

+Shubhrajyoti

On 7/23/21 11:52 PM, Sean Anderson wrote:
> This uses read_poll_timeout_atomic to spin while waiting on uart_in32.
> 
> Signed-off-by: Sean Anderson <sean.anderson@seco.com>
> ---
> 
>  drivers/tty/serial/uartlite.c | 18 +++++-------------
>  1 file changed, 5 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/tty/serial/uartlite.c b/drivers/tty/serial/uartlite.c
> index f42ccc40ffa6..106bbbc86c87 100644
> --- a/drivers/tty/serial/uartlite.c
> +++ b/drivers/tty/serial/uartlite.c
> @@ -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>
> @@ -448,24 +449,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)
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tty: serial: uartlite: Use read_poll_timeout for a polling loop
  2021-07-23 21:52 [PATCH] tty: serial: uartlite: Use read_poll_timeout for a polling loop Sean Anderson
  2021-07-23 21:55 ` Sean Anderson
  2021-07-26 14:19 ` Michal Simek
@ 2021-07-29 14:59 ` Greg Kroah-Hartman
  2021-07-29 15:31   ` Sean Anderson
  2 siblings, 1 reply; 5+ messages in thread
From: Greg Kroah-Hartman @ 2021-07-29 14:59 UTC (permalink / raw)
  To: Sean Anderson; +Cc: linux-serial, Peter Korsgaard, Michal Simek

On Fri, Jul 23, 2021 at 05:52:20PM -0400, Sean Anderson wrote:
> This uses read_poll_timeout_atomic to spin while waiting on uart_in32.

That says what you are doing, but nothing about _why_ you are making
this change.  Please fix up.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tty: serial: uartlite: Use read_poll_timeout for a polling loop
  2021-07-29 14:59 ` Greg Kroah-Hartman
@ 2021-07-29 15:31   ` Sean Anderson
  0 siblings, 0 replies; 5+ messages in thread
From: Sean Anderson @ 2021-07-29 15:31 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-serial, Peter Korsgaard, Michal Simek



On 7/29/21 10:59 AM, Greg Kroah-Hartman wrote:
> On Fri, Jul 23, 2021 at 05:52:20PM -0400, Sean Anderson wrote:
>> This uses read_poll_timeout_atomic to spin while waiting on uart_in32.
>
> That says what you are doing, but nothing about _why_ you are making
> this change.  Please fix up.

Ok, how about

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-07-29 15:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-23 21:52 [PATCH] tty: serial: uartlite: Use read_poll_timeout for a polling loop Sean Anderson
2021-07-23 21:55 ` Sean Anderson
2021-07-26 14:19 ` Michal Simek
2021-07-29 14:59 ` Greg Kroah-Hartman
2021-07-29 15:31   ` Sean Anderson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.