Skip to contentSkip to conversation

PM / watchdog: iTCO: stop watchdog during system suspend

PATCH In review Rafael J. Wysocki 3 participants 9 messages Apr 2, 2015 – Apr 3, 2015 Watchdog device drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PM / watchdog: iTCO: stop watchdog during system suspend

From: Rafael J. Wysocki <[email protected]>

If the target sleep state of the system is not an ACPI sleep state (S1, S2 or S3), the TCO watchdog needs to be stopped during system suspend, because it may not be possible to ping it any more after timekeeping has been suspended (suspend-to-idle does that for one example).

For this reason, provide ->suspend_noirq and ->resume_noirq callbacks for the iTCO watchdog driver and use them to stop and restart the watchdog during system suspend and resume, respectively, if the system is not going to enter an ACPI sleep state (in which case the watchdog will be stopped by the platform firmware before the state is entered).

---
 drivers/watchdog/iTCO_wdt.c |   51 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
drivers/watchdog/iTCO_wdt.c +51 -0
Index: linux-pm/drivers/watchdog/iTCO_wdt.c
===================================================================
@@ -51,6 +51,7 @@
 #define DRV_VERSION	"1.11"
 
 /* Includes */
+#include <linux/acpi.h>			/* For ACPI support */
 #include <linux/module.h>		/* For module specific items */
 #include <linux/moduleparam.h>		/* For new moduleparam's */
 #include <linux/types.h>		/* For standard types (like size_t) */
@@ -103,6 +104,8 @@ static struct {		/* this is private data
 	struct platform_device *dev;
 	/* the PCI-device */
 	struct pci_dev *pdev;
+	/* whether or not the watchdog has been suspended */
+	bool suspended;
 } iTCO_wdt_private;
 
 /* module parameters */
@@ -571,12 +574,60 @@ static void iTCO_wdt_shutdown(struct pla
 	iTCO_wdt_stop(NULL);
 }
 
+#ifdef CONFIG_PM_SLEEP
+/*
+ * Suspend-to-idle requires this, because it stops the ticks and timekeeping, so
+ * the watchdog cannot be pinged while in that state.  In ACPI sleep states the
+ * watchdog is stopped by the platform firmware.
+ */
+
+#ifdef CONFIG_ACPI
+static inline bool need_suspend(void)
+{
+	return acpi_target_system_state() == ACPI_STATE_S0;
+}
+#else
+static inline bool need_suspend(void) { return true; }
+#endif
+
+static int iTCO_wdt_suspend_noirq(struct device *dev)
+{
+	int ret = 0;
+
+	iTCO_wdt_private.suspended = false;
+	if (watchdog_active(&iTCO_wdt_watchdog_dev) && need_suspend()) {
+		ret = iTCO_wdt_stop(&iTCO_wdt_watchdog_dev);
+		if (!ret)
+			iTCO_wdt_private.suspended = true;
+	}
+	return ret;
+}
+
+static int iTCO_wdt_resume_noirq(struct device *dev)
+{
+	if (iTCO_wdt_private.suspended)
+		iTCO_wdt_start(&iTCO_wdt_watchdog_dev);
+
+	return 0;
+}
+
+struct dev_pm_ops iTCO_wdt_pm = {
+	.suspend_noirq = iTCO_wdt_suspend_noirq,
+	.resume_noirq = iTCO_wdt_resume_noirq,
+};
+
+#define ITCO_WDT_PM_OPS	&iTCO_wdt_pm
+#else
+#define ITCO_WDT_PM_OPS	NULL
+#endif /* CONFIG_PM_SLEEP */
+
 static struct platform_driver iTCO_wdt_driver = {
 	.probe          = iTCO_wdt_probe,
 	.remove         = iTCO_wdt_remove,
 	.shutdown       = iTCO_wdt_shutdown,
 	.driver         = {
 		.name   = DRV_NAME,
+		.pm     = ITCO_WDT_PM_OPS,
 	},
 };
 
#1 lore raw

Hi Rafael,
watchdog_active() function is not implemented in your patch. Pls. add it.

static int watchdog_active(struct device *dev)

{
       unsigned int val;

       spin_lock(&iTCO_wdt_private.io_lock);
       val = inw(TCO1_CNT);
       spin_unlock(&iTCO_wdt_private.io_lock);

       /* Bit 11: TCO Timer Halt */
       if (val & 0x0800)
               return 0;
       else
               return 1;
}

Regards,
Borun
-----Original Message-----
From: Rafael J. Wysocki [mailto:[email protected]]
Sent: Thursday, April 02, 2015 8:31
To: [email protected]
Cc: Linux Kernel Mailing List; Linux PM list; Wim Van Sebroeck; Li, Aubrey; Fu, Borun
Subject: [PATCH] PM / watchdog: iTCO: stop watchdog during system suspend

