[PATCH 19/33] serial: 8250: extract serial8250_set_trigger_for_slow_speed()

Jiri Slaby (SUSE) posted 33 patches 4 months ago
[PATCH 19/33] serial: 8250: extract serial8250_set_trigger_for_slow_speed()
Posted by Jiri Slaby (SUSE) 4 months ago
serial8250_do_set_termios() consists of many registers and up flags
settings. Extract all these into separate functions. This time, setting
of trigger level for slow speeds.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_port.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index edfbaa6b7a1b..52385314c426 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -2686,6 +2686,24 @@ static void serial8250_set_mini(struct uart_port *port, struct ktermios *termios
 	}
 }
 
+static void serial8250_set_trigger_for_slow_speed(struct uart_port *port, struct ktermios *termios,
+						  unsigned int baud)
+{
+	struct uart_8250_port *up = up_to_u8250p(port);
+
+	if (!(up->capabilities & UART_CAP_FIFO))
+		return;
+	if (port->fifosize <= 1)
+		return;
+	if (baud >= 2400)
+		return;
+	if (up->dma)
+		return;
+
+	up->fcr &= ~UART_FCR_TRIGGER_MASK;
+	up->fcr |= UART_FCR_TRIGGER_1;
+}
+
 void
 serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
 		          const struct ktermios *old)
@@ -2710,13 +2728,7 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
 	uart_port_lock_irqsave(port, &flags);
 
 	up->lcr = cval;					/* Save computed LCR */
-
-	if (up->capabilities & UART_CAP_FIFO && port->fifosize > 1) {
-		if (baud < 2400 && !up->dma) {
-			up->fcr &= ~UART_FCR_TRIGGER_MASK;
-			up->fcr |= UART_FCR_TRIGGER_1;
-		}
-	}
+	serial8250_set_trigger_for_slow_speed(port, termios, baud);
 
 	/*
 	 * MCR-based auto flow control.  When AFE is enabled, RTS will be
-- 
2.49.0
Re: [PATCH 19/33] serial: 8250: extract serial8250_set_trigger_for_slow_speed()
Posted by Ilpo Järvinen 4 months ago
On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:

> serial8250_do_set_termios() consists of many registers and up flags
> settings. Extract all these into separate functions. This time, setting
> of trigger level for slow speeds.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> ---
>  drivers/tty/serial/8250/8250_port.c | 26 +++++++++++++++++++-------
>  1 file changed, 19 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index edfbaa6b7a1b..52385314c426 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -2686,6 +2686,24 @@ static void serial8250_set_mini(struct uart_port *port, struct ktermios *termios
>  	}
>  }
>  
> +static void serial8250_set_trigger_for_slow_speed(struct uart_port *port, struct ktermios *termios,
> +						  unsigned int baud)
> +{
> +	struct uart_8250_port *up = up_to_u8250p(port);
> +
> +	if (!(up->capabilities & UART_CAP_FIFO))
> +		return;
> +	if (port->fifosize <= 1)
> +		return;
> +	if (baud >= 2400)
> +		return;
> +	if (up->dma)

Nit, I'd have put the DMA check before the speed check.

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

> +		return;
> +
> +	up->fcr &= ~UART_FCR_TRIGGER_MASK;
> +	up->fcr |= UART_FCR_TRIGGER_1;
> +}
> +
>  void
>  serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
>  		          const struct ktermios *old)
> @@ -2710,13 +2728,7 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
>  	uart_port_lock_irqsave(port, &flags);
>  
>  	up->lcr = cval;					/* Save computed LCR */
> -
> -	if (up->capabilities & UART_CAP_FIFO && port->fifosize > 1) {
> -		if (baud < 2400 && !up->dma) {
> -			up->fcr &= ~UART_FCR_TRIGGER_MASK;
> -			up->fcr |= UART_FCR_TRIGGER_1;
> -		}
> -	}
> +	serial8250_set_trigger_for_slow_speed(port, termios, baud);
>  
>  	/*
>  	 * MCR-based auto flow control.  When AFE is enabled, RTS will be
> 

-- 
 i.