watchdog: omap_wdt: implement get_timeleft
authorLars Poeschel <poeschel@lemonage.de>
Wed, 17 Jun 2015 08:58:59 +0000 (10:58 +0200)
committerWim Van Sebroeck <wim@iguana.be>
Mon, 22 Jun 2015 13:54:35 +0000 (15:54 +0200)
The omap watchdog hardware is able to read the watchdog timer counter
register. This implements this functionality in the omap_wdt driver, so
one is can read the time until the watchdog will trigger the reset in
seconds using WDIOC_GETTIMELEFT.

Signed-off-by: Lars Poeschel <poeschel@lemonage.de>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
drivers/watchdog/omap_wdt.c
drivers/watchdog/omap_wdt.h

index 1a74bc7fb4586207b94a77a7ad8c14219e06238f..ebea6e66fba97087253c8f18ed6e744a10f9dad8 100644 (file)
@@ -198,6 +198,16 @@ static int omap_wdt_set_timeout(struct watchdog_device *wdog,
        return 0;
 }
 
+static unsigned int omap_wdt_get_timeleft(struct watchdog_device *wdog)
+{
+       struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog);
+       void __iomem *base = wdev->base;
+       u32 value;
+
+       value = readl_relaxed(base + OMAP_WATCHDOG_CRR);
+       return GET_WCCR_SECS(value);
+}
+
 static const struct watchdog_info omap_wdt_info = {
        .options = WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING,
        .identity = "OMAP Watchdog",
@@ -209,6 +219,7 @@ static const struct watchdog_ops omap_wdt_ops = {
        .stop           = omap_wdt_stop,
        .ping           = omap_wdt_ping,
        .set_timeout    = omap_wdt_set_timeout,
+       .get_timeleft   = omap_wdt_get_timeleft,
 };
 
 static int omap_wdt_probe(struct platform_device *pdev)
index 09b774cf75b9be8ebd83fefbdbc199e2c432a631..42f31ec5e90d0e0a3ff65034a322532635f12d12 100644 (file)
@@ -50,5 +50,6 @@
 
 #define PTV                    0       /* prescale */
 #define GET_WLDR_VAL(secs)     (0xffffffff - ((secs) * (32768/(1<<PTV))) + 1)
+#define GET_WCCR_SECS(val)     ((0xffffffff - (val) + 1) / (32768/(1<<PTV)))
 
 #endif                         /* _OMAP_WATCHDOG_H */