aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/rtc-sh.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rtc/rtc-sh.c')
-rw-r--r--drivers/rtc/rtc-sh.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c
index 1d3de2a3d1a4..579b3ff5c644 100644
--- a/drivers/rtc/rtc-sh.c
+++ b/drivers/rtc/rtc-sh.c
@@ -276,6 +276,9 @@ static int sh_rtc_read_time(struct device *dev, struct rtc_time *tm)
276 struct sh_rtc *rtc = dev_get_drvdata(dev); 276 struct sh_rtc *rtc = dev_get_drvdata(dev);
277 unsigned int sec128, sec2, yr, yr100, cf_bit; 277 unsigned int sec128, sec2, yr, yr100, cf_bit;
278 278
279 if (!(readb(rtc->regbase + RCR2) & RCR2_RTCEN))
280 return -EINVAL;
281
279 do { 282 do {
280 unsigned int tmp; 283 unsigned int tmp;
281 284
@@ -466,7 +469,6 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
466{ 469{
467 struct sh_rtc *rtc; 470 struct sh_rtc *rtc;
468 struct resource *res; 471 struct resource *res;
469 struct rtc_time r;
470 char clk_name[6]; 472 char clk_name[6];
471 int clk_id, ret; 473 int clk_id, ret;
472 474
@@ -528,6 +530,10 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
528 rtc->clk = NULL; 530 rtc->clk = NULL;
529 } 531 }
530 532
533 rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
534 if (IS_ERR(rtc->rtc_dev))
535 return PTR_ERR(rtc->rtc_dev);
536
531 clk_enable(rtc->clk); 537 clk_enable(rtc->clk);
532 538
533 rtc->capabilities = RTC_DEF_CAPABILITIES; 539 rtc->capabilities = RTC_DEF_CAPABILITIES;
@@ -591,21 +597,21 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
591 sh_rtc_setaie(&pdev->dev, 0); 597 sh_rtc_setaie(&pdev->dev, 0);
592 sh_rtc_setcie(&pdev->dev, 0); 598 sh_rtc_setcie(&pdev->dev, 0);
593 599
594 rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, "sh", 600 rtc->rtc_dev->ops = &sh_rtc_ops;
595 &sh_rtc_ops, THIS_MODULE);
596 if (IS_ERR(rtc->rtc_dev)) {
597 ret = PTR_ERR(rtc->rtc_dev);
598 goto err_unmap;
599 }
600
601 rtc->rtc_dev->max_user_freq = 256; 601 rtc->rtc_dev->max_user_freq = 256;
602 602
603 /* reset rtc to epoch 0 if time is invalid */ 603 if (rtc->capabilities & RTC_CAP_4_DIGIT_YEAR) {
604 if (rtc_read_time(rtc->rtc_dev, &r) < 0) { 604 rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_1900;
605 rtc_time_to_tm(0, &r); 605 rtc->rtc_dev->range_max = RTC_TIMESTAMP_END_9999;
606 rtc_set_time(rtc->rtc_dev, &r); 606 } else {
607 rtc->rtc_dev->range_min = mktime64(1999, 1, 1, 0, 0, 0);
608 rtc->rtc_dev->range_max = mktime64(2098, 12, 31, 23, 59, 59);
607 } 609 }
608 610
611 ret = rtc_register_device(rtc->rtc_dev);
612 if (ret)
613 goto err_unmap;
614
609 device_init_wakeup(&pdev->dev, 1); 615 device_init_wakeup(&pdev->dev, 1);
610 return 0; 616 return 0;
611 617