usb: io_ti: Make edge_remove_sysfs_attrs the port_remove method.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / watchdog / watchdog_core.c
blobcfa1a1518aadaa19c7d4e296c9ce2e5826e3e5f0
1 /*
2 * watchdog_core.c
4 * (c) Copyright 2008-2011 Alan Cox <alan@lxorguk.ukuu.org.uk>,
5 * All Rights Reserved.
7 * (c) Copyright 2008-2011 Wim Van Sebroeck <wim@iguana.be>.
9 * This source code is part of the generic code that can be used
10 * by all the watchdog timer drivers.
12 * Based on source code of the following authors:
13 * Matt Domsch <Matt_Domsch@dell.com>,
14 * Rob Radez <rob@osinvestor.com>,
15 * Rusty Lynch <rusty@linux.co.intel.com>
16 * Satyam Sharma <satyam@infradead.org>
17 * Randy Dunlap <randy.dunlap@oracle.com>
19 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU General Public License
21 * as published by the Free Software Foundation; either version
22 * 2 of the License, or (at your option) any later version.
24 * Neither Alan Cox, CymruNet Ltd., Wim Van Sebroeck nor Iguana vzw.
25 * admit liability nor provide warranty for any of this software.
26 * This material is provided "AS-IS" and at no charge.
29 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31 #include <linux/module.h> /* For EXPORT_SYMBOL/module stuff/... */
32 #include <linux/types.h> /* For standard types */
33 #include <linux/errno.h> /* For the -ENODEV/... values */
34 #include <linux/kernel.h> /* For printk/panic/... */
35 #include <linux/watchdog.h> /* For watchdog specific items */
36 #include <linux/init.h> /* For __init/__exit/... */
38 #include "watchdog_dev.h" /* For watchdog_dev_register/... */
40 /**
41 * watchdog_register_device() - register a watchdog device
42 * @wdd: watchdog device
44 * Register a watchdog device with the kernel so that the
45 * watchdog timer can be accessed from userspace.
47 * A zero is returned on success and a negative errno code for
48 * failure.
50 int watchdog_register_device(struct watchdog_device *wdd)
52 int ret;
54 if (wdd == NULL || wdd->info == NULL || wdd->ops == NULL)
55 return -EINVAL;
57 /* Mandatory operations need to be supported */
58 if (wdd->ops->start == NULL || wdd->ops->stop == NULL)
59 return -EINVAL;
62 * Check that we have valid min and max timeout values, if
63 * not reset them both to 0 (=not used or unknown)
65 if (wdd->min_timeout > wdd->max_timeout) {
66 pr_info("Invalid min and max timeout values, resetting to 0!\n");
67 wdd->min_timeout = 0;
68 wdd->max_timeout = 0;
72 * Note: now that all watchdog_device data has been verified, we
73 * will not check this anymore in other functions. If data gets
74 * corrupted in a later stage then we expect a kernel panic!
77 /* We only support 1 watchdog device via the /dev/watchdog interface */
78 ret = watchdog_dev_register(wdd);
79 if (ret) {
80 pr_err("error registering /dev/watchdog (err=%d).\n", ret);
81 return ret;
84 return 0;
86 EXPORT_SYMBOL_GPL(watchdog_register_device);
88 /**
89 * watchdog_unregister_device() - unregister a watchdog device
90 * @wdd: watchdog device to unregister
92 * Unregister a watchdog device that was previously successfully
93 * registered with watchdog_register_device().
95 void watchdog_unregister_device(struct watchdog_device *wdd)
97 int ret;
99 if (wdd == NULL)
100 return;
102 ret = watchdog_dev_unregister(wdd);
103 if (ret)
104 pr_err("error unregistering /dev/watchdog (err=%d).\n", ret);
106 EXPORT_SYMBOL_GPL(watchdog_unregister_device);
108 MODULE_AUTHOR("Alan Cox <alan@lxorguk.ukuu.org.uk>");
109 MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
110 MODULE_DESCRIPTION("WatchDog Timer Driver Core");
111 MODULE_LICENSE("GPL");