[PATCH RFC v2] serial: esp32: Rearm TX interrupts when the FIFO is full

Vítor Hugo Silva vitorhg20080 at gmail.com
Fri Nov 27 07:56:23 PST 2026


When transmission starts with a full FIFO, queued data can be left
waiting with the TX interrupt disabled. Keep the TX FIFO empty
interrupt enabled while a high-priority character is pending or while
transmission can progress on queued data.

Use UART_TX_NOSTOP so the driver controls TX interrupt masking. If a
deferred x_char is sent while normal transmission is stopped, mask the
TX interrupt and leave the queued data for the next start_tx() call.
This prevents repeated TX interrupts while the queue is stopped.

Hold the port lock in the TX interrupt handler as required by the
serial core TX helpers.

A mocked FIFO test verified the deferred x_char case, IRQ masking and
TX restart. Normal serial console operation was tested on the
Waveshare ESP32-P4-Module-DEV-KIT.

AI assisted with driver development.

Signed-off-by: Vítor Hugo Silva <vitorhg20080 at gmail.com>
---
Changes in v2:
- Keep TX IRQ masking in the driver and mask the IRQ after sending a
  deferred x_char while TX is stopped.
- Verify the stopped-TX sequence with a mocked FIFO and run a serial
  console regression test on the ESP32-P4.

This replaces patch 12/19 and applies after patches 10 and 11 from v1.
v1: https://lore.kernel.org/linux-serial/20261125233020.1380594-13-vitorhg20080@gmail.com/

 drivers/tty/serial/esp32_uart.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/drivers/tty/serial/esp32_uart.c b/drivers/tty/serial/esp32_uart.c
index 304e134..2058bd6 100644
--- a/drivers/tty/serial/esp32_uart.c
+++ b/drivers/tty/serial/esp32_uart.c
@@ -354,25 +354,31 @@ static void esp32_uart_transmit_buffer(struct uart_port *port)
 	unsigned int pending;
 	u8 ch;
 
-	if (tx_fifo_used >= ESP32_UART_TX_FIFO_SIZE)
-		return;
-
-	pending = uart_port_tx_limited(port, ch,
-				       ESP32_UART_TX_FIFO_SIZE - tx_fifo_used,
-				       true, esp32_uart_put_char(port, ch),
-				       ({}));
-	if (pending) {
+	tx_fifo_used = min_t(u32, tx_fifo_used, ESP32_UART_TX_FIFO_SIZE);
+	pending = uart_port_tx_limited_flags(port, ch, UART_TX_NOSTOP,
+					    ESP32_UART_TX_FIFO_SIZE - tx_fifo_used,
+					    true, esp32_uart_put_char(port, ch),
+					    ({}));
+
+	/* Keep TX IRQs enabled while there is sendable data. */
+	if (port->x_char || (pending && !uart_tx_stopped(port))) {
 		u32 int_ena;
 
 		int_ena = esp32_uart_read(port, UART_INT_ENA_REG);
 		int_ena |= UART_TXFIFO_EMPTY_INT;
 		esp32_uart_write(port, UART_INT_ENA_REG, int_ena);
+	} else {
+		esp32_uart_stop_tx(port);
 	}
 }
 
 static void esp32_uart_txint(struct uart_port *port)
 {
+	unsigned long flags;
+
+	uart_port_lock_irqsave(port, &flags);
 	esp32_uart_transmit_buffer(port);
+	uart_port_unlock_irqrestore(port, flags);
 }
 
 static irqreturn_t esp32_uart_int(int irq, void *dev_id)



More information about the linux-riscv mailing list