xref: /openbmc/linux/include/linux/alarmtimer.h (revision fd928f3e)
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 
234b41308dSJohn Stultz enum alarmtimer_restart {
244b41308dSJohn Stultz 	ALARMTIMER_NORESTART,
254b41308dSJohn Stultz 	ALARMTIMER_RESTART,
264b41308dSJohn Stultz };
274b41308dSJohn Stultz 
28a28cde81SJohn Stultz 
29a28cde81SJohn Stultz #define ALARMTIMER_STATE_INACTIVE	0x00
30a28cde81SJohn Stultz #define ALARMTIMER_STATE_ENQUEUED	0x01
31a28cde81SJohn Stultz 
32180bf812SJohn Stultz /**
33180bf812SJohn Stultz  * struct alarm - Alarm timer structure
34180bf812SJohn Stultz  * @node:	timerqueue node for adding to the event list this value
35180bf812SJohn Stultz  *		also includes the expiration time.
36af4afb40SPratyush Patel  * @timer:	hrtimer used to schedule events while running
37180bf812SJohn Stultz  * @function:	Function pointer to be executed when the timer fires.
38af4afb40SPratyush Patel  * @type:	Alarm type (BOOTTIME/REALTIME).
39af4afb40SPratyush Patel  * @state:	Flag that represents if the alarm is set to fire or not.
40180bf812SJohn Stultz  * @data:	Internal data value.
41180bf812SJohn Stultz  */
42ff3ead96SJohn Stultz struct alarm {
43ff3ead96SJohn Stultz 	struct timerqueue_node	node;
44dae373beSJohn Stultz 	struct hrtimer		timer;
454b41308dSJohn Stultz 	enum alarmtimer_restart	(*function)(struct alarm *, ktime_t now);
46ff3ead96SJohn Stultz 	enum alarmtimer_type	type;
47a28cde81SJohn Stultz 	int			state;
48ff3ead96SJohn Stultz 	void			*data;
49ff3ead96SJohn Stultz };
50ff3ead96SJohn Stultz 
51ff3ead96SJohn Stultz void alarm_init(struct alarm *alarm, enum alarmtimer_type type,
524b41308dSJohn Stultz 		enum alarmtimer_restart (*function)(struct alarm *, ktime_t));
53b193217eSThomas Gleixner void alarm_start(struct alarm *alarm, ktime_t start);
54b193217eSThomas Gleixner void alarm_start_relative(struct alarm *alarm, ktime_t start);
556cffe00fSTodd Poynor void alarm_restart(struct alarm *alarm);
569082c465SJohn Stultz int alarm_try_to_cancel(struct alarm *alarm);
579082c465SJohn Stultz int alarm_cancel(struct alarm *alarm);
58ff3ead96SJohn Stultz 
59dce75a8cSJohn Stultz u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval);
606cffe00fSTodd Poynor u64 alarm_forward_now(struct alarm *alarm, ktime_t interval);
616cffe00fSTodd Poynor ktime_t alarm_expires_remaining(const struct alarm *alarm);
62dce75a8cSJohn Stultz 
63fd928f3eSStephen Boyd #ifdef CONFIG_RTC_CLASS
6457c498faSJohn Stultz /* Provide way to access the rtc device being used by alarmtimers */
6557c498faSJohn Stultz struct rtc_device *alarmtimer_get_rtcdev(void);
66fd928f3eSStephen Boyd #else
alarmtimer_get_rtcdev(void)67fd928f3eSStephen Boyd static inline struct rtc_device *alarmtimer_get_rtcdev(void) { return NULL; }
68fd928f3eSStephen Boyd #endif
6957c498faSJohn Stultz 
70ff3ead96SJohn Stultz #endif
71