blob: 52f3b7da4f2d4dbb181aa1fe5c8d73e4df8f1814 [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
John Stultza28cde82011-08-10 12:30:21 -070024
John Stultz180bf812011-04-28 12:58:11 -070025/**
26 * struct alarm - Alarm timer structure
27 * @node: timerqueue node for adding to the event list this value
28 * also includes the expiration time.
29 * @period: Period for recuring alarms
30 * @function: Function pointer to be executed when the timer fires.
31 * @type: Alarm type (BOOTTIME/REALTIME)
32 * @enabled: Flag that represents if the alarm is set to fire or not
33 * @data: Internal data value.
34 */
John Stultzff3ead92011-01-11 09:42:13 -080035struct alarm {
36 struct timerqueue_node node;
John Stultzdae373b2012-09-13 19:12:16 -040037 struct hrtimer timer;
John Stultz4b413082011-08-10 10:37:59 -070038 enum alarmtimer_restart (*function)(struct alarm *, ktime_t now);
John Stultzff3ead92011-01-11 09:42:13 -080039 enum alarmtimer_type type;
John Stultza28cde82011-08-10 12:30:21 -070040 int state;
John Stultzff3ead92011-01-11 09:42:13 -080041 void *data;
42};
43
44void alarm_init(struct alarm *alarm, enum alarmtimer_type type,
John Stultz4b413082011-08-10 10:37:59 -070045 enum alarmtimer_restart (*function)(struct alarm *, ktime_t));
Thomas Gleixnerb1932172015-04-14 21:09:18 +000046void alarm_start(struct alarm *alarm, ktime_t start);
47void alarm_start_relative(struct alarm *alarm, ktime_t start);
Todd Poynor6cffe002013-05-15 14:38:11 -070048void alarm_restart(struct alarm *alarm);
John Stultz9082c462011-08-10 12:41:36 -070049int alarm_try_to_cancel(struct alarm *alarm);
50int alarm_cancel(struct alarm *alarm);
John Stultzff3ead92011-01-11 09:42:13 -080051
John Stultzdce75a82011-08-10 11:31:03 -070052u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval);
Todd Poynor6cffe002013-05-15 14:38:11 -070053u64 alarm_forward_now(struct alarm *alarm, ktime_t interval);
54ktime_t alarm_expires_remaining(const struct alarm *alarm);
John Stultzdce75a82011-08-10 11:31:03 -070055
John Stultz57c498f2012-04-20 12:31:45 -070056/* Provide way to access the rtc device being used by alarmtimers */
57struct rtc_device *alarmtimer_get_rtcdev(void);
58
John Stultzff3ead92011-01-11 09:42:13 -080059#endif