1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2ff3ead96SJohn Stultz #ifndef _LINUX_ALARMTIMER_H
3ff3ead96SJohn Stultz #define _LINUX_ALARMTIMER_H
4ff3ead96SJohn Stultz
5ff3ead96SJohn Stultz #include <linux/time.h>
6ff3ead96SJohn Stultz #include <linux/hrtimer.h>
7ff3ead96SJohn Stultz #include <linux/timerqueue.h>
83758b0f8SThomas Gleixner
93758b0f8SThomas Gleixner struct rtc_device;
10ff3ead96SJohn Stultz
11ff3ead96SJohn Stultz enum alarmtimer_type {
12ff3ead96SJohn Stultz ALARM_REALTIME,
13ff3ead96SJohn Stultz ALARM_BOOTTIME,
14ff3ead96SJohn Stultz
154a057549SBaolin Wang /* Supported types end here */
16ff3ead96SJohn Stultz ALARM_NUMTYPE,
174a057549SBaolin Wang
184a057549SBaolin Wang /* Used for tracing information. No usable types. */
194a057549SBaolin Wang ALARM_REALTIME_FREEZER,
204a057549SBaolin Wang ALARM_BOOTTIME_FREEZER,
21ff3ead96SJohn Stultz };
22ff3ead96SJohn Stultz
23a28cde81SJohn Stultz #define ALARMTIMER_STATE_INACTIVE 0x00
24a28cde81SJohn Stultz #define ALARMTIMER_STATE_ENQUEUED 0x01
25a28cde81SJohn Stultz
26180bf812SJohn Stultz /**
27180bf812SJohn Stultz * struct alarm - Alarm timer structure
28180bf812SJohn Stultz * @node: timerqueue node for adding to the event list this value
29180bf812SJohn Stultz * also includes the expiration time.
30af4afb40SPratyush Patel * @timer: hrtimer used to schedule events while running
31180bf812SJohn Stultz * @function: Function pointer to be executed when the timer fires.
32af4afb40SPratyush Patel * @type: Alarm type (BOOTTIME/REALTIME).
33af4afb40SPratyush Patel * @state: Flag that represents if the alarm is set to fire or not.
34180bf812SJohn Stultz * @data: Internal data value.
35180bf812SJohn Stultz */
36ff3ead96SJohn Stultz struct alarm {
37ff3ead96SJohn Stultz struct timerqueue_node node;
38dae373beSJohn Stultz struct hrtimer timer;
39*2634303fSThomas Gleixner void (*function)(struct alarm *, ktime_t now);
40ff3ead96SJohn Stultz enum alarmtimer_type type;
41a28cde81SJohn Stultz int state;
42ff3ead96SJohn Stultz void *data;
43ff3ead96SJohn Stultz };
44ff3ead96SJohn Stultz
45ff3ead96SJohn Stultz void alarm_init(struct alarm *alarm, enum alarmtimer_type type,
46*2634303fSThomas Gleixner void (*function)(struct alarm *, ktime_t));
47b193217eSThomas Gleixner void alarm_start(struct alarm *alarm, ktime_t start);
48b193217eSThomas Gleixner void alarm_start_relative(struct alarm *alarm, ktime_t start);
496cffe00fSTodd Poynor void alarm_restart(struct alarm *alarm);
509082c465SJohn Stultz int alarm_try_to_cancel(struct alarm *alarm);
519082c465SJohn Stultz int alarm_cancel(struct alarm *alarm);
52ff3ead96SJohn Stultz
53dce75a8cSJohn Stultz u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval);
546cffe00fSTodd Poynor u64 alarm_forward_now(struct alarm *alarm, ktime_t interval);
556cffe00fSTodd Poynor ktime_t alarm_expires_remaining(const struct alarm *alarm);
56dce75a8cSJohn Stultz
57fd928f3eSStephen Boyd #ifdef CONFIG_RTC_CLASS
5857c498faSJohn Stultz /* Provide way to access the rtc device being used by alarmtimers */
5957c498faSJohn Stultz struct rtc_device *alarmtimer_get_rtcdev(void);
60fd928f3eSStephen Boyd #else
alarmtimer_get_rtcdev(void)61fd928f3eSStephen Boyd static inline struct rtc_device *alarmtimer_get_rtcdev(void) { return NULL; }
62fd928f3eSStephen Boyd #endif
6357c498faSJohn Stultz
64ff3ead96SJohn Stultz #endif
65