33 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
35 #include <linux/module.h>
36 #include <linux/types.h>
37 #include <linux/errno.h>
38 #include <linux/kernel.h>
40 #include <linux/watchdog.h>
48 static dev_t watchdog_devt;
73 if (!watchdog_active(wddev))
77 err = wddev->
ops->ping(wddev);
79 err = wddev->
ops->start(wddev);
106 if (watchdog_active(wddev))
109 err = wddev->
ops->start(wddev);
139 if (!watchdog_active(wddev))
143 dev_info(wddev->
dev,
"nowayout prevents watchdog being stopped!\n");
148 err = wddev->
ops->stop(wddev);
171 if (!wddev->
ops->status)
181 *status = wddev->
ops->status(wddev);
199 if ((wddev->
ops->set_timeout ==
NULL) ||
214 err = wddev->
ops->set_timeout(wddev, timeout);
230 unsigned int *timeleft)
235 if (!wddev->
ops->get_timeleft)
245 *timeleft = wddev->
ops->get_timeleft(wddev);
264 if (!wddev->
ops->ioctl)
274 err = wddev->
ops->ioctl(wddev, cmd, arg);
294 size_t len, loff_t *ppos)
310 for (i = 0; i != len; i++) {
333 static long watchdog_ioctl(
struct file *file,
unsigned int cmd,
342 err = watchdog_ioctl_op(wdd, cmd, arg);
351 err = watchdog_get_status(wdd, &val);
361 err = watchdog_stop(wdd);
366 err = watchdog_start(wdd);
379 err = watchdog_set_timeout(wdd, val);
393 err = watchdog_get_timeleft(wdd, &val);
412 static int watchdog_open(
struct inode *
inode,
struct file *file)
431 if (!try_module_get(wdd->
ops->owner))
434 err = watchdog_start(wdd);
447 module_put(wdd->
ops->owner);
463 static int watchdog_release(
struct inode *inode,
struct file *file)
475 err = watchdog_stop(wdd);
481 dev_crit(wdd->
dev,
"watchdog did not stop!\n");
487 module_put(wdd->
ops->owner);
494 wdd->
ops->unref(wdd);
501 .write = watchdog_write,
502 .unlocked_ioctl = watchdog_ioctl,
503 .open = watchdog_open,
504 .release = watchdog_release,
510 .fops = &watchdog_fops,
526 if (watchdog->
id == 0) {
530 pr_err(
"%s: cannot register miscdev on minor=%d (err=%d).\n",
533 pr_err(
"%s: a legacy watchdog module is probably present.\n",
534 watchdog->
info->identity);
543 watchdog->
cdev.owner = watchdog->
ops->owner;
548 pr_err(
"watchdog%d unable to add device %d:%d\n",
549 watchdog->
id,
MAJOR(watchdog_devt), watchdog->
id);
550 if (watchdog->
id == 0) {
572 if (watchdog->
id == 0) {
589 pr_err(
"watchdog: unable to allocate char dev region\n");