From: Rafael J. Wysocki <[email protected]>

If the target sleep state of the system is not an ACPI sleep state (S1, S2 or S3), the TCO watchdog needs to be stopped during system suspend, because it may not be possible to ping it any more after timekeeping has been suspended (suspend-to-idle does that for one example).

For this reason, provide ->suspend_noirq and ->resume_noirq callbacks for the iTCO watchdog driver and use them to stop and restart the watchdog during system suspend and resume, respectively, if the system is not going to enter an ACPI sleep state (in which case the watchdog will be stopped by the platform firmware before the state is entered).

---
 drivers/watchdog/iTCO_wdt.c |   51 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
drivers/watchdog/iTCO_wdt.c +47 -0
Index: linux-pm/drivers/watchdog/iTCO_wdt.c
===================================================================
@@ -51,6 +51,7 @@
 #define DRV_VERSION	"1.11"
 
 /* Includes */
+#include <linux/acpi.h>			/* For ACPI support */
 #include <linux/module.h>		/* For module specific items */
 #include <linux/moduleparam.h>		/* For new moduleparam's */
 #include <linux/types.h>		/* For standard types (like size_t) */
@@ -103,6 +104,8 @@ static struct {		/* this is private data
 	struct platform_device *dev;
 	/* the PCI-device */
 	struct pci_dev *pdev;
+	/* whether or not the watchdog has been suspended */
+	bool suspended;
 } iTCO_wdt_private;
 
 /* module parameters */
@@ -571,12 +574,60 @@ static void iTCO_wdt_shutdown(struct pla
 	iTCO_wdt_stop(NULL);
 }
 
+#ifdef CONFIG_PM_SLEEP
+/*
+ * Suspend-to-idle requires this, because it stops the ticks and 
+timekeeping, so
+ * the watchdog cannot be pinged while in that state.  In ACPI sleep 
+states the
+ * watchdog is stopped by the platform firmware.
+ */
+
+#ifdef CONFIG_ACPI
+static inline bool need_suspend(void)
+{
+	return acpi_target_system_state() == ACPI_STATE_S0; } #else static 
+inline bool need_suspend(void) { return true; } #endif
+
+static int iTCO_wdt_suspend_noirq(struct device *dev) {
+	int ret = 0;
+
+	iTCO_wdt_private.suspended = false;
+	if (watchdog_active(&iTCO_wdt_watchdog_dev) && need_suspend()) {
+		ret = iTCO_wdt_stop(&iTCO_wdt_watchdog_dev);
+		if (!ret)
+			iTCO_wdt_private.suspended = true;
+	}
+	return ret;
+}
+
+static int iTCO_wdt_resume_noirq(struct device *dev) {
+	if (iTCO_wdt_private.suspended)
+		iTCO_wdt_start(&iTCO_wdt_watchdog_dev);
+
+	return 0;
+}
+
+struct dev_pm_ops iTCO_wdt_pm = {
+	.suspend_noirq = iTCO_wdt_suspend_noirq,
+	.resume_noirq = iTCO_wdt_resume_noirq, };
+
+#define ITCO_WDT_PM_OPS	&iTCO_wdt_pm
+#else
+#define ITCO_WDT_PM_OPS	NULL
+#endif /* CONFIG_PM_SLEEP */
+
 static struct platform_driver iTCO_wdt_driver = {
 	.probe          = iTCO_wdt_probe,
 	.remove         = iTCO_wdt_remove,
 	.shutdown       = iTCO_wdt_shutdown,
 	.driver         = {
 		.name   = DRV_NAME,
+		.pm     = ITCO_WDT_PM_OPS,
 	},
 };
 
maintainer
#2 lore raw
Quoted 3 lines · Borun

Hi Rafael,
watchdog_active() function is not implemented in your patch. Pls. add it.

Please explain why using the standard watchdog_active() would not work here.

Guenter

Quoted 115 lines

static int watchdog_active(struct device *dev)

{
        unsigned int val;

        spin_lock(&iTCO_wdt_private.io_lock);
        val = inw(TCO1_CNT);
        spin_unlock(&iTCO_wdt_private.io_lock);

        /* Bit 11: TCO Timer Halt */
        if (val & 0x0800)
                return 0;
        else
                return 1;
}

Regards,
Borun
-----Original Message-----
From: Rafael J. Wysocki [mailto:[email protected]]
Sent: Thursday, April 02, 2015 8:31
To: [email protected]
Cc: Linux Kernel Mailing List; Linux PM list; Wim Van Sebroeck; Li, Aubrey; Fu, Borun
Subject: [PATCH] PM / watchdog: iTCO: stop watchdog during system suspend

