[PATCH v2 2/2] serial: 8250_mid: wait for LSR tx empty before setting termios

From: Tate Whiteberg

Date: Fri Aug 28 2026 - 13:59:32 EST


If mid8250_set_termios() is called while data is still in transmission,
the corresponding register updates will corrupt the transmission.

Fix this by locking the port and and waiting for the transmitter to
empty before performing updates. It is necessary to wait for both
UART_LSR_THRE and UART_LSR_TEMT to ensure the final character is sent.

Fixes: d9eda9bab237 ("serial: 8250_pci: Intel MID UART support to its own driver")
Signed-off-by: Tate Whiteberg <whiteberg@xxxxxxxxxx>
---
Changes in v2:
- Separate changes to 8250.h and 8250_port.c into prerequisite patch,
as recommended by andriy.shevchenko@xxxxxxxxx
- Apply feedback from andriy.shevchenko@xxxxxxxxx to 8250_mid.c

drivers/tty/serial/8250/8250_mid.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/drivers/tty/serial/8250/8250_mid.c b/drivers/tty/serial/8250/8250_mid.c
index 82656645b8a6..ce792888acfe 100644
--- a/drivers/tty/serial/8250/8250_mid.c
+++ b/drivers/tty/serial/8250/8250_mid.c
@@ -209,6 +209,7 @@ static void mid8250_set_termios(struct uart_port *p, struct ktermios *termios,
const struct ktermios *old)
{
unsigned int baud = tty_termios_baud_rate(termios);
+ struct uart_8250_port *up = up_to_u8250p(p);
struct mid8250 *mid = p->private_data;
unsigned short ps = 16;
unsigned long fuart = baud * ps;
@@ -231,12 +232,18 @@ static void mid8250_set_termios(struct uart_port *p, struct ktermios *termios,
}

rational_best_approximation(fuart, mid->board->freq, w, w, &mul, &div);
+
+ uart_port_lock_irq(p);
+
p->uartclk = fuart * 16 / ps; /* core uses ps = 16 always */
+ serial8250_wait_for_xmitr(up, UART_LSR_BOTH_EMPTY);

writel(ps, p->membase + INTEL_MID_UART_PS); /* set PS */
writel(mul, p->membase + INTEL_MID_UART_MUL); /* set MUL */
writel(div, p->membase + INTEL_MID_UART_DIV);

+ uart_port_unlock_irq(p);
+
serial8250_do_set_termios(p, termios, old);
}

--
2.43.0