14 #include <linux/module.h>
15 #include <linux/rtc.h>
16 #include <linux/kdev_t.h>
18 #include <linux/slab.h>
27 static void rtc_device_release(
struct device *
dev)
34 #ifdef CONFIG_RTC_HCTOSYS_DEVICE
39 #if defined(CONFIG_PM) && defined(CONFIG_RTC_HCTOSYS_DEVICE)
45 static struct timespec old_rtc, old_system, old_delta;
53 if (
strcmp(dev_name(&rtc->
dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0)
68 delta = timespec_sub(old_system, old_rtc);
69 delta_delta = timespec_sub(
delta, old_delta);
70 if (delta_delta.tv_sec < -2 || delta_delta.tv_sec >= 2) {
78 old_system = timespec_sub(old_system, delta_delta);
92 if (
strcmp(dev_name(&rtc->
dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0)
99 pr_debug(
"%s: bogus resume time\n", dev_name(&rtc->
dev));
105 if (new_rtc.tv_sec < old_rtc.tv_sec) {
106 pr_debug(
"%s: time travel!\n", dev_name(&rtc->
dev));
111 sleep_time = timespec_sub(new_rtc, old_rtc);
120 sleep_time = timespec_sub(sleep_time,
121 timespec_sub(new_system, old_system));
123 if (sleep_time.tv_sec >= 0)
130 #define rtc_suspend NULL
131 #define rtc_resume NULL
171 rtc->
dev.release = rtc_device_release;
211 dev_info(dev,
"rtc core: registered %s as %s\n",
212 rtc->
name, dev_name(&rtc->
dev));
223 dev_err(dev,
"rtc core: unable to register %s, err = %d\n",
254 static int __init rtc_init(
void)
257 if (IS_ERR(rtc_class)) {
259 return PTR_ERR(rtc_class);
268 static void __exit rtc_exit(
void)