[PATCH 3/5] serial: fsl_lpuart: Remove custom frame size calculation

Ilpo Järvinen posted 5 patches 3 years, 7 months ago
There is a newer version of this series
[PATCH 3/5] serial: fsl_lpuart: Remove custom frame size calculation
Posted by Ilpo Järvinen 3 years, 7 months ago
The number of bits can be calculated using tty_get_frame_size(), no
need for the driver to do it on its own.

Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/tty/serial/fsl_lpuart.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index f6c33cd228c8..926460f1dc08 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -1284,23 +1284,19 @@ static inline int lpuart_start_rx_dma(struct lpuart_port *sport)
 	struct dma_slave_config dma_rx_sconfig = {};
 	struct circ_buf *ring = &sport->rx_ring;
 	int ret, nent;
-	int bits, baud;
+	int baud;
 	struct tty_port *port = &sport->port.state->port;
 	struct tty_struct *tty = port->tty;
 	struct ktermios *termios = &tty->termios;
 	struct dma_chan *chan = sport->dma_rx_chan;
 
 	baud = tty_get_baud_rate(tty);
-
-	bits = (termios->c_cflag & CSIZE) == CS7 ? 9 : 10;
-	if (termios->c_cflag & PARENB)
-		bits++;
-
 	/*
 	 * Calculate length of one DMA buffer size to keep latency below
 	 * 10ms at any baud rate.
 	 */
-	sport->rx_dma_rng_buf_len = (DMA_RX_TIMEOUT * baud /  bits / 1000) * 2;
+	sport->rx_dma_rng_buf_len = (DMA_RX_TIMEOUT * baud / tty_get_frame_size(termios->c_cflag) /
+				     1000) * 2;
 	sport->rx_dma_rng_buf_len = (1 << (fls(sport->rx_dma_rng_buf_len) - 1));
 	if (sport->rx_dma_rng_buf_len < 16)
 		sport->rx_dma_rng_buf_len = 16;
-- 
2.30.2

Re: [PATCH 3/5] serial: fsl_lpuart: Remove custom frame size calculation
Posted by Andy Shevchenko 3 years, 7 months ago
On Thu, Aug 25, 2022 at 11:59 AM Ilpo Järvinen
<ilpo.jarvinen@linux.intel.com> wrote:
>
> The number of bits can be calculated using tty_get_frame_size(), no
> need for the driver to do it on its own.

...

>         struct dma_slave_config dma_rx_sconfig = {};
>         struct circ_buf *ring = &sport->rx_ring;
>         int ret, nent;
> -       int bits, baud;
> +       int baud;
>         struct tty_port *port = &sport->port.state->port;
>         struct tty_struct *tty = port->tty;
>         struct ktermios *termios = &tty->termios;
>         struct dma_chan *chan = sport->dma_rx_chan;
>
>         baud = tty_get_baud_rate(tty);

You can move baud and join with the assignment, right?
At the same time provide a temporary variable for bits here with the assignment.

> -       bits = (termios->c_cflag & CSIZE) == CS7 ? 9 : 10;
> -       if (termios->c_cflag & PARENB)
> -               bits++;
> -
>         /*
>          * Calculate length of one DMA buffer size to keep latency below
>          * 10ms at any baud rate.
>          */
> -       sport->rx_dma_rng_buf_len = (DMA_RX_TIMEOUT * baud /  bits / 1000) * 2;

This will be left untouched.

> +       sport->rx_dma_rng_buf_len = (DMA_RX_TIMEOUT * baud / tty_get_frame_size(termios->c_cflag) /
> +                                    1000) * 2;

And no strange indentation.

-- 
With Best Regards,
Andy Shevchenko