From: Evgeny Boger <boger@contactless.ru>
To: linux-watchdog@vger.kernel.org,
Alexander Shiyan <shc_work@mail.ru>,
linux-kernel@vger.kernel.org
Cc: Evgeny Boger <boger@contactless.ru>
Subject: [PATCH] Add support for always enabled watchdog timers
Date: Sun, 17 Aug 2014 04:45:38 +0400 [thread overview]
Message-ID: <1408236338-12555-1-git-send-email-boger@contactless.ru> (raw)
From: Evgeny Boger <boger@contactless.ru>
Add option to use with watchdog timers which are always enabled
in hardware, i.e. there is no way to enable/disable it via GPIO pin.
The driver will start pinging WDT immediately upon loading
and will continue to do so even after stopping the watchdog.
Signed-off-by: Evgeny Boger <boger@contactless.ru>
---
.../devicetree/bindings/watchdog/gpio-wdt.txt | 14 ++++++-
drivers/watchdog/gpio_wdt.c | 45 +++++++++++++++++-----
2 files changed, 48 insertions(+), 11 deletions(-)
diff --git a/Documentation/devicetree/bindings/watchdog/gpio-wdt.txt b/Documentation/devicetree/bindings/watchdog/gpio-wdt.txt
index 37afec1..1f8ca46 100644
--- a/Documentation/devicetree/bindings/watchdog/gpio-wdt.txt
+++ b/Documentation/devicetree/bindings/watchdog/gpio-wdt.txt
@@ -12,8 +12,11 @@ Required Properties:
the opposite level disables the WDT. Active level is determined
by the GPIO flags.
- hw_margin_ms: Maximum time to reset watchdog circuit (milliseconds).
+- always-enabled: Use with wathdog timer which is always enabled
+ in hardware, i.e. there is no way to enable/disable it via GPIO pin.
+ Driver will start pinging WDT immediately upon loading.
-Example:
+Examples:
watchdog: watchdog {
/* ADM706 */
compatible = "linux,wdt-gpio";
@@ -21,3 +24,12 @@ Example:
hw_algo = "toggle";
hw_margin_ms = <1600>;
};
+
+ watchdog: watchdog {
+ /* TPS3813 */
+ compatible = "linux,wdt-gpio";
+ gpios = <&gpio3 9 GPIO_ACTIVE_LOW>;
+ hw_algo = "toggle";
+ hw_margin_ms = <10000>;
+ always-enabled;
+ };
diff --git a/drivers/watchdog/gpio_wdt.c b/drivers/watchdog/gpio_wdt.c
index 220a9e0..29f9bff 100644
--- a/drivers/watchdog/gpio_wdt.c
+++ b/drivers/watchdog/gpio_wdt.c
@@ -37,6 +37,8 @@ struct gpio_wdt_priv {
struct notifier_block notifier;
struct timer_list timer;
struct watchdog_device wdd;
+ bool always_enabled;
+ bool started;
};
static void gpio_wdt_disable(struct gpio_wdt_priv *priv)
@@ -48,10 +50,8 @@ static void gpio_wdt_disable(struct gpio_wdt_priv *priv)
gpio_direction_input(priv->gpio);
}
-static int gpio_wdt_start(struct watchdog_device *wdd)
+static int gpio_wdt_start_timer(struct gpio_wdt_priv *priv)
{
- struct gpio_wdt_priv *priv = watchdog_get_drvdata(wdd);
-
priv->state = priv->active_low;
gpio_direction_output(priv->gpio, priv->state);
priv->last_jiffies = jiffies;
@@ -60,12 +60,28 @@ static int gpio_wdt_start(struct watchdog_device *wdd)
return 0;
}
-static int gpio_wdt_stop(struct watchdog_device *wdd)
+static int gpio_wdt_start(struct watchdog_device *wdd)
{
struct gpio_wdt_priv *priv = watchdog_get_drvdata(wdd);
+ priv->started = true;
+ if (priv->always_enabled) {
+ /* harware ping timer is already enabled */
+ priv->last_jiffies = jiffies;
+ } else {
+ gpio_wdt_start_timer(priv);
+ }
- mod_timer(&priv->timer, 0);
- gpio_wdt_disable(priv);
+ return 0;
+}
+
+static int gpio_wdt_stop(struct watchdog_device *wdd)
+{
+ struct gpio_wdt_priv *priv = watchdog_get_drvdata(wdd);
+ priv->started = false;
+ if (!priv->always_enabled) {
+ mod_timer(&priv->timer, 0);
+ gpio_wdt_disable(priv);
+ }
return 0;
}
@@ -91,10 +107,12 @@ static void gpio_wdt_hwping(unsigned long data)
struct watchdog_device *wdd = (struct watchdog_device *)data;
struct gpio_wdt_priv *priv = watchdog_get_drvdata(wdd);
- if (time_after(jiffies, priv->last_jiffies +
- msecs_to_jiffies(wdd->timeout * 1000))) {
- dev_crit(wdd->dev, "Timer expired. System will reboot soon!\n");
- return;
+ if (priv->started) {
+ if (time_after(jiffies, priv->last_jiffies +
+ msecs_to_jiffies(wdd->timeout * 1000))) {
+ dev_crit(wdd->dev, "Timer expired. System will reboot soon!\n");
+ return;
+ }
}
/* Restart timer */
@@ -197,6 +215,9 @@ static int gpio_wdt_probe(struct platform_device *pdev)
/* Use safe value (1/2 of real timeout) */
priv->hw_margin = msecs_to_jiffies(hw_margin / 2);
+ priv->always_enabled = of_property_read_bool(pdev->dev.of_node,
+ "always-enabled");
+
watchdog_set_drvdata(&priv->wdd, priv);
priv->wdd.info = &gpio_wdt_ident;
@@ -207,6 +228,7 @@ static int gpio_wdt_probe(struct platform_device *pdev)
if (watchdog_init_timeout(&priv->wdd, 0, &pdev->dev) < 0)
priv->wdd.timeout = SOFT_TIMEOUT_DEF;
+ priv->started = false;
setup_timer(&priv->timer, gpio_wdt_hwping, (unsigned long)&priv->wdd);
ret = watchdog_register_device(&priv->wdd);
@@ -218,6 +240,9 @@ static int gpio_wdt_probe(struct platform_device *pdev)
if (ret)
watchdog_unregister_device(&priv->wdd);
+ if (priv->always_enabled)
+ gpio_wdt_start_timer(priv);
+
return ret;
}
--
1.9.1
next reply other threads:[~2014-08-17 0:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-17 0:45 Evgeny Boger [this message]
2014-08-23 17:16 ` Guenter Roeck
2014-08-23 17:25 ` Alexander Shiyan
2014-08-23 17:33 ` Guenter Roeck
2014-09-06 16:49 ` Evgeny Boger
2014-09-06 16:47 ` [PATCH v2] Add support for always enabled watchdog timers to gpio_wdt driver Evgeny Boger
2014-09-07 17:23 ` 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=1408236338-12555-1-git-send-email-boger@contactless.ru \
--to=boger@contactless.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=shc_work@mail.ru \
/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
all inboxes | Powered by JetHome®