1 // SPDX-License-Identifier: GPL-2.0
3 * (c) Copyright 2021 Hewlett Packard Enterprise Development LP.
6 #include <linux/hrtimer.h>
7 #include <linux/watchdog.h>
9 #include "watchdog_core.h"
10 #include "watchdog_pretimeout.h"
12 static enum hrtimer_restart watchdog_hrtimer_pretimeout(struct hrtimer *timer)
14 struct watchdog_core_data *wd_data;
16 wd_data = container_of(timer, struct watchdog_core_data, pretimeout_timer);
18 watchdog_notify_pretimeout(wd_data->wdd);
19 return HRTIMER_NORESTART;
22 void watchdog_hrtimer_pretimeout_init(struct watchdog_device *wdd)
24 struct watchdog_core_data *wd_data = wdd->wd_data;
26 hrtimer_init(&wd_data->pretimeout_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
27 wd_data->pretimeout_timer.function = watchdog_hrtimer_pretimeout;
30 void watchdog_hrtimer_pretimeout_start(struct watchdog_device *wdd)
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),
38 hrtimer_cancel(&wdd->wd_data->pretimeout_timer);
41 void watchdog_hrtimer_pretimeout_stop(struct watchdog_device *wdd)
43 hrtimer_cancel(&wdd->wd_data->pretimeout_timer);