[PATCH v4 04/10] tty: serial: extract lqasc_tx_ready() from lqasc_tx_chars()

Jiri Slaby posted 10 patches 3 years, 6 months ago
There is a newer version of this series
[PATCH v4 04/10] tty: serial: extract lqasc_tx_ready() from lqasc_tx_chars()
Posted by Jiri Slaby 3 years, 6 months ago
The condition in lqasc_tx_chars()'s loop is barely readable. Extract it
to a separate function. This will make the cleanup in the next patches
easier too.

(Put it before lqasc_start_tx(), so that we can use it there later.)

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---

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

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

diff --git a/drivers/tty/serial/lantiq.c b/drivers/tty/serial/lantiq.c
index 6637b3caa6b7..6da1b7496c6c 100644
--- a/drivers/tty/serial/lantiq.c
+++ b/drivers/tty/serial/lantiq.c
@@ -139,6 +139,13 @@ lqasc_stop_tx(struct uart_port *port)
 	return;
 }
 
+static bool lqasc_tx_ready(struct uart_port *port)
+{
+	u32 fstat = __raw_readl(port->membase + LTQ_ASC_FSTAT);
+
+	return (fstat & ASCFSTAT_TXFREEMASK) >> ASCFSTAT_TXFREEOFF;
+}
+
 static void
 lqasc_start_tx(struct uart_port *port)
 {
@@ -228,8 +235,7 @@ lqasc_tx_chars(struct uart_port *port)
 		return;
 	}
 
-	while (((__raw_readl(port->membase + LTQ_ASC_FSTAT) &
-		ASCFSTAT_TXFREEMASK) >> ASCFSTAT_TXFREEOFF) != 0) {
+	while (lqasc_tx_ready(port)) {
 		if (port->x_char) {
 			writeb(port->x_char, port->membase + LTQ_ASC_TBUF);
 			port->icount.tx++;
-- 
2.37.3
Re: [PATCH v4 04/10] tty: serial: extract lqasc_tx_ready() from lqasc_tx_chars()
Posted by Ilpo Järvinen 3 years, 6 months ago
On Tue, 20 Sep 2022, Jiri Slaby wrote:

> The condition in lqasc_tx_chars()'s loop is barely readable. Extract it
> to a separate function. This will make the cleanup in the next patches
> easier too.
> 
> (Put it before lqasc_start_tx(), so that we can use it there later.)
> 
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> ---
> 
> Notes:
>     [v4] this is new in v4 -- extracted as a separate change
> 
>  drivers/tty/serial/lantiq.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/tty/serial/lantiq.c b/drivers/tty/serial/lantiq.c
> index 6637b3caa6b7..6da1b7496c6c 100644
> --- a/drivers/tty/serial/lantiq.c
> +++ b/drivers/tty/serial/lantiq.c
> @@ -139,6 +139,13 @@ lqasc_stop_tx(struct uart_port *port)
>  	return;
>  }
>  
> +static bool lqasc_tx_ready(struct uart_port *port)
> +{
> +	u32 fstat = __raw_readl(port->membase + LTQ_ASC_FSTAT);
> +
> +	return (fstat & ASCFSTAT_TXFREEMASK) >> ASCFSTAT_TXFREEOFF;

FIELD_GET(ASCFSTAT_TXFREEMASK, fstat)

> +}
> +
>  static void
>  lqasc_start_tx(struct uart_port *port)
>  {
> @@ -228,8 +235,7 @@ lqasc_tx_chars(struct uart_port *port)
>  		return;
>  	}
>  
> -	while (((__raw_readl(port->membase + LTQ_ASC_FSTAT) &
> -		ASCFSTAT_TXFREEMASK) >> ASCFSTAT_TXFREEOFF) != 0) {
> +	while (lqasc_tx_ready(port)) {
>  		if (port->x_char) {
>  			writeb(port->x_char, port->membase + LTQ_ASC_TBUF);
>  			port->icount.tx++;

There's similar construct in lqasc_console_putchar() that could take 
advantage of the same helper.

With FIELD_GET + the other place using the new helper, ASCFSTAT_TXFREEOFF 
can be dropped as well.


-- 
 i.