diff options
author | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-04-30 11:10:12 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-04-30 11:10:12 -0400 |
commit | 24a77daf3d80bddcece044e6dc3675e427eef3f3 (patch) | |
tree | 2c5e0b0bea394d6fe62c5d5857c252e83e48ac48 /arch/powerpc/sysdev/timer.c | |
parent | e389f9aec689209724105ae80a6c91fd2e747bc9 (diff) | |
parent | f900e9777fc9b65140cb9570438597bc8fae56ab (diff) |
Merge branch 'for-2.6.22' of git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc
* 'for-2.6.22' of git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc: (255 commits)
[POWERPC] Remove dev_dbg redefinition in drivers/ps3/vuart.c
[POWERPC] remove kernel module option for booke wdt
[POWERPC] Avoid putting cpu node twice
[POWERPC] Spinlock initializer cleanup
[POWERPC] ppc4xx_sgdma needs dma-mapping.h
[POWERPC] arch/powerpc/sysdev/timer.c build fix
[POWERPC] get_property cleanups
[POWERPC] Remove the unused HTDMSOUND driver
[POWERPC] cell: cbe_cpufreq cleanup and crash fix
[POWERPC] Declare enable_kernel_spe in a header
[POWERPC] Add dt_xlate_addr() to bootwrapper
[POWERPC] bootwrapper: CONFIG_ -> CONFIG_DEVICE_TREE
[POWERPC] Don't define a custom bd_t for Xilixn Virtex based boards.
[POWERPC] Add sane defaults for Xilinx EDK generated xparameters files
[POWERPC] Add uartlite boot console driver for the zImage wrapper
[POWERPC] Stop using ppc_sys for Xilinx Virtex boards
[POWERPC] New registration for common Xilinx Virtex ppc405 platform devices
[POWERPC] Merge common virtex header files
[POWERPC] Rework Kconfig dependancies for Xilinx Virtex ppc405 platform
[POWERPC] Clean up cpufreq Kconfig dependencies
...
Diffstat (limited to 'arch/powerpc/sysdev/timer.c')
-rw-r--r-- | arch/powerpc/sysdev/timer.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/arch/powerpc/sysdev/timer.c b/arch/powerpc/sysdev/timer.c new file mode 100644 index 000000000000..4a01748b4217 --- /dev/null +++ b/arch/powerpc/sysdev/timer.c | |||
@@ -0,0 +1,71 @@ | |||
1 | /* | ||
2 | * Common code to keep time when machine suspends. | ||
3 | * | ||
4 | * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> | ||
5 | * | ||
6 | * GPLv2 | ||
7 | */ | ||
8 | |||
9 | #include <linux/time.h> | ||
10 | #include <linux/sysdev.h> | ||
11 | #include <asm/rtc.h> | ||
12 | |||
13 | static unsigned long suspend_rtc_time; | ||
14 | |||
15 | /* | ||
16 | * Reset the time after a sleep. | ||
17 | */ | ||
18 | static int timer_resume(struct sys_device *dev) | ||
19 | { | ||
20 | struct timeval tv; | ||
21 | struct timespec ts; | ||
22 | struct rtc_time cur_rtc_tm; | ||
23 | unsigned long cur_rtc_time, diff; | ||
24 | |||
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); | ||
28 | |||
29 | diff = cur_rtc_time - suspend_rtc_time; | ||
30 | |||
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); | ||
37 | |||
38 | return 0; | ||
39 | } | ||
40 | |||
41 | static int timer_suspend(struct sys_device *dev, pm_message_t state) | ||
42 | { | ||
43 | struct rtc_time suspend_rtc_tm; | ||
44 | WARN_ON(!ppc_md.get_rtc_time); | ||
45 | |||
46 | get_rtc_time(&suspend_rtc_tm); | ||
47 | rtc_tm_to_time(&suspend_rtc_tm, &suspend_rtc_time); | ||
48 | |||
49 | return 0; | ||
50 | } | ||
51 | |||
52 | static struct sysdev_class timer_sysclass = { | ||
53 | .resume = timer_resume, | ||
54 | .suspend = timer_suspend, | ||
55 | set_kset_name("timer"), | ||
56 | }; | ||
57 | |||
58 | static struct sys_device device_timer = { | ||
59 | .id = 0, | ||
60 | .cls = &timer_sysclass, | ||
61 | }; | ||
62 | |||
63 | static int time_init_device(void) | ||
64 | { | ||
65 | int error = sysdev_class_register(&timer_sysclass); | ||
66 | if (!error) | ||
67 | error = sysdev_register(&device_timer); | ||
68 | return error; | ||
69 | } | ||
70 | |||
71 | device_initcall(time_init_device); | ||