From patchwork Fri Jul 15 08:15:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 9231309 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4BBD960574 for ; Fri, 15 Jul 2016 08:17:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C6412522B for ; Fri, 15 Jul 2016 08:17:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3145B28319; Fri, 15 Jul 2016 08:17:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B1AAF2522B for ; Fri, 15 Jul 2016 08:17:28 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bNyI2-0008RQ-2t; Fri, 15 Jul 2016 08:16:06 +0000 Received: from mail01.prevas.se ([62.95.78.3]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bNyHI-0006M6-JQ; Fri, 15 Jul 2016 08:15:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=prevas.dk; i=@prevas.dk; l=2300; q=dns/txt; s=ironport1; t=1468570520; x=1500106520; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=xNOIGF51Wk7DDkKK/HpFGR8VWq+rtOepjW5WGMoi8T0=; b=0OO6Xzlga5MxhJtwOPz8TKdGo2DKgjJkPIa+2tu2y5D++tjVw6jbzXjJ OhG27pmS+dAaikSLyXzuIr3K6uZHszY6hVhh+rVu1x/Z9gC4DU8Pab1Fa TXlzxixUAPVyXoawRnQ61YjOISfSqvoaXJI53+iY3SmXB2+LnTyhDaUXD 4=; X-IronPort-AV: E=Sophos;i="5.28,367,1464645600"; d="scan'208";a="999995" Received: from vmprevas3.prevas.se (HELO smtp.prevas.se) ([172.16.8.103]) by ironport1.prevas.se with ESMTP/TLS/AES256-SHA; 15 Jul 2016 10:14:50 +0200 Received: from prevas-ravi.prevas.se (172.16.11.27) by smtp.prevas.se (172.16.8.105) with Microsoft SMTP Server (TLS) id 14.2.347.0; Fri, 15 Jul 2016 10:14:50 +0200 From: Rasmus Villemoes To: Wim Van Sebroeck , Guenter Roeck , Stephen Warren , Lee Jones , Eric Anholt Subject: [PATCH 3/3] watchdog: bcm2835_wdt: set WDOG_HW_RUNNING bit when appropriate Date: Fri, 15 Jul 2016 10:15:23 +0200 Message-ID: <1468570524-18222-3-git-send-email-rasmus.villemoes@prevas.dk> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1468570524-18222-1-git-send-email-rasmus.villemoes@prevas.dk> References: <1468570524-18222-1-git-send-email-rasmus.villemoes@prevas.dk> MIME-Version: 1.0 X-Originating-IP: [172.16.11.27] X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160715_011521_081705_FE6C8A5A X-CRM114-Status: GOOD ( 13.68 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Rasmus Villemoes Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP A bootloader may start the watchdog device before handing control to the kernel - in that case, we should tell the kernel about it so the watchdog framework can keep it alive until userspace opens /dev/watchdog0. Signed-off-by: Rasmus Villemoes --- drivers/watchdog/bcm2835_wdt.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/watchdog/bcm2835_wdt.c b/drivers/watchdog/bcm2835_wdt.c index 4dddd82..9a08334 100644 --- a/drivers/watchdog/bcm2835_wdt.c +++ b/drivers/watchdog/bcm2835_wdt.c @@ -55,6 +55,15 @@ struct bcm2835_wdt { static unsigned int heartbeat; static bool nowayout = WATCHDOG_NOWAYOUT; +static bool bcm2835_wdt_is_running(struct bcm2835_wdt *wdt) +{ + uint32_t cur; + + cur = readl(wdt->base + PM_RSTC); + + return !!(cur & PM_RSTC_WRCFG_FULL_RESET); +} + static int bcm2835_wdt_start(struct watchdog_device *wdog) { struct bcm2835_wdt *wdt = watchdog_get_drvdata(wdog); @@ -70,6 +79,7 @@ static int bcm2835_wdt_start(struct watchdog_device *wdog) PM_RSTC_WRCFG_FULL_RESET, wdt->base + PM_RSTC); spin_unlock_irqrestore(&wdt->lock, flags); + set_bit(WDOG_HW_RUNNING, &wdog->status); return 0; } @@ -79,6 +89,7 @@ static int bcm2835_wdt_stop(struct watchdog_device *wdog) struct bcm2835_wdt *wdt = watchdog_get_drvdata(wdog); writel_relaxed(PM_PASSWORD | PM_RSTC_RESET, wdt->base + PM_RSTC); + clear_bit(WDOG_HW_RUNNING, &wdog->status); return 0; } @@ -181,6 +192,17 @@ static int bcm2835_wdt_probe(struct platform_device *pdev) watchdog_init_timeout(&bcm2835_wdt_wdd, heartbeat, dev); watchdog_set_nowayout(&bcm2835_wdt_wdd, nowayout); bcm2835_wdt_wdd.parent = &pdev->dev; + if (bcm2835_wdt_is_running(wdt)) { + /* + * The currently active timeout value (set by the + * bootloader) may be different from the module + * heartbeat parameter or the value in device + * tree. But we just need to set WDOG_HW_RUNNING, + * because then the framework will "immediately" ping + * the device, updating the timeout. + */ + set_bit(WDOG_HW_RUNNING, &bcm2835_wdt_wdd.status); + } err = watchdog_register_device(&bcm2835_wdt_wdd); if (err) { dev_err(dev, "Failed to register watchdog device");