aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/rtc-rs5c313.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rtc/rtc-rs5c313.c')
-rw-r--r--drivers/rtc/rtc-rs5c313.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/drivers/rtc/rtc-rs5c313.c b/drivers/rtc/rtc-rs5c313.c
index 9d6de371495b..66eb133bf5fd 100644
--- a/drivers/rtc/rtc-rs5c313.c
+++ b/drivers/rtc/rtc-rs5c313.c
@@ -126,7 +126,7 @@ static void rs5c313_write_data(unsigned char data)
126static unsigned char rs5c313_read_data(void) 126static unsigned char rs5c313_read_data(void)
127{ 127{
128 int i; 128 int i;
129 unsigned char data; 129 unsigned char data = 0;
130 130
131 for (i = 0; i < 8; i++) { 131 for (i = 0; i < 8; i++) {
132 ndelay(700); 132 ndelay(700);
@@ -194,7 +194,7 @@ static void rs5c313_write_reg(unsigned char addr, unsigned char data)
194 return; 194 return;
195} 195}
196 196
197static inline unsigned char rs5c313_read_cntreg(unsigned char addr) 197static inline unsigned char rs5c313_read_cntreg(void)
198{ 198{
199 return rs5c313_read_reg(RS5C313_ADDR_CNTREG); 199 return rs5c313_read_reg(RS5C313_ADDR_CNTREG);
200} 200}
@@ -212,7 +212,9 @@ static inline void rs5c313_write_intintvreg(unsigned char data)
212static int rs5c313_rtc_read_time(struct device *dev, struct rtc_time *tm) 212static int rs5c313_rtc_read_time(struct device *dev, struct rtc_time *tm)
213{ 213{
214 int data; 214 int data;
215 int cnt;
215 216
217 cnt = 0;
216 while (1) { 218 while (1) {
217 RS5C313_CEENABLE; /* CE:H */ 219 RS5C313_CEENABLE; /* CE:H */
218 220
@@ -225,6 +227,10 @@ static int rs5c313_rtc_read_time(struct device *dev, struct rtc_time *tm)
225 RS5C313_CEDISABLE; 227 RS5C313_CEDISABLE;
226 ndelay(700); /* CE:L */ 228 ndelay(700); /* CE:L */
227 229
230 if (cnt++ > 100) {
231 dev_err(dev, "%s: timeout error\n", __FUNCTION__);
232 return -EIO;
233 }
228 } 234 }
229 235
230 data = rs5c313_read_reg(RS5C313_ADDR_SEC); 236 data = rs5c313_read_reg(RS5C313_ADDR_SEC);
@@ -266,7 +272,9 @@ static int rs5c313_rtc_read_time(struct device *dev, struct rtc_time *tm)
266static int rs5c313_rtc_set_time(struct device *dev, struct rtc_time *tm) 272static int rs5c313_rtc_set_time(struct device *dev, struct rtc_time *tm)
267{ 273{
268 int data; 274 int data;
275 int cnt;
269 276
277 cnt = 0;
270 /* busy check. */ 278 /* busy check. */
271 while (1) { 279 while (1) {
272 RS5C313_CEENABLE; /* CE:H */ 280 RS5C313_CEENABLE; /* CE:H */
@@ -279,6 +287,11 @@ static int rs5c313_rtc_set_time(struct device *dev, struct rtc_time *tm)
279 RS5C313_MISCOP; 287 RS5C313_MISCOP;
280 RS5C313_CEDISABLE; 288 RS5C313_CEDISABLE;
281 ndelay(700); /* CE:L */ 289 ndelay(700); /* CE:L */
290
291 if (cnt++ > 100) {
292 dev_err(dev, "%s: timeout error\n", __FUNCTION__);
293 return -EIO;
294 }
282 } 295 }
283 296
284 data = BIN2BCD(tm->tm_sec); 297 data = BIN2BCD(tm->tm_sec);
@@ -317,6 +330,7 @@ static int rs5c313_rtc_set_time(struct device *dev, struct rtc_time *tm)
317static void rs5c313_check_xstp_bit(void) 330static void rs5c313_check_xstp_bit(void)
318{ 331{
319 struct rtc_time tm; 332 struct rtc_time tm;
333 int cnt;
320 334
321 RS5C313_CEENABLE; /* CE:H */ 335 RS5C313_CEENABLE; /* CE:H */
322 if (rs5c313_read_cntreg() & RS5C313_CNTREG_WTEN_XSTP) { 336 if (rs5c313_read_cntreg() & RS5C313_CNTREG_WTEN_XSTP) {
@@ -326,12 +340,16 @@ static void rs5c313_check_xstp_bit(void)
326 rs5c313_write_cntreg(0x07); 340 rs5c313_write_cntreg(0x07);
327 341
328 /* busy check. */ 342 /* busy check. */
329 while (rs5c313_read_cntreg() & RS5C313_CNTREG_ADJ_BSY) 343 for (cnt = 0; cnt < 100; cnt++) {
344 if (!(rs5c313_read_cntreg() & RS5C313_CNTREG_ADJ_BSY))
345 break;
330 RS5C313_MISCOP; 346 RS5C313_MISCOP;
347 }
331 348
332 memset(&tm, 0, sizeof(struct rtc_time)); 349 memset(&tm, 0, sizeof(struct rtc_time));
333 tm.tm_mday = 1; 350 tm.tm_mday = 1;
334 tm.tm_mon = 1; 351 tm.tm_mon = 1 - 1;
352 tm.tm_year = 2000 - 1900;
335 353
336 rs5c313_rtc_set_time(NULL, &tm); 354 rs5c313_rtc_set_time(NULL, &tm);
337 printk(KERN_ERR "RICHO RS5C313: invalid value, resetting to " 355 printk(KERN_ERR "RICHO RS5C313: invalid value, resetting to "
@@ -356,7 +374,7 @@ static int rs5c313_rtc_probe(struct platform_device *pdev)
356 374
357 platform_set_drvdata(pdev, rtc); 375 platform_set_drvdata(pdev, rtc);
358 376
359 return err; 377 return 0;
360} 378}
361 379
362static int __devexit rs5c313_rtc_remove(struct platform_device *pdev) 380static int __devexit rs5c313_rtc_remove(struct platform_device *pdev)