diff mbox series

[v3] rtc: ds1307: provide an indication that the watchdog has fired

Message ID 20200727034615.19755-1-chris.packham@alliedtelesis.co.nz (mailing list archive)
State Not Applicable
Headers show
Series [v3] rtc: ds1307: provide an indication that the watchdog has fired | expand

Commit Message

Chris Packham July 27, 2020, 3:46 a.m. UTC
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(+)

Comments

Guenter Roeck July 27, 2020, 1:32 p.m. UTC | #1
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;
>
Alexandre Belloni Aug. 4, 2020, 11:07 p.m. UTC | #2
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,
diff mbox series

Patch

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;