linux-watchdog.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: harshal chaudhari <harshalchau04@gmail.com>,
	Wim Van Sebroeck <wim@linux-watchdog.org>
Cc: linux-watchdog@vger.kernel.org
Subject: Re: [PATCH] watchdog: Read device status through sysfs attributes for GPIO-controlled Watchdog.
Date: Sun, 8 Dec 2019 10:51:03 -0800	[thread overview]
Message-ID: <00897846-a86d-8de4-8ecb-f7c79d30e06d@roeck-us.net> (raw)
In-Reply-To: <CAFEvwum0uu1p9wK66rFbqFi4YQjfEfZcGd54Yeswk9=0EryP1Q@mail.gmail.com>

On 12/8/19 10:45 AM, harshal chaudhari wrote:
> Hi Wim and Guenter,
> 
> This patch adds following attributes to GPIO-controlled watchdog device's sysfs interface to read its different status.
> 
> 
You lost me. What does this patch do that CONFIG_WATCHDOG_SYSFS doesn't do as well ?

Guenter

> * state - reads whether device is active or not
> 
> * identity - reads Watchdog device's identity string.
> 
> * timeout - reads current timeout.
> 
> * bootstatus - reads status of the watchdog device at boot.
> 
> * nowayout - reads whether nowayout feature was set or not.
> 
> 
> Testing with GPIO Watchdog:
> 
> 
> $ cat bootstatus
> 
> 0
> 
> $ cat identity
> 
> GPIO Watchdog
> 
> $ cat nowayout
> 
> 0
> 
> $ cat state
> 
> inactive
> 
> $ cat timeout
> 
> 60
> 
> 
> Signed-off-by: harshal chaudhari <harshalchau04@gmail.com <mailto:harshalchau04@gmail.com>>
> 
> 
> 
> diff --git a/Documentation/devicetree/bindings/watchdog/gpio-wdt.txt b/Documentation/devicetree/bindings/watchdog/gpio-wdt.txt
> index 198794963786..762149375280 100644
> --- a/Documentation/devicetree/bindings/watchdog/gpio-wdt.txt
> +++ b/Documentation/devicetree/bindings/watchdog/gpio-wdt.txt
> @@ -26,3 +26,31 @@ Example:
>                  hw_algo = "toggle";
>                  hw_margin_ms = <1600>;
>          };
> +
> +
> +* Read device status through sysfs attributes
> +
> +  state - reads whether device is active or not
> +
> +       It is a read only file. It gives active/inactive status of
> +       watchdog device.
> +
> +  identity - reads Watchdog device's identity string.
> +
> +       It is a read only file. It contains identity string of
> +       watchdog device.
> +
> +  timeout - reads current timeout.
> +       It is a read only file. It is read to know about current
> +       value of timeout programmed.
> +
> +  bootstatus - reads status of the watchdog device at boot
> +       It is a read only file. It contains status of the watchdog
> +       device at boot. It is equivalent to WDIOC_GETBOOTSTATUS of
> +       ioctl interface.
> +
> +  nowayout - reads whether nowayout feature was set or not
> +       It is a read only file. While reading, it gives '1' if that
> +       device supports nowayout feature else, it gives '0'.
> +
> +For more details refer the documents as in Documentation/ABI/testing/sysfs-class-watchdog
> 
> diff --git a/drivers/watchdog/gpio_wdt.c b/drivers/watchdog/gpio_wdt.c
> index 0923201ce874..d49eb77ec8f1 100644
> --- a/drivers/watchdog/gpio_wdt.c
> +++ b/drivers/watchdog/gpio_wdt.c
> @@ -90,6 +90,68 @@ static int gpio_wdt_stop(struct watchdog_device *wdd)
>          return 0;
>   }
> 
> +static ssize_t timeout_show(struct device *dev, struct device_attribute *attr,
> +                               char *buf)
> +{
> +       struct watchdog_device *wdd = dev_get_drvdata(dev);
> +
> +       return sprintf(buf, "%u\n", wdd->timeout);
> +}
> +static DEVICE_ATTR_RO(timeout);
> +
> +static ssize_t identity_show(struct device *dev, struct device_attribute *attr,
> +                               char *buf)
> +{
> +       struct watchdog_device *wdd = dev_get_drvdata(dev);
> +
> +       return sprintf(buf, "%s\n", wdd->info->identity);
> +}
> +static DEVICE_ATTR_RO(identity);
> +
> +static ssize_t state_show(struct device *dev, struct device_attribute *attr,
> +                               char *buf)
> +{
> +       struct watchdog_device *wdd = dev_get_drvdata(dev);
> +
> +       if (watchdog_active(wdd))
> +               return sprintf(buf, "active\n");
> +
> +       return sprintf(buf, "inactive\n");
> +}
> +static DEVICE_ATTR_RO(state);
> +
> +static ssize_t bootstatus_show(struct device *dev,
> +                               struct device_attribute *attr, char *buf)
> +{
> +       struct watchdog_device *wdd = dev_get_drvdata(dev);
> +
> +       return sprintf(buf, "%u\n", wdd->bootstatus);
> +}
> +static DEVICE_ATTR_RO(bootstatus);
> +
> +static ssize_t nowayout_show(struct device *dev, struct device_attribute *attr,
> +                               char *buf)
> +{
> +       struct watchdog_device *wdd = dev_get_drvdata(dev);
> +
> +       return sprintf(buf, "%d\n", !!test_bit(WDOG_NO_WAY_OUT, &wdd->status));
> +}
> +static DEVICE_ATTR_RO(nowayout);
> +
> +static struct attribute *wdt_attrs[] = {
> +       &dev_attr_state.attr,
> +       &dev_attr_identity.attr,
> +       &dev_attr_timeout.attr,
> +       &dev_attr_bootstatus.attr,
> +       &dev_attr_nowayout.attr,
> +       NULL,
> +};
> +
> +static const struct attribute_group wdt_group = {
> +       .attrs = wdt_attrs,
> +};
> +__ATTRIBUTE_GROUPS(wdt);
> +
>   static const struct watchdog_info gpio_wdt_ident = {
>          .options        = WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING |
>                            WDIOF_SETTIMEOUT,
> @@ -155,6 +217,7 @@ static int gpio_wdt_probe(struct platform_device *pdev)
>          priv->wdd.max_hw_heartbeat_ms = hw_margin;
>          priv->wdd.parent        = dev;
>          priv->wdd.timeout       = SOFT_TIMEOUT_DEF;
> +       priv->wdd.groups        = wdt_groups;
> 
>          watchdog_init_timeout(&priv->wdd, 0, dev);
>          watchdog_set_nowayout(&priv->wdd, nowayout);
> 
> 
> 


       reply	other threads:[~2019-12-08 18:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAFEvwum0uu1p9wK66rFbqFi4YQjfEfZcGd54Yeswk9=0EryP1Q@mail.gmail.com>
2019-12-08 18:51 ` Guenter Roeck [this message]
     [not found]   ` <CAFEvwu=0ge4D7CPVwu3D+wLu_5T=8GTjhFFi6D97m6Nxkga5Ew@mail.gmail.com>
2019-12-09 14:14     ` [PATCH] watchdog: Read device status through sysfs attributes for GPIO-controlled Watchdog Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=00897846-a86d-8de4-8ecb-f7c79d30e06d@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=harshalchau04@gmail.com \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=wim@linux-watchdog.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).