allow coexistance of N build and AC build.
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / arch / powerpc / sysdev / timer.c
blob4a01748b4217aa4272b81e8fa0e9528cdf727340
1 /*
2 * Common code to keep time when machine suspends.
4 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
6 * GPLv2
7 */
9 #include <linux/time.h>
10 #include <linux/sysdev.h>
11 #include <asm/rtc.h>
13 static unsigned long suspend_rtc_time;
16 * Reset the time after a sleep.
18 static int timer_resume(struct sys_device *dev)
20 struct timeval tv;
21 struct timespec ts;
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 */
33 do_gettimeofday(&tv);
34 ts.tv_sec = tv.tv_sec + diff;
35 ts.tv_nsec = tv.tv_usec * NSEC_PER_USEC;
36 do_settimeofday(&ts);
38 return 0;
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);
49 return 0;
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 = {
59 .id = 0,
60 .cls = &timer_sysclass,
63 static int time_init_device(void)
65 int error = sysdev_class_register(&timer_sysclass);
66 if (!error)
67 error = sysdev_register(&device_timer);
68 return error;
71 device_initcall(time_init_device);