blob: 05e758b8b894541c1388b8ec97300dc8573fa317 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
John Stultzff3ead92011-01-11 09:42:13 -08002#ifndef _LINUX_ALARMTIMER_H
3#define _LINUX_ALARMTIMER_H
4
5#include <linux/time.h>
6#include <linux/hrtimer.h>
7#include <linux/timerqueue.h>
Thomas Gleixner3758b0f2019-08-19 16:31:43 +02008
9struct rtc_device;
John Stultzff3ead92011-01-11 09:42:13 -080010
11enum alarmtimer_type {
12 ALARM_REALTIME,
13 ALARM_BOOTTIME,
14
Baolin Wang4a057542016-11-28 14:35:21 -080015 /* Supported types end here */
John Stultzff3ead92011-01-11 09:42:13 -080016 ALARM_NUMTYPE,
Baolin Wang4a057542016-11-28 14:35:21 -080017
18 /* Used for tracing information. No usable types. */
19 ALARM_REALTIME_FREEZER,
20 ALARM_BOOTTIME_FREEZER,
John Stultzff3ead92011-01-11 09:42:13 -080021};
22
John Stultz4b413082011-08-10 10:37:59 -070023enum alarmtimer_restart {
24 ALARMTIMER_NORESTART,
25 ALARMTIMER_RESTART,
26};
27
John Stultza28cde82011-08-10 12:30:21 -070028
29#define ALARMTIMER_STATE_INACTIVE 0x00
30#define ALARMTIMER_STATE_ENQUEUED 0x01
John Stultza28cde82011-08-10 12:30:21 -070031
John Stultz180bf812011-04-28 12:58:11 -070032/**
33 * struct alarm - Alarm timer structure
34 * @node: timerqueue node for adding to the event list this value
35 * also includes the expiration time.
Pratyush Patelaf4afb42016-06-14 11:00:42 +020036 * @timer: hrtimer used to schedule events while running
John Stultz180bf812011-04-28 12:58:11 -070037 * @function: Function pointer to be executed when the timer fires.
Pratyush Patelaf4afb42016-06-14 11:00:42 +020038 * @type: Alarm type (BOOTTIME/REALTIME).
39 * @state: Flag that represents if the alarm is set to fire or not.
John Stultz180bf812011-04-28 12:58:11 -070040 * @data: Internal data value.
41 */
John Stultzff3ead92011-01-11 09:42:13 -080042struct alarm {
43 struct timerqueue_node node;
John Stultzdae373b2012-09-13 19:12:16 -040044 struct hrtimer timer;
John Stultz4b413082011-08-10 10:37:59 -070045 enum alarmtimer_restart (*function)(struct alarm *, ktime_t now);
John Stultzff3ead92011-01-11 09:42:13 -080046 enum alarmtimer_type type;
John Stultza28cde82011-08-10 12:30:21 -070047 int state;
John Stultzff3ead92011-01-11 09:42:13 -080048 void *data;
49};
50
51void alarm_init(struct alarm *alarm, enum alarmtimer_type type,
John Stultz4b413082011-08-10 10:37:59 -070052 enum alarmtimer_restart (*function)(struct alarm *, ktime_t));
Thomas Gleixnerb1932172015-04-14 21:09:18 +000053void alarm_start(struct alarm *alarm, ktime_t start);
54void alarm_start_relative(struct alarm *alarm, ktime_t start);
Todd Poynor6cffe002013-05-15 14:38:11 -070055void alarm_restart(struct alarm *alarm);
John Stultz9082c462011-08-10 12:41:36 -070056int alarm_try_to_cancel(struct alarm *alarm);
57int alarm_cancel(struct alarm *alarm);
John Stultzff3ead92011-01-11 09:42:13 -080058
John Stultzdce75a82011-08-10 11:31:03 -070059u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval);
Todd Poynor6cffe002013-05-15 14:38:11 -070060u64 alarm_forward_now(struct alarm *alarm, ktime_t interval);
61ktime_t alarm_expires_remaining(const struct alarm *alarm);
John Stultzdce75a82011-08-10 11:31:03 -070062
Stephen Boydfd928f32020-01-23 21:58:48 -080063#ifdef CONFIG_RTC_CLASS
John Stultz57c498f2012-04-20 12:31:45 -070064/* Provide way to access the rtc device being used by alarmtimers */
65struct rtc_device *alarmtimer_get_rtcdev(void);
Stephen Boydfd928f32020-01-23 21:58:48 -080066#else
67static inline struct rtc_device *alarmtimer_get_rtcdev(void) { return NULL; }
68#endif
John Stultz57c498f2012-04-20 12:31:45 -070069
John Stultzff3ead92011-01-11 09:42:13 -080070#endif