[2/2] tty: serial: fsl_lpuart: improve lpuart32 registers clearing when shutdown

Message ID 20221109104515.17266-3-sherry.sun@nxp.com
State New
Headers
Series fsl_lpuart: improve Idle Line Interrupt and registers handle in .shutdown() |

Commit Message

Sherry Sun Nov. 9, 2022, 10:45 a.m. UTC
  Need to clear the UARTSTAT and UARTMODIR registers when shutdown the
uart port, also clear the Rx/Tx DMA enable bits and loopback
configuration bit.

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

Comments

Ilpo Järvinen Nov. 9, 2022, 12:19 p.m. UTC | #1
On Wed, 9 Nov 2022, Sherry Sun wrote:

> Need to clear the UARTSTAT and UARTMODIR registers when shutdown the
> uart port, also clear the Rx/Tx DMA enable bits and loopback
> configuration bit.

This lacks answer to "Why?" question. Think about somebody not as familiar 
with the HW as you are looking back to this very commit message like 5 
years from now and wondering why this change was made.

Preferrably make a separate change out of all these four changes if the 
answers to why question are different.

It would also help in deciding whether Fixes tag is necessary or not 
since you didn't seem to include.
  
Sherry Sun Nov. 10, 2022, 3:32 a.m. UTC | #2
> -----Original Message-----
> From: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> Sent: 2022年11月9日 20:19
> To: Sherry Sun <sherry.sun@nxp.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>; Jiri Slaby
> <jirislaby@kernel.org>; linux-serial <linux-serial@vger.kernel.org>; LKML
> <linux-kernel@vger.kernel.org>; dl-linux-imx <linux-imx@nxp.com>
> Subject: Re: [PATCH 2/2] tty: serial: fsl_lpuart: improve lpuart32 registers
> clearing when shutdown
> 
> On Wed, 9 Nov 2022, Sherry Sun wrote:
> 
> > Need to clear the UARTSTAT and UARTMODIR registers when shutdown the
> > uart port, also clear the Rx/Tx DMA enable bits and loopback
> > configuration bit.
> 
> This lacks answer to "Why?" question. Think about somebody not as familiar
> with the HW as you are looking back to this very commit message like 5 years
> from now and wondering why this change was made.
> 
> Preferrably make a separate change out of all these four changes if the
> answers to why question are different.
> 
> It would also help in deciding whether Fixes tag is necessary or not since you
> didn't seem to include.

Hi Ilpo,

Ok, maybe I need to separate the four changes in lpuart32_shutdown() to better describe the "why". Thanks for the comments.

Best Regards
Sherry


> 
> --
>  i.
> 
> > Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
> > ---
> >  drivers/tty/serial/fsl_lpuart.c | 13 ++++++++++++-
> >  1 file changed, 12 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/tty/serial/fsl_lpuart.c
> > b/drivers/tty/serial/fsl_lpuart.c index f5a0a14fa366..43d9d6a6e94a
> > 100644
> > --- a/drivers/tty/serial/fsl_lpuart.c
> > +++ b/drivers/tty/serial/fsl_lpuart.c
> > @@ -1771,11 +1771,22 @@ static void lpuart32_shutdown(struct
> uart_port
> > *port)
> >
> >  	spin_lock_irqsave(&port->lock, flags);
> >
> > +	/* clear statue */
> > +	temp = lpuart32_read(&sport->port, UARTSTAT);
> > +	lpuart32_write(&sport->port, temp, UARTSTAT);
> > +
> > +	/* disable Rx/Tx DMA */
> > +	temp = lpuart32_read(port, UARTBAUD);
> > +	temp &= ~(UARTBAUD_TDMAE | UARTBAUD_RDMAE);
> > +	lpuart32_write(port, temp, UARTBAUD);
> > +
> >  	/* disable Rx/Tx and interrupts */
> >  	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_LOOPS);
> >  	lpuart32_write(port, temp, UARTCTRL);
> > +	lpuart32_write(port, 0, UARTMODIR);
> >
> >  	spin_unlock_irqrestore(&port->lock, flags);
> >
> >
  

Patch

diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index f5a0a14fa366..43d9d6a6e94a 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -1771,11 +1771,22 @@  static void lpuart32_shutdown(struct uart_port *port)
 
 	spin_lock_irqsave(&port->lock, flags);
 
+	/* clear statue */
+	temp = lpuart32_read(&sport->port, UARTSTAT);
+	lpuart32_write(&sport->port, temp, UARTSTAT);
+
+	/* disable Rx/Tx DMA */
+	temp = lpuart32_read(port, UARTBAUD);
+	temp &= ~(UARTBAUD_TDMAE | UARTBAUD_RDMAE);
+	lpuart32_write(port, temp, UARTBAUD);
+
 	/* disable Rx/Tx and interrupts */
 	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_LOOPS);
 	lpuart32_write(port, temp, UARTCTRL);
+	lpuart32_write(port, 0, UARTMODIR);
 
 	spin_unlock_irqrestore(&port->lock, flags);