From: Rafael J. Wysocki <[email protected]>

If the target sleep state of the system is not an ACPI sleep state (S1, S2 or S3), the TCO watchdog needs to be stopped during system suspend, because it may not be possible to ping it any more after timekeeping has been suspended (suspend-to-idle does that for one example).

For this reason, provide ->suspend_noirq and ->resume_noirq callbacks for the iTCO watchdog driver and use them to stop and restart the watchdog during system suspend and resume, respectively, if the system is not going to enter an ACPI sleep state (in which case the watchdog will be stopped by the platform firmware before the state is entered).

---
  drivers/watchdog/iTCO_wdt.c |   51 ++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 51 insertions(+)

Index: linux-pm/drivers/watchdog/iTCO_wdt.c
===================================================================

drivers/watchdog/iTCO_wdt.c +47 -0
@@ -51,6 +51,7 @@
  #define DRV_VERSION	"1.11"
 
  /* Includes */
+#include <linux/acpi.h>			/* For ACPI support */
  #include <linux/module.h>		/* For module specific items */
  #include <linux/moduleparam.h>		/* For new moduleparam's */
  #include <linux/types.h>		/* For standard types (like size_t) */
@@ -103,6 +104,8 @@ static struct {		/* this is private data
  	struct platform_device *dev;
  	/* the PCI-device */
  	struct pci_dev *pdev;
+	/* whether or not the watchdog has been suspended */
+	bool suspended;
  } iTCO_wdt_private;
 
  /* module parameters */
@@ -571,12 +574,60 @@ static void iTCO_wdt_shutdown(struct pla
  	iTCO_wdt_stop(NULL);
  }
 
+#ifdef CONFIG_PM_SLEEP
+/*
+ * Suspend-to-idle requires this, because it stops the ticks and
+timekeeping, so
+ * the watchdog cannot be pinged while in that state.  In ACPI sleep
+states the
+ * watchdog is stopped by the platform firmware.
+ */
+
+#ifdef CONFIG_ACPI
+static inline bool need_suspend(void)
+{
+	return acpi_target_system_state() == ACPI_STATE_S0; } #else static
+inline bool need_suspend(void) { return true; } #endif
+
+static int iTCO_wdt_suspend_noirq(struct device *dev) {
+	int ret = 0;
+
+	iTCO_wdt_private.suspended = false;
+	if (watchdog_active(&iTCO_wdt_watchdog_dev) && need_suspend()) {
+		ret = iTCO_wdt_stop(&iTCO_wdt_watchdog_dev);
+		if (!ret)
+			iTCO_wdt_private.suspended = true;
+	}
+	return ret;
+}
+
+static int iTCO_wdt_resume_noirq(struct device *dev) {
+	if (iTCO_wdt_private.suspended)
+		iTCO_wdt_start(&iTCO_wdt_watchdog_dev);
+
+	return 0;
+}
+
+struct dev_pm_ops iTCO_wdt_pm = {
+	.suspend_noirq = iTCO_wdt_suspend_noirq,
+	.resume_noirq = iTCO_wdt_resume_noirq, };
+
+#define ITCO_WDT_PM_OPS	&iTCO_wdt_pm
+#else
+#define ITCO_WDT_PM_OPS	NULL
+#endif /* CONFIG_PM_SLEEP */
+
  static struct platform_driver iTCO_wdt_driver = {
  	.probe          = iTCO_wdt_probe,
  	.remove         = iTCO_wdt_remove,
  	.shutdown       = iTCO_wdt_shutdown,
  	.driver         = {
  		.name   = DRV_NAME,
+		.pm     = ITCO_WDT_PM_OPS,
  	},
  };
 
Quoted 1 line

