2 * Common code to keep time when machine suspends.
4 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
9 #include <linux/time.h>
10 #include <linux/sysdev.h>
13 static unsigned long suspend_rtc_time;
16 * Reset the time after a sleep.
18 static int timer_resume(struct sys_device *dev)
22 struct rtc_time cur_rtc_tm;
23 unsigned long cur_rtc_time, diff;
25 /* get current RTC time and convert to seconds */
26 get_rtc_time(&cur_rtc_tm);
27 cur_rtc_time = mktime(cur_rtc_tm.tm_year + 1900,
28 cur_rtc_tm.tm_mon + 1,
34 diff = cur_rtc_time - suspend_rtc_time;
36 /* adjust time of day by seconds that elapsed while
37 * we were suspended */
39 ts.tv_sec = tv.tv_sec + diff;
40 ts.tv_nsec = tv.tv_usec * NSEC_PER_USEC;
46 static int timer_suspend(struct sys_device *dev, pm_message_t state)
48 struct rtc_time suspend_rtc_tm;
49 WARN_ON(!ppc_md.get_rtc_time);
51 get_rtc_time(&suspend_rtc_tm);
52 suspend_rtc_time = mktime(suspend_rtc_tm.tm_year + 1900,
53 suspend_rtc_tm.tm_mon + 1,
54 suspend_rtc_tm.tm_mday,
55 suspend_rtc_tm.tm_hour,
56 suspend_rtc_tm.tm_min,
57 suspend_rtc_tm.tm_sec);
62 static struct sysdev_class timer_sysclass = {
63 .resume = timer_resume,
64 .suspend = timer_suspend,
65 set_kset_name("timer"),
68 static struct sys_device device_timer = {
70 .cls = &timer_sysclass,
73 static int time_init_device(void)
75 int error = sysdev_class_register(&timer_sysclass);
77 error = sysdev_register(&device_timer);
81 device_initcall(time_init_device);