Skip to content

Commit

Permalink
watchdog: Make set_timeout function optional
Browse files Browse the repository at this point in the history
For some watchdogs, the watchdog driver handles timeout changes without
explicitly setting any registers. In this situation, the watchdog driver
might only set the 'timeout' variable but do nothing else.
This can as well be handled by the infrastructure, so make the set_timeout
callback optional. If WDIOF_SETTIMEOUT is configured but the .set_timeout
callback is not available, update the timeout variable in the
infrastructure code.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
  • Loading branch information
Guenter Roeck authored and Wim Van Sebroeck committed Mar 16, 2016
1 parent e21f562 commit fb32e9b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Documentation/watchdog/watchdog-kernel-api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ they are supported. These optional routines/operations are:
because the watchdog does not necessarily has a 1 second resolution).
(Note: the WDIOF_SETTIMEOUT needs to be set in the options field of the
watchdog's info structure).
If the watchdog driver does not have to perform any action but setting the
watchdog_device.timeout, this callback can be omitted.
If set_timeout is not provided but, WDIOF_SETTIMEOUT is set, the watchdog
infrastructure updates the timeout value of the watchdog_device internally
to the requested value.
* get_timeleft: this routines returns the time that's left before a reset.
* restart: this routine restarts the machine. It returns 0 on success or a
negative errno code for failure.
Expand Down
11 changes: 9 additions & 2 deletions drivers/watchdog/watchdog_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,20 @@ static unsigned int watchdog_get_status(struct watchdog_device *wdd)
static int watchdog_set_timeout(struct watchdog_device *wdd,
unsigned int timeout)
{
if (!wdd->ops->set_timeout || !(wdd->info->options & WDIOF_SETTIMEOUT))
int err = 0;

if (!(wdd->info->options & WDIOF_SETTIMEOUT))
return -EOPNOTSUPP;

if (watchdog_timeout_invalid(wdd, timeout))
return -EINVAL;

return wdd->ops->set_timeout(wdd, timeout);
if (wdd->ops->set_timeout)
err = wdd->ops->set_timeout(wdd, timeout);
else
wdd->timeout = timeout;

return err;
}

/*
Expand Down

0 comments on commit fb32e9b

Please sign in to comment.