watchdog: rti_wdt: Fix calculation and evaluation of preset heartbeat
PATCH 1/1 watchdog: rti_wdt: Fix calculation and evaluation of preset heartbeat
From: Jan Kiszka <[email protected]>
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.
---
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/[email protected]/
drivers/watchdog/rti_wdt.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/watchdog/rti_wdt.c +5 -3
@@ -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);
Signature · 1 line
2.34.1
Quoted 11 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
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_msagainst 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 <[email protected]>
Quoted 38 lines
---
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/[email protected]/
drivers/watchdog/rti_wdt.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)drivers/watchdog/rti_wdt.c +5
-3@@ -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);