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 rtc_tm_to_time(&cur_rtc_tm, &cur_rtc_time);
29 diff = cur_rtc_time - suspend_rtc_time;
31 /* adjust time of day by seconds that elapsed while
32 * we were suspended */
34 ts.tv_sec = tv.tv_sec + diff;
35 ts.tv_nsec = tv.tv_usec * NSEC_PER_USEC;
41 static int timer_suspend(struct sys_device *dev, pm_message_t state)
43 struct rtc_time suspend_rtc_tm;
44 WARN_ON(!ppc_md.get_rtc_time);
46 get_rtc_time(&suspend_rtc_tm);
47 rtc_tm_to_time(&suspend_rtc_tm, &suspend_rtc_time);
52 static struct sysdev_class timer_sysclass = {
53 .resume = timer_resume,
54 .suspend = timer_suspend,
55 set_kset_name("timer"),
58 static struct sys_device device_timer = {
60 .cls = &timer_sysclass,
63 static int time_init_device(void)
65 int error = sysdev_class_register(&timer_sysclass);
67 error = sysdev_register(&device_timer);
71 device_initcall(time_init_device);