Linux-Watchdog Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v1 1/1] watchdog: atmel: atmel-sama5d4-wdt: Disable watchdog on system suspend
@ 2019-06-12 15:02 Ken Sloat
  2019-06-12 15:24 ` Guenter Roeck
  0 siblings, 1 reply; 3+ messages in thread
From: Ken Sloat @ 2019-06-12 15:02 UTC (permalink / raw)
  To: nicolas.ferre
  Cc: alexandre.belloni, ludovic.desroches, wim, linux, Ken Sloat,
	linux-arm-kernel, linux-watchdog, linux-kernel

From: Ken Sloat <ksloat@aampglobal.com>

Currently, the atmel-sama5d4-wdt continues to run after system suspend.
Unless the system resumes within the watchdog timeout period so the
userspace can kick it, the system will be reset. This change disables
the watchdog on suspend if it is active and re-enables on resume. These
actions occur during the late and early phases of suspend and resume
respectively to minimize chances where a lock could occur while the
watchdog is disabled.

Signed-off-by: Ken Sloat <ksloat@aampglobal.com>
---
 drivers/watchdog/sama5d4_wdt.c | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/drivers/watchdog/sama5d4_wdt.c b/drivers/watchdog/sama5d4_wdt.c
index 111695223aae..84eb4db23993 100644
--- a/drivers/watchdog/sama5d4_wdt.c
+++ b/drivers/watchdog/sama5d4_wdt.c
@@ -280,6 +280,18 @@ static const struct of_device_id sama5d4_wdt_of_match[] = {
 MODULE_DEVICE_TABLE(of, sama5d4_wdt_of_match);
 
 #ifdef CONFIG_PM_SLEEP
+static int sama5d4_wdt_suspend_late(struct device *dev)
+{
+	struct sama5d4_wdt *wdt;
+
+	wdt = dev_get_drvdata(dev);
+
+	if (watchdog_active(&wdt->wdd))
+		sama5d4_wdt_stop(&wdt->wdd);
+
+	return 0;
+}
+
 static int sama5d4_wdt_resume(struct device *dev)
 {
 	struct sama5d4_wdt *wdt = dev_get_drvdata(dev);
@@ -293,10 +305,25 @@ static int sama5d4_wdt_resume(struct device *dev)
 
 	return 0;
 }
+
+static int sama5d4_wdt_resume_early(struct device *dev)
+{
+	struct sama5d4_wdt *wdt;
+
+	wdt = dev_get_drvdata(dev);
+
+	if (watchdog_active(&wdt->wdd))
+		sama5d4_wdt_start(&wdt->wdd);
+
+	return 0;
+}
 #endif
 
-static SIMPLE_DEV_PM_OPS(sama5d4_wdt_pm_ops, NULL,
-			 sama5d4_wdt_resume);
+static const struct dev_pm_ops sama5d4_wdt_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(NULL, sama5d4_wdt_resume)
+	SET_LATE_SYSTEM_SLEEP_PM_OPS(sama5d4_wdt_suspend_late,
+			sama5d4_wdt_resume_early)
+};
 
 static struct platform_driver sama5d4_wdt_driver = {
 	.probe		= sama5d4_wdt_probe,
-- 
2.17.1


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

* Re: [PATCH v1 1/1] watchdog: atmel: atmel-sama5d4-wdt: Disable watchdog on system suspend
  2019-06-12 15:02 [PATCH v1 1/1] watchdog: atmel: atmel-sama5d4-wdt: Disable watchdog on system suspend Ken Sloat
@ 2019-06-12 15:24 ` Guenter Roeck
  2019-06-12 15:30   ` Ken Sloat
  0 siblings, 1 reply; 3+ messages in thread
From: Guenter Roeck @ 2019-06-12 15:24 UTC (permalink / raw)
  To: Ken Sloat, nicolas.ferre
  Cc: alexandre.belloni, ludovic.desroches, wim, linux-arm-kernel,
	linux-watchdog, linux-kernel

On 6/12/19 8:02 AM, Ken Sloat wrote:
> From: Ken Sloat <ksloat@aampglobal.com>
> 
> Currently, the atmel-sama5d4-wdt continues to run after system suspend.
> Unless the system resumes within the watchdog timeout period so the
> userspace can kick it, the system will be reset. This change disables
> the watchdog on suspend if it is active and re-enables on resume. These
> actions occur during the late and early phases of suspend and resume
> respectively to minimize chances where a lock could occur while the
> watchdog is disabled.
> 
> Signed-off-by: Ken Sloat <ksloat@aampglobal.com>
> ---
>   drivers/watchdog/sama5d4_wdt.c | 31 +++++++++++++++++++++++++++++--
>   1 file changed, 29 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/watchdog/sama5d4_wdt.c b/drivers/watchdog/sama5d4_wdt.c
> index 111695223aae..84eb4db23993 100644
> --- a/drivers/watchdog/sama5d4_wdt.c
> +++ b/drivers/watchdog/sama5d4_wdt.c
> @@ -280,6 +280,18 @@ static const struct of_device_id sama5d4_wdt_of_match[] = {
>   MODULE_DEVICE_TABLE(of, sama5d4_wdt_of_match);
>   
>   #ifdef CONFIG_PM_SLEEP
> +static int sama5d4_wdt_suspend_late(struct device *dev)
> +{
> +	struct sama5d4_wdt *wdt;
> +
> +	wdt = dev_get_drvdata(dev);
> +
> +	if (watchdog_active(&wdt->wdd))
> +		sama5d4_wdt_stop(&wdt->wdd);
> +
> +	return 0;
> +}
> +
>   static int sama5d4_wdt_resume(struct device *dev)
>   {
>   	struct sama5d4_wdt *wdt = dev_get_drvdata(dev);
> @@ -293,10 +305,25 @@ static int sama5d4_wdt_resume(struct device *dev)
>   
>   	return 0;
>   }
> +
> +static int sama5d4_wdt_resume_early(struct device *dev)
> +{
> +	struct sama5d4_wdt *wdt;
> +
> +	wdt = dev_get_drvdata(dev);
> +
> +	if (watchdog_active(&wdt->wdd))
> +		sama5d4_wdt_start(&wdt->wdd);
> +
> +	return 0;
> +}
>   #endif
>   
> -static SIMPLE_DEV_PM_OPS(sama5d4_wdt_pm_ops, NULL,
> -			 sama5d4_wdt_resume);
> +static const struct dev_pm_ops sama5d4_wdt_pm_ops = {
> +	SET_SYSTEM_SLEEP_PM_OPS(NULL, sama5d4_wdt_resume)
> +	SET_LATE_SYSTEM_SLEEP_PM_OPS(sama5d4_wdt_suspend_late,
> +			sama5d4_wdt_resume_early)

I don't think you need both sama5d4_wdt_resume()
and sama5d4_wdt_resume_early().

Guenter

> +};
>   
>   static struct platform_driver sama5d4_wdt_driver = {
>   	.probe		= sama5d4_wdt_probe,
> 


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

* RE: [PATCH v1 1/1] watchdog: atmel: atmel-sama5d4-wdt: Disable watchdog on system suspend
  2019-06-12 15:24 ` Guenter Roeck
