2022-08-25 09:03:14

by Ilpo Järvinen

[permalink] [raw]
Subject: [PATCH 2/5] serial: cpm_uart: Remove custom frame size calculation

The number of bits can be calculated using helpers in core, no need for
the driver to do it on its own.

The mode register is programmed with frame bits minus 1, rearrange the
comments related to that "feature" closer to the actual write.

Signed-off-by: Ilpo Järvinen <[email protected]>
---
drivers/tty/serial/cpm_uart/cpm_uart_core.c | 28 ++++++---------------
1 file changed, 7 insertions(+), 21 deletions(-)

diff --git a/drivers/tty/serial/cpm_uart/cpm_uart_core.c b/drivers/tty/serial/cpm_uart/cpm_uart_core.c
index db07d6a5d764..96c6ee379c03 100644
--- a/drivers/tty/serial/cpm_uart/cpm_uart_core.c
+++ b/drivers/tty/serial/cpm_uart/cpm_uart_core.c
@@ -489,7 +489,6 @@ static void cpm_uart_set_termios(struct uart_port *port,
int baud;
unsigned long flags;
u16 cval, scval, prev_mode;
- int bits, sbits;
struct uart_cpm_port *pinfo =
container_of(port, struct uart_cpm_port, port);
smc_t __iomem *smcp = pinfo->smcp;
@@ -515,28 +514,17 @@ static void cpm_uart_set_termios(struct uart_port *port,
if (maxidl > 0x10)
maxidl = 0x10;

- /* Character length programmed into the mode register is the
- * sum of: 1 start bit, number of data bits, 0 or 1 parity bit,
- * 1 or 2 stop bits, minus 1.
- * The value 'bits' counts this for us.
- */
cval = 0;
scval = 0;

- /* byte size */
- bits = tty_get_char_size(termios->c_cflag);
- sbits = bits - 5;
-
if (termios->c_cflag & CSTOPB) {
cval |= SMCMR_SL; /* Two stops */
scval |= SCU_PSMR_SL;
- bits++;
}

if (termios->c_cflag & PARENB) {
cval |= SMCMR_PEN;
scval |= SCU_PSMR_PEN;
- bits++;
if (!(termios->c_cflag & PARODD)) {
cval |= SMCMR_PM_EVEN;
scval |= (SCU_PSMR_REVP | SCU_PSMR_TEVP);
@@ -580,11 +568,6 @@ static void cpm_uart_set_termios(struct uart_port *port,

spin_lock_irqsave(&port->lock, flags);

- /* Start bit has not been added (so don't, because we would just
- * subtract it later), and we need to add one for the number of
- * stops bits (there is always at least one).
- */
- bits++;
if (IS_SMC(pinfo)) {
/*
* MRBLR can be changed while an SMC/SCC is operating only
@@ -604,13 +587,16 @@ static void cpm_uart_set_termios(struct uart_port *port,
*/
prev_mode = in_be16(&smcp->smc_smcmr) & (SMCMR_REN | SMCMR_TEN);
/* Output in *one* operation, so we don't interrupt RX/TX if they
- * were already enabled. */
- out_be16(&smcp->smc_smcmr, smcr_mk_clen(bits) | cval |
- SMCMR_SM_UART | prev_mode);
+ * were already enabled.
+ * Character length programmed into the register is frame bits minus 1.
+ */
+ out_be16(&smcp->smc_smcmr, smcr_mk_clen(tty_get_frame_size(termios->c_cflag) - 1) |
+ cval | SMCMR_SM_UART | prev_mode);
} else {
out_be16(&pinfo->sccup->scc_genscc.scc_mrblr, pinfo->rx_fifosize);
out_be16(&pinfo->sccup->scc_maxidl, maxidl);
- out_be16(&sccp->scc_psmr, (sbits << 12) | scval);
+ out_be16(&sccp->scc_psmr, (UART_LCR_WLEN(tty_get_char_size(termios->c_cflag))
+ << 12) | scval);
}

if (pinfo->clk)
--
2.30.2


2022-08-26 16:07:37

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 2/5] serial: cpm_uart: Remove custom frame size calculation

On Thu, Aug 25, 2022 at 11:58 AM Ilpo Järvinen
<[email protected]> wrote:
>
> The number of bits can be calculated using helpers in core, no need for
> the driver to do it on its own.
>
> The mode register is programmed with frame bits minus 1, rearrange the
> comments related to that "feature" closer to the actual write.

...

> + out_be16(&smcp->smc_smcmr, smcr_mk_clen(tty_get_frame_size(termios->c_cflag) - 1) |
> + cval | SMCMR_SM_UART | prev_mode);
> } else {
> out_be16(&pinfo->sccup->scc_genscc.scc_mrblr, pinfo->rx_fifosize);
> out_be16(&pinfo->sccup->scc_maxidl, maxidl);
> - out_be16(&sccp->scc_psmr, (sbits << 12) | scval);
> + out_be16(&sccp->scc_psmr, (UART_LCR_WLEN(tty_get_char_size(termios->c_cflag))
> + << 12) | scval);

Seems it's better to calc it beforehand in the temporary variable for
both branches of the conditional and fix a bit strange indentation
here.

> }


--
With Best Regards,
Andy Shevchenko