From patchwork Thu Feb 16 19:30:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Belloni X-Patchwork-Id: 9578217 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 25368600C5 for ; Thu, 16 Feb 2017 19:31:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1935F28665 for ; Thu, 16 Feb 2017 19:31:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0DE7E28671; Thu, 16 Feb 2017 19:31:33 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9C9FB28665 for ; Thu, 16 Feb 2017 19:31:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=hD6suJKx45+HBPExOrNQnne89+ZWJ1EPfc9uWs8brIs=; b=V5Jd+P6wURzgjQaBxgvo59w04h 8xGTL4nJuiS0j6wA7W+b7VbAaKRXez446M2W2IEMwni/FGM2YiAAGSAELV4jiVdHRdXjCZlLtlHFu Hq9+EhaHCuBjjME6ddsTrS7TmYtYHI/jBmDjqoD1reqLhVFltS7Q3pjc3lVru8aAiKsf5lA3kRoiF 9oVZDXZXTh0BOHsgz3cDguhHfUqp93zZ3vhgW118X+M1XIpxfs8x8nzO7UWaHmRi843dHLAcrJVJu AaL1OneSA/xL+PTTxOiWs8QYfk0cD49siysLBQDJjBbx4V1FiBnEH3bukfGxufiVoLQHQkYEg+DLP lhRpkeFw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ceRm0-0002gi-2c; Thu, 16 Feb 2017 19:31:24 +0000 Received: from mail.free-electrons.com ([62.4.15.54]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ceRlv-0002eK-Bd for linux-arm-kernel@lists.infradead.org; Thu, 16 Feb 2017 19:31:21 +0000 Received: by mail.free-electrons.com (Postfix, from userid 110) id 4934220BC4; Thu, 16 Feb 2017 20:30:57 +0100 (CET) Received: from localhost (unknown [88.191.26.124]) by mail.free-electrons.com (Postfix) with ESMTPSA id 241F620B7A; Thu, 16 Feb 2017 20:30:57 +0100 (CET) From: Alexandre Belloni To: Guenter Roeck Subject: [PATCH v2 3/3] watchdog: sama5d4: Implement resume hook Date: Thu, 16 Feb 2017 20:30:53 +0100 Message-Id: <20170216193053.5546-3-alexandre.belloni@free-electrons.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170216193053.5546-1-alexandre.belloni@free-electrons.com> References: <20170216193053.5546-1-alexandre.belloni@free-electrons.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170216_113119_580797_18FEF856 X-CRM114-Status: GOOD ( 11.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-watchdog@vger.kernel.org, Nicolas Ferre , linux-kernel@vger.kernel.org, Wim Van Sebroeck , Alexandre Belloni , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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 When resuming for the deepest state on sama5d2, it is necessary to restore MR as the registers are lost. Signed-off-by: Alexandre Belloni --- Changes in v2: - cache mr beofre suspending drivers/watchdog/sama5d4_wdt.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/watchdog/sama5d4_wdt.c b/drivers/watchdog/sama5d4_wdt.c index 2a60251806d2..5ddeb4803dc3 100644 --- a/drivers/watchdog/sama5d4_wdt.c +++ b/drivers/watchdog/sama5d4_wdt.c @@ -28,6 +28,7 @@ struct sama5d4_wdt { struct watchdog_device wdd; void __iomem *reg_base; + u32 mr; }; static int wdt_timeout = WDT_DEFAULT_TIMEOUT; @@ -248,11 +249,42 @@ static const struct of_device_id sama5d4_wdt_of_match[] = { }; MODULE_DEVICE_TABLE(of, sama5d4_wdt_of_match); +#ifdef CONFIG_PM_SLEEP +static int sama5d4_wdt_suspend(struct device *dev) +{ + struct sama5d4_wdt *wdt = dev_get_drvdata(dev); + + wdt->mr = wdt_read(wdt, AT91_WDT_MR); + + return 0; +} + +static int sama5d4_wdt_resume(struct device *dev) +{ + struct sama5d4_wdt *wdt = dev_get_drvdata(dev); + u32 reg; + + reg = wdt_read(wdt, AT91_WDT_MR); + if (reg & AT91_WDT_WDDIS) + wdt_write(wdt, AT91_WDT_MR, reg & ~AT91_WDT_WDDIS); + + wdt_write(wdt, AT91_WDT_MR, wdt->mr & ~AT91_WDT_WDDIS); + if (wdt->mr & AT91_WDT_WDDIS) + wdt_write(wdt, AT91_WDT_MR, wdt->mr); + + return 0; +} +#endif + +static SIMPLE_DEV_PM_OPS(sama5d4_wdt_pm_ops, sama5d4_wdt_suspend, + sama5d4_wdt_resume); + static struct platform_driver sama5d4_wdt_driver = { .probe = sama5d4_wdt_probe, .remove = sama5d4_wdt_remove, .driver = { .name = "sama5d4_wdt", + .pm = &sama5d4_wdt_pm_ops, .of_match_table = sama5d4_wdt_of_match, } };