Skip to content

Commit 392d39a

Browse files
andredWim Van Sebroeck
authored andcommitted
watchdog: mt7621: set WDOG_HW_RUNNING bit when appropriate
If the watchdog hardware is enabled/running during boot, e.g. due to a boot loader configuring it, we must tell the watchdog framework about this fact so that it can ping the watchdog until userspace opens the device and takes over control. Do so using the WDOG_HW_RUNNING flag that exists for exactly that use-case. Given the watchdog driver core doesn't know what timeout was originally set by whoever started the watchdog (boot loader), we make sure to update the timeout in the hardware according to what the watchdog core thinks it is. Signed-off-by: André Draszik <[email protected]> Cc: [email protected] Cc: John Crispin <[email protected]> Reviewed-by: Guenter Roeck <[email protected]> Signed-off-by: Guenter Roeck <[email protected]> Signed-off-by: Wim Van Sebroeck <[email protected]>
1 parent 0be2672 commit 392d39a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

drivers/watchdog/mt7621_wdt.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ static int mt7621_wdt_bootcause(void)
105105
return 0;
106106
}
107107

108+
static int mt7621_wdt_is_running(struct watchdog_device *w)
109+
{
110+
return !!(rt_wdt_r32(TIMER_REG_TMR1CTL) & TMR1CTL_ENABLE);
111+
}
112+
108113
static const struct watchdog_info mt7621_wdt_info = {
109114
.identity = "Mediatek Watchdog",
110115
.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
@@ -144,6 +149,20 @@ static int mt7621_wdt_probe(struct platform_device *pdev)
144149
watchdog_init_timeout(&mt7621_wdt_dev, mt7621_wdt_dev.max_timeout,
145150
&pdev->dev);
146151
watchdog_set_nowayout(&mt7621_wdt_dev, nowayout);
152+
if (mt7621_wdt_is_running(&mt7621_wdt_dev)) {
153+
/*
154+
* Make sure to apply timeout from watchdog core, taking
155+
* the prescaler of this driver here into account (the
156+
* boot loader might be using a different prescaler).
157+
*
158+
* To avoid spurious resets because of different scaling,
159+
* we first disable the watchdog, set the new prescaler
160+
* and timeout, and then re-enable the watchdog.
161+
*/
162+
mt7621_wdt_stop(&mt7621_wdt_dev);
163+
mt7621_wdt_start(&mt7621_wdt_dev);
164+
set_bit(WDOG_HW_RUNNING, &mt7621_wdt_dev.status);
165+
}
147166

148167
ret = watchdog_register_device(&mt7621_wdt_dev);
149168

0 commit comments

Comments
 (0)