Linux-Watchdog Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v3] rtc: ds1307: provide an indication that the watchdog has fired
@ 2020-07-27  3:46 Chris Packham
  2020-07-27 13:32 ` Guenter Roeck
  2020-08-04 23:07 ` Alexandre Belloni
  0 siblings, 2 replies; 3+ messages in thread
From: Chris Packham @ 2020-07-27  3:46 UTC (permalink / raw)
  To: a.zummo, alexandre.belloni, linux
  Cc: linux-rtc, linux-watchdog, linux-kernel, Chris Packham

There's not much feedback when the ds1388 watchdog fires. Generally it
yanks on the reset line and the board reboots. Capture the fact that the
watchdog has fired in the past so that userspace can retrieve it via
WDIOC_GETBOOTSTATUS. This should help distinguish a watchdog triggered
reset from a power interruption.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
Changes in v3:
- Check for watchdog flag in ds1307_wdt_register()
Changes in v2:
- Set bootstatus to WDIOF_CARDRESET and let userspace decide what to do with
  the information.

 drivers/rtc/rtc-ds1307.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 49702942bb08..54c85cdd019d 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -1668,6 +1668,8 @@ static const struct watchdog_ops ds1388_wdt_ops = {
 static void ds1307_wdt_register(struct ds1307 *ds1307)
 {
 	struct watchdog_device	*wdt;
+	int err;
+	int val;
 
 	if (ds1307->type != ds_1388)
 		return;
@@ -1676,6 +1678,10 @@ static void ds1307_wdt_register(struct ds1307 *ds1307)
 	if (!wdt)
 		return;
 
+	err = regmap_read(ds1307->regmap, DS1388_REG_FLAG, &val);
+	if (!err && val & DS1388_BIT_WF)
+		wdt->bootstatus = WDIOF_CARDRESET;
+
 	wdt->info = &ds1388_wdt_info;
 	wdt->ops = &ds1388_wdt_ops;
 	wdt->timeout = 99;
-- 
2.27.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] rtc: ds1307: provide an indication that the watchdog has fired
  2020-07-27  3:46 [PATCH v3] rtc: ds1307: provide an indication that the watchdog has fired Chris Packham
@ 2020-07-27 13:32 ` Guenter Roeck
  2020-08-04 23:07 ` Alexandre Belloni
  1 sibling, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2020-07-27 13:32 UTC (permalink / raw)
  To: Chris Packham, a.zummo, alexandre.belloni
  Cc: linux-rtc, linux-watchdog, linux-kernel

On 7/26/20 8:46 PM, Chris Packham wrote:
> There's not much feedback when the ds1388 watchdog fires. Generally it
> yanks on the reset line and the board reboots. Capture the fact that the
> watchdog has fired in the past so that userspace can retrieve it via
> WDIOC_GETBOOTSTATUS. This should help distinguish a watchdog triggered
> reset from a power interruption.
> 
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
> Changes in v3:
> - Check for watchdog flag in ds1307_wdt_register()
> Changes in v2:
> - Set bootstatus to WDIOF_CARDRESET and let userspace decide what to do with
>   the information.
> 
>  drivers/rtc/rtc-ds1307.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
> index 49702942bb08..54c85cdd019d 100644
> --- a/drivers/rtc/rtc-ds1307.c
> +++ b/drivers/rtc/rtc-ds1307.c
> @@ -1668,6 +1668,8 @@ static const struct watchdog_ops ds1388_wdt_ops = {
>  static void ds1307_wdt_register(struct ds1307 *ds1307)
>  {
>  	struct watchdog_device	*wdt;
> +	int err;
> +	int val;
>  
>  	if (ds1307->type != ds_1388)
>  		return;
> @@ -1676,6 +1678,10 @@ static void ds1307_wdt_register(struct ds1307 *ds1307)
>  	if (!wdt)
>  		return;
>  
> +	err = regmap_read(ds1307->regmap, DS1388_REG_FLAG, &val);
> +	if (!err && val & DS1388_BIT_WF)
> +		wdt->bootstatus = WDIOF_CARDRESET;
> +
>  	wdt->info = &ds1388_wdt_info;
>  	wdt->ops = &ds1388_wdt_ops;
>  	wdt->timeout = 99;
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] rtc: ds1307: provide an indication that the watchdog has fired
  2020-07-27  3:46 [PATCH v3] rtc: ds1307: provide an indication that the watchdog has fired Chris Packham
  2020-07-27 13:32 ` Guenter Roeck
@ 2020-08-04 23:07 ` Alexandre Belloni
  1 sibling, 0 replies; 3+ messages in thread
From: Alexandre Belloni @ 2020-08-04 23:07 UTC (permalink / raw)
  To: a.zummo, linux, Chris Packham
  Cc: Alexandre Belloni, linux-kernel, linux-watchdog, linux-rtc

On Mon, 27 Jul 2020 15:46:14 +1200, Chris Packham wrote:
> There's not much feedback when the ds1388 watchdog fires. Generally it
> yanks on the reset line and the board reboots. Capture the fact that the
> watchdog has fired in the past so that userspace can retrieve it via
> WDIOC_GETBOOTSTATUS. This should help distinguish a watchdog triggered
> reset from a power interruption.

Applied, thanks!

[1/1] rtc: ds1307: provide an indication that the watchdog has fired
      commit: 9bf1306257589b3a5ad46175538af9922d94e26f

Best regards,
-- 
Alexandre Belloni <alexandre.belloni@bootlin.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-27  3:46 [PATCH v3] rtc: ds1307: provide an indication that the watchdog has fired Chris Packham
2020-07-27 13:32 ` Guenter Roeck
2020-08-04 23:07 ` Alexandre Belloni

Linux-Watchdog Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-watchdog/0 linux-watchdog/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-watchdog linux-watchdog/ https://lore.kernel.org/linux-watchdog \
		linux-watchdog@vger.kernel.org
	public-inbox-index linux-watchdog

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-watchdog


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git