mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 1/2] mfd: da9063: fix TWDSCALE debug message
@ 2019-11-04 10:28 Marco Felsch
  2019-11-04 10:28 ` [PATCH v2 2/2] mfd: da9063: fix watchdog ping execution Marco Felsch
  0 siblings, 1 reply; 3+ messages in thread
From: Marco Felsch @ 2019-11-04 10:28 UTC (permalink / raw)
  To: barebox, a.fatoum

The TWDSCALE is the found scale + 1 as described in the datasheets
for the DA9062/3 devices. The driver logic is correct just the debug
message is wrong.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 drivers/mfd/da9063.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mfd/da9063.c b/drivers/mfd/da9063.c
index f0381944d9..4d459c7f18 100644
--- a/drivers/mfd/da9063.c
+++ b/drivers/mfd/da9063.c
@@ -270,7 +270,7 @@ static int da9063_watchdog_set_timeout(struct watchdog *wd, unsigned timeout)
 		while (timeout > (2048 << scale) && scale <= 6)
 			scale++;
 		dev_dbg(dev, "calculated TWDSCALE=%u (req=%ims calc=%ims)\n",
-				scale, timeout, 2048 << scale);
+			scale + 1, timeout, 2048 << scale);
 		scale++; /* scale 0 disables the WD */
 	}
 
-- 
2.20.1


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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2 2/2] mfd: da9063: fix watchdog ping execution
  2019-11-04 10:28 [PATCH v2 1/2] mfd: da9063: fix TWDSCALE debug message Marco Felsch
@ 2019-11-04 10:28 ` Marco Felsch
  2019-11-05 10:10   ` Sascha Hauer
  0 siblings, 1 reply; 3+ messages in thread
From: Marco Felsch @ 2019-11-04 10:28 UTC (permalink / raw)
  To: barebox, a.fatoum

The watchdog resets the system if the watchdog gets pinged to fast.
Between each watchdog ping must be a pause of at least 200ms. This
commit fixes that by rejecting two fast requests.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
Hi,

after the a discussion we decided to change the busy wait behaviour. Now
the driver won't wait and reject the ping-request immediately to ensure
the cool down phase.

Regards,
  Marco

 drivers/mfd/da9063.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/mfd/da9063.c b/drivers/mfd/da9063.c
index 4d459c7f18..b1e4116906 100644
--- a/drivers/mfd/da9063.c
+++ b/drivers/mfd/da9063.c
@@ -14,6 +14,7 @@
  */
 
 #include <common.h>
+#include <clock.h>
 #include <driver.h>
 #include <gpio.h>
 #include <restart.h>
@@ -33,6 +34,7 @@ struct da9063 {
 	struct i2c_client	*client1;
 	struct device_d		*dev;
 	unsigned int		timeout;
+	uint64_t		last_ping;
 };
 
 /* forbidden/impossible value; timeout will be set to this value initially to
@@ -237,6 +239,14 @@ static int da9063_watchdog_ping(struct da9063 *priv)
 	int ret;
 	u8 val;
 
+	/*
+	 * The watchdog has a cool down phase of 200ms and if we ping to fast
+	 * the da9062/3 resets the system. Reject those requests has a maximum
+	 * failure of 10% if the watchdog timeout is set to 2.048s.
+	 */
+	if ((int64_t)(priv->last_ping + 200 * MSECOND - get_time_ns()) > 0)
+		return 0;
+
 	dev_dbg(priv->dev, "ping\n");
 
 	/* reset watchdog timer; register is self clearing */
@@ -245,6 +255,8 @@ static int da9063_watchdog_ping(struct da9063 *priv)
 	if (ret < 0)
 		return ret;
 
+	priv->last_ping = get_time_ns();
+
 	return 0;
 }
 
-- 
2.20.1


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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2 2/2] mfd: da9063: fix watchdog ping execution
  2019-11-04 10:28 ` [PATCH v2 2/2] mfd: da9063: fix watchdog ping execution Marco Felsch
@ 2019-11-05 10:10   ` Sascha Hauer
  0 siblings, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2019-11-05 10:10 UTC (permalink / raw)
  To: Marco Felsch; +Cc: barebox, a.fatoum

On Mon, Nov 04, 2019 at 11:28:06AM +0100, Marco Felsch wrote:
> The watchdog resets the system if the watchdog gets pinged to fast.
> Between each watchdog ping must be a pause of at least 200ms. This
> commit fixes that by rejecting two fast requests.
> 
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> ---
> @@ -237,6 +239,14 @@ static int da9063_watchdog_ping(struct da9063 *priv)
>  	int ret;
>  	u8 val;
>  
> +	/*
> +	 * The watchdog has a cool down phase of 200ms and if we ping to fast
> +	 * the da9062/3 resets the system. Reject those requests has a maximum
> +	 * failure of 10% if the watchdog timeout is set to 2.048s.
> +	 */
> +	if ((int64_t)(priv->last_ping + 200 * MSECOND - get_time_ns()) > 0)
> +		return 0;

Changed this to:

	if (!is_timeout(priv->last_ping, 200 * MSECOND))
		return 0;

And applied, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-11-05 10:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-04 10:28 [PATCH v2 1/2] mfd: da9063: fix TWDSCALE debug message Marco Felsch
2019-11-04 10:28 ` [PATCH v2 2/2] mfd: da9063: fix watchdog ping execution Marco Felsch
2019-11-05 10:10   ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox