All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] Fix watchdog timeout setup for mt7623n (banana-pi r2)
@ 2019-06-10 13:53 shannon at quazillionaires.net
  2019-06-23 13:44 ` Frank Wunderlich
  0 siblings, 1 reply; 3+ messages in thread
From: shannon at quazillionaires.net @ 2019-06-10 13:53 UTC (permalink / raw)
  To: u-boot

Fixes a bugged implementation of watchdog reset for mediatek cores
Changeset 06985289d452ad2423145cfed8cece61a7f8cec6
 "watdchdog: Implement generic watchdog_reset() version"
 brought this bug to light

Moves reconfiguration call to mtk_wdt_reset to a more appropriate location in mtk_wdt_start


Signed-off-by: Shannon Barber <sbarber@dataspeedinc.com>
---
 drivers/watchdog/mtk_wdt.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/drivers/watchdog/mtk_wdt.c b/drivers/watchdog/mtk_wdt.c
index 0b501733f2..a7d4c7a3b8 100644
--- a/drivers/watchdog/mtk_wdt.c
+++ b/drivers/watchdog/mtk_wdt.c
@@ -70,18 +70,30 @@ static int mtk_wdt_expire_now(struct udevice *dev, ulong flags)
 	return 0;
 }
 
-static void mtk_wdt_set_timeout(struct udevice *dev, unsigned int timeout)
+static void mtk_wdt_set_timeout(struct udevice *dev, unsigned int timeout_ms)
 {
 	struct mtk_wdt_priv *priv = dev_get_priv(dev);
 
 	/*
-	 * One bit is the value of 512 ticks
-	 * The clock has 32 KHz
+	 * One WDT_LENGTH count is 512 ticks of the wdt clock
+	 * Clock runs at 32768 Hz
+	 * e.g. 15.625 ms per count (nominal)
+	 * We want the ceiling after dividing timeout_ms by 15.625 ms
+	 * We add 15624 prior to the divide to implement the ceiling
+	 * We prevent over-flow by clamping the timeout_ms value here
+	 *  as the maximum WDT_LENGTH counts is 1023 -> 15.984375 sec
+	 * We also enforce a minimum of 1 count
+	 * Many watchdog peripherals have a self-imposed count of 1
+	 *  that is added to the register counts.
+	 *  The MediaTek docs lack details to know if this is the case here.
+	 *  So we enforce a minimum of 1 to guarantee operation.
 	 */
-	timeout = WDT_LENGTH_TIMEOUT(timeout << 6) | WDT_LENGTH_KEY;
-	writel(timeout, priv->base + MTK_WDT_LENGTH);
-
-	mtk_wdt_reset(dev);
+	if(timeout_ms > 15984) timeout_ms = 15984;
+	u64 timeout_us = timeout_ms * 1000;
+	u32 timeout_cc = (u32) ( (15624 + timeout_us) / 15625 );
+	if(timeout_cc == 0) timeout_cc = 1;
+	u32 length = WDT_LENGTH_TIMEOUT(timeout_cc) | WDT_LENGTH_KEY;
+	writel(length, priv->base + MTK_WDT_LENGTH);
 }
 
 static int mtk_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
@@ -90,6 +102,8 @@ static int mtk_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
 
 	mtk_wdt_set_timeout(dev, timeout);
 
+        mtk_wdt_reset(dev);
+
 	/* Enable watchdog reset signal */
 	setbits_le32(priv->base + MTK_WDT_MODE,
 		     WDT_MODE_EN | WDT_MODE_KEY | WDT_MODE_EXTEN);
-- 
2.17.1

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

* [U-Boot] [PATCH] Fix watchdog timeout setup for mt7623n (banana-pi r2)
  2019-06-10 13:53 [U-Boot] [PATCH] Fix watchdog timeout setup for mt7623n (banana-pi r2) shannon at quazillionaires.net
@ 2019-06-23 13:44 ` Frank Wunderlich
  2019-06-24  7:47   ` Stefan Roese
  0 siblings, 1 reply; 3+ messages in thread
From: Frank Wunderlich @ 2019-06-23 13:44 UTC (permalink / raw)
  To: u-boot

Hi,

WDT on mt7623 (bananapi r2) is still broken, i cannot boot into uboot-console because the boards reboots after this line appears:

WDT:   Started with servicing (60s timeout)

without this patch it does it immediately with the patch after ~30s (not the 60s shown in message)

regards Frank

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

* [U-Boot] [PATCH] Fix watchdog timeout setup for mt7623n (banana-pi r2)
  2019-06-23 13:44 ` Frank Wunderlich
@ 2019-06-24  7:47   ` Stefan Roese
  0 siblings, 0 replies; 3+ messages in thread
From: Stefan Roese @ 2019-06-24  7:47 UTC (permalink / raw)
  To: u-boot

Hi Frank,

On 23.06.19 15:44, Frank Wunderlich wrote:
> Hi,
> 
> WDT on mt7623 (bananapi r2) is still broken, i cannot boot into uboot-console because the boards reboots after this line appears:
> 
> WDT:   Started with servicing (60s timeout)
> 
> without this patch it does it immediately with the patch after ~30s (not the 60s shown in message)

Could you perhaps debug and fix this issue in the watchdog driver
for this SoC? I don't have access to such a board, so I can't really
help here.

Thanks,
Stefan

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

end of thread, other threads:[~2019-06-24  7:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-10 13:53 [U-Boot] [PATCH] Fix watchdog timeout setup for mt7623n (banana-pi r2) shannon at quazillionaires.net
2019-06-23 13:44 ` Frank Wunderlich
2019-06-24  7:47   ` Stefan Roese

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.