Arve Hjønnevåg | b54b33d | 2008-10-14 17:38:04 -0700 | [diff] [blame] | 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 | |
Arve Hjønnevåg | fa56540 | 2009-05-04 14:09:15 -0700 | [diff] [blame] | 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); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 77 | void alarm_update_timedelta(struct timespec tv, struct timespec ts); |
Arve Hjønnevåg | fa56540 | 2009-05-04 14:09:15 -0700 | [diff] [blame] | 78 | |
| 79 | #endif |
| 80 | |
Arve Hjønnevåg | b54b33d | 2008-10-14 17:38:04 -0700 | [diff] [blame] | 81 | enum android_alarm_return_flags { |
| 82 | ANDROID_ALARM_RTC_WAKEUP_MASK = 1U << ANDROID_ALARM_RTC_WAKEUP, |
| 83 | ANDROID_ALARM_RTC_MASK = 1U << ANDROID_ALARM_RTC, |
| 84 | ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP_MASK = |
| 85 | 1U << ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP, |
| 86 | ANDROID_ALARM_ELAPSED_REALTIME_MASK = |
| 87 | 1U << ANDROID_ALARM_ELAPSED_REALTIME, |
| 88 | ANDROID_ALARM_SYSTEMTIME_MASK = 1U << ANDROID_ALARM_SYSTEMTIME, |
| 89 | ANDROID_ALARM_TIME_CHANGE_MASK = 1U << 16 |
| 90 | }; |
| 91 | |
| 92 | /* Disable alarm */ |
| 93 | #define ANDROID_ALARM_CLEAR(type) _IO('a', 0 | ((type) << 4)) |
| 94 | |
| 95 | /* Ack last alarm and wait for next */ |
| 96 | #define ANDROID_ALARM_WAIT _IO('a', 1) |
| 97 | |
| 98 | #define ALARM_IOW(c, type, size) _IOW('a', (c) | ((type) << 4), size) |
| 99 | /* Set alarm */ |
| 100 | #define ANDROID_ALARM_SET(type) ALARM_IOW(2, type, struct timespec) |
| 101 | #define ANDROID_ALARM_SET_AND_WAIT(type) ALARM_IOW(3, type, struct timespec) |
| 102 | #define ANDROID_ALARM_GET_TIME(type) ALARM_IOW(4, type, struct timespec) |
| 103 | #define ANDROID_ALARM_SET_RTC _IOW('a', 5, struct timespec) |
| 104 | #define ANDROID_ALARM_BASE_CMD(cmd) (cmd & ~(_IOC(0, 0, 0xf0, 0))) |
| 105 | #define ANDROID_ALARM_IOCTL_TO_TYPE(cmd) (_IOC_NR(cmd) >> 4) |
| 106 | |
| 107 | #endif |