@ 2019-06-12 15:30   ` Ken Sloat
  0 siblings, 0 replies; 3+ messages in thread
From: Ken Sloat @ 2019-06-12 15:30 UTC (permalink / raw)
  To: Guenter Roeck, nicolas.ferre
  Cc: alexandre.belloni, ludovic.desroches, wim, linux-arm-kernel,
	linux-watchdog, linux-kernel, Ken Sloat

Hi Guenter,

> -----Original Message-----
> From: Guenter Roeck <groeck7@gmail.com> On Behalf Of Guenter Roeck
> Sent: Wednesday, June 12, 2019 11:24 AM
> To: Ken Sloat <KSloat@aampglobal.com>; nicolas.ferre@microchip.com
> Cc: alexandre.belloni@bootlin.com; ludovic.desroches@microchip.com;
> wim@linux-watchdog.org; linux-arm-kernel@lists.infradead.org; linux-
> watchdog@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH v1 1/1] watchdog: atmel: atmel-sama5d4-wdt: Disable
> watchdog on system suspend
> 
> [This is an EXTERNAL EMAIL]
> ________________________________
> 
> On 6/12/19 8:02 AM, Ken Sloat wrote:
> > From: Ken Sloat <ksloat@aampglobal.com>
> >
> > Currently, the atmel-sama5d4-wdt continues to run after system suspend.
> > Unless the system resumes within the watchdog timeout period so the
> > userspace can kick it, the system will be reset. This change disables
> > the watchdog on suspend if it is active and re-enables on resume.
> > These actions occur during the late and early phases of suspend and
> > resume respectively to minimize chances where a lock could occur while
> > the watchdog is disabled.
> >
> > Signed-off-by: Ken Sloat <ksloat@aampglobal.com>
> > ---
> >   drivers/watchdog/sama5d4_wdt.c | 31
> +++++++++++++++++++++++++++++--
> >   1 file changed, 29 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/watchdog/sama5d4_wdt.c
> > b/drivers/watchdog/sama5d4_wdt.c index 111695223aae..84eb4db23993
> > 100644
> > --- a/drivers/watchdog/sama5d4_wdt.c
> > +++ b/drivers/watchdog/sama5d4_wdt.c
> > @@ -280,6 +280,18 @@ static const struct of_device_id
> sama5d4_wdt_of_match[] = {
> >   MODULE_DEVICE_TABLE(of, sama5d4_wdt_of_match);
> >
> >   #ifdef CONFIG_PM_SLEEP
> > +static int sama5d4_wdt_suspend_late(struct device *dev) {
> > +     struct sama5d4_wdt *wdt;
> > +
> > +     wdt = dev_get_drvdata(dev);
> > +
> > +     if (watchdog_active(&wdt->wdd))
> > +             sama5d4_wdt_stop(&wdt->wdd);
> > +
> > +     return 0;
> > +}
> > +
> >   static int sama5d4_wdt_resume(struct device *dev)
> >   {
> >       struct sama5d4_wdt *wdt = dev_get_drvdata(dev); @@ -293,10
> > +305,25 @@ static int sama5d4_wdt_resume(struct device *dev)
> >
> >       return 0;
> >   }
> > +
> > +static int sama5d4_wdt_resume_early(struct device *dev) {
> > +     struct sama5d4_wdt *wdt;
> > +
> > +     wdt = dev_get_drvdata(dev);
> > +
> > +     if (watchdog_active(&wdt->wdd))
> > +             sama5d4_wdt_start(&wdt->wdd);
> > +
> > +     return 0;
> > +}
> >   #endif
> >
> > -static SIMPLE_DEV_PM_OPS(sama5d4_wdt_pm_ops, NULL,
> > -                      sama5d4_wdt_resume);
> > +static const struct dev_pm_ops sama5d4_wdt_pm_ops = {
> > +     SET_SYSTEM_SLEEP_PM_OPS(NULL, sama5d4_wdt_resume)
> > +     SET_LATE_SYSTEM_SLEEP_PM_OPS(sama5d4_wdt_suspend_late,
> > +                     sama5d4_wdt_resume_early)
> 
> I don't think you need both sama5d4_wdt_resume() and
> sama5d4_wdt_resume_early().

Yes I was wondering about that but wanted feedback on the subject first.
I can simply consolidate the statements, the sama5d4_wdt_init statement
present now should probably be called first anyways, so something like this
within resume_early:

struct sama5d4_wdt = dev_get_drvdata(dev); 

sama5d4_wdt_init(wdt);

if (watchdog_active(&wdt->wdd))
        sama5d4_wdt_start(&wdt->wdd);

return 0;

If that sounds good I will resubmit.

> Guenter
> 
> > +};
> >
> >   static struct platform_driver sama5d4_wdt_driver = {
> >       .probe          = sama5d4_wdt_probe,
> >

Thanks,
Ken Sloat


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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-12 15:02 [PATCH v1 1/1] watchdog: atmel: atmel-sama5d4-wdt: Disable watchdog on system suspend Ken Sloat
2019-06-12 15:24 ` Guenter Roeck
2019-06-12 15:30   ` Ken Sloat

Linux-Watchdog Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-watchdog/0 linux-watchdog/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-watchdog linux-watchdog/ https://lore.kernel.org/linux-watchdog \
		linux-watchdog@vger.kernel.org linux-watchdog@archiver.kernel.org
	public-inbox-index linux-watchdog


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-watchdog


AGPL code for this site: git clone https://public-inbox.org/ public-inbox