RTC: RK808: fix the rtc time reading issue
PATCH 1/1 RTC: RK808: fix the rtc time reading issue
After we set the GET_TIME bit, the rtc time couldn'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 clear the GET_TIME bit after setting, the time of i2c transfer certainly more than 31.25us.
---
drivers/rtc/rtc-rk808.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/rtc/rtc-rk808.c +7 -2
@@ -67,15 +67,20 @@ static int rk808_rtc_readtime(struct device *dev, struct rtc_time *tm)/* Force an update of the shadowed registers right now */ ret =regmap_update_bits (rk808->regmap,RK808_RTC_CTRL_REG ,BIT_RTC_CTRL_REG_RTC_GET_TIME , -0 ); +BIT_RTC_CTRL_REG_RTC_GET_TIME );if (ret) {dev_err (dev,"Failed to update bits rtc_ctrl: %d\n" , ret);return ret; } +/* After we set the GET_TIME bit, the rtc time couldn't be read +* immediately, we should wait up to 31.25 us, about one cycle of +* 32khz. If we clear the GET_TIME bit here, the time of i2c transfer +* certainly more than 31.25us. +*/ ret =regmap_update_bits (rk808->regmap,RK808_RTC_CTRL_REG ,BIT_RTC_CTRL_REG_RTC_GET_TIME , -BIT_RTC_CTRL_REG_RTC_GET_TIME ); +0 );if (ret) {dev_err (dev,"Failed to update bits rtc_ctrl: %d\n" , ret);return ret;
Signature · 1 line
1.9.1
Quoted 22 lines · Chris Zhong
After we set the
GET_TIMEbit, the rtc time couldn'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 clear theGET_TIMEbit after setting, the time of i2c transfer certainly more than 31.25us.Signed-off-by Chris Zhong <[email protected]>---
drivers/rtc/rtc-rk808.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)drivers/rtc/rtc-rk808.c +1
-1@@ -67,15 +67,20 @@ static int rk808_rtc_readtime(struct device *dev, struct rtc_time *tm)/* Force an update of the shadowed registers right now */ ret =regmap_update_bits (rk808->regmap,RK808_RTC_CTRL_REG ,BIT_RTC_CTRL_REG_RTC_GET_TIME , -0 ); +BIT_RTC_CTRL_REG_RTC_GET_TIME );
drivers/rtc/rtc-rk808.c static int rk808_rtc_readtime(struct device *dev, struct rtc_time *tm) · line 80
Quoted 10 lines
drivers/rtc/rtc-rk808.c +5
-0if (ret) {dev_err (dev,"Failed to update bits rtc_ctrl: %d\n" , ret);return ret; } +/* After we set the GET_TIME bit, the rtc time couldn't be read +* immediately, we should wait up to 31.25 us, about one cycle of +* 32khz. If we clear the GET_TIME bit here, the time of i2c transfer +* certainly more than 31.25us. +*/
Chris, it looks like you swapped the set and the clear of this bit, and you're relying on the fact that the i2c transaction takes a
certain amount of time after the RTC_GET_TIME BIT is set. I'm not
sure how long it actually takes, but why not just put in a usleep() for the minimum wait time?
Quoted 15 lines
drivers/rtc/rtc-rk808.c +1
-2ret =regmap_update_bits (rk808->regmap,RK808_RTC_CTRL_REG ,BIT_RTC_CTRL_REG_RTC_GET_TIME , -BIT_RTC_CTRL_REG_RTC_GET_TIME ); +0 );if (ret) {dev_err (dev,"Failed to update bits rtc_ctrl: %d\n" , ret);return ret; --1.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Sonny,
Quoted 5 lines
Chris, it looks like you swapped the set and the clear of this bit, and you're relying on the fact that the i2c transaction takes a
certain amount of time after theRTC_GET_TIMEBIT is set. I'm not
sure how long it actually takes, but why not just put in ausleep()for the minimum wait time?
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
Personally I think what Chris has is fine, with the comment.
-Doug
Quoted 8 lines · Doug Anderson
Sonny,
Quoted 5 lines
Chris, it looks like you swapped the set and the clear of this bit, and you're relying on the fact that the i2c transaction takes a
certain amount of time after theRTC_GET_TIMEBIT is set. I'm not
sure how long it actually takes, but why not just put in ausleep()for the minimum wait time?
Quoted 8 lines
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
_atleast_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.25usPersonally I think what Chris has is fine, with the comment.
Ok, I'm fine with that if we're sure it's slow enough. Comment explaining would certainly help.
Quoted 2 lines
-Doug
Quoted 16 lines · On Wed, 14 Jan 2015 11:44:02 -0800 Sonny Rao <[email protected]> wrote:
Quoted 15 lines · Doug Anderson
Sonny,
Quoted 5 lines
Chris, it looks like you swapped the set and the clear of this bit, and you're relying on the fact that the i2c transaction takes a
certain amount of time after theRTC_GET_TIMEBIT is set. I'm not
sure how long it actually takes, but why not just put in ausleep()for the minimum wait time?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
_atleast_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
Quoted 4 lines
Quoted 1 line
Personally I think what Chris has is fine, with the comment.
Ok, I'm fine with that if we're sure it's slow enough. Comment explaining would certainly help.
Thanks, all. I did this:
drivers/rtc/rtc-rk808.c renamed from drivers/rtc/rtc-rk808.c~rtc-rk808-fix-the-rtc-time-reading-issue-fix +4 -3
@@ -73,10 +73,11 @@ static int rk808_rtc_readtime(struct devreturn ret; } -/* After we set the GET_TIME bit, the rtc time couldn't be read -* immediately, we should wait up to 31.25 us, about one cycle of +/* +* After we set the GET_TIME bit, the rtc time can't be read +* immediately. So we should wait up to 31.25 us, about one cycle of * 32khz. If we clear the GET_TIME bit here, the time of i2c transfer -* certainly more than 31.25us. +* certainly more than 31.25us: 16 * 2.5us at 400kHz bus frequency. */ ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG, BIT_RTC_CTRL_REG_RTC_GET_TIME,
_
Andrew,
Quoted 32 lines · Andrew Morton
Quoted 16 lines · On Wed, 14 Jan 2015 11:44:02 -0800 Sonny Rao <[email protected]> wrote:
Quoted 15 lines · Doug Anderson
Sonny,
Quoted 5 lines
Chris, it looks like you swapped the set and the clear of this bit, and you're relying on the fact that the i2c transaction takes a
certain amount of time after theRTC_GET_TIMEBIT is set. I'm not
sure how long it actually takes, but why not just put in ausleep()for the minimum wait time?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
_atleast_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.25usQuoted 4 lines
Quoted 1 line
Personally I think what Chris has is fine, with the comment.
Ok, I'm fine with that if we're sure it's slow enough. Comment explaining would certainly help.
Thanks, all. I did this:
drivers/rtc/rtc-rk808.c renamed from drivers/rtc/rtc-rk808.c~rtc-rk808-fix-the-rtc-time-reading-issue-fix +0
-1@@ -73,10 +73,11 @@ static int rk808_rtc_readtime(struct devreturn ret; } -/* After we set the GET_TIME bit, the rtc time couldn't be read
drivers/rtc/rtc-rk808.c static int rk808_rtc_readtime(struct dev · line 83
Quoted 10 lines
drivers/rtc/rtc-rk808.c renamed from drivers/rtc/rtc-rk808.c~rtc-rk808-fix-the-rtc-time-reading-issue-fix +4
-2-* immediately, we should wait up to 31.25 us, about one cycle of +/* +* After we set the GET_TIME bit, the rtc time can't be read +* immediately. So we should wait up to 31.25 us, about one cycle of * 32khz. If we clear the GET_TIME bit here, the time of i2c transfer -* certainly more than 31.25us. +* certainly more than 31.25us: 16 * 2.5us at 400kHz bus frequency. */ ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG, BIT_RTC_CTRL_REG_RTC_GET_TIME,
Looks great to me, thanks.
-Doug
Chris,
drivers/rtc/rtc-rk808.c static int rk808_rtc_readtime(struct device *dev, struct rtc_time *tm) · line 80
Quoted 5 lines · Chris Zhong
drivers/rtc/rtc-rk808.c +5
-0+/* After we set the GET_TIME bit, the rtc time couldn't be read +* immediately, we should wait up to 31.25 us, about one cycle of +* 32khz. If we clear the GET_TIME bit here, the time of i2c transfer +* certainly more than 31.25us. +*/
No idea what Andrew thinks of this, but other multiline comments in this file look slightly different (there's a line containing just /*).
drivers/rtc/rtc-rk808.c static int rk808_rtc_readtime(struct device *dev, struct rtc_time *tm) · line 86
Quoted 7 lines
ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG, BIT_RTC_CTRL_REG_RTC_GET_TIME,drivers/rtc/rtc-rk808.c +1
-1- BIT_RTC_CTRL_REG_RTC_GET_TIME); + 0);if (ret) {dev_err (dev,"Failed to update bits rtc_ctrl: %d\n" , ret);return ret;
Above is just a nit. I'll leave it up to Andrew to say whether he wants you to spin, or he'll fix it up, or he doesn't care and he'll land it as-is.