Skip to content

Commit

Permalink
serial: stm32: add FIFO flush when port is closed
Browse files Browse the repository at this point in the history
Transmission complete error is sent when ISR_TC is not set. If port closure
is requested despite data in TDR / TX FIFO has not been sent (because of
flow control), ISR_TC is not set and error message is sent on port closure
but also when a new port is opened.

Flush the data when port is closed, and send the transmission complete
error message only when ISR_TC is not set and TDR / TX FIFO is not empty.

Signed-off-by: Erwan Le Ray <[email protected]>
Change-Id: I30c4cc1535d3a7bc1e8acd25b003f31fb555cd78
Reviewed-on: https://gerrit.st.com/c/mpu/oe/st/linux-stm32/+/181423
Reviewed-by: CITOOLS <[email protected]>
Reviewed-by: CIBUILD <[email protected]>
Reviewed-by: Fabrice GASNIER <[email protected]>
  • Loading branch information
Erwan Le Ray authored and atorgue committed Oct 20, 2020
1 parent e5e4901 commit a56628a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions drivers/tty/serial/stm32-usart.c
Original file line number Diff line number Diff line change
Expand Up @@ -903,9 +903,18 @@ static void stm32_usart_shutdown(struct uart_port *port)
isr, (isr & USART_SR_TC),
10, 100000);

if (ret)
/*
* Send the TC error message only when ISR_TC is not set and
* data stored in TDR / TX FIFO.
*/
if (ret && !(readl_relaxed(port->membase + ofs->isr) & USART_SR_TXE))
dev_err(port->dev, "transmission complete not set\n");

/* flush RX & TX FIFO */
if (ofs->rqr != UNDEF_REG)
stm32_usart_set_bits(port, ofs->rqr,
USART_RQR_TXFRQ | USART_RQR_RXFRQ);

stm32_usart_clr_bits(port, ofs->cr1, val);

free_irq(port->irq, port);
Expand Down Expand Up @@ -968,7 +977,11 @@ static void stm32_usart_set_termios(struct uart_port *port,
(isr & USART_SR_TC),
10, 100000);

if (ret)
/*
* Send the TC error message only when ISR_TC is not set and
* data stored in TDR / TX FIFO.
*/
if (ret && !(readl_relaxed(port->membase + ofs->isr) & USART_SR_TXE))
dev_err(port->dev, "transmission complete not set\n");

/* Stop serial port and reset value */
Expand Down

0 comments on commit a56628a

Please sign in to comment.