* [PATCH v2] serial: 8250_of: set UART_CAP_NOTEMT for ports with rts-gpios
@ 2026-12-02 11:10 Nicolas Thibert
2026-12-02 11:29 ` sashiko-bot
0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Thibert @ 2026-12-02 11:10 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby
Cc: linux-serial, linux-kernel, Heiko Schocher, stable
Since commit 0c11b88883db ("tty: 8250_of: Use software emulated RS485
direction control"), 8250_of uses the software RS485 emulation (em485).
At the end of a transmission, em485 releases the direction line only
once the transmitter is empty (TEMT). A 16550 has no interrupt on TEMT,
so when the last THRE interrupt comes before the shift register is
empty, __stop_tx() returns and nothing releases the direction line
later: it stays asserted and the board cannot receive the answer from
the other RS485 node.
8250_dw solves the same problem by setting UART_CAP_NOTEMT, which makes
__stop_tx() release the line one frame time later instead. Do the same
in 8250_of for ports whose direction line is a GPIO (rts-gpios).
UART_CAP_NOTEMT is only used by the em485 stop path, so ports without
RS485 are not affected.
Tested on a QCA9531 board (ns16550a UART) with a CA-IS2092A RS485
transceiver whose DE/RE pins are driven by a GPIO (rts-gpios,
linux,rs485-enabled-at-boot-time). Without this patch the GPIO stays
high after the first transmission and no answer is received. With it,
the GPIO goes low after each transmission and the answers are
received.
The problem was analysed and this patch written with the help of an AI
coding assistant (Claude, Anthropic); the tests were run on hardware.
Fixes: 0c11b88883db ("tty: 8250_of: Use software emulated RS485 direction control")
Cc: stable@vger.kernel.org
Signed-off-by: Nicolas Thibert <nithibert@gmail.com>
---
v2:
- Rewrite the commit message.
- Drop the code comment.
- Put Signed-off-by last.
Answers to the review of v1:
- What changes on existing systems: UART_CAP_NOTEMT is only checked in
the em485 stop path, so only RS485 ports whose direction line is a
GPIO are affected. If the transmitter is already empty at the last
THRE interrupt, nothing changes. Otherwise the direction line is now
released one frame time later, instead of staying asserted.
- How it was tested: see the last paragraph of the commit message.
- v1 was sent twice by mistake, first with a mail client, then with
git send-email.
drivers/tty/serial/8250/8250_of.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/tty/serial/8250/8250_of.c b/drivers/tty/serial/8250/8250_of.c
index b41ca604083f..b58535f73cb8 100644
--- a/drivers/tty/serial/8250/8250_of.c
+++ b/drivers/tty/serial/8250/8250_of.c
@@ -292,6 +292,9 @@ static int of_platform_serial_probe(struct platform_device *ofdev)
&port8250.overrun_backoff_time_ms) != 0)
port8250.overrun_backoff_time_ms = 0;
+ if (of_property_present(ofdev->dev.of_node, "rts-gpios"))
+ port8250.capabilities |= UART_CAP_NOTEMT;
+
info->uport = serial8250_register_8250_port(&port8250);
if (IS_ERR(info->uport)) {
ret = PTR_ERR(info->uport);
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] serial: 8250_of: set UART_CAP_NOTEMT for ports with rts-gpios
2026-12-02 11:10 [PATCH v2] serial: 8250_of: set UART_CAP_NOTEMT for ports with rts-gpios Nicolas Thibert
@ 2026-12-02 11:29 ` sashiko-bot
2026-12-02 11:37 ` Nicolas Thibert
0 siblings, 1 reply; 3+ messages in thread
From: sashiko-bot @ 2026-12-02 11:29 UTC (permalink / raw)
To: Nicolas Thibert; +Cc: linux-serial
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] serial: 8250_of: setting UART_CAP_NOTEMT skips uart_config
default flags
- [Medium] serial: 8250_of: gating UART_CAP_NOTEMT on rts-gpios misses
native RTS em485
--
commit 3ce247ebc56619daf138861af9c248e9f1ac7b45
Author: Nicolas Thibert <nithibert@gmail.com>
serial: 8250_of: set UART_CAP_NOTEMT for ports with rts-gpios
This commit sets UART_CAP_NOTEMT on 8250_of ports when the rts-gpios
Device Tree property is present so that software-emulated RS485 direction
control releases the direction line after transmission completes.
> diff --git a/drivers/tty/serial/8250/8250_of.c b/drivers/tty/serial/8250/8250_of.c
> index b41ca604083f6..b58535f73cb88 100644
> --- a/drivers/tty/serial/8250/8250_of.c
> +++ b/drivers/tty/serial/8250/8250_of.c
> @@ -292,6 +292,9 @@ static int of_platform_serial_probe(struct platform_device *ofdev)
> &port8250.overrun_backoff_time_ms) != 0)
> port8250.overrun_backoff_time_ms = 0;
>
> + if (of_property_present(ofdev->dev.of_node, "rts-gpios"))
> + port8250.capabilities |= UART_CAP_NOTEMT;
> +
> info->uport = serial8250_register_8250_port(&port8250);
> if (IS_ERR(info->uport)) {
> ret = PTR_ERR(info->uport);
[Severity: High]
Does setting UART_CAP_NOTEMT here drop UART_CAP_FIFO and the rest of
uart_config[type].flags when the Device Tree node omits the optional
fifo-size property?
Earlier in of_platform_serial_probe(), UART_CAP_FIFO is only set if
port8250.port.fifosize is already non-zero. When fifo-size is not in
Device Tree, fifosize and capabilities are still 0 here, and
serial8250_register_8250_port() -> serial8250_set_defaults() only loads
the per-type default flags when capabilities is 0:
drivers/tty/serial/8250/8250_port.c:serial8250_set_defaults() {
...
if (!up->capabilities)
up->capabilities = uart_config[type].flags;
...
}
Because capabilities is now UART_CAP_NOTEMT, uart_config[type].flags is
skipped. Without UART_CAP_FIFO, serial8250_clear_fifos() becomes a no-op
(including during serial8250_em485_stop_tx()) and console writes fall back
from FIFO bursts to single-byte polling.
[Severity: Medium]
Should UART_CAP_NOTEMT also be set for RS485 ports that drive the
transceiver direction pin with the UART's native RTS signal instead of
rts-gpios?
of_platform_serial_setup() enables software-emulated RS485
(serial8250_em485_config) for all 8250_of ports, and serial8250_out_MCR()
toggles UART_MCR_RTS as well as any rts-gpios. Gating UART_CAP_NOTEMT on
rts-gpios leaves native-RTS RS485 ports with the same bug where
__stop_tx() returns early when UART_LSR_TEMT is not yet set and never
deasserts RTS.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202111032.981532-1-nithibert@gmail.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] serial: 8250_of: set UART_CAP_NOTEMT for ports with rts-gpios
2026-12-02 11:29 ` sashiko-bot
@ 2026-12-02 11:37 ` Nicolas Thibert
0 siblings, 0 replies; 3+ messages in thread
From: Nicolas Thibert @ 2026-12-02 11:37 UTC (permalink / raw)
To: sashiko-reviews; +Cc: linux-serial
> - [High] serial: 8250_of: setting UART_CAP_NOTEMT skips uart_config
> default flags
> - [Medium] serial: 8250_of: gating UART_CAP_NOTEMT on rts-gpios misses
> native RTS em485
Thanks, both points are right: setting the capability before
registration drops UART_CAP_FIFO when there is no fifo-size property,
and em485 also drives the native RTS. I will send a v3 that sets
UART_CAP_NOTEMT after serial8250_register_8250_port() for all ports.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-02 11:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 11:10 [PATCH v2] serial: 8250_of: set UART_CAP_NOTEMT for ports with rts-gpios Nicolas Thibert
2026-12-02 11:29 ` sashiko-bot
2026-12-02 11:37 ` Nicolas Thibert
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox