linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] watchdog: imx2_wdt: handle enabled watchdog properly
@ 2014-04-04 14:54 Anatolij Gustschin
  2014-04-04 15:20 ` Wolfram Sang
  0 siblings, 1 reply; 3+ messages in thread
From: Anatolij Gustschin @ 2014-04-04 14:54 UTC (permalink / raw)
  To: linux-arm-kernel

If the watchdog is already enabled (e.g. started by the boot loader),
we need to handle this case properly and start reloading the watchdog
time-out counter as frequently as needed.

Signed-off-by: Anatolij Gustschin <agust@denx.de>
Cc: Wolfram Sang <wsa@the-dreams.de>
Cc: Wim Van Sebroeck <wim@iguana.be>
---
 drivers/watchdog/imx2_wdt.c |   24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/drivers/watchdog/imx2_wdt.c b/drivers/watchdog/imx2_wdt.c
index dd51d95..bef9a9f 100644
--- a/drivers/watchdog/imx2_wdt.c
+++ b/drivers/watchdog/imx2_wdt.c
@@ -54,6 +54,7 @@
 #define IMX2_WDT_DEFAULT_TIME	60		/* in seconds */
 
 #define WDOG_SEC_TO_COUNT(s)	((s * 2 - 1) << 8)
+#define WDOG_COUNT_TO_SEC(c)	((((c) >> 8) + 1) / 2)
 
 #define IMX2_WDT_STATUS_OPEN	0
 #define IMX2_WDT_STATUS_STARTED	1
@@ -120,6 +121,27 @@ static void imx2_wdt_timer_ping(unsigned long arg)
 	mod_timer(&imx2_wdt.timer, jiffies + imx2_wdt.timeout * HZ / 2);
 }
 
+static inline void imx2_wdt_ping_if_active(void)
+{
+	u16 val = __raw_readw(imx2_wdt.base + IMX2_WDT_WCR);
+
+	if (val & IMX2_WDT_WCR_WDE) {
+		/* Must enable the clock, wdog service doesn't work otherwise */
+		clk_prepare_enable(imx2_wdt.clk);
+
+		set_bit(IMX2_WDT_STATUS_STARTED, &imx2_wdt.status);
+		imx2_wdt.timeout = WDOG_COUNT_TO_SEC(val);
+		if (imx2_wdt.timeout < 2) {
+			imx2_wdt.timeout = 2;
+			/* Set new watchdog time-out value */
+			val &= ~IMX2_WDT_WCR_WT;
+			val |= WDOG_SEC_TO_COUNT(imx2_wdt.timeout);
+			__raw_writew(val, imx2_wdt.base + IMX2_WDT_WCR);
+		}
+		imx2_wdt_timer_ping(0);
+	}
+}
+
 static void imx2_wdt_start(void)
 {
 	if (!test_and_set_bit(IMX2_WDT_STATUS_STARTED, &imx2_wdt.status)) {
@@ -283,6 +305,8 @@ static int __init imx2_wdt_probe(struct platform_device *pdev)
 	if (ret)
 		goto fail;
 
+	imx2_wdt_ping_if_active();
+
 	dev_info(&pdev->dev,
 		"IMX2+ Watchdog Timer enabled. timeout=%ds (nowayout=%d)\n",
 						imx2_wdt.timeout, nowayout);
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] watchdog: imx2_wdt: handle enabled watchdog properly
  2014-04-04 14:54 [PATCH] watchdog: imx2_wdt: handle enabled watchdog properly Anatolij Gustschin
@ 2014-04-04 15:20 ` Wolfram Sang
  2014-04-04 15:41   ` Guenter Roeck
  0 siblings, 1 reply; 3+ messages in thread
From: Wolfram Sang @ 2014-04-04 15:20 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Apr 04, 2014 at 04:54:01PM +0200, Anatolij Gustschin wrote:
> If the watchdog is already enabled (e.g. started by the boot loader),
> we need to handle this case properly and start reloading the watchdog
> time-out counter as frequently as needed.
> 
> Signed-off-by: Anatolij Gustschin <agust@denx.de>
> Cc: Wolfram Sang <wsa@the-dreams.de>
> Cc: Wim Van Sebroeck <wim@iguana.be>

Uh, this driver has not been converted to use the watchdog framework
yet? I'd suggest this should be the first step.

@Wim: Does the watchdog core already handle the case that the wdt might
have been started by the bootloader?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140404/e7bcaf92/attachment.sig>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] watchdog: imx2_wdt: handle enabled watchdog properly
  2014-04-04 15:20 ` Wolfram Sang
@ 2014-04-04 15:41   ` Guenter Roeck
  0 siblings, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2014-04-04 15:41 UTC (permalink / raw)
  To: linux-arm-kernel

On 04/04/2014 08:20 AM, Wolfram Sang wrote:
> On Fri, Apr 04, 2014 at 04:54:01PM +0200, Anatolij Gustschin wrote:
>> If the watchdog is already enabled (e.g. started by the boot loader),
>> we need to handle this case properly and start reloading the watchdog
>> time-out counter as frequently as needed.
>>
>> Signed-off-by: Anatolij Gustschin <agust@denx.de>
>> Cc: Wolfram Sang <wsa@the-dreams.de>
>> Cc: Wim Van Sebroeck <wim@iguana.be>
>
> Uh, this driver has not been converted to use the watchdog framework
> yet? I'd suggest this should be the first step.
>

Yes, that would make sense at this time, especially given the amount
of work going into it. There is also a separate patch set pending,
converting the driver to use regmap [1]; I am copying the author.
Maybe one of the people working with the driver would be willing
to do the conversion.

Guenter

[1] http://comments.gmane.org/gmane.linux.kernel/1677735

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-04-04 15:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-04 14:54 [PATCH] watchdog: imx2_wdt: handle enabled watchdog properly Anatolij Gustschin
2014-04-04 15:20 ` Wolfram Sang
2014-04-04 15:41   ` Guenter Roeck

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).