[PATCH 14/15] serial: 8250: allow UART drivers to override rx_trig_bytes handling

From: Crescent Hsieh

Date: Mon May 04 2026 - 04:53:34 EST


The rx_trig_bytes sysfs attribute currently relies on 8250-internal
helper functions and assumes a fixed mapping between trigger levels and
FIFO behavior.

Some UARTs provide hardware-specific RX trigger mechanisms that do not
fit this model. Add optional uart_port callbacks for setting and getting
the RX trigger level, and use them when provided, while preserving the
existing 8250 helpers as the default fallback.

Signed-off-by: Crescent Hsieh <crescentcy.hsieh@xxxxxxxx>
---
drivers/tty/serial/8250/8250_core.c | 4 ++++
drivers/tty/serial/8250/8250_port.c | 14 ++++++++++++--
include/linux/serial_core.h | 2 ++
3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
index 0a3355eb4bc3..a0a53b642d6c 100644
--- a/drivers/tty/serial/8250/8250_core.c
+++ b/drivers/tty/serial/8250/8250_core.c
@@ -802,6 +802,10 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
uart->port.pm = up->port.pm;
if (up->port.handle_break)
uart->port.handle_break = up->port.handle_break;
+ if (up->port.set_rxtrig)
+ uart->port.set_rxtrig = up->port.set_rxtrig;
+ if (up->port.get_rxtrig)
+ uart->port.get_rxtrig = up->port.get_rxtrig;
if (up->dl_read)
uart->dl_read = up->dl_read;
if (up->dl_write)
diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 72ecc0112b8a..2ece8af5d149 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -2999,9 +2999,14 @@ static ssize_t rx_trig_bytes_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct tty_port *port = dev_get_drvdata(dev);
+ struct uart_state *state = container_of(port, struct uart_state, port);
+ struct uart_port *uport = state->uart_port;
int rxtrig_bytes;

- rxtrig_bytes = do_serial8250_get_rxtrig(port);
+ if (uport->get_rxtrig)
+ rxtrig_bytes = uport->get_rxtrig(uport);
+ else
+ rxtrig_bytes = do_serial8250_get_rxtrig(port);
if (rxtrig_bytes < 0)
return rxtrig_bytes;

@@ -3044,6 +3049,8 @@ static ssize_t rx_trig_bytes_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
struct tty_port *port = dev_get_drvdata(dev);
+ struct uart_state *state = container_of(port, struct uart_state, port);
+ struct uart_port *uport = state->uart_port;
unsigned char bytes;
int ret;

@@ -3054,7 +3061,10 @@ static ssize_t rx_trig_bytes_store(struct device *dev,
if (ret < 0)
return ret;

- ret = do_serial8250_set_rxtrig(port, bytes);
+ if (uport->set_rxtrig)
+ ret = uport->set_rxtrig(uport, bytes);
+ else
+ ret = do_serial8250_set_rxtrig(port, bytes);
if (ret < 0)
return ret;

diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index d9e5e3d02003..bba6223d7b12 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -468,6 +468,8 @@ struct uart_port {
void (*pm)(struct uart_port *, unsigned int state,
unsigned int old);
void (*handle_break)(struct uart_port *);
+ int (*set_rxtrig)(struct uart_port *port, unsigned char bytes);
+ int (*get_rxtrig)(struct uart_port *port);
int (*rs485_config)(struct uart_port *,
struct ktermios *termios,
struct serial_rs485 *rs485);
--
2.43.0