blob: 320681a76770ef7ad9eb2c486444207c86be1ddf [file] [log] [blame]
Nicholas Flintham1e3d3112013-04-10 10:48:38 +01001/* 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
22enum android_alarm_type {
23
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
33
34};
35
36#ifdef __KERNEL__
37
38#include <linux/ktime.h>
39#include <linux/rbtree.h>
40
41
42
43struct alarm {
44 struct rb_node node;
45 enum android_alarm_type type;
46 ktime_t softexpires;
47 ktime_t expires;
48 void (*function)(struct alarm *);
49};
50
51void alarm_init(struct alarm *alarm,
52 enum android_alarm_type type, void (*function)(struct alarm *));
53void alarm_start_range(struct alarm *alarm, ktime_t start, ktime_t end);
54int alarm_try_to_cancel(struct alarm *alarm);
55int alarm_cancel(struct alarm *alarm);
56ktime_t alarm_get_elapsed_realtime(void);
57
58int alarm_set_rtc(const struct timespec ts);
59void alarm_update_timedelta(struct timespec tv, struct timespec ts);
60
61#endif
62
63enum android_alarm_return_flags {
64 ANDROID_ALARM_RTC_WAKEUP_MASK = 1U << ANDROID_ALARM_RTC_WAKEUP,
65 ANDROID_ALARM_RTC_MASK = 1U << ANDROID_ALARM_RTC,
66 ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP_MASK =
67 1U << ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP,
68 ANDROID_ALARM_ELAPSED_REALTIME_MASK =
69 1U << ANDROID_ALARM_ELAPSED_REALTIME,
70 ANDROID_ALARM_SYSTEMTIME_MASK = 1U << ANDROID_ALARM_SYSTEMTIME,
71 ANDROID_ALARM_TIME_CHANGE_MASK = 1U << 16
72};
73
74#define ANDROID_ALARM_CLEAR(type) _IO('a', 0 | ((type) << 4))
75
76#define ANDROID_ALARM_WAIT _IO('a', 1)
77
78#define ALARM_IOW(c, type, size) _IOW('a', (c) | ((type) << 4), size)
79#define ANDROID_ALARM_SET(type) ALARM_IOW(2, type, struct timespec)
80#define ANDROID_ALARM_SET_AND_WAIT(type) ALARM_IOW(3, type, struct timespec)
81#define ANDROID_ALARM_GET_TIME(type) ALARM_IOW(4, type, struct timespec)
82#define ANDROID_ALARM_SET_RTC _IOW('a', 5, struct timespec)
83#define ANDROID_ALARM_BASE_CMD(cmd) (cmd & ~(_IOC(0, 0, 0xf0, 0)))
84#define ANDROID_ALARM_IOCTL_TO_TYPE(cmd) (_IOC_NR(cmd) >> 4)
85
86#endif