All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@free-electrons.com>
To: Guenter Roeck <linux@roeck-us.net>
Cc: Wim Van Sebroeck <wim@iguana.be>,
	Nicolas Ferre <nicolas.ferre@atmel.com>,
	linux-watchdog@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	Alexandre Belloni <alexandre.belloni@free-electrons.com>
Subject: [PATCH v2 3/3] watchdog: sama5d4: Implement resume hook
Date: Thu, 16 Feb 2017 20:30:53 +0100	[thread overview]
Message-ID: <20170216193053.5546-3-alexandre.belloni@free-electrons.com> (raw)
In-Reply-To: <20170216193053.5546-1-alexandre.belloni@free-electrons.com>

When resuming for the deepest state on sama5d2, it is necessary to restore
MR as the registers are lost.

Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
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,
 	}
 };
-- 
2.11.0

WARNING: multiple messages have this Message-ID (diff)
From: alexandre.belloni@free-electrons.com (Alexandre Belloni)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 3/3] watchdog: sama5d4: Implement resume hook
Date: Thu, 16 Feb 2017 20:30:53 +0100	[thread overview]
Message-ID: <20170216193053.5546-3-alexandre.belloni@free-electrons.com> (raw)
In-Reply-To: <20170216193053.5546-1-alexandre.belloni@free-electrons.com>

When resuming for the deepest state on sama5d2, it is necessary to restore
MR as the registers are lost.

Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
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,
 	}
 };
-- 
2.11.0

  parent reply	other threads:[~2017-02-16 19:31 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-16 19:30 [PATCH v2 1/3] watchdog: sama5d4: Cleanup init Alexandre Belloni
2017-02-16 19:30 ` Alexandre Belloni
2017-02-16 19:30 ` [PATCH v2 2/3] watchdog: sama5d4: Fix setting timeout when watchdog is disabled Alexandre Belloni
2017-02-16 19:30   ` Alexandre Belloni
2017-02-17 14:40   ` Guenter Roeck
2017-02-17 14:40     ` Guenter Roeck
2017-02-17 15:16     ` Alexandre Belloni
2017-02-17 15:16       ` Alexandre Belloni
2017-02-19 16:57       ` Guenter Roeck
2017-02-19 16:57         ` Guenter Roeck
2017-02-19 23:52         ` Alexandre Belloni
2017-02-19 23:52           ` Alexandre Belloni
2017-02-20  4:46           ` Guenter Roeck
2017-02-20  4:46             ` Guenter Roeck
2017-03-02 17:35             ` Alexandre Belloni
2017-03-02 17:35               ` Alexandre Belloni
2017-02-16 19:30 ` Alexandre Belloni [this message]
2017-02-16 19:30   ` [PATCH v2 3/3] watchdog: sama5d4: Implement resume hook Alexandre Belloni
2017-02-17 14:47   ` Guenter Roeck
2017-02-17 14:47     ` Guenter Roeck
2017-02-17 15:22     ` Alexandre Belloni
2017-02-17 15:22       ` Alexandre Belloni
2017-02-19 17:05       ` Guenter Roeck
2017-02-19 17:05         ` Guenter Roeck
2017-02-17 14:48 ` [PATCH v2 1/3] watchdog: sama5d4: Cleanup init Guenter Roeck
2017-02-17 14:48   ` Guenter Roeck
2017-02-17 15:35   ` Alexandre Belloni
2017-02-17 15:35     ` Alexandre Belloni
2017-02-19 16:53     ` Guenter Roeck
2017-02-19 16:53       ` 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=20170216193053.5546-3-alexandre.belloni@free-electrons.com \
    --to=alexandre.belloni@free-electrons.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=nicolas.ferre@atmel.com \
    --cc=wim@iguana.be \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.