[PATCH RFC 12/19] serial: esp32: Rearm TX interrupts when the FIFO is full

Vítor Hugo Silva vitorhg20080 at gmail.com
Wed Nov 25 15:30:13 PST 2026


When transmission starts with a full FIFO, the driver can leave
queued data waiting with the TX interrupt disabled. Rearm the
interrupt whenever there is data ready to send, including a pending
high-priority character.

Hold the port lock in the TX interrupt handler as required by
uart_port_tx_limited().

Tested on a Waveshare ESP32-P4-Module-DEV-KIT. Verified that serial
output completed during SDMMC reads.

AI assisted with driver development.

Signed-off-by: Vítor Hugo Silva <vitorhg20080 at gmail.com>
---
 drivers/tty/serial/esp32_uart.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/serial/esp32_uart.c b/drivers/tty/serial/esp32_uart.c
index 304e1345518b..002d6fdbd875 100644
--- a/drivers/tty/serial/esp32_uart.c
+++ b/drivers/tty/serial/esp32_uart.c
@@ -354,14 +354,14 @@ 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;
-
+	tx_fifo_used = min_t(u32, tx_fifo_used, ESP32_UART_TX_FIFO_SIZE);
 	pending = uart_port_tx_limited(port, ch,
 				       ESP32_UART_TX_FIFO_SIZE - tx_fifo_used,
 				       true, esp32_uart_put_char(port, ch),
 				       ({}));
-	if (pending) {
+
+	/* Rearm TX even if the FIFO had no room for queued data. */
+	if (port->x_char || (pending && !uart_tx_stopped(port))) {
 		u32 int_ena;
 
 		int_ena = esp32_uart_read(port, UART_INT_ENA_REG);
@@ -372,7 +372,11 @@ static void esp32_uart_transmit_buffer(struct uart_port *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)
-- 
2.56.1




More information about the linux-riscv mailing list