+++ /dev/null
-#include <linux/android_alarm.h>\r
-#include <linux/mutex.h>\r
-#include <linux/kobject.h>\r
-#include <linux/string.h>\r
-\r
-#include "rk_pm_tests.h"\r
-#include "auto_wakeup.h"\r
-static struct alarm alarm;\r
-static struct timespec period;\r
-static int alarm_status = 0;\r
-static DEFINE_MUTEX(mutex);\r
-\r
-static int get_alarm_status(void)\r
-{\r
- return alarm_status;\r
-}\r
-\r
-static void alarm_update(struct alarm *alarm)\r
-{\r
- struct timespec now_time;\r
- struct timespec new_time;\r
-\r
- now_time = ktime_to_timespec(alarm_get_elapsed_realtime());\r
-\r
- PM_DBG("now_time %ld\n",now_time.tv_sec);\r
-\r
- new_time.tv_sec = now_time.tv_sec + period.tv_sec;\r
- new_time.tv_nsec = now_time.tv_nsec + period.tv_nsec;\r
-\r
- alarm_start_range(alarm, timespec_to_ktime(new_time), timespec_to_ktime(new_time));\r
-}\r
-\r
-static void stop_auto_wakeup(void)\r
-{\r
- mutex_lock(&mutex);\r
-\r
- if(alarm_status) {\r
- alarm_cancel(&alarm);\r
- alarm_status = 0;\r
- }\r
-\r
- mutex_unlock(&mutex);\r
-}\r
-\r
-static void start_auto_wakeup(long second)\r
-{\r
- stop_auto_wakeup();\r
-\r
- mutex_lock(&mutex);\r
-\r
- period.tv_sec = second;\r
- period.tv_nsec = 0;\r
-\r
- alarm_init(&alarm, ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP, alarm_update); \r
- alarm_update(&alarm);\r
- alarm_status = 1;\r
-\r
- mutex_unlock(&mutex);\r
-}\r
-\r
-ssize_t auto_wakeup_show(struct kobject *kobj, struct kobj_attribute *attr,\r
- char *buf)\r
-{\r
- char *s = buf;\r
-\r
- if(get_alarm_status())\r
- s += sprintf(s, "%s\n", "on");\r
- else\r
- s += sprintf(s, "%s\n", "off");\r
-\r
- return (s - buf);\r
-}\r
-\r
-ssize_t auto_wakeup_store(struct kobject *kobj, struct kobj_attribute *attr,\r
- const char *buf, size_t n)\r
-{\r
- char cmd[10];\r
- long val;\r
- int len;\r
- int error = -EINVAL;\r
-\r
- sscanf(buf, "%s %ld", cmd, &val);\r
- len = strlen(cmd);\r
-\r
- if (len == strlen("on") && !strncmp(cmd,"on",len)) {\r
- start_auto_wakeup(val);\r
- error = 0;\r
- }\r
- else if(len == strlen("off") && !strncmp(cmd,"off",len)) {\r
- stop_auto_wakeup();\r
- error = 0;\r
- }\r
-\r
- return error ? error : n;\r
-}\r
-\r
-\r