aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
authorOlof Johansson <olof@lixom.net>2011-12-16 01:02:34 -0500
committerOlof Johansson <olof@lixom.net>2011-12-16 01:02:34 -0500
commit02735a29d8ce882ec698803f064e17888874780c (patch)
tree6a4afa3bc8b6d4334df24910a56f77adf126b0c7 /drivers/rtc
parent8d685b7f4d9c9882442bf1b492558d5f17b694fa (diff)
parent3d911ad22e8405c1a333a6812e405cb1a5ae9829 (diff)
Merge branch 'at91/defconfig' into next/cleanup
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/class.c10
-rw-r--r--drivers/rtc/interface.c44
-rw-r--r--drivers/rtc/rtc-s3c.c2
3 files changed, 40 insertions, 16 deletions
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index e8326f26fa2f..dc4c2748bbc3 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -63,7 +63,7 @@ static int rtc_suspend(struct device *dev, pm_message_t mesg)
63 */ 63 */
64 delta = timespec_sub(old_system, old_rtc); 64 delta = timespec_sub(old_system, old_rtc);
65 delta_delta = timespec_sub(delta, old_delta); 65 delta_delta = timespec_sub(delta, old_delta);
66 if (abs(delta_delta.tv_sec) >= 2) { 66 if (delta_delta.tv_sec < -2 || delta_delta.tv_sec >= 2) {
67 /* 67 /*
68 * if delta_delta is too large, assume time correction 68 * if delta_delta is too large, assume time correction
69 * has occured and set old_delta to the current delta. 69 * has occured and set old_delta to the current delta.
@@ -97,9 +97,8 @@ static int rtc_resume(struct device *dev)
97 rtc_tm_to_time(&tm, &new_rtc.tv_sec); 97 rtc_tm_to_time(&tm, &new_rtc.tv_sec);
98 new_rtc.tv_nsec = 0; 98 new_rtc.tv_nsec = 0;
99 99
100 if (new_rtc.tv_sec <= old_rtc.tv_sec) { 100 if (new_rtc.tv_sec < old_rtc.tv_sec) {
101 if (new_rtc.tv_sec < old_rtc.tv_sec) 101 pr_debug("%s: time travel!\n", dev_name(&rtc->dev));
102 pr_debug("%s: time travel!\n", dev_name(&rtc->dev));
103 return 0; 102 return 0;
104 } 103 }
105 104
@@ -116,7 +115,8 @@ static int rtc_resume(struct device *dev)
116 sleep_time = timespec_sub(sleep_time, 115 sleep_time = timespec_sub(sleep_time,
117 timespec_sub(new_system, old_system)); 116 timespec_sub(new_system, old_system));
118 117
119 timekeeping_inject_sleeptime(&sleep_time); 118 if (sleep_time.tv_sec >= 0)
119 timekeeping_inject_sleeptime(&sleep_time);
120 return 0; 120 return 0;
121} 121}
122 122
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 8e286259a007..fa4d9f324189 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -319,6 +319,20 @@ int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
319} 319}
320EXPORT_SYMBOL_GPL(rtc_read_alarm); 320EXPORT_SYMBOL_GPL(rtc_read_alarm);
321 321
322static int ___rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
323{
324 int err;
325
326 if (!rtc->ops)
327 err = -ENODEV;
328 else if (!rtc->ops->set_alarm)
329 err = -EINVAL;
330 else
331 err = rtc->ops->set_alarm(rtc->dev.parent, alarm);
332
333 return err;
334}
335
322static int __rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) 336static int __rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
323{ 337{
324 struct rtc_time tm; 338 struct rtc_time tm;
@@ -342,14 +356,7 @@ static int __rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
342 * over right here, before we set the alarm. 356 * over right here, before we set the alarm.
343 */ 357 */
344 358
345 if (!rtc->ops) 359 return ___rtc_set_alarm(rtc, alarm);
346 err = -ENODEV;
347 else if (!rtc->ops->set_alarm)
348 err = -EINVAL;
349 else
350 err = rtc->ops->set_alarm(rtc->dev.parent, alarm);
351
352 return err;
353} 360}
354 361
355int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) 362int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
@@ -763,6 +770,20 @@ static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer)
763 return 0; 770 return 0;
764} 771}
765 772
773static void rtc_alarm_disable(struct rtc_device *rtc)
774{
775 struct rtc_wkalrm alarm;
776 struct rtc_time tm;
777
778 __rtc_read_time(rtc, &tm);
779
780 alarm.time = rtc_ktime_to_tm(ktime_add(rtc_tm_to_ktime(tm),
781 ktime_set(300, 0)));
782 alarm.enabled = 0;
783
784 ___rtc_set_alarm(rtc, &alarm);
785}
786
766/** 787/**
767 * rtc_timer_remove - Removes a rtc_timer from the rtc_device timerqueue 788 * rtc_timer_remove - Removes a rtc_timer from the rtc_device timerqueue
768 * @rtc rtc device 789 * @rtc rtc device
@@ -784,8 +805,10 @@ static void rtc_timer_remove(struct rtc_device *rtc, struct rtc_timer *timer)
784 struct rtc_wkalrm alarm; 805 struct rtc_wkalrm alarm;
785 int err; 806 int err;
786 next = timerqueue_getnext(&rtc->timerqueue); 807 next = timerqueue_getnext(&rtc->timerqueue);
787 if (!next) 808 if (!next) {
809 rtc_alarm_disable(rtc);
788 return; 810 return;
811 }
789 alarm.time = rtc_ktime_to_tm(next->expires); 812 alarm.time = rtc_ktime_to_tm(next->expires);
790 alarm.enabled = 1; 813 alarm.enabled = 1;
791 err = __rtc_set_alarm(rtc, &alarm); 814 err = __rtc_set_alarm(rtc, &alarm);
@@ -847,7 +870,8 @@ again:
847 err = __rtc_set_alarm(rtc, &alarm); 870 err = __rtc_set_alarm(rtc, &alarm);
848 if (err == -ETIME) 871 if (err == -ETIME)
849 goto again; 872 goto again;
850 } 873 } else
874 rtc_alarm_disable(rtc);
851 875
852 mutex_unlock(&rtc->ops_lock); 876 mutex_unlock(&rtc->ops_lock);
853} 877}
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index 7639ab906f02..5b979d9cc332 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -202,7 +202,6 @@ static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
202 void __iomem *base = s3c_rtc_base; 202 void __iomem *base = s3c_rtc_base;
203 int year = tm->tm_year - 100; 203 int year = tm->tm_year - 100;
204 204
205 clk_enable(rtc_clk);
206 pr_debug("set time %04d.%02d.%02d %02d:%02d:%02d\n", 205 pr_debug("set time %04d.%02d.%02d %02d:%02d:%02d\n",
207 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday, 206 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
208 tm->tm_hour, tm->tm_min, tm->tm_sec); 207 tm->tm_hour, tm->tm_min, tm->tm_sec);
@@ -214,6 +213,7 @@ static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
214 return -EINVAL; 213 return -EINVAL;
215 } 214 }
216 215
216 clk_enable(rtc_clk);
217 writeb(bin2bcd(tm->tm_sec), base + S3C2410_RTCSEC); 217 writeb(bin2bcd(tm->tm_sec), base + S3C2410_RTCSEC);
218 writeb(bin2bcd(tm->tm_min), base + S3C2410_RTCMIN); 218 writeb(bin2bcd(tm->tm_min), base + S3C2410_RTCMIN);
219 writeb(bin2bcd(tm->tm_hour), base + S3C2410_RTCHOUR); 219 writeb(bin2bcd(tm->tm_hour), base + S3C2410_RTCHOUR);