From patchwork Fri Apr 4 14:54:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anatolij Gustschin X-Patchwork-Id: 3939721 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 81B269F1EE for ; Fri, 4 Apr 2014 16:46:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A302A20382 for ; Fri, 4 Apr 2014 16:46:33 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3F67520374 for ; Fri, 4 Apr 2014 16:46:32 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WW5WM-000591-T7; Fri, 04 Apr 2014 14:55:07 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WW5W0-00052v-OK; Fri, 04 Apr 2014 14:54:44 +0000 Received: from mail-out.m-online.net ([212.18.0.10]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WW5Vi-0004xN-LC for linux-arm-kernel@lists.infradead.org; Fri, 04 Apr 2014 14:54:28 +0000 Received: from frontend1.mail.m-online.net (frontend1.mail.intern.m-online.net [192.168.8.180]) by mail-out.m-online.net (Postfix) with ESMTP id 3g0kgF17PQz3hjlT; Fri, 4 Apr 2014 16:54:01 +0200 (CEST) X-Auth-Info: ciLfR/rnUhjWZiucWTlf7tB0W3FeukQRQ0ItB1sEYno= Received: from localhost (p4FDE6DAA.dip0.t-ipconnect.de [79.222.109.170]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA id 3g0kgD68Klzbbcf; Fri, 4 Apr 2014 16:54:00 +0200 (CEST) From: Anatolij Gustschin To: linux-arm-kernel@lists.infradead.org, Shawn Guo Subject: [PATCH] watchdog: imx2_wdt: handle enabled watchdog properly Date: Fri, 4 Apr 2014 16:54:01 +0200 Message-Id: <1396623242-15234-1-git-send-email-agust@denx.de> X-Mailer: git-send-email 1.7.9.5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140404_105426_854176_338C5EFA X-CRM114-Status: GOOD ( 13.03 ) X-Spam-Score: -1.9 (-) Cc: Wim Van Sebroeck , linux-watchdog@vger.kernel.org, Wolfram Sang X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Cc: Wolfram Sang Cc: Wim Van Sebroeck --- 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);