[PATCH 7/7] serial: max310x: Three-state TX and RTS while the port is closed
From: Tapio Reijonen
Date: Wed Nov 11 2026 - 07:29:43 EST
Implement maxim,tristate-when-closed: keep TX and RTS undriven while
the port is closed, so that they do not back-feed an unpowered part
behind them.
The MODE1 register can three-state both pins. Do so on a channel with
the flag at probe time, before the port is registered, and as the last
thing in shutdown(); drive the pins again as the first thing in
startup(). What the part's inputs do while undriven is up to the part
and the board. The pins are driven from chip reset until this driver's
probe reaches each channel, after the MODE1 reset write, the clock
setup and the gpiochip registration.
Channels without the flag are left alone.
Signed-off-by: Tapio Reijonen <tapio.reijonen@xxxxxxxxxxx>
---
drivers/tty/serial/max310x.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
index 876bdd1f5496dcf46fdc790a89892342fd85a9e4..d5884c870d8e082ea99486cb0d2bf906815e98b2 100644
--- a/drivers/tty/serial/max310x.c
+++ b/drivers/tty/serial/max310x.c
@@ -315,6 +315,7 @@ struct max310x_one {
unsigned int char_time_us;
unsigned int baud;
bool sw_rts_during_tx;
+ bool tristate_when_closed;
bool cancel_tx_delay_tmr;
bool tx_teardown; /* envelope being torn down */
bool rs485_pending; /* rs_work not yet applied */
@@ -433,6 +434,20 @@ static void max310x_power(struct uart_port *port, int on)
msleep(50);
}
+/*
+ * Three-state TX and RTS while the port is closed, on channels that ask
+ * for it: a driven pin would back-feed an unpowered part behind it.
+ */
+static void max310x_set_tristate(struct uart_port *port, bool tristate)
+{
+ unsigned int mask = MAX310X_MODE1_TXHIZ_BIT | MAX310X_MODE1_RTSHIZ_BIT;
+
+ if (!to_max310x_port(port)->tristate_when_closed)
+ return;
+
+ max310x_port_update(port, MAX310X_MODE1_REG, mask, tristate ? mask : 0);
+}
+
static const struct max310x_devtype max3107_devtype = {
.name = "MAX3107",
.nr = 1,
@@ -1542,6 +1557,7 @@ static int max310x_startup(struct uart_port *port)
struct max310x_one *one = to_max310x_port(port);
unsigned int val;
+ max310x_set_tristate(port, false);
max310x_power(port, 1);
/*
@@ -1685,6 +1701,7 @@ static void max310x_shutdown(struct uart_port *port)
fsleep(max(one->char_time_us / 10, 100U));
}
+ max310x_set_tristate(port, true);
max310x_power(port, 0);
}
@@ -2042,6 +2059,9 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty
ret = uart_get_rs485_mode(&s->p[i].port);
if (!ret)
ret = uart_get_transceiver(&s->p[i].port);
+ s->p[i].tristate_when_closed =
+ device_property_read_bool(dev,
+ "maxim,tristate-when-closed");
device_set_node(dev, saved_fwnode);
of_node_put(port_np);
if (ret)
@@ -2050,6 +2070,9 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty
ret = uart_get_rs485_mode(&s->p[i].port);
if (!ret)
ret = uart_get_transceiver(&s->p[i].port);
+ s->p[i].tristate_when_closed =
+ device_property_read_bool(dev,
+ "maxim,tristate-when-closed");
if (ret)
goto out_clk;
}
@@ -2065,6 +2088,9 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty
}
s->p[i].port.line = line;
+ /* Pins float until the first open */
+ max310x_set_tristate(&s->p[i].port, true);
+
/* Register port */
ret = uart_add_one_port(&max310x_uart, &s->p[i].port);
if (ret)
--
2.47.3