John Stultz | ff3ead9 | 2011-01-11 09:42:13 -0800 | [diff] [blame] | 1 | #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 Jinlong | 2e1a4ae | 2016-02-17 15:21:49 +0800 | [diff] [blame] | 8 | #include <linux/types.h> |
John Stultz | ff3ead9 | 2011-01-11 09:42:13 -0800 | [diff] [blame] | 9 | |
| 10 | enum alarmtimer_type { |
| 11 | ALARM_REALTIME, |
| 12 | ALARM_BOOTTIME, |
Mao Jinlong | 2e1a4ae | 2016-02-17 15:21:49 +0800 | [diff] [blame] | 13 | ALARM_POWEROFF_REALTIME, |
John Stultz | ff3ead9 | 2011-01-11 09:42:13 -0800 | [diff] [blame] | 14 | |
| 15 | ALARM_NUMTYPE, |
| 16 | }; |
| 17 | |
John Stultz | 4b41308 | 2011-08-10 10:37:59 -0700 | [diff] [blame] | 18 | enum alarmtimer_restart { |
| 19 | ALARMTIMER_NORESTART, |
| 20 | ALARMTIMER_RESTART, |
| 21 | }; |
| 22 | |
John Stultz | a28cde8 | 2011-08-10 12:30:21 -0700 | [diff] [blame] | 23 | |
| 24 | #define ALARMTIMER_STATE_INACTIVE 0x00 |
| 25 | #define ALARMTIMER_STATE_ENQUEUED 0x01 |
John Stultz | a28cde8 | 2011-08-10 12:30:21 -0700 | [diff] [blame] | 26 | |
John Stultz | 180bf81 | 2011-04-28 12:58:11 -0700 | [diff] [blame] | 27 | /** |
| 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 Patel | af4afb4 | 2016-06-14 11:00:42 +0200 | [diff] [blame] | 31 | * @timer: hrtimer used to schedule events while running |
John Stultz | 180bf81 | 2011-04-28 12:58:11 -0700 | [diff] [blame] | 32 | * @function: Function pointer to be executed when the timer fires. |
Pratyush Patel | af4afb4 | 2016-06-14 11:00:42 +0200 | [diff] [blame] | 33 | * @type: Alarm type (BOOTTIME/REALTIME). |
| 34 | * @state: Flag that represents if the alarm is set to fire or not. |
John Stultz | 180bf81 | 2011-04-28 12:58:11 -0700 | [diff] [blame] | 35 | * @data: Internal data value. |
| 36 | */ |
John Stultz | ff3ead9 | 2011-01-11 09:42:13 -0800 | [diff] [blame] | 37 | struct alarm { |
| 38 | struct timerqueue_node node; |
John Stultz | dae373b | 2012-09-13 19:12:16 -0400 | [diff] [blame] | 39 | struct hrtimer timer; |
John Stultz | 4b41308 | 2011-08-10 10:37:59 -0700 | [diff] [blame] | 40 | enum alarmtimer_restart (*function)(struct alarm *, ktime_t now); |
John Stultz | ff3ead9 | 2011-01-11 09:42:13 -0800 | [diff] [blame] | 41 | enum alarmtimer_type type; |
John Stultz | a28cde8 | 2011-08-10 12:30:21 -0700 | [diff] [blame] | 42 | int state; |
John Stultz | ff3ead9 | 2011-01-11 09:42:13 -0800 | [diff] [blame] | 43 | void *data; |
| 44 | }; |
| 45 | |
| 46 | void alarm_init(struct alarm *alarm, enum alarmtimer_type type, |
John Stultz | 4b41308 | 2011-08-10 10:37:59 -0700 | [diff] [blame] | 47 | enum alarmtimer_restart (*function)(struct alarm *, ktime_t)); |
Thomas Gleixner | b193217 | 2015-04-14 21:09:18 +0000 | [diff] [blame] | 48 | void alarm_start(struct alarm *alarm, ktime_t start); |
| 49 | void alarm_start_relative(struct alarm *alarm, ktime_t start); |
Todd Poynor | 6cffe00 | 2013-05-15 14:38:11 -0700 | [diff] [blame] | 50 | void alarm_restart(struct alarm *alarm); |
John Stultz | 9082c46 | 2011-08-10 12:41:36 -0700 | [diff] [blame] | 51 | int alarm_try_to_cancel(struct alarm *alarm); |
| 52 | int alarm_cancel(struct alarm *alarm); |
Mao Jinlong | 2e1a4ae | 2016-02-17 15:21:49 +0800 | [diff] [blame] | 53 | void set_power_on_alarm(void); |
| 54 | void power_on_alarm_init(void); |
| 55 | enum alarmtimer_type clock2alarm(clockid_t clockid); |
John Stultz | ff3ead9 | 2011-01-11 09:42:13 -0800 | [diff] [blame] | 56 | |
John Stultz | dce75a8 | 2011-08-10 11:31:03 -0700 | [diff] [blame] | 57 | u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval); |
Todd Poynor | 6cffe00 | 2013-05-15 14:38:11 -0700 | [diff] [blame] | 58 | u64 alarm_forward_now(struct alarm *alarm, ktime_t interval); |
| 59 | ktime_t alarm_expires_remaining(const struct alarm *alarm); |
John Stultz | dce75a8 | 2011-08-10 11:31:03 -0700 | [diff] [blame] | 60 | |
John Stultz | 57c498f | 2012-04-20 12:31:45 -0700 | [diff] [blame] | 61 | /* Provide way to access the rtc device being used by alarmtimers */ |
| 62 | struct rtc_device *alarmtimer_get_rtcdev(void); |
Mohit Aggarwal | dad4295 | 2015-01-06 13:03:49 +0530 | [diff] [blame] | 63 | #ifdef CONFIG_RTC_DRV_QPNP |
| 64 | extern bool poweron_alarm; |
| 65 | #endif |
John Stultz | 57c498f | 2012-04-20 12:31:45 -0700 | [diff] [blame] | 66 | |
John Stultz | ff3ead9 | 2011-01-11 09:42:13 -0800 | [diff] [blame] | 67 | #endif |