N�����r��y���b�X��ǧv�^�)޺{.n�+����{���\�� �{ay�

ʇڙ�,j��f���h���z�
�w���
���j:+v���w�j�m��������zZ+�����ݢj"��!tml=

Quoted 1 line
#3 lore raw

Sorry, my fault. It should work as well.

-----Original Message-----
From: Guenter Roeck [mailto:[email protected]]
Sent: Thursday, April 02, 2015 9:11
To: Fu, Borun; Rafael J. Wysocki; [email protected]
Cc: Linux Kernel Mailing List; Linux PM list; Wim Van Sebroeck; Li, Aubrey; Wang, Frank
Subject: Re: [PATCH] PM / watchdog: iTCO: stop watchdog during system suspend

Quoted 3 lines · Borun

Hi Rafael,
watchdog_active() function is not implemented in your patch. Pls. add it.

Please explain why using the standard watchdog_active() would not work here.

Guenter

Quoted 115 lines
static int watchdog_active(struct device *dev) {
        unsigned int val;

        spin_lock(&iTCO_wdt_private.io_lock);
        val = inw(TCO1_CNT);
        spin_unlock(&iTCO_wdt_private.io_lock);

        /* Bit 11: TCO Timer Halt */
        if (val & 0x0800)
                return 0;
        else
                return 1;
}

Regards,
Borun
-----Original Message-----
From: Rafael J. Wysocki [mailto:[email protected]]
Sent: Thursday, April 02, 2015 8:31
To: [email protected]
Cc: Linux Kernel Mailing List; Linux PM list; Wim Van Sebroeck; Li, Aubrey; Fu, Borun
Subject: [PATCH] PM / watchdog: iTCO: stop watchdog during system suspend

From: Rafael J. Wysocki <[email protected]>

If the target sleep state of the system is not an ACPI sleep state (S1, S2 or S3), the TCO watchdog needs to be stopped during system suspend, because it may not be possible to ping it any more after timekeeping has been suspended (suspend-to-idle does that for one example).

For this reason, provide ->suspend_noirq and ->resume_noirq callbacks for the iTCO watchdog driver and use them to stop and restart the watchdog during system suspend and resume, respectively, if the system is not going to enter an ACPI sleep state (in which case the watchdog will be stopped by the platform firmware before the state is entered).

---
  drivers/watchdog/iTCO_wdt.c |   51 ++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 51 insertions(+)

Index: linux-pm/drivers/watchdog/iTCO_wdt.c
===================================================================

drivers/watchdog/iTCO_wdt.c +46 -0
@@ -51,6 +51,7 @@
  #define DRV_VERSION	"1.11"
 
  /* Includes */
+#include <linux/acpi.h>			/* For ACPI support */
  #include <linux/module.h>		/* For module specific items */
  #include <linux/moduleparam.h>		/* For new moduleparam's */
  #include <linux/types.h>		/* For standard types (like size_t) */
@@ -103,6 +104,8 @@ static struct {		/* this is private data
  	struct platform_device *dev;
  	/* the PCI-device */
  	struct pci_dev *pdev;
+	/* whether or not the watchdog has been suspended */
+	bool suspended;
  } iTCO_wdt_private;
 
  /* module parameters */
@@ -571,12 +574,60 @@ static void iTCO_wdt_shutdown(struct pla
  	iTCO_wdt_stop(NULL);
  }
 
+#ifdef CONFIG_PM_SLEEP
+/*
+ * Suspend-to-idle requires this, because it stops the ticks and 
+timekeeping, so
+ * the watchdog cannot be pinged while in that state.  In ACPI sleep 
+states the
+ * watchdog is stopped by the platform firmware.
+ */
+
+#ifdef CONFIG_ACPI
+static inline bool need_suspend(void) {
+	return acpi_target_system_state() == ACPI_STATE_S0; } #else static 
+inline bool need_suspend(void) { return true; } #endif
+
+static int iTCO_wdt_suspend_noirq(struct device *dev) {
+	int ret = 0;
+
+	iTCO_wdt_private.suspended = false;
+	if (watchdog_active(&iTCO_wdt_watchdog_dev) && need_suspend()) {
+		ret = iTCO_wdt_stop(&iTCO_wdt_watchdog_dev);
+		if (!ret)
+			iTCO_wdt_private.suspended = true;
+	}
+	return ret;
+}
+
+static int iTCO_wdt_resume_noirq(struct device *dev) {
+	if (iTCO_wdt_private.suspended)
+		iTCO_wdt_start(&iTCO_wdt_watchdog_dev);
+
+	return 0;
+}
+
+struct dev_pm_ops iTCO_wdt_pm = {
+	.suspend_noirq = iTCO_wdt_suspend_noirq,
+	.resume_noirq = iTCO_wdt_resume_noirq, };
+
+#define ITCO_WDT_PM_OPS	&iTCO_wdt_pm
+#else
+#define ITCO_WDT_PM_OPS	NULL
+#endif /* CONFIG_PM_SLEEP */
+
  static struct platform_driver iTCO_wdt_driver = {
  	.probe          = iTCO_wdt_probe,
  	.remove         = iTCO_wdt_remove,
  	.shutdown       = iTCO_wdt_shutdown,
  	.driver         = {
  		.name   = DRV_NAME,
+		.pm     = ITCO_WDT_PM_OPS,
  	},
  };
 
Quoted 1 line

N r y b X ǧv ^ )޺{.n + { \ {ay 

ʇڙ ,j

Quoted 1 line

f h z 

w
j:+v w j m zZ+ ݢj" !tml=

Quoted 1 line

���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay� ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m���� ������?�I�

maintainer
#4 lore raw
In reply to Rafael J. Wysocki
Quoted 76 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

If the target sleep state of the system is not an ACPI sleep state (S1, S2 or S3), the TCO watchdog needs to be stopped during system suspend, because it may not be possible to ping it any more after timekeeping has been suspended (suspend-to-idle does that for one example).

For this reason, provide ->suspend_noirq and ->resume_noirq callbacks for the iTCO watchdog driver and use them to stop and restart the watchdog during system suspend and resume, respectively, if the system is not going to enter an ACPI sleep state (in which case the watchdog will be stopped by the platform firmware before the state is entered).

---
  drivers/watchdog/iTCO_wdt.c |   51 ++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 51 insertions(+)

Index: linux-pm/drivers/watchdog/iTCO_wdt.c
===================================================================

drivers/watchdog/iTCO_wdt.c +33 -0
@@ -51,6 +51,7 @@
  #define DRV_VERSION	"1.11"
 
  /* Includes */
+#include <linux/acpi.h>			/* For ACPI support */
  #include <linux/module.h>		/* For module specific items */
  #include <linux/moduleparam.h>		/* For new moduleparam's */
  #include <linux/types.h>		/* For standard types (like size_t) */
@@ -103,6 +104,8 @@ static struct {		/* this is private data
  	struct platform_device *dev;
  	/* the PCI-device */
  	struct pci_dev *pdev;
+	/* whether or not the watchdog has been suspended */
+	bool suspended;
  } iTCO_wdt_private;
 
  /* module parameters */
@@ -571,12 +574,60 @@ static void iTCO_wdt_shutdown(struct pla
  	iTCO_wdt_stop(NULL);
  }
 
+#ifdef CONFIG_PM_SLEEP
+/*
+ * Suspend-to-idle requires this, because it stops the ticks and timekeeping, so
+ * the watchdog cannot be pinged while in that state.  In ACPI sleep states the
+ * watchdog is stopped by the platform firmware.
+ */
+
+#ifdef CONFIG_ACPI
+static inline bool need_suspend(void)
+{
+	return acpi_target_system_state() == ACPI_STATE_S0;
+}
+#else
+static inline bool need_suspend(void) { return true; }
+#endif
+
+static int iTCO_wdt_suspend_noirq(struct device *dev)
+{
+	int ret = 0;
+
+	iTCO_wdt_private.suspended = false;
+	if (watchdog_active(&iTCO_wdt_watchdog_dev) && need_suspend()) {
+		ret = iTCO_wdt_stop(&iTCO_wdt_watchdog_dev);
+		if (!ret)
+			iTCO_wdt_private.suspended = true;
+	}
+	return ret;
+}
+
+static int iTCO_wdt_resume_noirq(struct device *dev)

drivers/watchdog/iTCO_wdt.c static void iTCO_wdt_shutdown(struct pla · line 616

Quoted 10 lines
drivers/watchdog/iTCO_wdt.c +10 -0
+{
+	if (iTCO_wdt_private.suspended)
+		iTCO_wdt_start(&iTCO_wdt_watchdog_dev);
+
+	return 0;
+}
+
+struct dev_pm_ops iTCO_wdt_pm = {
+	.suspend_noirq = iTCO_wdt_suspend_noirq,
+	.resume_noirq = iTCO_wdt_resume_noirq,

Hi Rafael,

This only covers suspend and resume, but not any of the other sleep operations (like SIMPLE_DEV_PM_OPS would do). Is that intentional ?

drivers/watchdog/iTCO_wdt.c static void iTCO_wdt_shutdown(struct pla · line 619

Quoted 3 lines
drivers/watchdog/iTCO_wdt.c +3 -0
+};
+
+#define ITCO_WDT_PM_OPS	&iTCO_wdt_pm

Checkpatch wants to see (&iTCO_wdt_pm).

ERROR: Macros with complex values should be enclosed in parentheses

Thanks,
Guenter

#5 lore raw
Quoted 2 lines · Guenter Roeck
Quoted 1 line · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

[cut]

Quoted 5 lines

Hi Rafael,

This only covers suspend and resume, but not any of the other sleep operations (like SIMPLE_DEV_PM_OPS would do). Is that intentional ?

Yes, it is:
(1) The problemm at hand is strictly specific to system suspend.
(2) The SIMPLE_DEV_PM_OPS etc macros don't cover the _noirq callback variants (and we want to use the _noirq variants, because we want the watchdog to be stopped as late and restarted as early as reasonably possible).
(3) I'm not even sure if adding runtime PM support to this driver would make

     any sense. :-)
Quoted 8 lines

Review

Quoted 4 lines
(quoted diff) +3 -0
+};
+
+#define ITCO_WDT_PM_OPS	&iTCO_wdt_pm

Checkpatch wants to see (&iTCO_wdt_pm).

ERROR: Macros with complex values should be enclosed in parentheses

Please find an updated patch below.

Rafael

---
From: Rafael J. Wysocki <[email protected]>
Subject: PM / watchdog: iTCO: stop watchdog during system suspend

If the target sleep state of the system is not an ACPI sleep state (S1, S2 or S3), the TCO watchdog needs to be stopped during system suspend, because it may not be possible to ping it any more after timekeeping has been suspended (suspend-to-idle does that for one example).

For this reason, provide ->suspend_noirq and ->resume_noirq callbacks for the iTCO watchdog driver and use them to stop and restart the watchdog during system suspend and resume, respectively, if the system is not going to enter an ACPI sleep state (in which case the watchdog will be stopped by the platform firmware before the state is entered).

---
 drivers/watchdog/iTCO_wdt.c |   51 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
drivers/watchdog/iTCO_wdt.c +51 -0
Index: linux-pm/drivers/watchdog/iTCO_wdt.c
===================================================================
@@ -51,6 +51,7 @@
 #define DRV_VERSION	"1.11"
 
 /* Includes */
+#include <linux/acpi.h>			/* For ACPI support */
 #include <linux/module.h>		/* For module specific items */
 #include <linux/moduleparam.h>		/* For new moduleparam's */
 #include <linux/types.h>		/* For standard types (like size_t) */
@@ -103,6 +104,8 @@ static struct {		/* this is private data
 	struct platform_device *dev;
 	/* the PCI-device */
 	struct pci_dev *pdev;
+	/* whether or not the watchdog has been suspended */
+	bool suspended;
 } iTCO_wdt_private;
 
 /* module parameters */
@@ -571,12 +574,60 @@ static void iTCO_wdt_shutdown(struct pla
 	iTCO_wdt_stop(NULL);
 }
 
+#ifdef CONFIG_PM_SLEEP
+/*
+ * Suspend-to-idle requires this, because it stops the ticks and timekeeping, so
+ * the watchdog cannot be pinged while in that state.  In ACPI sleep states the
+ * watchdog is stopped by the platform firmware.
+ */
+
+#ifdef CONFIG_ACPI
+static inline bool need_suspend(void)
+{
+	return acpi_target_system_state() == ACPI_STATE_S0;
+}
+#else
+static inline bool need_suspend(void) { return true; }
+#endif
+
+static int iTCO_wdt_suspend_noirq(struct device *dev)
+{
+	int ret = 0;
+
+	iTCO_wdt_private.suspended = false;
+	if (watchdog_active(&iTCO_wdt_watchdog_dev) && need_suspend()) {
+		ret = iTCO_wdt_stop(&iTCO_wdt_watchdog_dev);
+		if (!ret)
+			iTCO_wdt_private.suspended = true;
+	}
+	return ret;
+}
+
+static int iTCO_wdt_resume_noirq(struct device *dev)
+{
+	if (iTCO_wdt_private.suspended)
+		iTCO_wdt_start(&iTCO_wdt_watchdog_dev);
+
+	return 0;
+}
+
+struct dev_pm_ops iTCO_wdt_pm = {
+	.suspend_noirq = iTCO_wdt_suspend_noirq,
+	.resume_noirq = iTCO_wdt_resume_noirq,
+};
+
+#define ITCO_WDT_PM_OPS	(&iTCO_wdt_pm)
+#else
+#define ITCO_WDT_PM_OPS	NULL
+#endif /* CONFIG_PM_SLEEP */
+
 static struct platform_driver iTCO_wdt_driver = {
 	.probe          = iTCO_wdt_probe,
 	.remove         = iTCO_wdt_remove,
 	.shutdown       = iTCO_wdt_shutdown,
 	.driver         = {
 		.name   = DRV_NAME,
+		.pm     = ITCO_WDT_PM_OPS,
 	},
 };
 
Tested-by
#6 lore raw
Quoted 27 lines · Rafael J. Wysocki
Quoted 2 lines · Guenter Roeck
Quoted 1 line · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

[cut]

Quoted 5 lines

Hi Rafael,

This only covers suspend and resume, but not any of the other sleep operations (like SIMPLE_DEV_PM_OPS would do). Is that intentional ?

Yes, it is:
(1) The problemm at hand is strictly specific to system suspend.
(2) The SIMPLE_DEV_PM_OPS etc macros don't cover the _noirq callback
variants
(and we want to use the _noirq variants, because we want the watchdog to be stopped as late and restarted as early as reasonably possible). (3) I'm not even sure if adding runtime PM support to this driver would make any sense. :-)

Quoted 7 lines

drivers/watchdog/iTCO_wdt.c static void iTCO_wdt_shutdown(struct pla

Quoted 4 lines
drivers/watchdog/iTCO_wdt.c +3 -0
+};
+
+#define ITCO_WDT_PM_OPS	&iTCO_wdt_pm

Checkpatch wants to see (&iTCO_wdt_pm).

Quoted 7 lines
Quoted 1 line

ERROR: Macros with complex values should be enclosed in parentheses

Please find an updated patch below.

Rafael

Borun

Quoted 62 lines

---
From: Rafael J. Wysocki <[email protected]>
Subject: PM / watchdog: iTCO: stop watchdog during system suspend

If the target sleep state of the system is not an ACPI sleep state (S1, S2 or S3), the TCO watchdog needs to be stopped during system suspend, because it may not be possible to ping it any more after timekeeping has been suspended (suspend-to-idle does that for one example).

For this reason, provide ->suspend_noirq and ->resume_noirq callbacks for the iTCO watchdog driver and use them to stop and restart the watchdog during system suspend and resume, respectively, if the system is not going to enter an ACPI sleep state (in which case the watchdog will be stopped by the platform firmware before the state is entered).

---
 drivers/watchdog/iTCO_wdt.c |   51

++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)
Index: linux-pm/drivers/watchdog/iTCO_wdt.c ================================================================ === --- linux-pm.orig/drivers/watchdog/iTCO_wdt.c +++ linux-pm/drivers/watchdog/iTCO_wdt.c @@ -51,6 +51,7 @@
#define DRV_VERSION "1.11"

/* Includes */ +#include <linux/acpi.h> /* For ACPI support */
#include <linux/module.h> /* For module specific items */ #include
<linux/moduleparam.h> /* For new moduleparam's */ #include
<linux/types.h> /* For standard types (like size_t) */ @@ -103,6
+104,8 @@ static struct { /* this is private data struct
platform_device *dev; /* the PCI-device */ struct pci_dev *pdev;

drivers/watchdog/iTCO_wdt.c +3 -0
+	/* whether or not the watchdog has been suspended */
+	bool suspended;
 } iTCO_wdt_private;
 
 /* module parameters */ @@ -571,12 +574,60 @@ static void
 iTCO_wdt_shutdown(struct pla 	iTCO_wdt_stop(NULL); }
+#ifdef CONFIG_PM_SLEEP +/* + * Suspend-to-idle requires this, because

it stops the ticks and timekeeping, so + * the watchdog cannot be pinged while in that state. In ACPI sleep states the + * watchdog is stopped by the platform firmware. + */ + +#ifdef CONFIG_ACPI +static inline bool
need_suspend(void) +{ + return acpi_target_system_state() ==
ACPI_STATE_S0; +} +#else +static inline bool need_suspend(void) { return true; } +#endif + +static int iTCO_wdt_suspend_noirq(struct device *dev)
+{ + int ret = 0; + + iTCO_wdt_private.suspended = false; + if
(watchdog_active(&iTCO_wdt_watchdog_dev) && need_suspend()) { + ret =
iTCO_wdt_stop(&iTCO_wdt_watchdog_dev); + if (!ret)

(quoted diff) +1 -0
+			iTCO_wdt_private.suspended = true; +	} +	return ret; +} + +static

int iTCO_wdt_resume_noirq(struct device *dev) +{ + if
(iTCO_wdt_private.suspended) + iTCO_wdt_start(&iTCO_wdt_watchdog_dev);
+ + return 0; +} + +struct dev_pm_ops iTCO_wdt_pm = { + .suspend_noirq =
iTCO_wdt_suspend_noirq, + .resume_noirq = iTCO_wdt_resume_noirq, +}; +
+#define ITCO_WDT_PM_OPS (&iTCO_wdt_pm) +#else +#define
ITCO_WDT_PM_OPS NULL +#endif /* CONFIG_PM_SLEEP */ +
static struct platform_driver iTCO_wdt_driver = { .probe =
iTCO_wdt_probe, .remove = iTCO_wdt_remove, .shutdown =
iTCO_wdt_shutdown, .driver = { .name = DRV_NAME, + .pm
= ITCO_WDT_PM_OPS, }, };

maintainer Reviewed-by
#7 lore raw
In reply to Rafael J. Wysocki

On 04/02/2015 03:04 PM, Rafael J. Wysocki wrote:
[ ... ]

Quoted 18 lines

---
From: Rafael J. Wysocki <[email protected]>
Subject: PM / watchdog: iTCO: stop watchdog during system suspend

If the target sleep state of the system is not an ACPI sleep state (S1, S2 or S3), the TCO watchdog needs to be stopped during system suspend, because it may not be possible to ping it any more after timekeeping has been suspended (suspend-to-idle does that for one example).

For this reason, provide ->suspend_noirq and ->resume_noirq callbacks for the iTCO watchdog driver and use them to stop and restart the watchdog during system suspend and resume, respectively, if the system is not going to enter an ACPI sleep state (in which case the watchdog will be stopped by the platform firmware before the state is entered).

Quoted 2 lines
Quoted 92 lines
---
  drivers/watchdog/iTCO_wdt.c |   51 ++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 51 insertions(+)

Index: linux-pm/drivers/watchdog/iTCO_wdt.c
===================================================================

drivers/watchdog/iTCO_wdt.c +51 -1
@@ -51,6 +51,7 @@
  #define DRV_VERSION	"1.11"
 
  /* Includes */
+#include <linux/acpi.h>			/* For ACPI support */
  #include <linux/module.h>		/* For module specific items */
  #include <linux/moduleparam.h>		/* For new moduleparam's */
  #include <linux/types.h>		/* For standard types (like size_t) */
@@ -103,6 +104,8 @@ static struct {		/* this is private data
  	struct platform_device *dev;
  	/* the PCI-device */
  	struct pci_dev *pdev;
+	/* whether or not the watchdog has been suspended */
+	bool suspended;
  } iTCO_wdt_private;
 
  /* module parameters */
@@ -571,12 +574,60 @@ static void iTCO_wdt_shutdown(struct pla
  	iTCO_wdt_stop(NULL);
  }
 
+#ifdef CONFIG_PM_SLEEP
+/*
+ * Suspend-to-idle requires this, because it stops the ticks and timekeeping, so
+ * the watchdog cannot be pinged while in that state.  In ACPI sleep states the
+ * watchdog is stopped by the platform firmware.
+ */
+
+#ifdef CONFIG_ACPI
+static inline bool need_suspend(void)
+{
+	return acpi_target_system_state() == ACPI_STATE_S0;
+}
+#else
+static inline bool need_suspend(void) { return true; }
+#endif
+
+static int iTCO_wdt_suspend_noirq(struct device *dev)
+{
+	int ret = 0;
+
+	iTCO_wdt_private.suspended = false;
+	if (watchdog_active(&iTCO_wdt_watchdog_dev) && need_suspend()) {
+		ret = iTCO_wdt_stop(&iTCO_wdt_watchdog_dev);
+		if (!ret)
+			iTCO_wdt_private.suspended = true;
+	}
+	return ret;
+}
+
+static int iTCO_wdt_resume_noirq(struct device *dev)
+{
+	if (iTCO_wdt_private.suspended)
+		iTCO_wdt_start(&iTCO_wdt_watchdog_dev);
+
+	return 0;
+}
+
+struct dev_pm_ops iTCO_wdt_pm = {
+	.suspend_noirq = iTCO_wdt_suspend_noirq,
+	.resume_noirq = iTCO_wdt_resume_noirq,
+};
+
+#define ITCO_WDT_PM_OPS	(&iTCO_wdt_pm)
+#else
+#define ITCO_WDT_PM_OPS	NULL
+#endif /* CONFIG_PM_SLEEP */
+
  static struct platform_driver iTCO_wdt_driver = {
  	.probe          = iTCO_wdt_probe,
  	.remove         = iTCO_wdt_remove,
  	.shutdown       = iTCO_wdt_shutdown,
  	.driver         = {
  		.name   = DRV_NAME,
+		.pm     = ITCO_WDT_PM_OPS,
  	},
  };
 
 
--

To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw
Quoted 20 lines · Guenter Roeck

On 04/02/2015 03:04 PM, Rafael J. Wysocki wrote:
[ ... ]

Quoted 18 lines

---
From: Rafael J. Wysocki <[email protected]>
Subject: PM / watchdog: iTCO: stop watchdog during system suspend

If the target sleep state of the system is not an ACPI sleep state (S1, S2 or S3), the TCO watchdog needs to be stopped during system suspend, because it may not be possible to ping it any more after timekeeping has been suspended (suspend-to-idle does that for one example).

For this reason, provide ->suspend_noirq and ->resume_noirq callbacks for the iTCO watchdog driver and use them to stop and restart the watchdog during system suspend and resume, respectively, if the system is not going to enter an ACPI sleep state (in which case the watchdog will be stopped by the platform firmware before the state is entered).

Quoted 4 lines
Quoted 2 lines

Thanks!

I'll take it into the PM tree, unless anyone objects.

Rafael