[PATCH V2] watchdog: Add watchdog device control through sysfs attributes
This patch adds following attributes to watchdog device's sysfs interface. * state - reads whether device is active or not * identity - reads Watchdog device's identity string. * timeout - reads current timeout. * timeleft - reads timeleft before watchdog generates a reset * bootstatus - reads status of the watchdog device at boot * status - reads watchdog device's internal status bits * nowayout - reads whether nowayout feature was set or not Testing with iTCO_wdt: # cd /sys/class/watchdog/watchdog1/ # ls bootstatus dev device identity nowayout power state subsystem timeleft timeout uevent # cat identity iTCO_wdt # cat timeout 30 # cat state inactive # echo > /dev/watchdog1 # cat timeleft 26 # cat state active # cat bootstatus 0 # cat nowayout 0 Signed-off-by: Pratyush Anand --- Changes since V1(RFC): * Removed keepalive and start ABI * timeout is read only now * state returns text * only supported ABI visible * ABI contact changed to MAINTAINER * unnecessary mutex removed * aligned continuation with '(' * unnecessary initialization of status (= 0) corrected * unnecessary else removed * used __ATTRIBUTE_GROUPS * removed watchdog_device_create and added functionality in watchdog_dev_register. * optimized nowayout_show * Now no -EOPNOTSUPP return for timeout read in case of wdd->timeout = 0. Documentation/ABI/testing/sysfs-class-watchdog | 51 ++ drivers/watchdog/watchdog_core.c | 16 +-- drivers/watchdog/watchdog_core.h | 3 +- drivers/watchdog/watchdog_dev.c| 132 - 4 files changed, 183 insertions(+), 19 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-class-watchdog diff --git a/Documentation/ABI/testing/sysfs-class-watchdog b/Documentation/ABI/testing/sysfs-class-watchdog new file mode 100644 index ..736046b33040 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-class-watchdog @@ -0,0 +1,51 @@ +What: /sys/class/watchdog/watchdogn/bootstatus +Date: August 2015 +Contact: Wim Van Sebroeck +Description: + It is a read only file. It contains status of the watchdog + device at boot. It is equivalent to WDIOC_GETBOOTSTATUS of + ioctl interface. + +What: /sys/class/watchdog/watchdogn/identity +Date: August 2015 +Contact: Wim Van Sebroeck +Description: + It is a read only file. It contains identity string of + watchdog device. + +What: /sys/class/watchdog/watchdogn/nowayout +Date: August 2015 +Contact: Wim Van Sebroeck +Description: + It is a read only file. While reading, it gives '1' if that + device supports nowayout feature else, it gives '0'. + +What: /sys/class/watchdog/watchdogn/state +Date: August 2015 +Contact: Wim Van Sebroeck +Description: + It is a read only file. It gives active/inactive status of + watchdog device. + +What: /sys/class/watchdog/watchdogn/status +Date: August 2015 +Contact: Wim Van Sebroeck +Description: + It is a read only file. It contains watchdog device's + internal status bits. It is equivalent to WDIOC_GETSTATUS + of ioctl interface. + +What: /sys/class/watchdog/watchdogn/timeleft +Date: August 2015 +Contact: Wim Van Sebroeck +Description: + It is a read only file. It contains value of time left for + reset generation. It is equivalent to WDIOC_GETTIMELEFT of + ioctl interface. + +What: /sys/class/watchdog/watchdogn/timeout +Date: August 2015 +Contact: Wim Van Sebroeck +Description: + It is a read only file. It is read to know about current + value of timeout programmed. diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c index 1a8059455413..3f9eb13b2023 100644 --- a/drivers/watchdog/watchdog_core.c +++ b/drivers/watchdog/watchdog_core.c @@ -139,7 +139,7 @@ EXPORT_SYMBOL_GPL(watchdog_init_timeout); static int __watchdog_register_device(struct watchdog_device *wdd) { - int ret, id, devno; + int ret, id; if (wdd == NULL || wdd->info == NULL || wdd->ops == NULL) return -EINVAL; @@ -162,7 +162,7 @@ static int __watchdog_register_device(struct watchdog_device *wdd) return id; wdd->id = id; - ret = watchdog_dev_register(wdd); + ret = watchdog_dev_register(wdd, watchdog_class); if (ret) { ida_simple_remove(_ida, id); if (!(id == 0 && ret == -EBUSY)) @@ -174,23 +174,13 @@ static int __watchdog_register_device(struct watchdog_device *wdd) return id; wdd->id = id; - ret = watchdog_dev_register(wdd); + ret =
[PATCH V2] watchdog: Add watchdog device control through sysfs attributes
This patch adds following attributes to watchdog device's sysfs interface. * state - reads whether device is active or not * identity - reads Watchdog device's identity string. * timeout - reads current timeout. * timeleft - reads timeleft before watchdog generates a reset * bootstatus - reads status of the watchdog device at boot * status - reads watchdog device's internal status bits * nowayout - reads whether nowayout feature was set or not Testing with iTCO_wdt: # cd /sys/class/watchdog/watchdog1/ # ls bootstatus dev device identity nowayout power state subsystem timeleft timeout uevent # cat identity iTCO_wdt # cat timeout 30 # cat state inactive # echo > /dev/watchdog1 # cat timeleft 26 # cat state active # cat bootstatus 0 # cat nowayout 0 Signed-off-by: Pratyush Anand--- Changes since V1(RFC): * Removed keepalive and start ABI * timeout is read only now * state returns text * only supported ABI visible * ABI contact changed to MAINTAINER * unnecessary mutex removed * aligned continuation with '(' * unnecessary initialization of status (= 0) corrected * unnecessary else removed * used __ATTRIBUTE_GROUPS * removed watchdog_device_create and added functionality in watchdog_dev_register. * optimized nowayout_show * Now no -EOPNOTSUPP return for timeout read in case of wdd->timeout = 0. Documentation/ABI/testing/sysfs-class-watchdog | 51 ++ drivers/watchdog/watchdog_core.c | 16 +-- drivers/watchdog/watchdog_core.h | 3 +- drivers/watchdog/watchdog_dev.c| 132 - 4 files changed, 183 insertions(+), 19 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-class-watchdog diff --git a/Documentation/ABI/testing/sysfs-class-watchdog b/Documentation/ABI/testing/sysfs-class-watchdog new file mode 100644 index ..736046b33040 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-class-watchdog @@ -0,0 +1,51 @@ +What: /sys/class/watchdog/watchdogn/bootstatus +Date: August 2015 +Contact: Wim Van Sebroeck +Description: + It is a read only file. It contains status of the watchdog + device at boot. It is equivalent to WDIOC_GETBOOTSTATUS of + ioctl interface. + +What: /sys/class/watchdog/watchdogn/identity +Date: August 2015 +Contact: Wim Van Sebroeck +Description: + It is a read only file. It contains identity string of + watchdog device. + +What: /sys/class/watchdog/watchdogn/nowayout +Date: August 2015 +Contact: Wim Van Sebroeck +Description: + It is a read only file. While reading, it gives '1' if that + device supports nowayout feature else, it gives '0'. + +What: /sys/class/watchdog/watchdogn/state +Date: August 2015 +Contact: Wim Van Sebroeck +Description: + It is a read only file. It gives active/inactive status of + watchdog device. + +What: /sys/class/watchdog/watchdogn/status +Date: August 2015 +Contact: Wim Van Sebroeck +Description: + It is a read only file. It contains watchdog device's + internal status bits. It is equivalent to WDIOC_GETSTATUS + of ioctl interface. + +What: /sys/class/watchdog/watchdogn/timeleft +Date: August 2015 +Contact: Wim Van Sebroeck +Description: + It is a read only file. It contains value of time left for + reset generation. It is equivalent to WDIOC_GETTIMELEFT of + ioctl interface. + +What: /sys/class/watchdog/watchdogn/timeout +Date: August 2015 +Contact: Wim Van Sebroeck +Description: + It is a read only file. It is read to know about current + value of timeout programmed. diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c index 1a8059455413..3f9eb13b2023 100644 --- a/drivers/watchdog/watchdog_core.c +++ b/drivers/watchdog/watchdog_core.c @@ -139,7 +139,7 @@ EXPORT_SYMBOL_GPL(watchdog_init_timeout); static int __watchdog_register_device(struct watchdog_device *wdd) { - int ret, id, devno; + int ret, id; if (wdd == NULL || wdd->info == NULL || wdd->ops == NULL) return -EINVAL; @@ -162,7 +162,7 @@ static int __watchdog_register_device(struct watchdog_device *wdd) return id; wdd->id = id; - ret = watchdog_dev_register(wdd); + ret = watchdog_dev_register(wdd, watchdog_class); if (ret) { ida_simple_remove(_ida, id); if (!(id == 0 && ret == -EBUSY)) @@ -174,23 +174,13 @@ static int __watchdog_register_device(struct watchdog_device *wdd) return