blob: 8a6377086a775fd1240af95370726e9970cb9a16 [file] [log] [blame]
John Stultzff3ead92011-01-11 09:42:13 -08001#ifndef _LINUX_ALARMTIMER_H
2#define _LINUX_ALARMTIMER_H
3
4#include <linux/time.h>
5#include <linux/hrtimer.h>
6#include <linux/timerqueue.h>
7#include <linux/rtc.h>
8
9enum alarmtimer_type {
10 ALARM_REALTIME,
11 ALARM_BOOTTIME,
12
13 ALARM_NUMTYPE,
14};
15
John Stultz4b413082011-08-10 10:37:59 -070016enum alarmtimer_restart {
17 ALARMTIMER_NORESTART,
18 ALARMTIMER_RESTART,
19};
20
John Stultza28cde82011-08-10 12:30:21 -070021
22#define ALARMTIMER_STATE_INACTIVE 0x00
23#define ALARMTIMER_STATE_ENQUEUED 0x01
24#define ALARMTIMER_STATE_CALLBACK 0x02
25
John Stultz180bf812011-04-28 12:58:11 -070026/**
27 * struct alarm - Alarm timer structure
28 * @node: timerqueue node for adding to the event list this value
29 * also includes the expiration time.
30 * @period: Period for recuring alarms
31 * @function: Function pointer to be executed when the timer fires.
32 * @type: Alarm type (BOOTTIME/REALTIME)
33 * @enabled: Flag that represents if the alarm is set to fire or not
34 * @data: Internal data value.
35 */
John Stultzff3ead92011-01-11 09:42:13 -080036struct alarm {
37 struct timerqueue_node node;
John Stultz244badb2012-09-17 23:12:53 -040038 struct hrtimer timer;
John Stultz4b413082011-08-10 10:37:59 -070039 enum alarmtimer_restart (*function)(struct alarm *, ktime_t now);
John Stultzff3ead92011-01-11 09:42:13 -080040 enum alarmtimer_type type;
John Stultza28cde82011-08-10 12:30:21 -070041 int state;
John Stultzff3ead92011-01-11 09:42:13 -080042 void *data;
43};
44
45void alarm_init(struct alarm *alarm, enum alarmtimer_type type,
John Stultz4b413082011-08-10 10:37:59 -070046 enum alarmtimer_restart (*function)(struct alarm *, ktime_t));
John Stultz244badb2012-09-17 23:12:53 -040047int alarm_start(struct alarm *alarm, ktime_t start);
Todd Poynorbd75a522013-05-10 17:41:06 -070048int alarm_start_relative(struct alarm *alarm, ktime_t start);
Todd Poynordf339ff2013-05-08 15:49:18 -070049void alarm_restart(struct alarm *alarm);
John Stultz9082c462011-08-10 12:41:36 -070050int alarm_try_to_cancel(struct alarm *alarm);
51int alarm_cancel(struct alarm *alarm);
Matthew Qin0287c962013-12-23 20:07:48 +080052void set_power_on_alarm(long secs, bool enable);
John Stultzff3ead92011-01-11 09:42:13 -080053
John Stultzdce75a82011-08-10 11:31:03 -070054u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval);
Todd Poynorac58b202013-05-10 17:10:42 -070055u64 alarm_forward_now(struct alarm *alarm, ktime_t interval);
Todd Poynorc0bb2eb2013-05-07 20:43:29 -070056ktime_t alarm_expires_remaining(const struct alarm *alarm);
John Stultzdce75a82011-08-10 11:31:03 -070057
John Stultza28cde82011-08-10 12:30:21 -070058/*
59 * A alarmtimer is active, when it is enqueued into timerqueue or the
60 * callback function is running.
61 */
62static inline int alarmtimer_active(const struct alarm *timer)
63{
64 return timer->state != ALARMTIMER_STATE_INACTIVE;
65}
66
67/*
68 * Helper function to check, whether the timer is on one of the queues
69 */
70static inline int alarmtimer_is_queued(struct alarm *timer)
71{
72 return timer->state & ALARMTIMER_STATE_ENQUEUED;
73}
74
75/*
76 * Helper function to check, whether the timer is running the callback
77 * function
78 */
79static inline int alarmtimer_callback_running(struct alarm *timer)
80{
81 return timer->state & ALARMTIMER_STATE_CALLBACK;
82}
83
84
John Stultzbec4ab42011-12-09 18:44:02 -080085/* Provide way to access the rtc device being used by alarmtimers */
John Stultzbec4ab42011-12-09 18:44:02 -080086struct rtc_device *alarmtimer_get_rtcdev(void);
John Stultzbec4ab42011-12-09 18:44:02 -080087
John Stultzff3ead92011-01-11 09:42:13 -080088#endif