From: Guenter Roeck <linux@roeck-us.net>
To: linux-watchdog@vger.kernel.org
Cc: "Wim Van Sebroeck" <wim@iguana.be>,
linux-kernel@vger.kernel.org,
"Timo Kokkonen" <timo.kokkonen@offcode.fi>,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
linux-doc@vger.kernel.org, "Jonathan Corbet" <corbet@lwn.net>,
"Guenter Roeck" <linux@roeck-us.net>
Subject: [PATCH 5/8] watchdog: imx2: Convert to use infrastructure triggered keepalives
Date: Mon, 3 Aug 2015 19:13:31 -0700 [thread overview]
Message-ID: <1438654414-29259-6-git-send-email-linux@roeck-us.net> (raw)
In-Reply-To: <1438654414-29259-1-git-send-email-linux@roeck-us.net>
The watchdog infrastructure now supports handling watchdog keepalive
if the watchdog is running while the watchdog device is closed.
Convert the driver to use this infrastructure.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
drivers/watchdog/imx2_wdt.c | 72 ++++++++-------------------------------------
1 file changed, 12 insertions(+), 60 deletions(-)
diff --git a/drivers/watchdog/imx2_wdt.c b/drivers/watchdog/imx2_wdt.c
index 0bb1a1d1b170..66feef254661 100644
--- a/drivers/watchdog/imx2_wdt.c
+++ b/drivers/watchdog/imx2_wdt.c
@@ -25,7 +25,6 @@
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/io.h>
-#include <linux/jiffies.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
@@ -34,7 +33,6 @@
#include <linux/platform_device.h>
#include <linux/reboot.h>
#include <linux/regmap.h>
-#include <linux/timer.h>
#include <linux/watchdog.h>
#define DRIVER_NAME "imx2-wdt"
@@ -62,7 +60,6 @@
struct imx2_wdt_device {
struct clk *clk;
struct regmap *regmap;
- struct timer_list timer; /* Pings the watchdog when closed */
struct watchdog_device wdog;
struct notifier_block restart_handler;
};
@@ -151,16 +148,6 @@ static int imx2_wdt_ping(struct watchdog_device *wdog)
return 0;
}
-static void imx2_wdt_timer_ping(unsigned long arg)
-{
- struct watchdog_device *wdog = (struct watchdog_device *)arg;
- struct imx2_wdt_device *wdev = watchdog_get_drvdata(wdog);
-
- /* ping it every wdog->timeout / 2 seconds to prevent reboot */
- imx2_wdt_ping(wdog);
- mod_timer(&wdev->timer, jiffies + wdog->timeout * HZ / 2);
-}
-
static int imx2_wdt_set_timeout(struct watchdog_device *wdog,
unsigned int new_timeout)
{
@@ -177,40 +164,19 @@ static int imx2_wdt_start(struct watchdog_device *wdog)
{
struct imx2_wdt_device *wdev = watchdog_get_drvdata(wdog);
- if (imx2_wdt_is_running(wdev)) {
- /* delete the timer that pings the watchdog after close */
- del_timer_sync(&wdev->timer);
+ if (imx2_wdt_is_running(wdev))
imx2_wdt_set_timeout(wdog, wdog->timeout);
- } else
+ else
imx2_wdt_setup(wdog);
- return imx2_wdt_ping(wdog);
-}
-
-static int imx2_wdt_stop(struct watchdog_device *wdog)
-{
- /*
- * We don't need a clk_disable, it cannot be disabled once started.
- * We use a timer to ping the watchdog while /dev/watchdog is closed
- */
- imx2_wdt_timer_ping((unsigned long)wdog);
- return 0;
-}
-
-static inline void imx2_wdt_ping_if_active(struct watchdog_device *wdog)
-{
- struct imx2_wdt_device *wdev = watchdog_get_drvdata(wdog);
+ set_bit(WDOG_RUNNING, &wdog->status);
- if (imx2_wdt_is_running(wdev)) {
- imx2_wdt_set_timeout(wdog, wdog->timeout);
- imx2_wdt_timer_ping((unsigned long)wdog);
- }
+ return imx2_wdt_ping(wdog);
}
static const struct watchdog_ops imx2_wdt_ops = {
.owner = THIS_MODULE,
.start = imx2_wdt_start,
- .stop = imx2_wdt_stop,
.ping = imx2_wdt_ping,
.set_timeout = imx2_wdt_set_timeout,
};
@@ -277,9 +243,10 @@ static int __init imx2_wdt_probe(struct platform_device *pdev)
watchdog_set_nowayout(wdog, nowayout);
watchdog_init_timeout(wdog, timeout, &pdev->dev);
- setup_timer(&wdev->timer, imx2_wdt_timer_ping, (unsigned long)wdog);
-
- imx2_wdt_ping_if_active(wdog);
+ if (imx2_wdt_is_running(wdev)) {
+ imx2_wdt_set_timeout(wdog, wdog->timeout);
+ set_bit(WDOG_RUNNING, &wdog->status);
+ }
/*
* Disable the watchdog power down counter at boot. Otherwise the power
@@ -320,7 +287,6 @@ static int __exit imx2_wdt_remove(struct platform_device *pdev)
watchdog_unregister_device(wdog);
if (imx2_wdt_is_running(wdev)) {
- del_timer_sync(&wdev->timer);
imx2_wdt_ping(wdog);
dev_crit(&pdev->dev, "Device removed: Expect reboot!\n");
}
@@ -334,10 +300,9 @@ static void imx2_wdt_shutdown(struct platform_device *pdev)
if (imx2_wdt_is_running(wdev)) {
/*
- * We are running, we need to delete the timer but will
- * give max timeout before reboot will take place
+ * We are running, configure max timeout before reboot
+ * will take place.
*/
- del_timer_sync(&wdev->timer);
imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME);
imx2_wdt_ping(wdog);
dev_crit(&pdev->dev, "Device shutdown: Expect reboot!\n");
@@ -355,10 +320,6 @@ static int imx2_wdt_suspend(struct device *dev)
if (imx2_wdt_is_running(wdev)) {
imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME);
imx2_wdt_ping(wdog);
-
- /* The watchdog is not active */
- if (!watchdog_active(wdog))
- del_timer_sync(&wdev->timer);
}
clk_disable_unprepare(wdev->clk);
@@ -384,19 +345,10 @@ static int imx2_wdt_resume(struct device *dev)
* watchdog again.
*/
imx2_wdt_setup(wdog);
+ }
+ if (imx2_wdt_is_running(wdev)) {
imx2_wdt_set_timeout(wdog, wdog->timeout);
imx2_wdt_ping(wdog);
- } else if (imx2_wdt_is_running(wdev)) {
- /* Resuming from non-deep sleep state. */
- imx2_wdt_set_timeout(wdog, wdog->timeout);
- imx2_wdt_ping(wdog);
- /*
- * But the watchdog is not active, then start
- * the timer again.
- */
- if (!watchdog_active(wdog))
- mod_timer(&wdev->timer,
- jiffies + wdog->timeout * HZ / 2);
}
return 0;
--
2.1.4
next prev parent reply other threads:[~2015-08-04 2:14 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-04 2:13 [PATCH 0/8] watchdog: Add support for keepalives triggered by infrastructure Guenter Roeck
2015-08-04 2:13 ` [PATCH 1/8] watchdog: watchdog_dev: Use single variable name for struct watchdog_device Guenter Roeck
2015-08-04 11:26 ` Uwe Kleine-König
2015-08-04 2:13 ` [PATCH 2/8] watchdog: Introduce hardware maximum timeout in watchdog core Guenter Roeck
2015-08-04 12:18 ` Uwe Kleine-König
2015-08-04 15:31 ` Guenter Roeck
2015-08-04 15:52 ` Uwe Kleine-König
2015-08-04 16:03 ` Guenter Roeck
2015-08-05 8:22 ` Uwe Kleine-König
2015-08-05 9:14 ` Guenter Roeck
2015-08-04 2:13 ` [PATCH 3/8] watchdog: Introduce WDOG_RUNNING flag Guenter Roeck
2015-08-04 12:25 ` Uwe Kleine-König
2015-08-04 15:41 ` Uwe Kleine-König
2015-08-04 15:56 ` Guenter Roeck
2015-08-04 2:13 ` [PATCH 4/8] watchdog: Make set_timeout function optional Guenter Roeck
2015-08-04 15:38 ` Uwe Kleine-König
2015-08-04 16:43 ` Guenter Roeck
2015-08-04 2:13 ` Guenter Roeck [this message]
2015-08-04 15:44 ` [PATCH 5/8] watchdog: imx2: Convert to use infrastructure triggered keepalives Uwe Kleine-König
2015-08-04 2:13 ` [PATCH 6/8] watchdog: retu: " Guenter Roeck
2015-08-04 2:13 ` [PATCH 7/8] watchdog: gpio_wdt: " Guenter Roeck
2015-08-04 2:13 ` [PATCH 8/8] watchdog: at91sam9: " Guenter Roeck
2015-08-04 11:24 ` [PATCH 0/8] watchdog: Add support for keepalives triggered by infrastructure Uwe Kleine-König
2015-08-04 15:01 ` Guenter Roeck
2015-08-04 23:43 ` Pádraig Brady
2015-08-05 0:49 ` Guenter Roeck
2015-08-05 7:36 ` Uwe Kleine-König
2015-08-05 7:50 ` Guenter Roeck
2015-08-05 8:27 ` Uwe Kleine-König
2015-08-05 17:13 ` David Teigland
2015-08-05 17:41 ` Guenter Roeck
2015-08-05 17:51 ` David Teigland
2015-08-05 19:01 ` Guenter Roeck
2015-08-05 19:51 ` David Teigland
2015-08-05 20:21 ` Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1438654414-29259-6-git-send-email-linux@roeck-us.net \
--to=linux@roeck-us.net \
--cc=corbet@lwn.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=timo.kokkonen@offcode.fi \
--cc=u.kleine-koenig@pengutronix.de \
--cc=wim@iguana.be \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).