Generic Watchdog Timer Driver
Subsystems (2)
PATCH v2 5/10 Generic Watchdog Timer Driver
watchdog: WatchDog Timer Driver Core - Part 5
This part add's the WDIOC_SETTIMEOUT and WDIOC_GETTIMEOUT ioctl functionality to the WatchDog Timer Driver Core framework.
Signed-off-by Alan Cox <[email protected]>
Signed-off-by Wim Van Sebroeck <[email protected]>
Documentation/watchdog/src/watchdog-with-timer-example.c +13 -1
@@ -110,12 +110,20 @@return 0 ; } +static int wdt_set_timeout (struct watchdog_device *wdd,int new_timeout) +{ +if (new_timeout <1 ) +return -EINVAL ; +return 0 ; +} +/* * The watchdog kernel structures */ static const struct watchdog_info wdt_info = { .identity =DRV_NAME , - .options =WDIOF_KEEPALIVEPING , + .options =WDIOF_SETTIMEOUT | +WDIOF_KEEPALIVEPING , };static const struct watchdog_ops wdt_ops = {
@@ -123,6 +131,7 @@ .start = wdt_start, .stop = wdt_stop, .ping = wdt_ping, + .set_timeout = wdt_set_timeout, };static struct watchdog_device wdt_dev = {
@@ -140,6 +149,9 @@/* Register other stuff */ +/* Set watchdog_device parameters */ + wdt_dev.timeout = timeout; +/* Register the watchdog timer device */ res =watchdog_register_device (&wdt_dev);if (res) {
Documentation/watchdog/watchdog-kernel-api.txt +9 -0
@@ -42,6 +42,7 @@ char *name; const struct watchdog_info *info; const struct watchdog_ops *ops; + int timeout; int bootstatus; long status; };
@@ -51,6 +52,7 @@ * info: a pointer to a watchdog_info structure. This structure gives some additional information about the watchdog timer itself. * ops: a pointer to the list of watchdog operations that the watchdog supports. +* timeout: the watchdog timer's timeout value (in seconds). * bootstatus: status of the device after booting (reported with watchdog WDIOF_* status bits). * status: this field contains a number of status bits that give extra
@@ -68,6 +70,7 @@ /* optional operations */ int (*ping)(struct watchdog_device *); int (*status)(struct watchdog_device *); + int (*set_timeout)(struct watchdog_device *, int); }; It is important that you first define the module owner of the watchdog timer
@@ -107,6 +110,12 @@ info structure). * status: this routine checks the status of the watchdog timer device. The status of the device is reported with watchdog WDIOF_* status flags/bits. +* set_timeout: this routine checks and changes the timeout of the watchdog + timer device. It returns 0 on success and an errno code on failure. On success + the timeout value of the watchdog_device will be changed to the value that + was just used to re-program the watchdog timer device. + (Note: the WDIOF_SETTIMEOUT needs to be set in the options field of the + watchdog's info structure). The status bits should (preferably) be set with the set_bit and clear_bit alike bit-operations. The status bit's that are defined are:
drivers/watchdog/core/watchdog_dev.c +20 -0
@@ -223,6 +223,26 @@return -EOPNOTSUPP ;watchdog_ping (wdd);return 0 ; +case WDIOC_SETTIMEOUT : +if ((wdd->ops->set_timeout ==NULL ) || + !(wdd->info->options &WDIOF_SETTIMEOUT )) +return -EOPNOTSUPP ; +if (get_user (val, p)) +return -EFAULT ; + err = wdd->ops->set_timeout (wdd, val); +if (err <0 ) +return err; + wdd->timeout = val; +/* If the watchdog is active then we sent a keepalive ping +* to make sure that the watchdog keep's running (and if +* possible that it takes the new timeout) */ +watchdog_ping (wdd); +/* Fall */ +case WDIOC_GETTIMEOUT : +/* timeout == 0 means that we don't know the timeout */ +if (wdd->timeout) +return put_user (wdd->timeout, p); +return -EOPNOTSUPP ;default :return -ENOTTY ; }
include/linux/watchdog.h +2 -0
@@ -71,6 +71,7 @@/* optional operations */ int (*ping)(struct watchdog_device *);int (*status)(struct watchdog_device *); +int (*set_timeout)(struct watchdog_device *,int ); };/* The structure that defines a watchdog device */
@@ -79,6 +80,7 @@const struct watchdog_info *info;const struct watchdog_ops *ops;int bootstatus; +int timeout;long status;#define WDOG_ACTIVE 0/* is the watchdog running/active */ #define WDOG_DEV_OPEN 1/* is the watchdog opened via
Quoted 7 lines · On Saturday 18 June 2011 19:23:57 Wim Van Sebroeck wrote:
watchdog: WatchDog Timer Driver Core - Part 5
This part add's the
WDIOC_SETTIMEOUTandWDIOC_GETTIMEOUTioctl functionality to the WatchDog Timer Driver Core framework.Signed-off-by Alan Cox <[email protected]>Signed-off-by Wim Van Sebroeck <[email protected]>
Acked-by Arnd Bergmann <[email protected]>