Commit | Line | Data |
---|---|---|
841cb11c AH |
1 | /* include/linux/android_alarm.h |
2 | * | |
3 | * Copyright (C) 2006-2007 Google, Inc. | |
4 | * | |
5 | * This software is licensed under the terms of the GNU General Public | |
6 | * License version 2, as published by the Free Software Foundation, and | |
7 | * may be copied, distributed, and modified under those terms. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | */ | |
15 | ||
16 | #ifndef _LINUX_ANDROID_ALARM_H | |
17 | #define _LINUX_ANDROID_ALARM_H | |
18 | ||
19 | #include <linux/ioctl.h> | |
20 | #include <linux/time.h> | |
21 | ||
22 | enum android_alarm_type { | |
23 | /* return code bit numbers or set alarm arg */ | |
24 | ANDROID_ALARM_RTC_WAKEUP, | |
25 | ANDROID_ALARM_RTC, | |
26 | ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP, | |
27 | ANDROID_ALARM_ELAPSED_REALTIME, | |
28 | ANDROID_ALARM_SYSTEMTIME, | |
29 | ||
30 | ANDROID_ALARM_TYPE_COUNT, | |
31 | ||
32 | /* return code bit numbers */ | |
33 | /* ANDROID_ALARM_TIME_CHANGE = 16 */ | |
34 | }; | |
35 | ||
36 | #ifdef __KERNEL__ | |
37 | ||
38 | #include <linux/ktime.h> | |
39 | #include <linux/rbtree.h> | |
40 | ||
41 | /* | |
42 | * The alarm interface is similar to the hrtimer interface but adds support | |
43 | * for wakeup from suspend. It also adds an elapsed realtime clock that can | |
44 | * be used for periodic timers that need to keep runing while the system is | |
45 | * suspended and not be disrupted when the wall time is set. | |
46 | */ | |
47 | ||
48 | /** | |
49 | * struct alarm - the basic alarm structure | |
50 | * @node: red black tree node for time ordered insertion | |
51 | * @type: alarm type. rtc/elapsed-realtime/systemtime, wakeup/non-wakeup. | |
52 | * @softexpires: the absolute earliest expiry time of the alarm. | |
53 | * @expires: the absolute expiry time. | |
54 | * @function: alarm expiry callback function | |
55 | * | |
56 | * The alarm structure must be initialized by alarm_init() | |
57 | * | |
58 | */ | |
59 | ||
60 | struct alarm { | |
61 | struct rb_node node; | |
62 | enum android_alarm_type type; | |
63 | ktime_t softexpires; | |
64 | ktime_t expires; | |
65 | void (*function)(struct alarm *); | |
66 | }; | |
67 | ||
68 | void alarm_init(struct alarm *alarm, | |
69 | enum android_alarm_type type, void (*function)(struct alarm *)); | |
70 | void alarm_start_range(struct alarm *alarm, ktime_t start, ktime_t end); | |
71 | int alarm_try_to_cancel(struct alarm *alarm); | |
72 | int alarm_cancel(struct alarm *alarm); | |
73 | ktime_t alarm_get_elapsed_realtime(void); | |
74 | ||
75 | /* set rtc while preserving elapsed realtime */ | |
76 | int alarm_set_rtc(const struct timespec ts); | |
77 | ||
78 | #endif | |
79 | ||
80 | enum android_alarm_return_flags { | |
81 | ANDROID_ALARM_RTC_WAKEUP_MASK = 1U << ANDROID_ALARM_RTC_WAKEUP, | |
82 | ANDROID_ALARM_RTC_MASK = 1U << ANDROID_ALARM_RTC, | |
83 | ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP_MASK = | |
84 | 1U << ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP, | |
85 | ANDROID_ALARM_ELAPSED_REALTIME_MASK = | |
86 | 1U << ANDROID_ALARM_ELAPSED_REALTIME, | |
87 | ANDROID_ALARM_SYSTEMTIME_MASK = 1U << ANDROID_ALARM_SYSTEMTIME, | |
88 | ANDROID_ALARM_TIME_CHANGE_MASK = 1U << 16 | |
89 | }; | |
90 | ||
91 | /* Disable alarm */ | |
92 | #define ANDROID_ALARM_CLEAR(type) _IO('a', 0 | ((type) << 4)) | |
93 | ||
94 | /* Ack last alarm and wait for next */ | |
95 | #define ANDROID_ALARM_WAIT _IO('a', 1) | |
96 | ||
97 | #define ALARM_IOW(c, type, size) _IOW('a', (c) | ((type) << 4), size) | |
98 | /* Set alarm */ | |
99 | #define ANDROID_ALARM_SET(type) ALARM_IOW(2, type, struct timespec) | |
100 | #define ANDROID_ALARM_SET_AND_WAIT(type) ALARM_IOW(3, type, struct timespec) | |
101 | #define ANDROID_ALARM_GET_TIME(type) ALARM_IOW(4, type, struct timespec) | |
102 | #define ANDROID_ALARM_SET_RTC _IOW('a', 5, struct timespec) | |
103 | #define ANDROID_ALARM_BASE_CMD(cmd) (cmd & ~(_IOC(0, 0, 0xf0, 0))) | |
104 | #define ANDROID_ALARM_IOCTL_TO_TYPE(cmd) (_IOC_NR(cmd) >> 4) | |
105 | ||
106 | #endif |