On 24.06.20 13:45, Tero Kristo wrote:
If the RTI watchdog has been started by someone (like bootloader) when
the driver probes, we must adjust the initial ping timeout to match the
currently running watchdog window to avoid generating watchdog reset.
Signed-off-by: Tero Kristo <t-kristo@xxxxxx>
---
 drivers/watchdog/rti_wdt.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
diff --git a/drivers/watchdog/rti_wdt.c b/drivers/watchdog/rti_wdt.c
index d456dd72d99a..02ea2b2435f5 100644
--- a/drivers/watchdog/rti_wdt.c
+++ b/drivers/watchdog/rti_wdt.c
@@ -55,11 +55,13 @@ static int heartbeat;
ÂÂ * @base - base io address of WD device
ÂÂ * @freq - source clock frequency of WDT
 * @wdd - hold watchdog device as is in WDT core
+ * @min_hw_heartbeat_save - save of the min hw heartbeat value
ÂÂ */
 struct rti_wdt_device {
ÂÂÂÂÂ void __iomemÂÂÂÂÂÂÂ *base;
ÂÂÂÂÂ unsigned longÂÂÂÂÂÂÂ freq;
ÂÂÂÂÂ struct watchdog_deviceÂÂÂ wdd;
+ÂÂÂ unsigned intÂÂÂÂÂÂÂ min_hw_heartbeat_save;
 };
 static int rti_wdt_start(struct watchdog_device *wdd)
@@ -107,6 +109,11 @@ static int rti_wdt_ping(struct watchdog_device *wdd)
ÂÂÂÂÂ /* put watchdog in active state */
ÂÂÂÂÂ writel_relaxed(WDKEY_SEQ1, wdt->base + RTIWDKEY);
+ÂÂÂ if (wdt->min_hw_heartbeat_save) {
+ÂÂÂÂÂÂÂ wdd->min_hw_heartbeat_ms = wdt->min_hw_heartbeat_save;
+ÂÂÂÂÂÂÂ wdt->min_hw_heartbeat_save = 0;
+ÂÂÂ }
+
ÂÂÂÂÂ return 0;
 }
@@ -201,6 +208,24 @@ static int rti_wdt_probe(struct platform_device *pdev)
ÂÂÂÂÂÂÂÂÂ goto err_iomap;
ÂÂÂÂÂ }
+ÂÂÂ if (readl(wdt->base + RTIDWDCTRL) == WDENABLE_KEY) {
+ÂÂÂÂÂÂÂ u32 time_left;
+ÂÂÂÂÂÂÂ u32 heartbeat;
+
+ÂÂÂÂÂÂÂ set_bit(WDOG_HW_RUNNING, &wdd->status);
+ÂÂÂÂÂÂÂ time_left = rti_wdt_get_timeleft(wdd);
+ÂÂÂÂÂÂÂ heartbeat = readl(wdt->base + RTIDWDPRLD);
+ÂÂÂÂÂÂÂ heartbeat <<= WDT_PRELOAD_SHIFT;
+ÂÂÂÂÂÂÂ heartbeat /= wdt->freq;
+ÂÂÂÂÂÂÂ if (time_left < heartbeat / 2)
+ÂÂÂÂÂÂÂÂÂÂÂ wdd->min_hw_heartbeat_ms = 0;
+ÂÂÂÂÂÂÂ else
+ÂÂÂÂÂÂÂÂÂÂÂ wdd->min_hw_heartbeat_ms =
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ (time_left - heartbeat / 2 + 1) * 1000;
+
+ÂÂÂÂÂÂÂ wdt->min_hw_heartbeat_save = 11 * heartbeat * 1000 / 20;
+ÂÂÂ }
+
ÂÂÂÂÂ ret = watchdog_register_device(wdd);
ÂÂÂÂÂ if (ret) {
ÂÂÂÂÂÂÂÂÂ dev_err(dev, "cannot register watchdog device\n");
This assumes that the bootloader also programmed a 50% window, right? The pending U-Boot patch will do that, but what if that may chance or someone uses a different setup?