Skip to content

Commit a11b6c4

Browse files
Villemoesalexandrebelloni
authored andcommitted
rtc: isl12022: trigger battery level detection during probe
Since the meaning of the SR_LBAT85 and SR_LBAT75 bits are different in battery backup mode, they may very well be set after power on, and stay set for up to a minute (i.e. until the battery detection in VDD mode happens when the seconds counter hits 59). This would mean that userspace doing a ioctl(RTC_VL_READ) early on could get a false positive. The battery level detection can also be triggered by explicitly writing a 1 to the TSE bit in the BETA register. Do that once during boot. Empirically, this does not immediately update the bits in the status register (i.e., an immediate read of SR after this write can still show stale values), but the update is done after a few milliseconds, so certainly before the RTC device gets registered and userspace has a chance of doing the ioctl() on this device. Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Link: https://lore.kernel.org/r/20230615105826.411953-7-linux@rasmusvillemoes.dk Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent eccebd8 commit a11b6c4

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

drivers/rtc/rtc-isl12022.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,16 @@ static void isl12022_set_trip_levels(struct device *dev)
272272
ret = regmap_update_bits(regmap, ISL12022_REG_PWR_VBAT, mask, val);
273273
if (ret)
274274
dev_warn(dev, "unable to set battery alarm levels: %d\n", ret);
275+
276+
/*
277+
* Force a write of the TSE bit in the BETA register, in order
278+
* to trigger an update of the LBAT75 and LBAT85 bits in the
279+
* status register. In battery backup mode, those bits have
280+
* another meaning, so without this, they may contain stale
281+
* values for up to a minute after power-on.
282+
*/
283+
regmap_write_bits(regmap, ISL12022_REG_BETA,
284+
ISL12022_BETA_TSE, ISL12022_BETA_TSE);
275285
}
276286

277287
static int isl12022_probe(struct i2c_client *client)

0 commit comments

Comments
 (0)