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>
Cc: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
Subject: [PATCH 1/9] mfd: da9063: reset watchdog timer
Date: Thu, 12 Apr 2018 09:22:23 +0200	[thread overview]
Message-ID: <20180412072231.31207-2-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20180412072231.31207-1-s.hauer@pengutronix.de>

From: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>

Setting the new timeout does not suffice for restarting the watchdog;
the self-clearing bit in CONTROL_F must be set too.

barebox does not provide a ping function in its watchdog api to restart
the watchdog timer.  Detect ping vs. set_timeout() by comparing the
actual with the previous timeout value.

Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
Tested-by: Stefan Christ <s.christ@phytec.de>
Signed-off-by: Christian Hemp <c.hemp@phytec.de>
---
 drivers/mfd/da9063.c | 36 ++++++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/drivers/mfd/da9063.c b/drivers/mfd/da9063.c
index ac303611c0..74ad5bfdab 100644
--- a/drivers/mfd/da9063.c
+++ b/drivers/mfd/da9063.c
@@ -28,8 +28,13 @@ struct da9063 {
 	struct watchdog		wd;
 	struct i2c_client	*client;
 	struct device_d		*dev;
+	unsigned int		timeout;
 };
 
+/* forbidden/impossible value; timeout will be set to this value initially to
+ * detect ping vs. set_timeout() operations. */
+#define DA9063_INITIAL_TIMEOUT	(~0u)
+
 /* System Control and Event Registers */
 #define DA9063_REG_FAULT_LOG	0x05
 #define DA9063_REG_CONTROL_D	0x11
@@ -44,8 +49,25 @@ struct da9063 {
 #define DA9063_TWDSCALE_MASK	0x07
 
 /* DA9063_REG_CONTROL_F (addr=0x13) */
+#define DA9063_WATCHDOG		0x01
 #define DA9063_SHUTDOWN		0x02
 
+static int da9063_watchdog_ping(struct da9063 *priv)
+{
+	int ret;
+	u8 val;
+
+	dev_dbg(priv->dev, "ping\n");
+
+	/* reset watchdog timer; register is self clearing */
+	val = DA9063_WATCHDOG;
+	ret = i2c_write_reg(priv->client, DA9063_REG_CONTROL_F, &val, 1);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
 static int da9063_watchdog_set_timeout(struct watchdog *wd, unsigned timeout)
 {
 	struct da9063 *priv = container_of(wd, struct da9063, wd);
@@ -57,8 +79,14 @@ static int da9063_watchdog_set_timeout(struct watchdog *wd, unsigned timeout)
 	if (timeout > 131)
 		return -EINVAL;
 
+	timeout *= 1000; /* convert to ms */
+
+	if (timeout == priv->timeout)
+		/* set_timeout called with previous parameter; just ping the
+		 * watchdog */
+		goto out;
+
 	if (timeout) {
-		timeout *= 1000; /* convert to ms */
 		scale = 0;
 		while (timeout > (2048 << scale) && scale <= 6)
 			scale++;
@@ -78,7 +106,10 @@ static int da9063_watchdog_set_timeout(struct watchdog *wd, unsigned timeout)
 	if (ret < 0)
 		return ret;
 
-	return 0;
+	priv->timeout = timeout;
+
+out:
+	return da9063_watchdog_ping(priv);
 }
 
 static void da9063_detect_reset_source(struct da9063 *priv)
@@ -127,6 +158,7 @@ static int da9063_probe(struct device_d *dev)
 	priv->wd.priority = of_get_watchdog_priority(dev->device_node);
 	priv->wd.set_timeout = da9063_watchdog_set_timeout;
 	priv->wd.hwdev = dev;
+	priv->timeout = DA9063_INITIAL_TIMEOUT;
 	priv->client = to_i2c_client(dev);
 	priv->dev = dev;
 
-- 
2.16.1


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

  reply	other threads:[~2018-04-12  7:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-12  7:22 [PATCH 0/9] Dialog da9063 updates Sascha Hauer
2018-04-12  7:22 ` Sascha Hauer [this message]
2018-04-12  7:22 ` [PATCH 2/9] mfd: da9063: added generic reg_update() function Sascha Hauer
2018-04-12  7:22 ` [PATCH 3/9] mfd: da9063: use da906x_reg_update() Sascha Hauer
2018-04-12  7:22 ` [PATCH 4/9] mfd: da9063: add device specific init function Sascha Hauer
2018-04-12  7:22 ` [PATCH 5/9] mfd: da9063: added of_device_id information Sascha Hauer
2018-04-12  7:22 ` [PATCH 6/9] mfd: da9063: read out and report device id Sascha Hauer
2018-04-12  7:22 ` [PATCH 7/9] mfd: da9063: update Kconfig for DA9062 Sascha Hauer
2018-04-12  7:22 ` [PATCH 8/9] ARM: i.MX: phycore-som: added and enabled DA9062 PMIC Sascha Hauer
2018-04-12  7:22 ` [PATCH 9/9] ARM: i.MX: pfla02: set priority of da9063 watchdog 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=20180412072231.31207-2-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=enrico.scholz@sigma-chemnitz.de \
    /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