linux-watchdog.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] watchdog: ftwdt010_wdt: implement _restart() function
@ 2022-08-27 14:24 Sergei Antonov
  2022-08-28 14:39 ` Guenter Roeck
  0 siblings, 1 reply; 3+ messages in thread
From: Sergei Antonov @ 2022-08-27 14:24 UTC (permalink / raw)
  To: linux-watchdog; +Cc: wim, linux, Sergei Antonov

Implement ftwdt010_wdt_restart(). It enables watchdog with timeout = 0
and disabled IRQ. Since it needs code similar to ftwdt010_wdt_start(),
add a new function ftwdt010_enable() and move common code there.

v1 -> v2:
Do not let IRQ trigger when restarting.
Add a helper function ftwdt010_enable().

Suggested-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Sergei Antonov <saproj@gmail.com>
---
 drivers/watchdog/ftwdt010_wdt.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/watchdog/ftwdt010_wdt.c b/drivers/watchdog/ftwdt010_wdt.c
index 21dcc7765688..0a5bbfd2823f 100644
--- a/drivers/watchdog/ftwdt010_wdt.c
+++ b/drivers/watchdog/ftwdt010_wdt.c
@@ -47,21 +47,28 @@ struct ftwdt010_wdt *to_ftwdt010_wdt(struct watchdog_device *wdd)
 	return container_of(wdd, struct ftwdt010_wdt, wdd);
 }
 
-static int ftwdt010_wdt_start(struct watchdog_device *wdd)
+static void ftwdt010_enable(struct ftwdt010_wdt *gwdt,
+			    unsigned int timeout,
+			    bool need_irq)
 {
-	struct ftwdt010_wdt *gwdt = to_ftwdt010_wdt(wdd);
 	u32 enable;
 
-	writel(wdd->timeout * WDT_CLOCK, gwdt->base + FTWDT010_WDLOAD);
+	writel(timeout * WDT_CLOCK, gwdt->base + FTWDT010_WDLOAD);
 	writel(WDRESTART_MAGIC, gwdt->base + FTWDT010_WDRESTART);
 	/* set clock before enabling */
 	enable = WDCR_CLOCK_5MHZ | WDCR_SYS_RST;
 	writel(enable, gwdt->base + FTWDT010_WDCR);
-	if (gwdt->has_irq)
+	if (need_irq)
 		enable |= WDCR_WDINTR;
 	enable |= WDCR_ENABLE;
 	writel(enable, gwdt->base + FTWDT010_WDCR);
+}
 
+static int ftwdt010_wdt_start(struct watchdog_device *wdd)
+{
+	struct ftwdt010_wdt *gwdt = to_ftwdt010_wdt(wdd);
+
+	ftwdt010_enable(gwdt, wdd->timeout, gwdt->has_irq);
 	return 0;
 }
 
@@ -93,6 +100,13 @@ static int ftwdt010_wdt_set_timeout(struct watchdog_device *wdd,
 	return 0;
 }
 
+static int ftwdt010_wdt_restart(struct watchdog_device *wdd,
+				unsigned long action, void *data)
+{
+	ftwdt010_enable(to_ftwdt010_wdt(wdd), 0, false);
+	return 0;
+}
+
 static irqreturn_t ftwdt010_wdt_interrupt(int irq, void *data)
 {
 	struct ftwdt010_wdt *gwdt = data;
@@ -107,6 +121,7 @@ static const struct watchdog_ops ftwdt010_wdt_ops = {
 	.stop		= ftwdt010_wdt_stop,
 	.ping		= ftwdt010_wdt_ping,
 	.set_timeout	= ftwdt010_wdt_set_timeout,
+	.restart	= ftwdt010_wdt_restart,
 	.owner		= THIS_MODULE,
 };
 
-- 
2.34.1


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

* Re: [PATCH v2] watchdog: ftwdt010_wdt: implement _restart() function
  2022-08-27 14:24 [PATCH v2] watchdog: ftwdt010_wdt: implement _restart() function Sergei Antonov
@ 2022-08-28 14:39 ` Guenter Roeck
  2022-08-29  9:03   ` Sergei Antonov
  0 siblings, 1 reply; 3+ messages in thread
From: Guenter Roeck @ 2022-08-28 14:39 UTC (permalink / raw)
  To: Sergei Antonov, linux-watchdog; +Cc: wim

On 8/27/22 07:24, Sergei Antonov wrote:
> Implement ftwdt010_wdt_restart(). It enables watchdog with timeout = 0
> and disabled IRQ. Since it needs code similar to ftwdt010_wdt_start(),
> add a new function ftwdt010_enable() and move common code there.
> 
> v1 -> v2:
> Do not let IRQ trigger when restarting.
> Add a helper function ftwdt010_enable().
> 

Version history should be after ---. Otherwise

Reviewed-by: Guenter Roeck <linux@roeck-us.net>


> Suggested-by: Guenter Roeck <linux@roeck-us.net>
> Signed-off-by: Sergei Antonov <saproj@gmail.com>
> ---
>   drivers/watchdog/ftwdt010_wdt.c | 23 +++++++++++++++++++----
>   1 file changed, 19 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/watchdog/ftwdt010_wdt.c b/drivers/watchdog/ftwdt010_wdt.c
> index 21dcc7765688..0a5bbfd2823f 100644
> --- a/drivers/watchdog/ftwdt010_wdt.c
> +++ b/drivers/watchdog/ftwdt010_wdt.c
> @@ -47,21 +47,28 @@ struct ftwdt010_wdt *to_ftwdt010_wdt(struct watchdog_device *wdd)
>   	return container_of(wdd, struct ftwdt010_wdt, wdd);
>   }
>   
> -static int ftwdt010_wdt_start(struct watchdog_device *wdd)
> +static void ftwdt010_enable(struct ftwdt010_wdt *gwdt,
> +			    unsigned int timeout,
> +			    bool need_irq)
>   {
> -	struct ftwdt010_wdt *gwdt = to_ftwdt010_wdt(wdd);
>   	u32 enable;
>   
> -	writel(wdd->timeout * WDT_CLOCK, gwdt->base + FTWDT010_WDLOAD);
> +	writel(timeout * WDT_CLOCK, gwdt->base + FTWDT010_WDLOAD);
>   	writel(WDRESTART_MAGIC, gwdt->base + FTWDT010_WDRESTART);
>   	/* set clock before enabling */
>   	enable = WDCR_CLOCK_5MHZ | WDCR_SYS_RST;
>   	writel(enable, gwdt->base + FTWDT010_WDCR);
> -	if (gwdt->has_irq)
> +	if (need_irq)
>   		enable |= WDCR_WDINTR;
>   	enable |= WDCR_ENABLE;
>   	writel(enable, gwdt->base + FTWDT010_WDCR);
> +}
>   
> +static int ftwdt010_wdt_start(struct watchdog_device *wdd)
> +{
> +	struct ftwdt010_wdt *gwdt = to_ftwdt010_wdt(wdd);
> +
> +	ftwdt010_enable(gwdt, wdd->timeout, gwdt->has_irq);
>   	return 0;
>   }
>   
> @@ -93,6 +100,13 @@ static int ftwdt010_wdt_set_timeout(struct watchdog_device *wdd,
>   	return 0;
>   }
>   
> +static int ftwdt010_wdt_restart(struct watchdog_device *wdd,
> +				unsigned long action, void *data)
> +{
> +	ftwdt010_enable(to_ftwdt010_wdt(wdd), 0, false);
> +	return 0;
> +}
> +
>   static irqreturn_t ftwdt010_wdt_interrupt(int irq, void *data)
>   {
>   	struct ftwdt010_wdt *gwdt = data;
> @@ -107,6 +121,7 @@ static const struct watchdog_ops ftwdt010_wdt_ops = {
>   	.stop		= ftwdt010_wdt_stop,
>   	.ping		= ftwdt010_wdt_ping,
>   	.set_timeout	= ftwdt010_wdt_set_timeout,
> +	.restart	= ftwdt010_wdt_restart,
>   	.owner		= THIS_MODULE,
>   };
>   


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

* Re: [PATCH v2] watchdog: ftwdt010_wdt: implement _restart() function
  2022-08-28 14:39 ` Guenter Roeck
@ 2022-08-29  9:03   ` Sergei Antonov
  0 siblings, 0 replies; 3+ messages in thread
From: Sergei Antonov @ 2022-08-29  9:03 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: linux-watchdog, wim

On Sun, 28 Aug 2022 at 17:39, Guenter Roeck <linux@roeck-us.net> wrote:
>
> On 8/27/22 07:24, Sergei Antonov wrote:
> > Implement ftwdt010_wdt_restart(). It enables watchdog with timeout = 0
> > and disabled IRQ. Since it needs code similar to ftwdt010_wdt_start(),
> > add a new function ftwdt010_enable() and move common code there.
> >
> > v1 -> v2:
> > Do not let IRQ trigger when restarting.
> > Add a helper function ftwdt010_enable().
> >
>
> Version history should be after ---.

Thanks. Forgot about it. I will send v3 then with only that little change.

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

end of thread, other threads:[~2022-08-29  9:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-27 14:24 [PATCH v2] watchdog: ftwdt010_wdt: implement _restart() function Sergei Antonov
2022-08-28 14:39 ` Guenter Roeck
2022-08-29  9:03   ` Sergei Antonov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).