linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] tty: serial: fsl_lpuart/imx: improve the TX break settings
@ 2022-12-14  3:11 Sherry Sun
  2022-12-14  3:11 ` [PATCH 1/3] tty: serial: fsl_lpuart: disable the CTS when send break signal Sherry Sun
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sherry Sun @ 2022-12-14  3:11 UTC (permalink / raw)
  To: gregkh, jirislaby; +Cc: linux-serial, linux-kernel, linux-imx

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(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] tty: serial: fsl_lpuart: disable the CTS when send break signal
  2022-12-14  3:11 [PATCH 0/3] tty: serial: fsl_lpuart/imx: improve the TX break settings Sherry Sun
@ 2022-12-14  3:11 ` Sherry Sun
  2022-12-14  3:11 ` [PATCH 2/3] tty: serial: fsl_lpuart: disable the break condition when shutdown the uart port Sherry Sun
  2022-12-14  3:11 ` [PATCH 3/3] tty: serial: imx: " Sherry Sun
  2 siblings, 0 replies; 4+ messages in thread
From: Sherry Sun @ 2022-12-14  3:11 UTC (permalink / raw)
  To: gregkh, jirislaby; +Cc: linux-serial, linux-kernel, linux-imx

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.

Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
---
 drivers/tty/serial/fsl_lpuart.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index bb12b328e224..f487d3d2effe 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -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);
 }
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] tty: serial: fsl_lpuart: disable the break condition when shutdown the uart port
  2022-12-14  3:11 [PATCH 0/3] tty: serial: fsl_lpuart/imx: improve the TX break settings Sherry Sun
  2022-12-14  3:11 ` [PATCH 1/3] tty: serial: fsl_lpuart: disable the CTS when send break signal Sherry Sun
@ 2022-12-14  3:11 ` Sherry Sun
  2022-12-14  3:11 ` [PATCH 3/3] tty: serial: imx: " Sherry Sun
  2 siblings, 0 replies; 4+ messages in thread
From: Sherry Sun @ 2022-12-14  3:11 UTC (permalink / raw)
  To: gregkh, jirislaby; +Cc: linux-serial, linux-kernel, linux-imx

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

Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
---
 drivers/tty/serial/fsl_lpuart.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index f487d3d2effe..584b26e0b947 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -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);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] tty: serial: imx: disable the break condition when shutdown the uart port
  2022-12-14  3:11 [PATCH 0/3] tty: serial: fsl_lpuart/imx: improve the TX break settings Sherry Sun
  2022-12-14  3:11 ` [PATCH 1/3] tty: serial: fsl_lpuart: disable the CTS when send break signal Sherry Sun
  2022-12-14  3:11 ` [PATCH 2/3] tty: serial: fsl_lpuart: disable the break condition when shutdown the uart port Sherry Sun
@ 2022-12-14  3:11 ` Sherry Sun
  2 siblings, 0 replies; 4+ messages in thread
From: Sherry Sun @ 2022-12-14  3:11 UTC (permalink / raw)
  To: gregkh, jirislaby; +Cc: linux-serial, linux-kernel, linux-imx

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.

Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
---
 drivers/tty/serial/imx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 757825edb0cd..74c9e68fc3bd 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -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 &&
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-12-14  3:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-14  3:11 [PATCH 0/3] tty: serial: fsl_lpuart/imx: improve the TX break settings Sherry Sun
2022-12-14  3:11 ` [PATCH 1/3] tty: serial: fsl_lpuart: disable the CTS when send break signal Sherry Sun
2022-12-14  3:11 ` [PATCH 2/3] tty: serial: fsl_lpuart: disable the break condition when shutdown the uart port Sherry Sun
2022-12-14  3:11 ` [PATCH 3/3] tty: serial: imx: " Sherry Sun

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).