1 #include <linux/android_alarm.h>
2 #include <linux/device.h>
3 #include <linux/miscdevice.h>
4 #include <linux/platform_device.h>
6 #include <linux/sched.h>
7 #include <linux/spinlock.h>
8 #include <linux/sysdev.h>
9 #include <linux/wakelock.h>
10 #include <linux/power_supply.h>
11 #include <linux/suspend.h>
13 #include <asm/mach/time.h>
18 struct timespec timer;
19 //struct notifier_block pm_nb;
22 static struct auto_wake auto_wake;
23 struct timespec set_atuo_wake_time( struct timespec timer)
25 struct timespec new_time;
26 struct timespec tmp_time;
28 tmp_time =ktime_to_timespec(alarm_get_elapsed_realtime());
30 printk("nowtime = %ld \n",tmp_time.tv_sec);
32 new_time.tv_nsec = timer.tv_nsec+ tmp_time.tv_nsec;
33 new_time.tv_sec = timer.tv_sec+ tmp_time.tv_sec;
38 static void auto_wake_update(struct auto_wake *auto_wake)
41 struct timespec new_alarm_time;
43 // printk("auto_wake_update\n");
44 new_alarm_time = set_atuo_wake_time(auto_wake->timer);
45 alarm_start_range(&auto_wake->alarm,
46 timespec_to_ktime(new_alarm_time),
47 timespec_to_ktime(new_alarm_time));
50 static void atuo_wake_trigger(struct alarm *alarm)
53 struct auto_wake *auto_wake = container_of(alarm, struct auto_wake,
56 auto_wake_update(auto_wake);
61 static void auto_wake_cancel(struct auto_wake *auto_wake)
63 alarm_cancel(&auto_wake->alarm);
68 static int auto_wake_callback(struct notifier_block *nfb,
73 struct auto_wake *auto_wake = container_of(nfb, struct auto_wake,
78 case PM_SUSPEND_PREPARE:
80 printk("PM_SUSPEND_PREPARExsf \n");
81 auto_wake_update(auto_wake);
86 printk("PM_POST_SUSPENDxsf \n");
87 // auto_wake_cancel(auto_wake);
96 static struct notifier_block auto_wake_pm_notifier = {
97 .notifier_call = auto_wake_callback,
103 void auto_wake_init(struct auto_wake *auto_wake,struct timespec timer)
105 // auto_wake->pm_nb = auto_wake_pm_notifier;
106 auto_wake->timer = timer;
108 alarm_init(&auto_wake->alarm, ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP, atuo_wake_trigger);
110 //register_pm_notifier(&auto_wake->pm_nb);// xsf
114 static int __init start_auto_wake(void)
117 struct timespec timer;
119 printk("CONFIG_AUTO_WAKE_UP_PERIOD = %d\n", CONFIG_AUTO_WAKE_UP_PERIOD);
120 timer.tv_sec = CONFIG_AUTO_WAKE_UP_PERIOD;
123 auto_wake_init(&auto_wake,timer);
124 auto_wake_update(&auto_wake);
128 late_initcall_sync(start_auto_wake);