public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH] watchdog: imx: Support set timeout by wdt command
@ 2020-07-01  9:15 Mo, Yuezhang
  2020-07-16  9:07 ` Stefano Babic
  0 siblings, 1 reply; 3+ messages in thread
From: Mo, Yuezhang @ 2020-07-01  9:15 UTC (permalink / raw)
  To: u-boot

After "4b969deac0 watchdog: imx: Add DM support", the imx watchdog
can be started by wdt command. But the imx watchdog driver only
support start with the default timeout.

This commit adds the support for setting the timeout which pass from
the wdt command into the imx watchdog. If the timeout out of the
valid range(0.5~128s), start the watchdog with a timeout within the
valid range and the timeout is the one which closest to the passed
timeout.

Signed-off-by: Yuezhang.Mo <yuezhang.mo@sony.com>
Reviewed-by: Andy.Wu <Andy.Wu@sony.com>
---
 drivers/watchdog/imx_watchdog.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/watchdog/imx_watchdog.c b/drivers/watchdog/imx_watchdog.c
index 01762df019..b90c2daece 100644
--- a/drivers/watchdog/imx_watchdog.c
+++ b/drivers/watchdog/imx_watchdog.c
@@ -16,6 +16,10 @@
 #include <asm/arch/immap_lsch2.h>
 #endif
 #include <fsl_wdog.h>
+#include <div64.h>
+
+#define TIMEOUT_MAX	128000
+#define TIMEOUT_MIN	500
 
 static void imx_watchdog_expire_now(struct watchdog_regs *wdog, bool ext_reset)
 {
@@ -57,9 +61,9 @@ static void imx_watchdog_reset(struct watchdog_regs *wdog)
 #endif /* CONFIG_WATCHDOG_RESET_DISABLE*/
 }
 
-static void imx_watchdog_init(struct watchdog_regs *wdog, bool ext_reset)
+static void imx_watchdog_init(struct watchdog_regs *wdog, bool ext_reset,
+			      u64 timeout)
 {
-	u16 timeout;
 	u16 wcr;
 
 	/*
@@ -70,7 +74,11 @@ static void imx_watchdog_init(struct watchdog_regs *wdog, bool ext_reset)
 #ifndef CONFIG_WATCHDOG_TIMEOUT_MSECS
 #define CONFIG_WATCHDOG_TIMEOUT_MSECS 128000
 #endif
-	timeout = (CONFIG_WATCHDOG_TIMEOUT_MSECS / 500) - 1;
+
+	timeout = max_t(u64, timeout, TIMEOUT_MIN);
+	timeout = min_t(u64, timeout, TIMEOUT_MAX);
+	timeout = lldiv(timeout, 500) - 1;
+
 #ifdef CONFIG_FSL_LSCH2
 	wcr = (WCR_WDA | WCR_SRS | WCR_WDE) << 8 | timeout;
 #else
@@ -95,7 +103,7 @@ void hw_watchdog_init(void)
 {
 	struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
 
-	imx_watchdog_init(wdog, true);
+	imx_watchdog_init(wdog, true, CONFIG_WATCHDOG_TIMEOUT_MSECS);
 }
 #else
 struct imx_wdt_priv {
@@ -126,7 +134,7 @@ static int imx_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
 {
 	struct imx_wdt_priv *priv = dev_get_priv(dev);
 
-	imx_watchdog_init(priv->base, priv->ext_reset);
+	imx_watchdog_init(priv->base, priv->ext_reset, timeout);
 
 	return 0;
 }
-- 
2.17.1

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

* [PATCH] watchdog: imx: Support set timeout by wdt command
  2020-07-01  9:15 Mo, Yuezhang
@ 2020-07-16  9:07 ` Stefano Babic
  0 siblings, 0 replies; 3+ messages in thread
From: Stefano Babic @ 2020-07-16  9:07 UTC (permalink / raw)
  To: u-boot

On 01.07.20 11:15, Mo, Yuezhang wrote:
> After "4b969deac0 watchdog: imx: Add DM support", the imx watchdog
> can be started by wdt command. But the imx watchdog driver only
> support start with the default timeout.
> 
> This commit adds the support for setting the timeout which pass from
> the wdt command into the imx watchdog. If the timeout out of the
> valid range(0.5~128s), start the watchdog with a timeout within the
> valid range and the timeout is the one which closest to the passed
> timeout.
> 

Thanks, it looks useful to me.

