mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-09-18 22:14:16 +00:00
rtc: bq32k: Fix handling of oscillator failure flag
While the oscillator failure flag is set, the RTC registers should be considered invalid. bq32k_rtc_read_time() now returns an error instead of an invalid time. The failure flag is cleared the next time the clock is set. Signed-off-by: Jan Östlund <jao@hms.se> Signed-off-by: Daniel Romell <daro@hms.se> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
This commit is contained in:
parent
6ed1a51e0b
commit
421a5ba24b
1 changed files with 9 additions and 5 deletions
|
@ -93,6 +93,13 @@ static int bq32k_rtc_read_time(struct device *dev, struct rtc_time *tm)
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* In case of oscillator failure, the register contents should be
|
||||||
|
* considered invalid. The flag is cleared the next time the RTC is set.
|
||||||
|
*/
|
||||||
|
if (regs.minutes & BQ32K_OF)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
tm->tm_sec = bcd2bin(regs.seconds & BQ32K_SECONDS_MASK);
|
tm->tm_sec = bcd2bin(regs.seconds & BQ32K_SECONDS_MASK);
|
||||||
tm->tm_min = bcd2bin(regs.minutes & BQ32K_MINUTES_MASK);
|
tm->tm_min = bcd2bin(regs.minutes & BQ32K_MINUTES_MASK);
|
||||||
tm->tm_hour = bcd2bin(regs.cent_hours & BQ32K_HOURS_MASK);
|
tm->tm_hour = bcd2bin(regs.cent_hours & BQ32K_HOURS_MASK);
|
||||||
|
@ -204,13 +211,10 @@ static int bq32k_probe(struct i2c_client *client,
|
||||||
|
|
||||||
/* Check Oscillator Failure flag */
|
/* Check Oscillator Failure flag */
|
||||||
error = bq32k_read(dev, ®, BQ32K_MINUTES, 1);
|
error = bq32k_read(dev, ®, BQ32K_MINUTES, 1);
|
||||||
if (!error && (reg & BQ32K_OF)) {
|
|
||||||
dev_warn(dev, "Oscillator Failure. Check RTC battery.\n");
|
|
||||||
reg &= ~BQ32K_OF;
|
|
||||||
error = bq32k_write(dev, ®, BQ32K_MINUTES, 1);
|
|
||||||
}
|
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
|
if (reg & BQ32K_OF)
|
||||||
|
dev_warn(dev, "Oscillator Failure. Check RTC battery.\n");
|
||||||
|
|
||||||
if (client->dev.of_node)
|
if (client->dev.of_node)
|
||||||
trickle_charger_of_init(dev, client->dev.of_node);
|
trickle_charger_of_init(dev, client->dev.of_node);
|
||||||
|
|
Loading…
Add table
Reference in a new issue