Linux Serial subsystem development
 help / color / mirror / Atom feed
* [PATCH v2 0/3] serial: core: add transceiver interface select GPIO
@ 2026-11-05  7:12 Tapio Reijonen
  2026-11-05  7:12 ` [PATCH v2 1/3] serial: core: Forget the RS485 GPIO descriptors when a port is removed Tapio Reijonen
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Tapio Reijonen @ 2026-11-05  7:12 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley
  Cc: linux-serial, devicetree, linux-kernel, Lukas Wunner,
	Christoph Niedermaier, Ilpo Järvinen, Lino Sanfilippo,
	Hugo Villeneuve, Tapio Reijonen

Multiprotocol transceivers such as the LTC2873 provide an RS485
interface and an alternative interface, typically RS232, on the same
bus pins and choose between them with an interface select input. Add
an optional rs485-select-gpios property next to the existing
rs485-term-gpios and rs485-rx-during-tx-gpios, and let the serial core
drive it from the RS485 configuration state, so that every UART driver
using uart_get_rs485_mode() supports such transceivers without driver
changes.

Patch 1 is new in v2 and fixes a pre-existing problem the review
found: the RS485 GPIO descriptors stored in struct uart_port were
never cleared, so a port that outlives its device, as the 8250 ports
do, kept descriptors of lines devres had already released. The select
GPIO would have made that worse, since it is driven whenever RS485 is
reconfigured, not only while RS485 is enabled.

Tested on an i.MX6SX UART and on a MAX14830 channel, each wired to an
LTC2873, by observing the bus line while switching RS485 on and off
with TIOCSRS485, across probe, unbind and rebind of both drivers.

Tool use: Claude Code (Anthropic) was used throughout. It drafted the
code and the commit messages, reviewed the series against the serial
core and the 8250 port lifetime, and prepared the v2 changes from the
review findings. I decided the design, in particular that the select
line keeps its strapped level until the port is configured, reviewed
every change against the code, and ran the hardware tests. The code
and the messages are mine to defend.

Signed-off-by: Tapio Reijonen <tapio.reijonen@vaisala.com>
---
Changes in v2:
- New patch 1: forget the RS485 GPIO descriptors when a port is
  removed, on entry to uart_get_rs485_mode() and on its error paths,
  so a port never carries descriptors of a device it no longer belongs
  to.
- Request the select GPIO without changing its state and make it an
  output at the level it already has, or inactive when that level
  cannot be read back, as on output-only GPIO controllers, so the
  transceiver keeps the interface it was strapped for until
  uart_rs485_config() has placed RTS at its RS485 idle level; forget
  the descriptor if the request fails.
- Commit message of the select patch explains the ordering of the GPIO
  against the driver callback and why the select line, unlike the
  termination and RX-during-TX lines, must not be driven at request
  time.
- Rebased onto v7.4-rc1; Rob's Reviewed-by added to the binding, which
  is unchanged.
- Link to v1: https://lore.kernel.org/r/20261021-serial-rs485-mode-gpio-v1-0-80d7b0903d93@vaisala.com

---
Tapio Reijonen (3):
      serial: core: Forget the RS485 GPIO descriptors when a port is removed
      dt-bindings: serial: rs485: Add transceiver interface select GPIO
      serial: core: Drive the transceiver interface select GPIO

 .../devicetree/bindings/serial/rs485.yaml          |  8 +++
 drivers/tty/serial/serial_core.c                   | 73 ++++++++++++++++++++--
 include/linux/serial_core.h                        |  1 +
 3 files changed, 77 insertions(+), 5 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261019-serial-rs485-mode-gpio-e76bb72b6f21

Best regards,
-- 
Tapio Reijonen <tapio.reijonen@vaisala.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-05  7:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-05  7:12 [PATCH v2 0/3] serial: core: add transceiver interface select GPIO Tapio Reijonen
2026-11-05  7:12 ` [PATCH v2 1/3] serial: core: Forget the RS485 GPIO descriptors when a port is removed Tapio Reijonen
2026-11-05  7:25   ` sashiko-bot
2026-11-05  7:12 ` [PATCH v2 2/3] dt-bindings: serial: rs485: Add transceiver interface select GPIO Tapio Reijonen
2026-11-05  7:18   ` sashiko-bot
2026-11-05  7:12 ` [PATCH v2 3/3] serial: core: Drive the " Tapio Reijonen
2026-11-05  7:26   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox