blob: c70aac13244aa68930e248d9fef21300f167d38f [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
Baolin Wang4a057542016-11-28 14:35:21 -080013 /* Supported types end here */
John Stultzff3ead92011-01-11 09:42:13 -080014 ALARM_NUMTYPE,
Baolin Wang4a057542016-11-28 14:35:21 -080015
16 /* Used for tracing information. No usable types. */
17 ALARM_REALTIME_FREEZER,
18 ALARM_BOOTTIME_FREEZER,
John Stultzff3ead92011-01-11 09:42:13 -080019};
20
John Stultz4b413082011-08-10 10:37:59 -070021enum alarmtimer_restart {
22 ALARMTIMER_NORESTART,
23 ALARMTIMER_RESTART,
24};
25
John Stultza28cde82011-08-10 12:30:21 -070026
27#define ALARMTIMER_STATE_INACTIVE 0x00
28#define ALARMTIMER_STATE_ENQUEUED 0x01
John Stultza28cde82011-08-10 12:30:21 -070029
John Stultz180bf812011-04-28 12:58:11 -070030/**
31 * struct alarm - Alarm timer structure
32 * @node: timerqueue node for adding to the event list this value
33 * also includes the expiration time.
Pratyush Patelaf4afb42016-06-14 11:00:42 +020034 * @timer: hrtimer used to schedule events while running
John Stultz180bf812011-04-28 12:58:11 -070035 * @function: Function pointer to be executed when the timer fires.
Pratyush Patelaf4afb42016-06-14 11:00:42 +020036 * @type: Alarm type (BOOTTIME/REALTIME).
37 * @state: Flag that represents if the alarm is set to fire or not.
John Stultz180bf812011-04-28 12:58:11 -070038 * @data: Internal data value.
39 */
John Stultzff3ead92011-01-11 09:42:13 -080040struct alarm {
41 struct timerqueue_node node;
John Stultzdae373b2012-09-13 19:12:16 -040042 struct hrtimer timer;
John Stultz4b413082011-08-10 10:37:59 -070043 enum alarmtimer_restart (*function)(struct alarm *, ktime_t now);
John Stultzff3ead92011-01-11 09:42:13 -080044 enum alarmtimer_type type;
John Stultza28cde82011-08-10 12:30:21 -070045 int state;
John Stultzff3ead92011-01-11 09:42:13 -080046 void *data;
47};
48
49void alarm_init(struct alarm *alarm, enum alarmtimer_type type,
John Stultz4b413082011-08-10 10:37:59 -070050 enum alarmtimer_restart (*function)(struct alarm *, ktime_t));
Thomas Gleixnerb1932172015-04-14 21:09:18 +000051void alarm_start(struct alarm *alarm, ktime_t start);
52void alarm_start_relative(struct alarm *alarm, ktime_t start);
Todd Poynor6cffe002013-05-15 14:38:11 -070053void alarm_restart(struct alarm *alarm);
John Stultz9082c462011-08-10 12:41:36 -070054int alarm_try_to_cancel(struct alarm *alarm);
55int alarm_cancel(struct alarm *alarm);
John Stultzff3ead92011-01-11 09:42:13 -080056
John Stultzdce75a82011-08-10 11:31:03 -070057u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval);
Todd Poynor6cffe002013-05-15 14:38:11 -070058u64 alarm_forward_now(struct alarm *alarm, ktime_t interval);
59ktime_t alarm_expires_remaining(const struct alarm *alarm);
John Stultzdce75a82011-08-10 11:31:03 -070060
John Stultz57c498f2012-04-20 12:31:45 -070061/* Provide way to access the rtc device being used by alarmtimers */
62struct rtc_device *alarmtimer_get_rtcdev(void);
63
John Stultzff3ead92011-01-11 09:42:13 -080064#endif