diff mbox series

[v3] tty/serial: atmel: fix out of range clock divider handling

Message ID 20191216085403.17050-1-david.engraf@sysgo.com (mailing list archive)
State Mainlined
Commit cb47b9f8630ae3fa3f5fbd0c7003faba7abdf711
Headers show
Series [v3] tty/serial: atmel: fix out of range clock divider handling | expand

Commit Message

David Engraf Dec. 16, 2019, 8:54 a.m. UTC
Use MCK_DIV8 when the clock divider is > 65535. Unfortunately the mode
register was already written thus the clock selection is ignored.

Fix by doing the baud rate calulation before setting the mode.

Fixes: 5bf5635ac170 ("tty/serial: atmel: add fractional baud rate support")
Signed-off-by: David Engraf <david.engraf@sysgo.com>
---
Changes since v1: 
 - moves set baud rate block before setting the mode register because
   ATMEL_US_RTSDIS and ATMEL_US_RTSEN depend on ATMEL_US_MR.mode

---
 drivers/tty/serial/atmel_serial.c | 43 ++++++++++++++++---------------
 1 file changed, 22 insertions(+), 21 deletions(-)

Comments

Richard Genoud Dec. 16, 2019, 10:03 a.m. UTC | #1
Le 16/12/2019 à 09:54, David Engraf a écrit :
> Use MCK_DIV8 when the clock divider is > 65535. Unfortunately the mode
> register was already written thus the clock selection is ignored.
> 
> Fix by doing the baud rate calulation before setting the mode.
> 
> Fixes: 5bf5635ac170 ("tty/serial: atmel: add fractional baud rate support")
> Signed-off-by: David Engraf <david.engraf@sysgo.com>

Acked-by: Richard Genoud <richard.genoud@gmail.com>


> ---
> Changes since v1: 
>  - moves set baud rate block before setting the mode register because
>    ATMEL_US_RTSDIS and ATMEL_US_RTSEN depend on ATMEL_US_MR.mode
> 
> ---
>  drivers/tty/serial/atmel_serial.c | 43 ++++++++++++++++---------------
>  1 file changed, 22 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
> index a8dc8af83f39..1ba9bc667e13 100644
> --- a/drivers/tty/serial/atmel_serial.c
> +++ b/drivers/tty/serial/atmel_serial.c
> @@ -2270,27 +2270,6 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
>  		mode |= ATMEL_US_USMODE_NORMAL;
>  	}
>  
> -	/* set the mode, clock divisor, parity, stop bits and data size */
> -	atmel_uart_writel(port, ATMEL_US_MR, mode);
> -
> -	/*
> -	 * when switching the mode, set the RTS line state according to the
> -	 * new mode, otherwise keep the former state
> -	 */
> -	if ((old_mode & ATMEL_US_USMODE) != (mode & ATMEL_US_USMODE)) {
> -		unsigned int rts_state;
> -
> -		if ((mode & ATMEL_US_USMODE) == ATMEL_US_USMODE_HWHS) {
> -			/* let the hardware control the RTS line */
> -			rts_state = ATMEL_US_RTSDIS;
> -		} else {
> -			/* force RTS line to low level */
> -			rts_state = ATMEL_US_RTSEN;
> -		}
> -
> -		atmel_uart_writel(port, ATMEL_US_CR, rts_state);
> -	}
> -
>  	/*
>  	 * Set the baud rate:
>  	 * Fractional baudrate allows to setup output frequency more
> @@ -2317,6 +2296,28 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
>  
>  	if (!(port->iso7816.flags & SER_ISO7816_ENABLED))
>  		atmel_uart_writel(port, ATMEL_US_BRGR, quot);
> +
> +	/* set the mode, clock divisor, parity, stop bits and data size */
> +	atmel_uart_writel(port, ATMEL_US_MR, mode);
> +
> +	/*
> +	 * when switching the mode, set the RTS line state according to the
> +	 * new mode, otherwise keep the former state
> +	 */
> +	if ((old_mode & ATMEL_US_USMODE) != (mode & ATMEL_US_USMODE)) {
> +		unsigned int rts_state;
> +
> +		if ((mode & ATMEL_US_USMODE) == ATMEL_US_USMODE_HWHS) {
> +			/* let the hardware control the RTS line */
> +			rts_state = ATMEL_US_RTSDIS;
> +		} else {
> +			/* force RTS line to low level */
> +			rts_state = ATMEL_US_RTSEN;
> +		}
> +
> +		atmel_uart_writel(port, ATMEL_US_CR, rts_state);
> +	}
> +
>  	atmel_uart_writel(port, ATMEL_US_CR, ATMEL_US_RSTSTA | ATMEL_US_RSTRX);
>  	atmel_uart_writel(port, ATMEL_US_CR, ATMEL_US_TXEN | ATMEL_US_RXEN);
>  	atmel_port->tx_stopped = false;
> 

Thanks !
Ludovic Desroches Dec. 16, 2019, 10:26 a.m. UTC | #2
On Mon, Dec 16, 2019 at 09:54:03AM +0100, David Engraf wrote:
> Use MCK_DIV8 when the clock divider is > 65535. Unfortunately the mode
> register was already written thus the clock selection is ignored.
> 
> Fix by doing the baud rate calulation before setting the mode.
> 
> Fixes: 5bf5635ac170 ("tty/serial: atmel: add fractional baud rate support")
> Signed-off-by: David Engraf <david.engraf@sysgo.com>
Acked-by: Ludovic Desroches <ludovic.desroches@microchip.com>

Thanks for the fix

Regards

