All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] watchdog: rti_wdt: Fix calculation and evaluation of preset heartbeat
@ 2022-02-21 16:22 Jan Kiszka
  2022-05-14 14:00 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Kiszka @ 2022-02-21 16:22 UTC (permalink / raw)
  To: Hari Nagalla, Nishanth Menon, Wim Van Sebroeck, Guenter Roeck
  Cc: linux-watchdog, Linux Kernel Mailing List

From: Jan Kiszka <jan.kiszka@siemens.com>

This ensures that the same value is read back as was eventually
programmed when using seconds as accuracy. Even then, comparing the more
precise heartbeat_ms against heartbeat in seconds will almost never
provide a match and will needlessly raise a warning. Fix by comparing
apples to apples.

Tested in combination with U-Boot as watchdog starter.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---

To fully work, it also needs a U-Boot patch to add the same 10% margin 
to the clock frequency:

https://patchwork.ozlabs.org/project/uboot/patch/9b3603a3-1bf4-eb57-c378-20d5c2accc34@siemens.com/

 drivers/watchdog/rti_wdt.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/watchdog/rti_wdt.c b/drivers/watchdog/rti_wdt.c
index 117bc2a8eb0a..3ecd14e180fb 100644
--- a/drivers/watchdog/rti_wdt.c
+++ b/drivers/watchdog/rti_wdt.c
@@ -252,6 +252,7 @@ static int rti_wdt_probe(struct platform_device *pdev)
 	}
 
 	if (readl(wdt->base + RTIDWDCTRL) == WDENABLE_KEY) {
+		int preset_heartbeat;
 		u32 time_left_ms;
 		u64 heartbeat_ms;
 		u32 wsize;
@@ -262,11 +263,12 @@ static int rti_wdt_probe(struct platform_device *pdev)
 		heartbeat_ms <<= WDT_PRELOAD_SHIFT;
 		heartbeat_ms *= 1000;
 		do_div(heartbeat_ms, wdt->freq);
-		if (heartbeat_ms != heartbeat * 1000)
+		preset_heartbeat = heartbeat_ms + 500;
+		preset_heartbeat /= 1000;
+		if (preset_heartbeat != heartbeat)
 			dev_warn(dev, "watchdog already running, ignoring heartbeat config!\n");
 
-		heartbeat = heartbeat_ms;
-		heartbeat /= 1000;
+		heartbeat = preset_heartbeat;
 
 		wsize = readl(wdt->base + RTIWWDSIZECTRL);
 		ret = rti_wdt_setup_hw_hb(wdd, wsize);
-- 
2.34.1

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

* Re: [PATCH] watchdog: rti_wdt: Fix calculation and evaluation of preset heartbeat
  2022-02-21 16:22 [PATCH] watchdog: rti_wdt: Fix calculation and evaluation of preset heartbeat Jan Kiszka
@ 2022-05-14 14:00 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2022-05-14 14:00 UTC (permalink / raw)
  To: Jan Kiszka
  Cc: Hari Nagalla, Nishanth Menon, Wim Van Sebroeck, linux-watchdog,
	Linux Kernel Mailing List

On Mon, Feb 21, 2022 at 05:22:38PM +0100, Jan Kiszka wrote:
> From: Jan Kiszka <jan.kiszka@siemens.com>
> 
> This ensures that the same value is read back as was eventually
> programmed when using seconds as accuracy. Even then, comparing the more
> precise heartbeat_ms against heartbeat in seconds will almost never
> provide a match and will needlessly raise a warning. Fix by comparing
> apples to apples.
> 
> Tested in combination with U-Boot as watchdog starter.
> 
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>

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

> ---
> 
> To fully work, it also needs a U-Boot patch to add the same 10% margin 
> to the clock frequency:
> 
> https://patchwork.ozlabs.org/project/uboot/patch/9b3603a3-1bf4-eb57-c378-20d5c2accc34@siemens.com/
> 
>  drivers/watchdog/rti_wdt.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/watchdog/rti_wdt.c b/drivers/watchdog/rti_wdt.c
> index 117bc2a8eb0a..3ecd14e180fb 100644
> --- a/drivers/watchdog/rti_wdt.c
> +++ b/drivers/watchdog/rti_wdt.c
> @@ -252,6 +252,7 @@ static int rti_wdt_probe(struct platform_device *pdev)
>  	}
>  
>  	if (readl(wdt->base + RTIDWDCTRL) == WDENABLE_KEY) {
> +		int preset_heartbeat;
>  		u32 time_left_ms;
>  		u64 heartbeat_ms;
>  		u32 wsize;
> @@ -262,11 +263,12 @@ static int rti_wdt_probe(struct platform_device *pdev)
>  		heartbeat_ms <<= WDT_PRELOAD_SHIFT;
>  		heartbeat_ms *= 1000;
>  		do_div(heartbeat_ms, wdt->freq);
> -		if (heartbeat_ms != heartbeat * 1000)
> +		preset_heartbeat = heartbeat_ms + 500;
> +		preset_heartbeat /= 1000;
> +		if (preset_heartbeat != heartbeat)
>  			dev_warn(dev, "watchdog already running, ignoring heartbeat config!\n");
>  
> -		heartbeat = heartbeat_ms;
> -		heartbeat /= 1000;
> +		heartbeat = preset_heartbeat;
>  
>  		wsize = readl(wdt->base + RTIWWDSIZECTRL);
>  		ret = rti_wdt_setup_hw_hb(wdd, wsize);

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

end of thread, other threads:[~2022-05-14 14:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-21 16:22 [PATCH] watchdog: rti_wdt: Fix calculation and evaluation of preset heartbeat Jan Kiszka
2022-05-14 14:00 ` Guenter Roeck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.