16 #include <linux/time.h>
17 #include <linux/module.h>
18 #include <linux/device.h>
22 #include <linux/sched.h>
28 #define ANDROID_ALARM_PRINT_INFO (1U << 0)
29 #define ANDROID_ALARM_PRINT_IO (1U << 1)
30 #define ANDROID_ALARM_PRINT_INT (1U << 2)
35 #define alarm_dbg(debug_level_mask, fmt, ...) \
37 if (debug_mask & ANDROID_ALARM_PRINT_##debug_level_mask) \
38 pr_info(fmt, ##__VA_ARGS__); \
41 #define ANDROID_ALARM_WAKEUP_MASK ( \
42 ANDROID_ALARM_RTC_WAKEUP_MASK | \
43 ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP_MASK)
46 #define ANDROID_ALARM_SET_OLD _IOW('a', 2, time_t)
47 #define ANDROID_ALARM_SET_AND_WAIT_OLD _IOW('a', 3, time_t)
49 static int alarm_opened;
77 if (is_wakeup(alrm->
type))
84 static int devalarm_try_to_cancel(
struct devalarm *alrm)
86 if (is_wakeup(alrm->
type))
91 static void devalarm_cancel(
struct devalarm *alrm)
93 if (is_wakeup(alrm->
type))
100 static long alarm_ioctl(
struct file *
file,
unsigned int cmd,
unsigned long arg)
110 uint32_t alarm_type_mask = 1
U << alarm_type;
122 spin_unlock_irqrestore(&alarm_slock, flags);
127 spin_unlock_irqrestore(&alarm_slock, flags);
135 devalarm_try_to_cancel(&alarms[alarm_type]);
137 alarm_pending &= ~alarm_type_mask;
138 if (!alarm_pending && !wait_pending)
141 alarm_enabled &= ~alarm_type_mask;
142 spin_unlock_irqrestore(&alarm_slock, flags);
147 if (
get_user(new_alarm_time.tv_sec, (
int __user *)arg)) {
151 new_alarm_time.tv_nsec = 0;
152 goto from_old_alarm_set;
157 sizeof(new_alarm_time))) {
165 new_alarm_time.tv_sec, new_alarm_time.tv_nsec);
166 alarm_enabled |= alarm_type_mask;
167 devalarm_start(&alarms[alarm_type],
168 timespec_to_ktime(new_alarm_time));
169 spin_unlock_irqrestore(&alarm_slock, flags);
177 if (!alarm_pending && wait_pending) {
181 spin_unlock_irqrestore(&alarm_slock, flags);
189 spin_unlock_irqrestore(&alarm_slock, flags);
193 sizeof(new_rtc_time))) {
207 spin_unlock_irqrestore(&alarm_slock, flags);
212 switch (alarm_type) {
242 static int alarm_open(
struct inode *
inode,
struct file *file)
248 static int alarm_release(
struct inode *
inode,
struct file *file)
257 if (alarm_enabled & alarm_type_mask) {
259 "%s: clear alarm, pending %d\n",
261 !!(alarm_pending & alarm_type_mask));
262 alarm_enabled &= ~alarm_type_mask;
264 spin_unlock_irqrestore(&alarm_slock, flags);
265 devalarm_cancel(&alarms[i]);
268 if (alarm_pending | wait_pending) {
271 __func__, alarm_pending);
278 spin_unlock_irqrestore(&alarm_slock, flags);
289 if (alarm_enabled & alarm_type_mask) {
291 alarm_enabled &= ~alarm_type_mask;
292 alarm_pending |= alarm_type_mask;
295 spin_unlock_irqrestore(&alarm_slock, flags);
303 devalarm_triggered(devalrm);
312 devalarm_triggered(devalrm);
319 .unlocked_ioctl = alarm_ioctl,
321 .release = alarm_release,
330 static int __init alarm_dev_init(
void)
353 alarms[
i].u.hrt.function = devalarm_hrthandler;
356 wakeup_source_init(&alarm_wake_lock,
"alarm");
360 static void __exit alarm_dev_exit(
void)
363 wakeup_source_trash(&alarm_wake_lock);