blob: 8a30cb5f8889df9cd107b9749625db2843095173 [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>
Mao Jinlong2e1a4ae2016-02-17 15:21:49 +08008#include <linux/types.h>
John Stultzff3ead92011-01-11 09:42:13 -08009
10enum alarmtimer_type {
11 ALARM_REALTIME,
12 ALARM_BOOTTIME,
Mao Jinlong2e1a4ae2016-02-17 15:21:49 +080013 ALARM_POWEROFF_REALTIME,
John Stultzff3ead92011-01-11 09:42:13 -080014
15 ALARM_NUMTYPE,
16};
17
John Stultz4b413082011-08-10 10:37:59 -070018enum alarmtimer_restart {
19 ALARMTIMER_NORESTART,
20 ALARMTIMER_RESTART,
21};
22
John Stultza28cde82011-08-10 12:30:21 -070023
24#define ALARMTIMER_STATE_INACTIVE 0x00
25#define ALARMTIMER_STATE_ENQUEUED 0x01
John Stultza28cde82011-08-10 12:30:21 -070026
John Stultz180bf812011-04-28 12:58:11 -070027/**
28 * struct alarm - Alarm timer structure
29 * @node: timerqueue node for adding to the event list this value
30 * also includes the expiration time.
Pratyush Patelaf4afb42016-06-14 11:00:42 +020031 * @timer: hrtimer used to schedule events while running
John Stultz180bf812011-04-28 12:58:11 -070032 * @function: Function pointer to be executed when the timer fires.
Pratyush Patelaf4afb42016-06-14 11:00:42 +020033 * @type: Alarm type (BOOTTIME/REALTIME).
34 * @state: Flag that represents if the alarm is set to fire or not.
John Stultz180bf812011-04-28 12:58:11 -070035 * @data: Internal data value.
36 */
John Stultzff3ead92011-01-11 09:42:13 -080037struct alarm {
38 struct timerqueue_node node;
John Stultzdae373b2012-09-13 19:12:16 -040039 struct hrtimer timer;
John Stultz4b413082011-08-10 10:37:59 -070040 enum alarmtimer_restart (*function)(struct alarm *, ktime_t now);
John Stultzff3ead92011-01-11 09:42:13 -080041 enum alarmtimer_type type;
John Stultza28cde82011-08-10 12:30:21 -070042 int state;
John Stultzff3ead92011-01-11 09:42:13 -080043 void *data;
44};
45
46void alarm_init(struct alarm *alarm, enum alarmtimer_type type,
John Stultz4b413082011-08-10 10:37:59 -070047 enum alarmtimer_restart (*function)(struct alarm *, ktime_t));
Thomas Gleixnerb1932172015-04-14 21:09:18 +000048void alarm_start(struct alarm *alarm, ktime_t start);
49void alarm_start_relative(struct alarm *alarm, ktime_t start);
Todd Poynor6cffe002013-05-15 14:38:11 -070050void alarm_restart(struct alarm *alarm);
John Stultz9082c462011-08-10 12:41:36 -070051int alarm_try_to_cancel(struct alarm *alarm);
52int alarm_cancel(struct alarm *alarm);
Mao Jinlong2e1a4ae2016-02-17 15:21:49 +080053void set_power_on_alarm(void);
54void power_on_alarm_init(void);
55enum alarmtimer_type clock2alarm(clockid_t clockid);
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);
Mohit Aggarwaldad42952015-01-06 13:03:49 +053063#ifdef CONFIG_RTC_DRV_QPNP
64extern bool poweron_alarm;
65#endif
John Stultz57c498f2012-04-20 12:31:45 -070066
John Stultzff3ead92011-01-11 09:42:13 -080067#endif