* [PATCH] serial: 8250_dwlib: Restore NOTEMT for em485
@ 2026-11-21 6:35 Fuyao Kashizuku
2026-11-21 6:42 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Fuyao Kashizuku @ 2026-11-21 6:35 UTC (permalink / raw)
To: Ilpo Järvinen, linux-serial
Cc: Andy Shevchenko, Greg Kroah-Hartman, Jiri Slaby, linux-kernel
From: Fuyao Kashizuku <fuyao@sjterm.com>
A DesignWare UART using software RS485 can transmit one byte and then
leave the next write queued indefinitely.
dw8250_setup_port() sets UART_CAP_NOTEMT because the UART does not
interrupt when the shift register becomes empty. If neither hardware
nor platform data supplies a component parameter register (CPR) value,
the driver leaves UPF_FIXED_TYPE clear. When autoconfig() identifies
a 16550A, it replaces the capabilities with the type defaults and drops
UART_CAP_NOTEMT.
If the TX FIFO empties while the shift register is still busy, __stop_tx()
then returns without arming the stop timer or clearing THRI. With no
further interrupt when the last bit leaves the wire, em485 can stay in
transmit mode and a subsequent write can remain queued.
Restore UART_CAP_NOTEMT in the DW software RS485 configuration callback.
This lets the existing em485 timer finish the transmission and release
RTS after the last character.
Fixes: 5ff33917faca ("serial: 8250_dwlib: Implement SW half duplex support")
Assisted-by: Codex:gpt-6
Signed-off-by: Fuyao Kashizuku <fuyao@sjterm.com>
---
Tested on UART1 of an Allwinner T113 board running a 6.12.60-based BSP.
The board uses a GPIO for direction. The BSP forces the DW software RS485
path for this wiring. Both runs used 115200 baud and a 1 ms RTS delay
before and after transmission.
Two one-byte writes ('V', then '7' about 300 ms later) each returned 1.
Before the fix the peer received only 'V', the TX counter stayed at 1,
and TIOCOUTQ still reported 1. With the fix the peer received 'V7',
TIOCOUTQ returned 0, and the board received the peer's six-byte reply.
The change was built and run on the BSP. It was checked for clean
application to the mainline base below.
Codex assisted with diagnosis, the code change and the test runs.
drivers/tty/serial/8250/8250_dwlib.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/drivers/tty/serial/8250/8250_dwlib.c b/drivers/tty/serial/8250/8250_dwlib.c
index 9bb02a4ab11f..5a6ba9e921b0 100644
--- a/drivers/tty/serial/8250/8250_dwlib.c
+++ b/drivers/tty/serial/8250/8250_dwlib.c
@@ -170,6 +170,21 @@ static int dw8250_rs485_config(struct uart_port *p, struct ktermios *termios,
return 0;
}
+static int dw8250_em485_config(struct uart_port *p, struct ktermios *termios,
+ struct serial_rs485 *rs485)
+{
+
+ struct uart_8250_port *up = up_to_u8250p(p);
+
+ /*
+ * Without CPR, 8250 autoconfiguration can overwrite capabilities.
+ * Restore NOTEMT before enabling emulation: DW has no TEMT interrupt.
+ */
+ up->capabilities |= UART_CAP_NOTEMT;
+
+ return serial8250_em485_config(p, termios, rs485);
+}
+
/*
* Tests if RE_EN register can have non-zero value to see if RS-485 HW support
* is present.
@@ -202,7 +217,7 @@ void dw8250_setup_port(struct uart_port *p)
up->lsr_save_mask = LSR_SAVE_FLAGS | DW_UART_LSR_ADDR_RCVD;
p->rs485_supported = dw8250_rs485_supported;
} else {
- p->rs485_config = serial8250_em485_config;
+ p->rs485_config = dw8250_em485_config;
p->rs485_supported = serial8250_em485_supported;
up->rs485_start_tx = serial8250_em485_start_tx;
up->rs485_stop_tx = serial8250_em485_stop_tx;
base-commit: c44104f3642da720164042623e4832836aefdd8e
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] serial: 8250_dwlib: Restore NOTEMT for em485
2026-11-21 6:35 [PATCH] serial: 8250_dwlib: Restore NOTEMT for em485 Fuyao Kashizuku
@ 2026-11-21 6:42 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-21 6:42 UTC (permalink / raw)
To: Fuyao Kashizuku, linux-serial
> From: Fuyao Kashizuku <fuyao@sjterm.com>
>
> A DesignWare UART using software RS485 can transmit one byte and then
> leave the next write queued indefinitely.
>
> dw8250_setup_port() sets UART_CAP_NOTEMT because the UART does not
> interrupt when the shift register becomes empty. If neither hardware
> nor platform data supplies a component parameter register (CPR) value,
> the driver leaves UPF_FIXED_TYPE clear. When autoconfig() identifies
> a 16550A, it replaces the capabilities with the type defaults and drops
> UART_CAP_NOTEMT.
>
> If the TX FIFO empties while the shift register is still busy, __stop_tx()
> then returns without arming the stop timer or clearing THRI. With no
> further interrupt when the last bit leaves the wire, em485 can stay in
> transmit mode and a subsequent write can remain queued.
>
> Restore UART_CAP_NOTEMT in the DW software RS485 configuration callback.
> This lets the existing em485 timer finish the transmission and release
> RTS after the last character.
>
> Fixes: 5ff33917faca ("serial: 8250_dwlib: Implement SW half duplex support")
> Assisted-by: Codex:gpt-6
> Signed-off-by: Fuyao Kashizuku <fuyao@sjterm.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/awE7o4z1DMGb-YMg@debian.cyg?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-21 6:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-21 6:35 [PATCH] serial: 8250_dwlib: Restore NOTEMT for em485 Fuyao Kashizuku
2026-11-21 6:42 ` sashiko-bot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.