Re: [PATCH v4 2/5] serial: 8250: share the RX trigger conversion helper
From: Ilpo Järvinen
Date: Wed Oct 28 2026 - 04:31:08 EST
On Tue, 27 Oct 2026, James Hilliard wrote:
> Extract the receive-trigger threshold search into serial8250_bytes_to_fcr()
> so drivers with per-port threshold tables can use the same conversion as
> the generic 8250 implementation.
>
> Include the unsupported-table check in the helper and preserve the existing
> nearest-lower selection and highest-encoding fallback.
>
> Signed-off-by: James Hilliard <james.hilliard1@xxxxxxxxx>
> ---
> drivers/tty/serial/8250/8250.h | 16 ++++++++++++++++
> drivers/tty/serial/8250/8250_port.c | 12 +-----------
> 2 files changed, 17 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/tty/serial/8250/8250.h b/drivers/tty/serial/8250/8250.h
> index 21ed9c41b751..195ed58a2231 100644
> --- a/drivers/tty/serial/8250/8250.h
> +++ b/drivers/tty/serial/8250/8250.h
> @@ -8,6 +8,7 @@
> */
>
> #include <linux/bits.h>
> +#include <linux/errno.h>
> #include <linux/serial_8250.h>
> #include <linux/serial_core.h>
> #include <linux/dmaengine.h>
> @@ -73,6 +74,21 @@ struct serial8250_config {
> unsigned int flags;
> };
>
> +static inline int serial8250_bytes_to_fcr(const unsigned char *rxtrig_bytes,
This looks way to complicated to be inline function so I think it should
be kept in 8250_port and exported from there.
> + unsigned char bytes)
> +{
> + if (!rxtrig_bytes[UART_FCR_R_TRIG_BITS(UART_FCR_R_TRIG_00)])
> + return -EOPNOTSUPP;
> +
> + for (unsigned int i = 1; i < UART_FCR_R_TRIG_MAX_STATE; i++) {
> + if (bytes < rxtrig_bytes[i])
> + /* Use the nearest lower value */
> + return (i - 1) << UART_FCR_R_TRIG_SHIFT;
> + }
> +
> + return UART_FCR_R_TRIG_11;
> +}
> +
> enum uart_port_type {
> /* Internal 8250 only */
> UART_PORT_AIROHA = 124,
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index 36b2b0a2c05c..c332963dc2ed 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -3018,18 +3018,8 @@ static int fcr_get_rxtrig_bytes(struct uart_8250_port *up)
> static int bytes_to_fcr_rxtrig(struct uart_8250_port *up, unsigned char bytes)
> {
> const struct serial8250_config *conf_type = &uart_config[up->port.type];
> - int i;
>
> - if (!conf_type->rxtrig_bytes[UART_FCR_R_TRIG_BITS(UART_FCR_R_TRIG_00)])
> - return -EOPNOTSUPP;
> -
> - for (i = 1; i < UART_FCR_R_TRIG_MAX_STATE; i++) {
> - if (bytes < conf_type->rxtrig_bytes[i])
> - /* Use the nearest lower value */
> - return (--i) << UART_FCR_R_TRIG_SHIFT;
> - }
> -
> - return UART_FCR_R_TRIG_11;
> + return serial8250_bytes_to_fcr(conf_type->rxtrig_bytes, bytes);
> }
>
> static int do_get_rxtrig(struct tty_port *port)
>
>
--
i.