Skip to content

Commit 4cf9a88

Browse files
jktjktgregkh
authored andcommitted
serial: max310x: Check the clock readiness
This chip has a diagnostics status bit informing about the state and stability of the clock subsystem. According to the datasheet (STSint register, bit 5, ClockReady), this bit works with the crystal oscillator, but even without the PLL. Therefore: - ensure that the clock check is done even when PLL is not active - warn when the chip thinks that the clock is not ready yet There are HW features which would let us wait asynchronously (there's a maskable IRQ for that bit), but I think that even this simple check is a net improvement. It would have saved me two days of debugging :). Signed-off-by: Jan Kundrát <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c884f87 commit 4cf9a88

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

drivers/tty/serial/max310x.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,8 @@ static int max310x_update_best_err(unsigned long f, long *besterr)
531531
return 1;
532532
}
533533

534-
static int max310x_set_ref_clk(struct max310x_port *s, unsigned long freq,
535-
bool xtal)
534+
static int max310x_set_ref_clk(struct device *dev, struct max310x_port *s,
535+
unsigned long freq, bool xtal)
536536
{
537537
unsigned int div, clksrc, pllcfg = 0;
538538
long besterr = -1;
@@ -588,8 +588,14 @@ static int max310x_set_ref_clk(struct max310x_port *s, unsigned long freq,
588588
regmap_write(s->regmap, MAX310X_CLKSRC_REG, clksrc);
589589

590590
/* Wait for crystal */
591-
if (pllcfg && xtal)
591+
if (xtal) {
592+
unsigned int val;
592593
msleep(10);
594+
regmap_read(s->regmap, MAX310X_STS_IRQSTS_REG, &val);
595+
if (!(val & MAX310X_STS_CLKREADY_BIT)) {
596+
dev_warn(dev, "clock is not stable yet\n");
597+
}
598+
}
593599

594600
return (int)bestfreq;
595601
}
@@ -1260,7 +1266,7 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype,
12601266
MAX310X_MODE1_AUTOSLEEP_BIT);
12611267
}
12621268

1263-
uartclk = max310x_set_ref_clk(s, freq, xtal);
1269+
uartclk = max310x_set_ref_clk(dev, s, freq, xtal);
12641270
dev_dbg(dev, "Reference clock set to %i Hz\n", uartclk);
12651271

12661272
mutex_init(&s->mutex);

0 commit comments

Comments
 (0)