]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
ff3ead96 JS |
2 | #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> | |
8 | #include <linux/rtc.h> | |
9 | ||
10 | enum alarmtimer_type { | |
11 | ALARM_REALTIME, | |
12 | ALARM_BOOTTIME, | |
13 | ||
4a057549 | 14 | /* Supported types end here */ |
ff3ead96 | 15 | ALARM_NUMTYPE, |
4a057549 BW |
16 | |
17 | /* Used for tracing information. No usable types. */ | |
18 | ALARM_REALTIME_FREEZER, | |
19 | ALARM_BOOTTIME_FREEZER, | |
ff3ead96 JS |
20 | }; |
21 | ||
4b41308d JS |
22 | enum alarmtimer_restart { |
23 | ALARMTIMER_NORESTART, | |
24 | ALARMTIMER_RESTART, | |
25 | }; | |
26 | ||
a28cde81 JS |
27 | |
28 | #define ALARMTIMER_STATE_INACTIVE 0x00 | |
29 | #define ALARMTIMER_STATE_ENQUEUED 0x01 | |
a28cde81 | 30 | |
180bf812 JS |
31 | /** |
32 | * struct alarm - Alarm timer structure | |
33 | * @node: timerqueue node for adding to the event list this value | |
34 | * also includes the expiration time. | |
af4afb40 | 35 | * @timer: hrtimer used to schedule events while running |
180bf812 | 36 | * @function: Function pointer to be executed when the timer fires. |
af4afb40 PP |
37 | * @type: Alarm type (BOOTTIME/REALTIME). |
38 | * @state: Flag that represents if the alarm is set to fire or not. | |
180bf812 JS |
39 | * @data: Internal data value. |
40 | */ | |
ff3ead96 JS |
41 | struct alarm { |
42 | struct timerqueue_node node; | |
dae373be | 43 | struct hrtimer timer; |
4b41308d | 44 | enum alarmtimer_restart (*function)(struct alarm *, ktime_t now); |
ff3ead96 | 45 | enum alarmtimer_type type; |
a28cde81 | 46 | int state; |
ff3ead96 JS |
47 | void *data; |
48 | }; | |
49 | ||
50 | void alarm_init(struct alarm *alarm, enum alarmtimer_type type, | |
4b41308d | 51 | enum alarmtimer_restart (*function)(struct alarm *, ktime_t)); |
b193217e TG |
52 | void alarm_start(struct alarm *alarm, ktime_t start); |
53 | void alarm_start_relative(struct alarm *alarm, ktime_t start); | |
6cffe00f | 54 | void alarm_restart(struct alarm *alarm); |
9082c465 JS |
55 | int alarm_try_to_cancel(struct alarm *alarm); |
56 | int alarm_cancel(struct alarm *alarm); | |
ff3ead96 | 57 | |
dce75a8c | 58 | u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval); |
6cffe00f TP |
59 | u64 alarm_forward_now(struct alarm *alarm, ktime_t interval); |
60 | ktime_t alarm_expires_remaining(const struct alarm *alarm); | |
dce75a8c | 61 | |
57c498fa JS |
62 | /* Provide way to access the rtc device being used by alarmtimers */ |
63 | struct rtc_device *alarmtimer_get_rtcdev(void); | |
64 | ||
ff3ead96 | 65 | #endif |