1 #include <linux/android_alarm.h>
\r
2 #include <linux/mutex.h>
\r
3 #include <linux/kobject.h>
\r
4 #include <linux/string.h>
\r
6 #include "rk_pm_tests.h"
\r
7 #include "auto_wakeup.h"
\r
8 static struct alarm alarm;
\r
9 static struct timespec period;
\r
10 static int alarm_status = 0;
\r
11 static DEFINE_MUTEX(mutex);
\r
13 static int get_alarm_status(void)
\r
15 return alarm_status;
\r
18 static void alarm_update(struct alarm *alarm)
\r
20 struct timespec now_time;
\r
21 struct timespec new_time;
\r
23 now_time = ktime_to_timespec(alarm_get_elapsed_realtime());
\r
25 PM_DBG("now_time %ld\n",now_time.tv_sec);
\r
27 new_time.tv_sec = now_time.tv_sec + period.tv_sec;
\r
28 new_time.tv_nsec = now_time.tv_nsec + period.tv_nsec;
\r
30 alarm_start_range(alarm, timespec_to_ktime(new_time), timespec_to_ktime(new_time));
\r
33 static void stop_auto_wakeup(void)
\r
38 alarm_cancel(&alarm);
\r
42 mutex_unlock(&mutex);
\r
45 static void start_auto_wakeup(long second)
\r
51 period.tv_sec = second;
\r
54 alarm_init(&alarm, ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP, alarm_update);
\r
55 alarm_update(&alarm);
\r
58 mutex_unlock(&mutex);
\r
61 ssize_t auto_wakeup_show(struct kobject *kobj, struct kobj_attribute *attr,
\r
66 if(get_alarm_status())
\r
67 s += sprintf(s, "%s\n", "on");
\r
69 s += sprintf(s, "%s\n", "off");
\r
74 ssize_t auto_wakeup_store(struct kobject *kobj, struct kobj_attribute *attr,
\r
75 const char *buf, size_t n)
\r
80 int error = -EINVAL;
\r
82 sscanf(buf, "%s %ld", cmd, &val);
\r
85 if (len == strlen("on") && !strncmp(cmd,"on",len)) {
\r
86 start_auto_wakeup(val);
\r
89 else if(len == strlen("off") && !strncmp(cmd,"off",len)) {
\r
94 return error ? error : n;
\r