[PATCH v2 1/4] MIPS: SiByte: Fix console message clobbering at channel resets

From: Maciej W. Rozycki

Date: Mon Apr 13 2026 - 00:04:04 EST


Ensure any characters outstanding have been sent before issuing channel
resets so as to prevent messages issued to the bootconsole from getting
clobbered.

Contrary to device documentation at the time the transmitter empty bit
is set only the transmit FIFO has been drained and there is still data
outstanding in the transmitter shift register, so wait an extra amount
of time for that register to drain too. This also prevents subsequent
messages produced to the console from getting clobbered, owing to what
seems a transmitter synchronisation issue.

When called from sbd_serial_console_init() it is too early for fsleep()
to work and even before lpj has been calculated and therefore the delay
is actually not sufficient for the transmitter to drain and is merely a
placeholder now. This will be addressed in a follow-up change.

Fixes: 84a9582fd203 ("serial: core: Start managing serial controllers to enable runtime PM")
Signed-off-by: Maciej W. Rozycki <macro@xxxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx # v6.5+
---
No change from v1.
---
drivers/tty/serial/sb1250-duart.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)

linux-serial-sb1250-duart-reset-drain.diff
Index: linux-macro/drivers/tty/serial/sb1250-duart.c
===================================================================
--- linux-macro.orig/drivers/tty/serial/sb1250-duart.c
+++ linux-macro/drivers/tty/serial/sb1250-duart.c
@@ -516,6 +516,28 @@ static void sbd_init_port(struct sbd_por

if (sport->initialised)
return;
+ /*
+ * Contrary to documentation, which says that the transmitter
+ * empty bit is set when "there are no characters to send and
+ * the transmitter is idle," the bit is already set by hardware
+ * once the transmit FIFO has been drained only and while the
+ * transmitter shift register still holds data being supplied
+ * to the line. Consequently issuing a transmitter reset at
+ * this point causes the final character outstanding to be lost.
+ *
+ * Moreover, resetting the transmitter while transmission is
+ * in progress appears to make the transmitter go out of sync
+ * and subsequent characters issued after the transmitter has
+ * been reprogrammed and re-enabled are sent corrupted or with
+ * their bit patterns shifted.
+ *
+ * So once the transmitter empty bit has been set wait an extra
+ * amount of time, sufficient for the transmitter shift register
+ * to drain at 115200bps, which is the baud rate setting used by
+ * a standard CFE firmware compilation.
+ */
+ sbd_line_drain(sport);
+ udelay(100);

/* There is no DUART reset feature, so just set some sane defaults. */
write_sbdchn(sport, R_DUART_CMD, V_DUART_MISC_CMD_RESET_TX);