watchdog: renesas_wdt: don't set divider while watchdog is running
authorWolfram Sang <wsa+renesas@sang-engineering.com>
Wed, 7 Nov 2018 19:46:02 +0000 (20:46 +0100)
committerWim Van Sebroeck <wim@linux-watchdog.org>
Sun, 9 Dec 2018 14:03:27 +0000 (15:03 +0100)
The datasheet says we must stop the timer before changing the clock
divider. This can happen when the restart handler is called while the
watchdog is running.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Fabrizio Castro <fabrizio.castro@bp.renesas.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
drivers/watchdog/renesas_wdt.c

index b570962e84f32f3fad6a80d0aebd4c0e242b2fcb..c450e23e24a898529fe4710bf88af95b23c7b1a8 100644 (file)
@@ -74,12 +74,17 @@ static int rwdt_init_timeout(struct watchdog_device *wdev)
 static int rwdt_start(struct watchdog_device *wdev)
 {
        struct rwdt_priv *priv = watchdog_get_drvdata(wdev);
+       u8 val;
 
        pm_runtime_get_sync(wdev->parent);
 
-       rwdt_write(priv, 0, RWTCSRB);
-       rwdt_write(priv, priv->cks, RWTCSRA);
+       /* Stop the timer before we modify any register */
+       val = readb_relaxed(priv->base + RWTCSRA) & ~RWTCSRA_TME;
+       rwdt_write(priv, val, RWTCSRA);
+
        rwdt_init_timeout(wdev);
+       rwdt_write(priv, priv->cks, RWTCSRA);
+       rwdt_write(priv, 0, RWTCSRB);
 
        while (readb_relaxed(priv->base + RWTCSRA) & RWTCSRA_WRFLG)
                cpu_relax();