Merge tag 'for-6.9/dm-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/device...
[linux-2.6-microblaze.git] / drivers / watchdog / watchdog_hrtimer_pretimeout.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * (c) Copyright 2021 Hewlett Packard Enterprise Development LP.
4  */
5
6 #include <linux/hrtimer.h>
7 #include <linux/watchdog.h>
8
9 #include "watchdog_core.h"
10 #include "watchdog_pretimeout.h"
11
12 static enum hrtimer_restart watchdog_hrtimer_pretimeout(struct hrtimer *timer)
13 {
14         struct watchdog_core_data *wd_data;
15
16         wd_data = container_of(timer, struct watchdog_core_data, pretimeout_timer);
17
18         watchdog_notify_pretimeout(wd_data->wdd);
19         return HRTIMER_NORESTART;
20 }
21
22 void watchdog_hrtimer_pretimeout_init(struct watchdog_device *wdd)
23 {
24         struct watchdog_core_data *wd_data = wdd->wd_data;
25
26         hrtimer_init(&wd_data->pretimeout_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
27         wd_data->pretimeout_timer.function = watchdog_hrtimer_pretimeout;
28 }
29
30 void watchdog_hrtimer_pretimeout_start(struct watchdog_device *wdd)
31 {
32         if (!(wdd->info->options & WDIOF_PRETIMEOUT) &&
33             !watchdog_pretimeout_invalid(wdd, wdd->pretimeout))
34                 hrtimer_start(&wdd->wd_data->pretimeout_timer,
35                               ktime_set(wdd->timeout - wdd->pretimeout, 0),
36                               HRTIMER_MODE_REL);
37         else
38                 hrtimer_cancel(&wdd->wd_data->pretimeout_timer);
39 }
40
41 void watchdog_hrtimer_pretimeout_stop(struct watchdog_device *wdd)
42 {
43         hrtimer_cancel(&wdd->wd_data->pretimeout_timer);
44 }