From 997ab6d6e2ca214a7d6609ec2a1c0f57f3ff0080 Mon Sep 17 00:00:00 2001 From: Robin Gong Date: Mon, 2 Nov 2015 16:39:02 +0800 Subject: MLK-11808-2: watchdog: add WDIOC_SETPRETIMEOUT and WDIOC_GETPRETIMEOUT Since the watchdog common framework centrialize the IOCTL interfaces of device driver now, the SETPRETIMEOUT and GETPRETIMEOUT need to be added in common code Signed-off-by: Robin Gong --- drivers/watchdog/watchdog_dev.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'drivers/watchdog/watchdog_dev.c') diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c index 6aaefbad303e..02632fe8fa84 100644 --- a/drivers/watchdog/watchdog_dev.c +++ b/drivers/watchdog/watchdog_dev.c @@ -217,6 +217,37 @@ out_timeout: return err; } +/* + * watchdog_set_pretimeout: set the watchdog timer pretimeout + * @wddev: the watchdog device to set the timeout for + * @timeout: pretimeout to set in seconds + */ + +static int watchdog_set_pretimeout(struct watchdog_device *wddev, + unsigned int timeout) +{ + int err; + + if ((wddev->ops->set_pretimeout == NULL) || + !(wddev->info->options & WDIOF_PRETIMEOUT)) + return -EOPNOTSUPP; + if (watchdog_pretimeout_invalid(wddev, timeout)) + return -EINVAL; + + mutex_lock(&wddev->lock); + + if (test_bit(WDOG_UNREGISTERED, &wddev->status)) { + err = -ENODEV; + goto out_timeout; + } + + err = wddev->ops->set_pretimeout(wddev, timeout); + +out_timeout: + mutex_unlock(&wddev->lock); + return err; +} + /* * watchdog_get_timeleft: wrapper to get the time left before a reboot * @wddev: the watchdog device to get the remaining time from @@ -393,6 +424,13 @@ static long watchdog_ioctl(struct file *file, unsigned int cmd, if (err) return err; return put_user(val, p); + case WDIOC_SETPRETIMEOUT: + if (get_user(val, p)) + return -EFAULT; + err = watchdog_set_pretimeout(wdd, val); + return err; + case WDIOC_GETPRETIMEOUT: + return put_user(wdd->pretimeout, p); default: return -ENOTTY; } -- cgit v1.2.3