diff mbox series

[U-Boot,2/2] watchdog: imx: Use immediate reset bits for expire_now

Message ID 1565111130-18777-3-git-send-email-hancock@sedsystems.ca
State Accepted
Commit f2929d11a6394fa815741cbdbcc5d616e7bae860
Delegated to: Stefano Babic
Headers show
Series imx watchdog updates | expand

Commit Message

Robert Hancock Aug. 6, 2019, 5:05 p.m. UTC
The expire_now function was previously setting the watchdog timeout to
minimum and waiting for the watchdog to expire. However, this watchdog
also has bits to trigger immediate reset. Use those instead, like the
Linux imx2_wdt driver does.

Signed-off-by: Robert Hancock <hancock@sedsystems.ca>
---
 drivers/watchdog/imx_watchdog.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

Comments

Stefano Babic Nov. 4, 2019, 8:56 a.m. UTC | #1
> The expire_now function was previously setting the watchdog timeout to
> minimum and waiting for the watchdog to expire. However, this watchdog
> also has bits to trigger immediate reset. Use those instead, like the
> Linux imx2_wdt driver does.
> Signed-off-by: Robert Hancock <hancock@sedsystems.ca>

Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/drivers/watchdog/imx_watchdog.c b/drivers/watchdog/imx_watchdog.c
index 05bbfe0..c030360 100644
--- a/drivers/watchdog/imx_watchdog.c
+++ b/drivers/watchdog/imx_watchdog.c
@@ -15,15 +15,23 @@ 
 #endif
 #include <fsl_wdog.h>
 
-static void imx_watchdog_expire_now(struct watchdog_regs *wdog)
+static void imx_watchdog_expire_now(struct watchdog_regs *wdog, bool ext_reset)
 {
-	clrsetbits_le16(&wdog->wcr, WCR_WT_MSK, WCR_WDE);
+	u16 wcr = WCR_WDE;
+
+	if (ext_reset)
+		wcr |= WCR_SRS; /* do not assert internal reset */
+	else
+		wcr |= WCR_WDA; /* do not assert external reset */
+
+	/* Write 3 times to ensure it works, due to IMX6Q errata ERR004346 */
+	writew(wcr, &wdog->wcr);
+	writew(wcr, &wdog->wcr);
+	writew(wcr, &wdog->wcr);
 
-	writew(0x5555, &wdog->wsr);
-	writew(0xaaaa, &wdog->wsr);	/* load minimum 1/2 second timeout */
 	while (1) {
 		/*
-		 * spin for .5 seconds before reset
+		 * spin before reset
 		 */
 	}
 }
@@ -34,7 +42,7 @@  void __attribute__((weak)) reset_cpu(ulong addr)
 {
 	struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
 
-	imx_watchdog_expire_now(wdog);
+	imx_watchdog_expire_now(wdog, true);
 }
 #endif
 
@@ -106,7 +114,7 @@  static int imx_wdt_expire_now(struct udevice *dev, ulong flags)
 {
 	struct imx_wdt_priv *priv = dev_get_priv(dev);
 
-	imx_watchdog_expire_now(priv->base);
+	imx_watchdog_expire_now(priv->base, priv->ext_reset);
 	hang();
 
 	return 0;