[PATCH v3 3/3] serial: rsci: Refactor baud rate clock selection

From: Biju

Date: Mon Apr 20 2026 - 11:22:11 EST


From: Biju Das <biju.das.jz@xxxxxxxxxxxxxx>

Since RSCI only uses a single clock source (SCI_FCK), the multi-clock
tracking variables (best_clk, min_err, brr1, srr1, cks1) are redundant
and removed. ccr0_val and ccr4_val are likewise dropped, replaced with
hardcoded 0 at their write sites, as they were never modified from their
initial zero values.

No functional change intended.

Signed-off-by: Biju Das <biju.das.jz@xxxxxxxxxxxxxx>
---
v2->v3:
* Dropped reported by tag as the goto statement in rsci_set_termios()
removed in the previous patch.
* baud check removed by previous patch.
* Added missing macro CCR0_RE while dropping ccr0_val variable.
* Updated commit description.
v1->v2:
* Dropped the check (abs(err) < abs(min_err) as it is always true.
* Dropped the check (abs(err) < abs(min_err) as it is always true.
* Dropped variables best_clk and min_err as they are no longer needed.
* Dropped intermediate variables brr1, cks1 and srr1; results are now
written directly into brr, cks and srr.
* Moved dev_dbg() inside the if (baud) block.
* Dropped ccr0_val and ccr4_val, replaced with hardcoded 0 at their
write sites, as they were never modified from their initial values.
* Scoped variables err and srr locally within the if (baud) block.
* Updated commit description.
---
drivers/tty/serial/rsci.c | 31 ++++++++++---------------------
1 file changed, 10 insertions(+), 21 deletions(-)

diff --git a/drivers/tty/serial/rsci.c b/drivers/tty/serial/rsci.c
index 40db9daa4272..444e89696310 100644
--- a/drivers/tty/serial/rsci.c
+++ b/drivers/tty/serial/rsci.c
@@ -217,16 +217,15 @@ static void rsci_set_termios(struct uart_port *port, struct ktermios *termios,
const struct ktermios *old)
{
unsigned int ccr2_val = CCR2_INIT, ccr3_val = CCR3_INIT;
- unsigned int ccr0_val = 0, ccr1_val = 0, ccr4_val = 0;
- unsigned int brr1 = 255, cks1 = 0, srr1 = 15;
struct sci_port *s = to_sci_port(port);
unsigned int brr = 255, cks = 0;
- int min_err = INT_MAX, err;
- unsigned long max_freq = 0;
+ unsigned int ccr1_val = 0;
+ unsigned long max_freq;
unsigned int baud, i;
unsigned long flags;
unsigned int ctrl;
- int best_clk = -1;
+ unsigned int srr;
+ int err;

if ((termios->c_cflag & CSIZE) == CS7) {
ccr3_val |= CCR3_CHR0;
@@ -267,25 +266,16 @@ static void rsci_set_termios(struct uart_port *port, struct ktermios *termios,
baud = uart_get_baud_rate(port, termios, old, 0, max_freq);

/* Divided Functional Clock using standard Bit Rate Register */
- err = sci_scbrr_calc(s, baud, &brr1, &srr1, &cks1);
- if (abs(err) < abs(min_err)) {
- best_clk = SCI_FCK;
- ccr0_val = 0;
- min_err = err;
- brr = brr1;
- cks = cks1;
- }
-
- if (best_clk >= 0)
- dev_dbg(port->dev, "Using clk %pC for %u%+d bps\n",
- s->clks[best_clk], baud, min_err);
+ err = sci_scbrr_calc(s, baud, &brr, &srr, &cks);
+ dev_dbg(port->dev, "Using clk %pC for %u%+d bps\n", s->clks[SCI_FCK],
+ baud, err);

sci_port_enable(s);
uart_port_lock_irqsave(port, &flags);

uart_update_timeout(port, termios->c_cflag, baud);

- rsci_serial_out(port, CCR0, ccr0_val);
+ rsci_serial_out(port, CCR0, 0);

ccr3_val |= CCR3_FM;
rsci_serial_out(port, CCR3, ccr3_val);
@@ -294,7 +284,7 @@ static void rsci_set_termios(struct uart_port *port, struct ktermios *termios,
rsci_serial_out(port, CCR2, ccr2_val);

rsci_serial_out(port, CCR1, ccr1_val);
- rsci_serial_out(port, CCR4, ccr4_val);
+ rsci_serial_out(port, CCR4, 0);

ctrl = rsci_serial_in(port, FCR);
ctrl |= (FCR_RFRST | FCR_TFRST);
@@ -315,8 +305,7 @@ static void rsci_set_termios(struct uart_port *port, struct ktermios *termios,
rsci_serial_out(port, CFCLR, CFCLR_CLRFLAG);
rsci_serial_out(port, FFCLR, FFCLR_DRC);

- ccr0_val |= CCR0_RE;
- rsci_serial_out(port, CCR0, ccr0_val);
+ rsci_serial_out(port, CCR0, CCR0_RE);

if ((termios->c_cflag & CREAD) != 0)
rsci_start_rx(port);
--
2.43.0