Skip to content

Commit c412c60

Browse files
zywang33torvalds
authored andcommitted
drivers/rtc/rtc-rk808.c: fix rtc time reading issue
After we set the GET_TIME bit, the rtc time can't be read immediately. We should wait up to 31.25 us, about one cycle of 32khz. Otherwise reading RTC time will return a old time. If we clear the GET_TIME bit after setting, the time of i2c transfer is certainly more than 31.25us. Doug said: : I think we are safe. At 400kHz (the max speed of this part) each bit can : be transferred no faster than 2.5us. In order to do a valid i2c : transaction we need to _at least_ write the address of the device and the : data onto the bus, which is 16 bits. 16 * 2.5us = 40us. That's above the : 31.25us [[email protected]: tweak comment per review discussion] Signed-off-by: Chris Zhong <[email protected]> Reviewed-by: Doug Anderson <[email protected]> Cc: Sonny Rao <[email protected]> Cc: Heiko Stübner <[email protected]> Cc: Alessandro Zummo <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 1ef2816 commit c412c60

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

drivers/rtc/rtc-rk808.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,21 @@ static int rk808_rtc_readtime(struct device *dev, struct rtc_time *tm)
6767
/* Force an update of the shadowed registers right now */
6868
ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
6969
BIT_RTC_CTRL_REG_RTC_GET_TIME,
70-
0);
70+
BIT_RTC_CTRL_REG_RTC_GET_TIME);
7171
if (ret) {
7272
dev_err(dev, "Failed to update bits rtc_ctrl: %d\n", ret);
7373
return ret;
7474
}
7575

76+
/*
77+
* After we set the GET_TIME bit, the rtc time can't be read
78+
* immediately. So we should wait up to 31.25 us, about one cycle of
79+
* 32khz. If we clear the GET_TIME bit here, the time of i2c transfer
80+
* certainly more than 31.25us: 16 * 2.5us at 400kHz bus frequency.
81+
*/
7682
ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
7783
BIT_RTC_CTRL_REG_RTC_GET_TIME,
78-
BIT_RTC_CTRL_REG_RTC_GET_TIME);
84+
0);
7985
if (ret) {
8086
dev_err(dev, "Failed to update bits rtc_ctrl: %d\n", ret);
8187
return ret;

0 commit comments

Comments
 (0)