From: Tapio Reijonen <tapio.reijonen@vaisala.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Markus Probst <markus.probst@posteo.de>
Cc: linux-serial@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, "Lukas Wunner" <lukas@wunner.de>,
"Christoph Niedermaier" <cniedermaier@dh-electronics.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Lino Sanfilippo" <l.sanfilippo@kunbus.com>,
"Hugo Villeneuve" <hvilleneuve@dimonoff.com>,
"Tapio Reijonen" <tapio.reijonen@vaisala.com>
Subject: [PATCH 7/7] serial: max310x: Three-state TX and RTS while the port is closed
Date: Wed, 11 Nov 2026 12:28:06 +0000 [thread overview]
Message-ID: <20261111-serial-transceiver-supply-v1-7-40bad0f912f2@vaisala.com> (raw)
In-Reply-To: <20261111-serial-transceiver-supply-v1-0-40bad0f912f2@vaisala.com>
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@vaisala.com>
---
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
prev parent reply other threads:[~2026-11-11 12:28 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 12:27 [PATCH 0/7] serial: core: Power the line transceiver with the port Tapio Reijonen
2026-11-11 12:28 ` [PATCH 1/7] serial: max310x: Look up all channels before adding any port Tapio Reijonen
2026-11-11 12:28 ` [PATCH 2/7] dt-bindings: serial: Add the line transceiver enable GPIO Tapio Reijonen
2026-11-23 8:03 ` Krzysztof Kozlowski
2026-11-23 8:08 ` Krzysztof Kozlowski
2026-11-11 12:28 ` [PATCH 3/7] dt-bindings: serial: sc16is7xx: Disallow transceiver GPIO on dual parts Tapio Reijonen
2026-11-23 8:00 ` Krzysztof Kozlowski
2026-11-11 12:28 ` [PATCH 4/7] serial: core: Power the line transceiver with the port Tapio Reijonen
2026-11-11 12:28 ` [PATCH 5/7] serial: max310x: Request the line transceiver per port Tapio Reijonen
2026-11-11 12:28 ` [PATCH 6/7] dt-bindings: serial: max310x: Add maxim,tristate-when-closed Tapio Reijonen
2026-11-23 8:05 ` Krzysztof Kozlowski
2026-11-11 12:28 ` Tapio Reijonen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261111-serial-transceiver-supply-v1-7-40bad0f912f2@vaisala.com \
--to=tapio.reijonen@vaisala.com \
--cc=cniedermaier@dh-electronics.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=hvilleneuve@dimonoff.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jirislaby@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=l.sanfilippo@kunbus.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=markus.probst@posteo.de \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®