Skip to contentSkip to conversation

tty: serial: fsl_lpuart/imx: improve the TX break settings

PATCH New Sherry Sun 1 participant 4 messages Dec 14, 2022

Subsystems (2)
lore
Share & tools
lore

Sherry Sun

author
#0 lore raw

cover tty: serial: fsl_lpuart/imx: improve the TX break settings

This patch set improve the TX break settings for lpuart and imx uart driver. Add workaround patch for a LPUART IP bug about sending break signal. Also disable the break in .shutdown() for lpuart and imx uart like other uart drivers.

This patch set has been verified on imx8mm(imx uart) and imx8ulp(lpuart).

Sherry Sun (3):
tty: serial: fsl_lpuart: disable the CTS when send break signal
tty: serial: fsl_lpuart: disable the break condition when shutdown the
uart port
tty: serial: imx: disable the break condition when shutdown the uart
port

 drivers/tty/serial/fsl_lpuart.c | 28 ++++++++++++++++++++++++----
 drivers/tty/serial/imx.c        |  3 ++-
 2 files changed, 26 insertions(+), 5 deletions(-)
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH 1/3 tty: serial: fsl_lpuart: disable the CTS when send break signal

LPUART IP has a bug that it treats the CTS as higher priority than the break signal, which cause the break signal sending through UARTCTRL_SBK may impacted by the CTS input if the HW flow control is enabled.

Add this workaround patch to fix the IP bug, we can disable CTS before asserting SBK to avoid any interference from CTS, and re-enable it when break off.

Such as for the bluetooth chip power save feature, host can let the BT chip get into sleep state by sending a UART break signal, and wake it up by turning off the UART break. If the BT chip enters the sleep mode successfully, it will pull up the CTS line, if the BT chip is woken up, it will pull down the CTS line. If without this workaround patch, the UART TX pin cannot send the break signal successfully as it affected by the BT CTS pin. After adding this patch, the BT power save feature can work well.

---
 drivers/tty/serial/fsl_lpuart.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
drivers/tty/serial/fsl_lpuart.c +22 -2
index bb12b328e224..f487d3d2effe 100644
@@ -1464,12 +1464,32 @@ static void lpuart_break_ctl(struct uart_port *port, int break_state)
 
 static void lpuart32_break_ctl(struct uart_port *port, int break_state)
 {
-	unsigned long temp;
+	unsigned long temp, modem;
+	struct tty_struct *tty;
+	unsigned int cflag = 0;
+
+	tty = tty_port_tty_get(&port->state->port);
+	if (tty) {
+		cflag = tty->termios.c_cflag;
+		tty_kref_put(tty);
+	}
 
 	temp = lpuart32_read(port, UARTCTRL) & ~UARTCTRL_SBK;
+	modem = lpuart32_read(port, UARTMODIR);
 
-	if (break_state != 0)
+	if (break_state != 0) {
 		temp |= UARTCTRL_SBK;
+		/*
+		 * LPUART CTS has higher priority than SBK, need to disable CTS before
+		 * asserting SBK to avoid any interference if flow control is enabled.
+		 */
+		if (cflag & CRTSCTS && modem & UARTMODIR_TXCTSE)
+			lpuart32_write(port, modem & ~UARTMODIR_TXCTSE, UARTMODIR);
+	} else {
+		/* Re-enable the CTS when break off. */
+		if (cflag & CRTSCTS && !(modem & UARTMODIR_TXCTSE))
+			lpuart32_write(port, modem | UARTMODIR_TXCTSE, UARTMODIR);
+	}
 
 	lpuart32_write(port, temp, UARTCTRL);
 }
Signature · 1 line
2.17.1
author
#2 lore raw

PATCH 2/3 tty: serial: fsl_lpuart: disable the break condition when shutdown the uart port

In reply to Sherry Sun

Need to disable the break condition for lpuart driver when closing the uart port like other uart drivers do.

---
 drivers/tty/serial/fsl_lpuart.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/tty/serial/fsl_lpuart.c +2 -2
index f487d3d2effe..584b26e0b947 100644
@@ -1839,10 +1839,10 @@ static void lpuart32_shutdown(struct uart_port *port)
 	temp &= ~(UARTBAUD_TDMAE | UARTBAUD_RDMAE);
 	lpuart32_write(port, temp, UARTBAUD);
 
-	/* disable Rx/Tx and interrupts */
+	/* disable Rx/Tx and interrupts and break condition */
 	temp = lpuart32_read(port, UARTCTRL);
 	temp &= ~(UARTCTRL_TE | UARTCTRL_RE | UARTCTRL_ILIE |
-			UARTCTRL_TIE | UARTCTRL_TCIE | UARTCTRL_RIE);
+			UARTCTRL_TIE | UARTCTRL_TCIE | UARTCTRL_RIE | UARTCTRL_SBK);
 	lpuart32_write(port, temp, UARTCTRL);
 
 	spin_unlock_irqrestore(&port->lock, flags);
Signature · 1 line
2.17.1
author
#3 lore raw

PATCH 3/3 tty: serial: imx: disable the break condition when shutdown the uart port

In reply to Sherry Sun

The comment in imx_uart_shutdown() says to disable the break condition, but it doesn't actually do that, here fix this by disabling UCR1_SNDBRK when closing the uart port like other uart drivers do.

---
 drivers/tty/serial/imx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/tty/serial/imx.c +2 -1
index 757825edb0cd..74c9e68fc3bd 100644
@@ -1564,7 +1564,8 @@ static void imx_uart_shutdown(struct uart_port *port)
 	spin_lock_irqsave(&sport->port.lock, flags);
 
 	ucr1 = imx_uart_readl(sport, UCR1);
-	ucr1 &= ~(UCR1_TRDYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_RXDMAEN | UCR1_ATDMAEN);
+	ucr1 &= ~(UCR1_TRDYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_RXDMAEN |
+		  UCR1_ATDMAEN | UCR1_SNDBRK);
 	/* See SER_RS485_ENABLED/UTS_LOOP comment in imx_uart_probe() */
 	if (port->rs485.flags & SER_RS485_ENABLED &&
 	    port->rs485.flags & SER_RS485_RTS_ON_SEND &&
Signature · 1 line
2.17.1