mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 1/2] watchdog: i.MX: add soc_reset operation
Date: Thu, 19 Jan 2017 16:03:51 +0100	[thread overview]
Message-ID: <20170119150352.5421-1-s.hauer@pengutronix.de> (raw)

On i.MX21 watchdog type the reset operation is really different
from the watchdog enable/set timeout operation, so create an
extra callback for this instead of folding both things together.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/watchdog/imxwd.c | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/drivers/watchdog/imxwd.c b/drivers/watchdog/imxwd.c
index 03e116ea2..c736fdaa3 100644
--- a/drivers/watchdog/imxwd.c
+++ b/drivers/watchdog/imxwd.c
@@ -26,6 +26,7 @@ struct imx_wd;
 
 struct imx_wd_ops {
 	int (*set_timeout)(struct imx_wd *, int);
+	void (*soc_reset)(struct imx_wd *);
 	int (*init)(struct imx_wd *);
 };
 
@@ -76,10 +77,7 @@ static int imx1_watchdog_set_timeout(struct imx_wd *priv, int timeout)
 		return 0;
 	}
 
-	if (timeout > 0)
-		val = (timeout * 2 - 1) << 8;
-	else
-		val = 0;
+	val = (timeout * 2 - 1) << 8;
 
 	writew(val, priv->base + IMX1_WDOG_WCR);
 	writew(IMX1_WDOG_WCR_WDE | val, priv->base + IMX1_WDOG_WCR);
@@ -91,6 +89,11 @@ static int imx1_watchdog_set_timeout(struct imx_wd *priv, int timeout)
 	return 0;
 }
 
+static void imx1_soc_reset(struct imx_wd *priv)
+{
+	writew(IMX1_WDOG_WCR_WDE, priv->base + IMX1_WDOG_WCR);
+}
+
 static int imx21_watchdog_set_timeout(struct imx_wd *priv, int timeout)
 {
 	u16 val;
@@ -103,13 +106,9 @@ static int imx21_watchdog_set_timeout(struct imx_wd *priv, int timeout)
 	if (timeout == 0) /* bit 2 (WDE) cannot be set to 0 again */
 		return -ENOSYS;
 
-	if (timeout > 0)
-		val = ((timeout * 2 - 1) << 8) | IMX21_WDOG_WCR_SRS |
-			IMX21_WDOG_WCR_WDA;
-	else
-		val = 0;
+	val = ((timeout * 2 - 1) << 8) | IMX21_WDOG_WCR_SRS |
+		IMX21_WDOG_WCR_WDA;
 
-	writew(val, priv->base + IMX21_WDOG_WCR);
 	writew(IMX21_WDOG_WCR_WDE | val, priv->base + IMX21_WDOG_WCR);
 
 	/* Write Service Sequence */
@@ -119,6 +118,15 @@ static int imx21_watchdog_set_timeout(struct imx_wd *priv, int timeout)
 	return 0;
 }
 
+static void imx21_soc_reset(struct imx_wd *priv)
+{
+	u16 val;
+
+	val = IMX21_WDOG_WCR_SRS | IMX21_WDOG_WCR_WDA;
+
+	writew(val, priv->base + IMX21_WDOG_WCR);
+}
+
 static int imx_watchdog_set_timeout(struct watchdog *wd, unsigned timeout)
 {
 	struct imx_wd *priv = (struct imx_wd *)to_imx_wd(wd);
@@ -130,7 +138,7 @@ static void __noreturn imxwd_force_soc_reset(struct restart_handler *rst)
 {
 	struct imx_wd *priv = container_of(rst, struct imx_wd, restart);
 
-	priv->ops->set_timeout(priv, -1);
+	priv->ops->soc_reset(priv);
 
 	mdelay(1000);
 
@@ -227,11 +235,13 @@ on_error:
 
 static const struct imx_wd_ops imx21_wd_ops = {
 	.set_timeout = imx21_watchdog_set_timeout,
+	.soc_reset = imx21_soc_reset,
 	.init = imx21_wd_init,
 };
 
 static const struct imx_wd_ops imx1_wd_ops = {
 	.set_timeout = imx1_watchdog_set_timeout,
+	.soc_reset = imx1_soc_reset,
 };
 
 static __maybe_unused struct of_device_id imx_wdt_dt_ids[] = {
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

             reply	other threads:[~2017-01-19 15:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-19 15:03 Sascha Hauer [this message]
2017-01-19 15:03 ` [PATCH 2/2] watchdog: i.MX: Fix internal/external reset Sascha Hauer
2017-01-20  5:39 ` [PATCH 1/2] watchdog: i.MX: add soc_reset operation Sam Ravnborg
2017-01-20  5:44   ` Sam Ravnborg
2017-01-20  8:10     ` Sascha Hauer

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=20170119150352.5421-1-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox