1 /* include/linux/android_alarm.h
3 * Copyright (C) 2006-2007 Google, Inc.
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.
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.
16 #ifndef _LINUX_ANDROID_ALARM_H
17 #define _LINUX_ANDROID_ALARM_H
19 #include <linux/ioctl.h>
20 #include <linux/time.h>
22 enum android_alarm_type {
23 /* return code bit numbers or set alarm arg */
24 ANDROID_ALARM_RTC_WAKEUP,
26 ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP,
27 ANDROID_ALARM_ELAPSED_REALTIME,
28 ANDROID_ALARM_SYSTEMTIME,
30 ANDROID_ALARM_TYPE_COUNT,
32 /* return code bit numbers */
33 /* ANDROID_ALARM_TIME_CHANGE = 16 */
38 #include <linux/ktime.h>
39 #include <linux/rbtree.h>
40 #include <linux/hrtimer.h>
43 * The alarm interface is similar to the hrtimer interface but adds support
44 * for wakeup from suspend. It also adds an elapsed realtime clock that can
45 * be used for periodic timers that need to keep running while the system is
46 * suspended and not be disrupted when the wall time is set.
50 * struct alarm - the basic alarm structure
51 * @node: red black tree node for time ordered insertion
52 * @type: alarm type. rtc/elapsed-realtime/systemtime, wakeup/non-wakeup.
53 * @softexpires: the absolute earliest expiry time of the alarm.
54 * @expires: the absolute expiry time.
55 * @function: alarm expiry callback function
57 * The alarm structure must be initialized by alarm_init()
61 struct android_alarm {
63 enum android_alarm_type type;
66 void (*function)(struct android_alarm *);
69 void android_alarm_init(struct android_alarm *alarm,
70 enum android_alarm_type type, void (*function)(struct android_alarm *));
71 void android_alarm_start_range(struct android_alarm *alarm, ktime_t start,
73 int android_alarm_try_to_cancel(struct android_alarm *alarm);
74 int android_alarm_cancel(struct android_alarm *alarm);
76 static inline ktime_t alarm_get_elapsed_realtime(void)
78 return ktime_get_boottime();
81 /* set rtc while preserving elapsed realtime */
82 int android_alarm_set_rtc(const struct timespec ts);
84 #ifdef CONFIG_ANDROID_ALARM_OLDDRV_COMPAT
86 * Some older drivers depend on the old API,
87 * so provide compatability macros for now.
89 #define alarm android_alarm
90 #define alarm_init(x, y, z) android_alarm_init(x, y, z)
91 #define alarm_start_range(x, y, z) android_alarm_start_range(x, y, z)
92 #define alarm_try_to_cancel(x) android_alarm_try_to_cancel(x)
93 #define alarm_cancel(x) android_alarm_cancel(x)
94 #define alarm_set_rtc(x) android_alarm_set_rtc(x)
100 enum android_alarm_return_flags {
101 ANDROID_ALARM_RTC_WAKEUP_MASK = 1U << ANDROID_ALARM_RTC_WAKEUP,
102 ANDROID_ALARM_RTC_MASK = 1U << ANDROID_ALARM_RTC,
103 ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP_MASK =
104 1U << ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP,
105 ANDROID_ALARM_ELAPSED_REALTIME_MASK =
106 1U << ANDROID_ALARM_ELAPSED_REALTIME,
107 ANDROID_ALARM_SYSTEMTIME_MASK = 1U << ANDROID_ALARM_SYSTEMTIME,
108 ANDROID_ALARM_TIME_CHANGE_MASK = 1U << 16
112 #define ANDROID_ALARM_CLEAR(type) _IO('a', 0 | ((type) << 4))
114 /* Ack last alarm and wait for next */
115 #define ANDROID_ALARM_WAIT _IO('a', 1)
117 #define ALARM_IOW(c, type, size) _IOW('a', (c) | ((type) << 4), size)
119 #define ANDROID_ALARM_SET(type) ALARM_IOW(2, type, struct timespec)
120 #define ANDROID_ALARM_SET_AND_WAIT(type) ALARM_IOW(3, type, struct timespec)
121 #define ANDROID_ALARM_GET_TIME(type) ALARM_IOW(4, type, struct timespec)
122 #define ANDROID_ALARM_SET_RTC _IOW('a', 5, struct timespec)
123 #define ANDROID_ALARM_BASE_CMD(cmd) (cmd & ~(_IOC(0, 0, 0xf0, 0)))
124 #define ANDROID_ALARM_IOCTL_TO_TYPE(cmd) (_IOC_NR(cmd) >> 4)