aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
authorBenoît Thébaudeau <benoit@wsystem.com>2016-07-21 06:41:31 -0400
committerAlexandre Belloni <alexandre.belloni@free-electrons.com>2016-07-28 03:59:41 -0400
commitd3700b6b6479d25c646f7c34a6295872322e6410 (patch)
treef50dc7bde007828d6284a1e79d20d4611da11049 /drivers/rtc
parentd522649e2686ec98eb03078583736fdcb4ef8880 (diff)
rtc: rv8803: Stop the clock while setting the time
According to the application manual of the RX8900, the RESET bit must be set to 1 to prevent a timer update while setting the time. This also resets the subsecond counter. The application manual of the RV-8803 does not mention such a requirement, and it says that the 100th Seconds register is cleared when writing to the Seconds register, but using the RESET bit for the RV-8803 too should not be an issue and is probably safer. This change also ensures that the RESET bit is initialized properly in all cases. Indeed, all the registers must be initialized if the voltage has been lower than VLOW2 (triggering V2F), but not low enough to trigger a POR. Signed-off-by: Benoît Thébaudeau <benoit@wsystem.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/rtc-rv8803.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/drivers/rtc/rtc-rv8803.c b/drivers/rtc/rtc-rv8803.c
index 09ab5cb1fa8a..24c688eec527 100644
--- a/drivers/rtc/rtc-rv8803.c
+++ b/drivers/rtc/rtc-rv8803.c
@@ -223,11 +223,21 @@ static int rv8803_set_time(struct device *dev, struct rtc_time *tm)
223{ 223{
224 struct rv8803_data *rv8803 = dev_get_drvdata(dev); 224 struct rv8803_data *rv8803 = dev_get_drvdata(dev);
225 u8 date[7]; 225 u8 date[7];
226 int flags, ret; 226 int ctrl, flags, ret;
227 227
228 if ((tm->tm_year < 100) || (tm->tm_year > 199)) 228 if ((tm->tm_year < 100) || (tm->tm_year > 199))
229 return -EINVAL; 229 return -EINVAL;
230 230
231 ctrl = rv8803_read_reg(rv8803->client, RV8803_CTRL);
232 if (ctrl < 0)
233 return ctrl;
234
235 /* Stop the clock */
236 ret = rv8803_write_reg(rv8803->client, RV8803_CTRL,
237 ctrl | RV8803_CTRL_RESET);
238 if (ret)
239 return ret;
240
231 date[RV8803_SEC] = bin2bcd(tm->tm_sec); 241 date[RV8803_SEC] = bin2bcd(tm->tm_sec);
232 date[RV8803_MIN] = bin2bcd(tm->tm_min); 242 date[RV8803_MIN] = bin2bcd(tm->tm_min);
233 date[RV8803_HOUR] = bin2bcd(tm->tm_hour); 243 date[RV8803_HOUR] = bin2bcd(tm->tm_hour);
@@ -240,6 +250,12 @@ static int rv8803_set_time(struct device *dev, struct rtc_time *tm)
240 if (ret) 250 if (ret)
241 return ret; 251 return ret;
242 252
253 /* Restart the clock */
254 ret = rv8803_write_reg(rv8803->client, RV8803_CTRL,
255 ctrl & ~RV8803_CTRL_RESET);
256 if (ret)
257 return ret;
258
243 mutex_lock(&rv8803->flags_lock); 259 mutex_lock(&rv8803->flags_lock);
244 260
245 flags = rv8803_read_reg(rv8803->client, RV8803_FLAG); 261 flags = rv8803_read_reg(rv8803->client, RV8803_FLAG);