aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Zhong <zyw@rock-chips.com>2015-02-13 17:40:54 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-02-14 00:21:43 -0500
commitc412c6034aaf38ff718296f3b77cb8e76b541985 (patch)
tree8714c27538a638e3a927609b9a6d4bf195aa7cef
parent1ef2816f26a1d962d6317f7545218fa2ae3643bb (diff)
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 [akpm@linux-foundation.org: tweak comment per review discussion] Signed-off-by: Chris Zhong <zyw@rock-chips.com> Reviewed-by: Doug Anderson <dianders@chromium.org> Cc: Sonny Rao <sonnyrao@chromium.org> Cc: Heiko Stübner <heiko@sntech.de> Cc: Alessandro Zummo <a.zummo@towertech.it> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/rtc/rtc-rk808.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/drivers/rtc/rtc-rk808.c b/drivers/rtc/rtc-rk808.c
index df42257668ac..91ca0bc1b484 100644
--- a/drivers/rtc/rtc-rk808.c
+++ b/drivers/rtc/rtc-rk808.c
@@ -67,15 +67,21 @@ static int rk808_rtc_readtime(struct device *dev, struct rtc_time *tm)
67 /* Force an update of the shadowed registers right now */ 67 /* Force an update of the shadowed registers right now */
68 ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG, 68 ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
69 BIT_RTC_CTRL_REG_RTC_GET_TIME, 69 BIT_RTC_CTRL_REG_RTC_GET_TIME,
70 0); 70 BIT_RTC_CTRL_REG_RTC_GET_TIME);
71 if (ret) { 71 if (ret) {
72 dev_err(dev, "Failed to update bits rtc_ctrl: %d\n", ret); 72 dev_err(dev, "Failed to update bits rtc_ctrl: %d\n", ret);
73 return ret; 73 return ret;
74 } 74 }
75 75
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 */
76 ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG, 82 ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
77 BIT_RTC_CTRL_REG_RTC_GET_TIME, 83 BIT_RTC_CTRL_REG_RTC_GET_TIME,
78 BIT_RTC_CTRL_REG_RTC_GET_TIME); 84 0);
79 if (ret) { 85 if (ret) {
80 dev_err(dev, "Failed to update bits rtc_ctrl: %d\n", ret); 86 dev_err(dev, "Failed to update bits rtc_ctrl: %d\n", ret);
81 return ret; 87 return ret;