]> Pileus Git - ~andy/linux/blob - drivers/staging/android/android_alarm.h
a1121772bc2eef2640aa759eafee1181bc1a285e
[~andy/linux] / drivers / staging / android / android_alarm.h
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 #include <linux/hrtimer.h>
41
42 /*
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.
47  */
48
49 /**
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
56  *
57  * The alarm structure must be initialized by alarm_init()
58  *
59  */
60
61 struct android_alarm {
62         struct rb_node          node;
63         enum android_alarm_type type;
64         ktime_t                 softexpires;
65         ktime_t                 expires;
66         void                    (*function)(struct android_alarm *);
67 };
68
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,
72                                                                 ktime_t end);
73 int android_alarm_try_to_cancel(struct android_alarm *alarm);
74 int android_alarm_cancel(struct android_alarm *alarm);
75
76 static inline ktime_t alarm_get_elapsed_realtime(void)
77 {
78         return ktime_get_boottime();
79 }
80
81 /* set rtc while preserving elapsed realtime */
82 int android_alarm_set_rtc(const struct timespec ts);
83
84 #ifdef CONFIG_ANDROID_ALARM_OLDDRV_COMPAT
85 /*
86  * Some older drivers depend on the old API,
87  * so provide compatability macros for now.
88  */
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)
95 #endif
96
97
98 #endif
99
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
109 };
110
111 /* Disable alarm */
112 #define ANDROID_ALARM_CLEAR(type)           _IO('a', 0 | ((type) << 4))
113
114 /* Ack last alarm and wait for next */
115 #define ANDROID_ALARM_WAIT                  _IO('a', 1)
116
117 #define ALARM_IOW(c, type, size)            _IOW('a', (c) | ((type) << 4), size)
118 /* Set alarm */
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)
125
126 #endif