> Signed-off-by: Yuezhang.Mo <yuezhang.mo@sony.com>
> Reviewed-by: Andy.Wu <Andy.Wu@sony.com>
> ---
>  drivers/watchdog/imx_watchdog.c | 18 +++++++++++++-----
>  1 file changed, 13 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/watchdog/imx_watchdog.c b/drivers/watchdog/imx_watchdog.c
> index 01762df019..b90c2daece 100644
> --- a/drivers/watchdog/imx_watchdog.c
> +++ b/drivers/watchdog/imx_watchdog.c
> @@ -16,6 +16,10 @@
>  #include <asm/arch/immap_lsch2.h>
>  #endif
>  #include <fsl_wdog.h>
> +#include <div64.h>
> +
> +#define TIMEOUT_MAX	128000
> +#define TIMEOUT_MIN	500
>  
>  static void imx_watchdog_expire_now(struct watchdog_regs *wdog, bool ext_reset)
>  {
> @@ -57,9 +61,9 @@ static void imx_watchdog_reset(struct watchdog_regs *wdog)
>  #endif /* CONFIG_WATCHDOG_RESET_DISABLE*/
>  }
>  
> -static void imx_watchdog_init(struct watchdog_regs *wdog, bool ext_reset)
> +static void imx_watchdog_init(struct watchdog_regs *wdog, bool ext_reset,
> +			      u64 timeout)
>  {
> -	u16 timeout;
>  	u16 wcr;
>  
>  	/*
> @@ -70,7 +74,11 @@ static void imx_watchdog_init(struct watchdog_regs *wdog, bool ext_reset)
>  #ifndef CONFIG_WATCHDOG_TIMEOUT_MSECS
>  #define CONFIG_WATCHDOG_TIMEOUT_MSECS 128000
>  #endif
> -	timeout = (CONFIG_WATCHDOG_TIMEOUT_MSECS / 500) - 1;
> +
> +	timeout = max_t(u64, timeout, TIMEOUT_MIN);
> +	timeout = min_t(u64, timeout, TIMEOUT_MAX);
> +	timeout = lldiv(timeout, 500) - 1;
> +
>  #ifdef CONFIG_FSL_LSCH2
>  	wcr = (WCR_WDA | WCR_SRS | WCR_WDE) << 8 | timeout;
>  #else
> @@ -95,7 +103,7 @@ void hw_watchdog_init(void)
>  {
>  	struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
>  
> -	imx_watchdog_init(wdog, true);
> +	imx_watchdog_init(wdog, true, CONFIG_WATCHDOG_TIMEOUT_MSECS);
>  }
>  #else
>  struct imx_wdt_priv {
> @@ -126,7 +134,7 @@ static int imx_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
>  {
>  	struct imx_wdt_priv *priv = dev_get_priv(dev);
>  
> -	imx_watchdog_init(priv->base, priv->ext_reset);
> +	imx_watchdog_init(priv->base, priv->ext_reset, timeout);
>  
>  	return 0;
>  }
> 

Reviewed-by: stefano Babic <sbabic@denx.de>

Best regards,
Stefano Babic


-- 
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================

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

* [PATCH] watchdog: imx: Support set timeout by wdt command
@ 2020-07-16 17:49 sbabic at denx.de
  0 siblings, 0 replies; 3+ messages in thread
From: sbabic at denx.de @ 2020-07-16 17:49 UTC (permalink / raw)
  To: u-boot

> After "4b969deac0 watchdog: imx: Add DM support", the imx watchdog
> can be started by wdt command. But the imx watchdog driver only
> support start with the default timeout.
> This commit adds the support for setting the timeout which pass from
> the wdt command into the imx watchdog. If the timeout out of the
> valid range(0.5~128s), start the watchdog with a timeout within the
> valid range and the timeout is the one which closest to the passed
> timeout.
> Signed-off-by: Yuezhang.Mo <yuezhang.mo@sony.com>
> Reviewed-by: Andy.Wu <Andy.Wu@sony.com>
> Reviewed-by: stefano Babic <sbabic@denx.de>
Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

-- 
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================

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

end of thread, other threads:[~2020-07-16 17:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-16 17:49 [PATCH] watchdog: imx: Support set timeout by wdt command sbabic at denx.de
  -- strict thread matches above, loose matches on Subject: below --
2020-07-01  9:15 Mo, Yuezhang
2020-07-16  9:07 ` Stefano Babic

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