watchdog: mt7621: set WDOG_HW_RUNNING bit when appropriate

"Linux Kernel Mailing List" <[email protected]>
Newsgroups gmane.linux.kernel.commits.head
Message-ID <[email protected]>
Web:        https://git.kernel.org/torvalds/c/392d39a863583eb6439e2ec543818250b57ef99d
Commit:     392d39a863583eb6439e2ec543818250b57ef99d
Parent:     0be267255cef64e1c58475baa7b25568355a3816
Refname:    refs/heads/master
Author:     André Draszik <[email protected]>
AuthorDate: Fri Jan 12 09:44:53 2018 +0000
Committer:  Wim Van Sebroeck <[email protected]>
CommitDate: Sun Jan 21 12:44:58 2018 +0100

    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]>
---
 drivers/watchdog/mt7621_wdt.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/watchdog/mt7621_wdt.c b/drivers/watchdog/mt7621_wdt.c
index db38f8017218..eec57e5e1eae 100644
--- a/drivers/watchdog/mt7621_wdt.c
+++ b/drivers/watchdog/mt7621_wdt.c
@@ -105,6 +105,11 @@ static int mt7621_wdt_bootcause(void)
 	return 0;
 }
 
+static int mt7621_wdt_is_running(struct watchdog_device *w)
+{
+	return !!(rt_wdt_r32(TIMER_REG_TMR1CTL) & TMR1CTL_ENABLE);
+}
+
 static const struct watchdog_info mt7621_wdt_info = {
 	.identity = "Mediatek Watchdog",
 	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
@@ -144,6 +149,20 @@ static int mt7621_wdt_probe(struct platform_device *pdev)
 	watchdog_init_timeout(&mt7621_wdt_dev, mt7621_wdt_dev.max_timeout,
 			      &pdev->dev);
 	watchdog_set_nowayout(&mt7621_wdt_dev, nowayout);
+	if (mt7621_wdt_is_running(&mt7621_wdt_dev)) {
+		/*
+		 * Make sure to apply timeout from watchdog core, taking
+		 * the prescaler of this driver here into account (the
+		 * boot loader might be using a different prescaler).
+		 *
+		 * To avoid spurious resets because of different scaling,
+		 * we first disable the watchdog, set the new prescaler
+		 * and timeout, and then re-enable the watchdog.
+		 */
+		mt7621_wdt_stop(&mt7621_wdt_dev);
+		mt7621_wdt_start(&mt7621_wdt_dev);
+		set_bit(WDOG_HW_RUNNING, &mt7621_wdt_dev.status);
+	}
 
 	ret = watchdog_register_device(&mt7621_wdt_dev);
 
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.