From: 许盛飞 Date: Wed, 4 Jan 2012 11:51:31 +0000 (+0800) Subject: RTC: system suspend, RTC can auto wake up the system X-Git-Tag: firefly_0821_release~9688^2~4 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=5122c4ae79584cdbce89d793eba37783f4c56aa2;p=firefly-linux-kernel-4.4.55.git RTC: system suspend, RTC can auto wake up the system --- diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 68a0c106eb6a..a567a8e131e7 100755 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -123,6 +123,14 @@ config RTC_INTF_ALARM_DEV help Exports the alarm interface to user-space. +config AUTO_WAKE_UP + tristate "Support auto wake up" + depends on RTC_INTF_ALARM_DEV + +config AUTO_WAKE_UP_PERIOD + int "auto wake up period(sec)" + depends on AUTO_WAKE_UP + default 3600 config RTC_DRV_TEST tristate "Test driver/device" diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index a488d45cf72f..3f5e0685673b 100755 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile @@ -15,6 +15,8 @@ rtc-core-$(CONFIG_RTC_INTF_DEV) += rtc-dev.o rtc-core-$(CONFIG_RTC_INTF_PROC) += rtc-proc.o rtc-core-$(CONFIG_RTC_INTF_SYSFS) += rtc-sysfs.o +obj-$(CONFIG_AUTO_WAKE_UP) += auto-wake.o + # Keep the list ordered. obj-$(CONFIG_RTC_DRV_88PM860X) += rtc-88pm860x.o diff --git a/drivers/rtc/auto-wake.c b/drivers/rtc/auto-wake.c new file mode 100755 index 000000000000..4642867c6ea0 --- /dev/null +++ b/drivers/rtc/auto-wake.c @@ -0,0 +1,128 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +struct auto_wake +{ + struct alarm alarm; + struct timespec timer; + //struct notifier_block pm_nb; +}; + +static struct auto_wake auto_wake; +struct timespec set_atuo_wake_time( struct timespec timer) +{ + struct timespec new_time; + struct timespec tmp_time; + + tmp_time =ktime_to_timespec(alarm_get_elapsed_realtime()); + + printk("nowtime = %ld \n",tmp_time.tv_sec); + + new_time.tv_nsec = timer.tv_nsec+ tmp_time.tv_nsec; + new_time.tv_sec = timer.tv_sec+ tmp_time.tv_sec; + + return new_time; +} + +static void auto_wake_update(struct auto_wake *auto_wake) +{ + + struct timespec new_alarm_time; + +// printk("auto_wake_update\n"); + new_alarm_time = set_atuo_wake_time(auto_wake->timer); + alarm_start_range(&auto_wake->alarm, + timespec_to_ktime(new_alarm_time), + timespec_to_ktime(new_alarm_time)); +} + +static void atuo_wake_trigger(struct alarm *alarm) +{ + + struct auto_wake *auto_wake = container_of(alarm, struct auto_wake, + alarm); + + auto_wake_update(auto_wake); +} + + +#if 0 +static void auto_wake_cancel(struct auto_wake *auto_wake) +{ + alarm_cancel(&auto_wake->alarm); +} + + + +static int auto_wake_callback(struct notifier_block *nfb, + unsigned long action, + void *ignored) +{ + + struct auto_wake *auto_wake = container_of(nfb, struct auto_wake, + pm_nb); + + switch (action) + { + case PM_SUSPEND_PREPARE: + { + printk("PM_SUSPEND_PREPARExsf \n"); + auto_wake_update(auto_wake); + return NOTIFY_OK; + } + case PM_POST_SUSPEND: + { + printk("PM_POST_SUSPENDxsf \n"); + // auto_wake_cancel(auto_wake); + return NOTIFY_OK; + } + } + + return NOTIFY_DONE; +} + + +static struct notifier_block auto_wake_pm_notifier = { + .notifier_call = auto_wake_callback, + .priority = 0, +}; + +#endif + +void auto_wake_init(struct auto_wake *auto_wake,struct timespec timer) +{ +// auto_wake->pm_nb = auto_wake_pm_notifier; + auto_wake->timer = timer; + + alarm_init(&auto_wake->alarm, ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP, atuo_wake_trigger); + + //register_pm_notifier(&auto_wake->pm_nb);// xsf + +} + +static int __init start_auto_wake(void) +{ + + struct timespec timer; + + printk("CONFIG_AUTO_WAKE_UP_PERIOD = %d\n", CONFIG_AUTO_WAKE_UP_PERIOD); + timer.tv_sec = CONFIG_AUTO_WAKE_UP_PERIOD; + timer.tv_nsec = 0; + + auto_wake_init(&auto_wake,timer); + auto_wake_update(&auto_wake); + return 0; +} + +late_initcall_sync(start_auto_wake);