> ---
> Changes since v1:
>  - moves set baud rate block before setting the mode register because
>    ATMEL_US_RTSDIS and ATMEL_US_RTSEN depend on ATMEL_US_MR.mode
> 
> ---
>  drivers/tty/serial/atmel_serial.c | 43 ++++++++++++++++---------------
>  1 file changed, 22 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
> index a8dc8af83f39..1ba9bc667e13 100644
> --- a/drivers/tty/serial/atmel_serial.c
> +++ b/drivers/tty/serial/atmel_serial.c
> @@ -2270,27 +2270,6 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
>                 mode |= ATMEL_US_USMODE_NORMAL;
>         }
> 
> -       /* set the mode, clock divisor, parity, stop bits and data size */
> -       atmel_uart_writel(port, ATMEL_US_MR, mode);
> -
> -       /*
> -        * when switching the mode, set the RTS line state according to the
> -        * new mode, otherwise keep the former state
> -        */
> -       if ((old_mode & ATMEL_US_USMODE) != (mode & ATMEL_US_USMODE)) {
> -               unsigned int rts_state;
> -
> -               if ((mode & ATMEL_US_USMODE) == ATMEL_US_USMODE_HWHS) {
> -                       /* let the hardware control the RTS line */
> -                       rts_state = ATMEL_US_RTSDIS;
> -               } else {
> -                       /* force RTS line to low level */
> -                       rts_state = ATMEL_US_RTSEN;
> -               }
> -
> -               atmel_uart_writel(port, ATMEL_US_CR, rts_state);
> -       }
> -
>         /*
>          * Set the baud rate:
>          * Fractional baudrate allows to setup output frequency more
> @@ -2317,6 +2296,28 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
> 
>         if (!(port->iso7816.flags & SER_ISO7816_ENABLED))
>                 atmel_uart_writel(port, ATMEL_US_BRGR, quot);
> +
> +       /* set the mode, clock divisor, parity, stop bits and data size */
> +       atmel_uart_writel(port, ATMEL_US_MR, mode);
> +
> +       /*
> +        * when switching the mode, set the RTS line state according to the
> +        * new mode, otherwise keep the former state
> +        */
> +       if ((old_mode & ATMEL_US_USMODE) != (mode & ATMEL_US_USMODE)) {
> +               unsigned int rts_state;
> +
> +               if ((mode & ATMEL_US_USMODE) == ATMEL_US_USMODE_HWHS) {
> +                       /* let the hardware control the RTS line */
> +                       rts_state = ATMEL_US_RTSDIS;
> +               } else {
> +                       /* force RTS line to low level */
> +                       rts_state = ATMEL_US_RTSEN;
> +               }
> +
> +               atmel_uart_writel(port, ATMEL_US_CR, rts_state);
> +       }
> +
>         atmel_uart_writel(port, ATMEL_US_CR, ATMEL_US_RSTSTA | ATMEL_US_RSTRX);
>         atmel_uart_writel(port, ATMEL_US_CR, ATMEL_US_TXEN | ATMEL_US_RXEN);
>         atmel_port->tx_stopped = false;
> --
> 2.17.1
>
diff mbox series

Patch

diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index a8dc8af83f39..1ba9bc667e13 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -2270,27 +2270,6 @@  static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
 		mode |= ATMEL_US_USMODE_NORMAL;
 	}
 
-	/* set the mode, clock divisor, parity, stop bits and data size */
-	atmel_uart_writel(port, ATMEL_US_MR, mode);
-
-	/*
-	 * when switching the mode, set the RTS line state according to the
-	 * new mode, otherwise keep the former state
-	 */
-	if ((old_mode & ATMEL_US_USMODE) != (mode & ATMEL_US_USMODE)) {
-		unsigned int rts_state;
-
-		if ((mode & ATMEL_US_USMODE) == ATMEL_US_USMODE_HWHS) {
-			/* let the hardware control the RTS line */
-			rts_state = ATMEL_US_RTSDIS;
-		} else {
-			/* force RTS line to low level */
-			rts_state = ATMEL_US_RTSEN;
-		}
-
-		atmel_uart_writel(port, ATMEL_US_CR, rts_state);
-	}
-
 	/*
 	 * Set the baud rate:
 	 * Fractional baudrate allows to setup output frequency more
@@ -2317,6 +2296,28 @@  static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
 
 	if (!(port->iso7816.flags & SER_ISO7816_ENABLED))
 		atmel_uart_writel(port, ATMEL_US_BRGR, quot);
+
+	/* set the mode, clock divisor, parity, stop bits and data size */
+	atmel_uart_writel(port, ATMEL_US_MR, mode);
+
+	/*
+	 * when switching the mode, set the RTS line state according to the
+	 * new mode, otherwise keep the former state
+	 */
+	if ((old_mode & ATMEL_US_USMODE) != (mode & ATMEL_US_USMODE)) {
+		unsigned int rts_state;
+
+		if ((mode & ATMEL_US_USMODE) == ATMEL_US_USMODE_HWHS) {
+			/* let the hardware control the RTS line */
+			rts_state = ATMEL_US_RTSDIS;
+		} else {
+			/* force RTS line to low level */
+			rts_state = ATMEL_US_RTSEN;
+		}
+
+		atmel_uart_writel(port, ATMEL_US_CR, rts_state);
+	}
+
 	atmel_uart_writel(port, ATMEL_US_CR, ATMEL_US_RSTSTA | ATMEL_US_RSTRX);
 	atmel_uart_writel(port, ATMEL_US_CR, ATMEL_US_TXEN | ATMEL_US_RXEN);
 	atmel_port->tx_stopped = false;