linux-sh.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Linux PM mailing list <linux-pm@lists.linux-foundation.org>
Cc: Greg KH <gregkh@suse.de>, LKML <linux-kernel@vger.kernel.org>,
	Kevin Hilman <khilman@ti.com>,
	Grant Likely <grant.likely@secretlab.ca>,
	Magnus Damm <magnus.damm@gmail.com>,
	linux-sh@vger.kernel.org, MyungJoo Ham <myungjoo.ham@gmail.com>,
	Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Subject: [Update][PATCH 3/5] PM: System-wide power transitions support for generic power domains
Date: Mon, 09 May 2011 22:10:28 +0000	[thread overview]
Message-ID: <201105100010.28810.rjw@sisk.pl> (raw)
In-Reply-To: <201105082324.19674.rjw@sisk.pl>

From: Rafael J. Wysocki <rjw@sisk.pl>

Make generic power domains support system-wide power transitions
(system suspend and hibernation).  Add suspend, resume, freeze and
thaw callbacks to be associated with struct generic_power_domain
objects and make pm_genpd_init() use them as appropriate.

The new callbacks do nothing for devices belonging to power domains
that were powered down at run time (before the transition).  For the
other devices the action carried out depends on the type of the
transition.  During system suspend the power domain ->suspend()
callback executes pm_generic_suspend() for the device, while the
power domain ->suspend_noirq() callback stops the device and
eventually removes power from the power domain it belongs to (after
all devices in the power domain have been stopped).  During system
resume the power domain ->resume_noirq() callback powers up the power
domain (when executed for the first time for the given power domain)
and starts the device, while the ->resume() callback executes
pm_generic_resume() for the device.  Finally, the ->complete()
callback executes pm_runtime_idle() for the device which should put
it back into the suspended state if its runtime PM usage count is
equal to zero at that time.

The actions carried out during hibernation and resume from it are
analogous to the ones described above.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---

Hi,

In this version of the patch I added ->prepare() and ->complete() power domain
callbacks behaving as described in the changelog (ie. doing nothing if power
has been removed from the power domain).  On the system I tested this patch
none of the drivers implements ->prepare() and ->complete(), so I didn't see
the problem before.

I also made the system-wide PM callbacks access genpd->power_is_off without
locking, because that test cannot race with the runtime PM code modifying
that field.

Thanks,
Rafael

---
 drivers/base/power/domain.c |  328 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/pm_domain.h   |    2 
 2 files changed, 330 insertions(+)

Index: linux-2.6/drivers/base/power/domain.c
=================================--- linux-2.6.orig/drivers/base/power/domain.c
+++ linux-2.6/drivers/base/power/domain.c
@@ -273,6 +273,316 @@ static int pm_genpd_runtime_resume(struc
 
 #endif /* CONFIG_PM_RUNTIME */
 
+#ifdef CONFIG_PM_SLEEP
+
+/**
+ * pm_genpd_prepare - Start power transition of a device in a power domain.
+ * @dev: Device to start the transition of.
+ *
+ * Start a power transition of a device (during a system-wide power transition)
+ * under the assumption that its pwr_domain field points to the domain member of
+ * an object of type struct generic_power_domain representing a power domain
+ * consisting of I/O devices.
+ */
+static int pm_genpd_prepare(struct device *dev)
+{
+	struct generic_power_domain *genpd;
+
+	dev_dbg(dev, "%s()\n", __func__);
+
+	if (IS_ERR_OR_NULL(dev->pwr_domain))
+		return -EINVAL;
+
+	genpd = container_of(dev->pwr_domain,
+			     struct generic_power_domain, domain);
+
+	return genpd->power_is_off ? 0 : pm_generic_prepare(dev);
+}
+
+/**
+ * pm_genpd_suspend - Suspend a device belonging to an I/O power domain.
+ * @dev: Device to suspend.
+ *
+ * Suspend a device under the assumption that its pwr_domain field points to the
+ * domain member of an object of type struct generic_power_domain representing
+ * a power domain consisting of I/O devices.
+ */
+static int pm_genpd_suspend(struct device *dev)
+{
+	struct generic_power_domain *genpd;
+
+	dev_dbg(dev, "%s()\n", __func__);
+
+	if (IS_ERR_OR_NULL(dev->pwr_domain))
+		return -EINVAL;
+
+	genpd = container_of(dev->pwr_domain,
+			     struct generic_power_domain, domain);
+
+	if (genpd->power_is_off)
+		return 0;
+
+	/*
+	 * If the device is in the (runtime) "suspended" state, call
+	 * ->start_device() for it, if defined.
+	 */
+	pm_runtime_resume(dev);
+
+	return pm_generic_suspend(dev);
+}
+
+/**
+ * pm_genpd_suspend_noirq - Late suspend of a device from an I/O power domain.
+ * @dev: Device to suspend.
+ *
+ * Carry out a late suspend of a device under the assumption that its
+ * pwr_domain field points to the domain member of an object of type
+ * struct generic_power_domain representing a power domain consisting of I/O
+ * devices.
+ */
+static int pm_genpd_suspend_noirq(struct device *dev)
+{
+	struct generic_power_domain *genpd;
+
+	dev_dbg(dev, "%s()\n", __func__);
+
+	if (IS_ERR_OR_NULL(dev->pwr_domain))
+		return -EINVAL;
+
+	genpd = container_of(dev->pwr_domain,
+			     struct generic_power_domain, domain);
+
+	if (genpd->power_is_off)
+		return 0;
+
+	if (genpd->stop_device)
+		genpd->stop_device(dev);
+
+	mutex_lock(&genpd->lock);
+	if (++genpd->suspended_count = genpd->device_count) {
+		if (genpd->power_off)
+			genpd->power_off(&genpd->domain);
+	}
+	mutex_unlock(&genpd->lock);
+
+	return 0;
+}
+
+/**
+ * pm_genpd_resume_noirq - Early resume of a device from an I/O power domain.
+ * @dev: Device to resume.
+ *
+ * Carry out an early resume of a device under the assumption that its
+ * pwr_domain field points to the domain member of an object of type
+ * struct generic_power_domain representing a power domain consisting of I/O
+ * devices.
+ */
+static int pm_genpd_resume_noirq(struct device *dev)
+{
+	struct generic_power_domain *genpd;
+
+	dev_dbg(dev, "%s()\n", __func__);
+
+	if (IS_ERR_OR_NULL(dev->pwr_domain))
+		return -EINVAL;
+
+	genpd = container_of(dev->pwr_domain,
+			     struct generic_power_domain, domain);
+
+	if (genpd->power_is_off)
+		return 0;
+
+	mutex_lock(&genpd->lock);
+	if (genpd->suspended_count = genpd->device_count) {
+		if (genpd->power_on) {
+			int ret = genpd->power_on(&genpd->domain);
+			if (ret) {
+				mutex_unlock(&genpd->lock);
+				return ret;
+			}
+		}
+	}
+	genpd->suspended_count--;
+	mutex_unlock(&genpd->lock);
+
+	if (genpd->start_device)
+		genpd->start_device(dev);
+
+	return 0;
+}
+
+/**
+ * pm_genpd_resume - Resume a device belonging to an I/O power domain.
+ * @dev: Device to resume.
+ *
+ * Resume a device under the assumption that its pwr_domain field points to the
+ * domain member of an object of type struct generic_power_domain representing
+ * a power domain consisting of I/O devices.
+ */
+static int pm_genpd_resume(struct device *dev)
+{
+	struct generic_power_domain *genpd;
+
+	dev_dbg(dev, "%s()\n", __func__);
+
+	if (IS_ERR_OR_NULL(dev->pwr_domain))
+		return -EINVAL;
+
+	genpd = container_of(dev->pwr_domain,
+			     struct generic_power_domain, domain);
+
+	return genpd->power_is_off ? 0 : pm_generic_resume(dev);
+}
+
+/**
+ * pm_genpd_freeze - Freeze a device belonging to an I/O power domain.
+ * @dev: Device to freeze.
+ *
+ * Freeze a device under the assumption that its pwr_domain field points to the
+ * domain member of an object of type struct generic_power_domain representing
+ * a power domain consisting of I/O devices.
+ */
+static int pm_genpd_freeze(struct device *dev)
+{
+	struct generic_power_domain *genpd;
+
+	dev_dbg(dev, "%s()\n", __func__);
+
+	if (IS_ERR_OR_NULL(dev->pwr_domain))
+		return -EINVAL;
+
+	genpd = container_of(dev->pwr_domain,
+			     struct generic_power_domain, domain);
+
+	if (genpd->power_is_off)
+		return 0;
+
+	/*
+	 * If the device is in the (runtime) "suspended" state, call
+	 * ->start_device() for it, if defined.
+	 */
+	pm_runtime_resume(dev);
+
+	return pm_generic_freeze(dev);
+}
+
+/**
+ * pm_genpd_freeze_noirq - Late freeze of a device from an I/O power domain.
+ * @dev: Device to freeze.
+ *
+ * Carry out a late freeze of a device under the assumption that its
+ * pwr_domain field points to the domain member of an object of type
+ * struct generic_power_domain representing a power domain consisting of I/O
+ * devices.
+ */
+static int pm_genpd_freeze_noirq(struct device *dev)
+{
+	struct generic_power_domain *genpd;
+
+	dev_dbg(dev, "%s()\n", __func__);
+
+	if (IS_ERR_OR_NULL(dev->pwr_domain))
+		return -EINVAL;
+
+	genpd = container_of(dev->pwr_domain,
+			     struct generic_power_domain, domain);
+
+	if (!genpd->power_is_off && genpd->stop_device)
+		genpd->stop_device(dev);
+
+	return 0;
+}
+
+/**
+ * pm_genpd_thaw_noirq - Early thaw of a device from an I/O power domain.
+ * @dev: Device to thaw.
+ *
+ * Carry out an early thaw of a device under the assumption that its
+ * pwr_domain field points to the domain member of an object of type
+ * struct generic_power_domain representing a power domain consisting of I/O
+ * devices.
+ */
+static int pm_genpd_thaw_noirq(struct device *dev)
+{
+	struct generic_power_domain *genpd;
+
+	dev_dbg(dev, "%s()\n", __func__);
+
+	if (IS_ERR_OR_NULL(dev->pwr_domain))
+		return -EINVAL;
+
+	genpd = container_of(dev->pwr_domain,
+			     struct generic_power_domain, domain);
+
+	if (!genpd->power_is_off && genpd->start_device)
+		genpd->start_device(dev);
+
+	return 0;
+}
+
+/**
+ * pm_genpd_thaw - Thaw a device belonging to an I/O power domain.
+ * @dev: Device to thaw.
+ *
+ * Thaw a device under the assumption that its pwr_domain field points to the
+ * domain member of an object of type struct generic_power_domain representing
+ * a power domain consisting of I/O devices.
+ */
+static int pm_genpd_thaw(struct device *dev)
+{
+	struct generic_power_domain *genpd;
+
+	dev_dbg(dev, "%s()\n", __func__);
+
+	if (IS_ERR_OR_NULL(dev->pwr_domain))
+		return -EINVAL;
+
+	genpd = container_of(dev->pwr_domain,
+			     struct generic_power_domain, domain);
+
+	return genpd->power_is_off ? 0 : pm_generic_thaw(dev);
+}
+
+/**
+ * pm_genpd_complete - Complete power transition of a device in a power domain.
+ * @dev: Device to complete the transition of.
+ *
+ * Complete a power transition of a device (during a system-wide power
+ * transition) under the assumption that its pwr_domain field points to the
+ * domain member of an object of type struct generic_power_domain representing
+ * a power domain consisting of I/O devices.
+ */
+static void pm_genpd_complete(struct device *dev)
+{
+	struct generic_power_domain *genpd;
+
+	dev_dbg(dev, "%s()\n", __func__);
+
+	if (IS_ERR_OR_NULL(dev->pwr_domain))
+		return;
+
+	genpd = container_of(dev->pwr_domain,
+			     struct generic_power_domain, domain);
+
+	if (!genpd->power_is_off)
+		pm_generic_complete(dev);
+}
+
+#else
+
+#define pm_genpd_prepare	NULL
+#define pm_genpd_suspend	NULL
+#define pm_genpd_suspend_noirq	NULL
+#define pm_genpd_resume_noirq	NULL
+#define pm_genpd_resume		NULL
+#define pm_genpd_freeze		NULL
+#define pm_genpd_freeze_noirq	NULL
+#define pm_genpd_thaw_noirq	NULL
+#define pm_genpd_thaw		NULL
+#define pm_genpd_complete	NULL
+
+#endif /* CONFIG_PM_SLEEP */
+
 /**
  * pm_genpd_add_device - Add a device to an I/O power domain.
  * @genpd: Power domain to add the device to.
@@ -304,6 +614,7 @@ int pm_genpd_add_device(struct generic_p
 
 	dle->dev = dev;
 	list_add_tail(&dle->node, &genpd->device_list);
+	genpd->device_count++;
 
 	spin_lock_irq(&dev->power.lock);
 	dev->pwr_domain = &genpd->domain;
@@ -341,6 +652,7 @@ int pm_genpd_remove_device(struct generi
 		dev->pwr_domain = NULL;
 		spin_unlock_irq(&dev->power.lock);
 
+		genpd->device_count--;
 		list_del(&dle->node);
 		kfree(dle);
 
@@ -438,7 +750,23 @@ void pm_genpd_init(struct generic_power_
 	genpd->gov = gov;
 	genpd->in_progress = 0;
 	genpd->power_is_off = is_off;
+	genpd->device_count = 0;
+	genpd->suspended_count = 0;
 	genpd->domain.ops.runtime_suspend = pm_genpd_runtime_suspend;
 	genpd->domain.ops.runtime_resume = pm_genpd_runtime_resume;
 	genpd->domain.ops.runtime_idle = pm_generic_runtime_idle;
+	genpd->domain.ops.prepare = pm_genpd_prepare;
+	genpd->domain.ops.suspend = pm_genpd_suspend;
+	genpd->domain.ops.suspend_noirq = pm_genpd_suspend_noirq;
+	genpd->domain.ops.resume_noirq = pm_genpd_resume_noirq;
+	genpd->domain.ops.resume = pm_genpd_resume;
+	genpd->domain.ops.freeze = pm_genpd_freeze;
+	genpd->domain.ops.freeze_noirq = pm_genpd_freeze_noirq;
+	genpd->domain.ops.thaw_noirq = pm_genpd_thaw_noirq;
+	genpd->domain.ops.thaw = pm_genpd_thaw;
+	genpd->domain.ops.poweroff = pm_genpd_suspend;
+	genpd->domain.ops.poweroff_noirq = pm_genpd_suspend_noirq;
+	genpd->domain.ops.restore_noirq = pm_genpd_resume_noirq;
+	genpd->domain.ops.restore = pm_genpd_resume;
+	genpd->domain.ops.complete = pm_genpd_complete;
 }
Index: linux-2.6/include/linux/pm_domain.h
=================================--- linux-2.6.orig/include/linux/pm_domain.h
+++ linux-2.6/include/linux/pm_domain.h
@@ -25,6 +25,8 @@ struct generic_power_domain {
 	struct dev_power_governor *gov;
 	unsigned int in_progress;
 	bool power_is_off;
+	unsigned int device_count;
+	unsigned int suspended_count;
 	int (*power_off)(struct dev_power_domain *domain);
 	int (*power_on)(struct dev_power_domain *domain);
 	int (*start_device)(struct device *dev);


  parent reply	other threads:[~2011-05-09 22:10 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-28 23:54 [RFC][PATCH 0/2] PM: Support for generic I/O power domains Rafael J. Wysocki
2011-04-28 23:54 ` [RFC][PATCH 1/2] PM / Runtime: " Rafael J. Wysocki
2011-04-29  1:26   ` [linux-pm] [RFC][PATCH 1/2] PM / Runtime: Support for generic I/O MyungJoo Ham
2011-04-29 20:11     ` [linux-pm] [RFC][PATCH 1/2] PM / Runtime: Support for generic I/O power domains Rafael J. Wysocki
2011-05-04  8:43       ` [linux-pm] [RFC][PATCH 1/2] PM / Runtime: Support for generic I/O MyungJoo Ham
2011-05-04 17:08         ` [linux-pm] [RFC][PATCH 1/2] PM / Runtime: Support for generic I/O power domains Rafael J. Wysocki
2011-04-29 20:54   ` [RFC][PATCH 1/2] PM / Runtime: Support for generic I/O power Greg KH
2011-04-30  0:54   ` [Update][RFC][PATCH 1/2] PM / Runtime: Support for generic I/O power domains (v2) Rafael J. Wysocki
2011-04-30  1:08     ` [Update][RFC][PATCH 1/2] PM / Runtime: Support for generic I/O Greg KH
2011-05-11  7:26     ` Kevin Hilman
2011-05-11 20:37       ` [Update][RFC][PATCH 1/2] PM / Runtime: Support for generic I/O power domains (v2) Rafael J. Wysocki
2011-04-28 23:55 ` [RFC][PATCH 2/2] ARM / shmobile: Support for I/O power domains for SH7372 Rafael J. Wysocki
2011-04-30  0:59   ` [Update][RFC][PATCH 2/2] ARM / shmobile: Support for I/O power domains for SH7372 (v2) Rafael J. Wysocki
2011-04-30  9:56     ` [RFC][PATCH] ARM / shmobile: Support for power domain A4MP on SH7372 Rafael J. Wysocki
2011-05-08 21:20 ` [RFC][PATCH 0/5] PM: Support for generic I/O power domains (v2) Rafael J. Wysocki
2011-05-08 21:22   ` [PATCH 1/5] PM / Runtime: Support for generic I/O power domains (v3) Rafael J. Wysocki
     [not found]     ` <BANLkTinPGQNUrFnyFVazqA72iyMbB-K_OA@mail.gmail.com>
2011-05-09 19:22       ` [linux-pm] " Rafael J. Wysocki
2011-05-10  8:22     ` Lin Ming
2011-05-10 19:03       ` Rafael J. Wysocki
2011-05-08 21:23   ` [PATCH 2/5] PM: Introduce generic prepare and complete callbacks for subsystems Rafael J. Wysocki
2011-05-08 21:24   ` [PATCH 3/5] PM: Support for system-wide power transitions in generic power domains Rafael J. Wysocki
2011-05-09 14:36     ` [linux-pm] [PATCH 3/5] PM: Support for system-wide power Alan Stern
2011-05-09 19:20       ` [linux-pm] [PATCH 3/5] PM: Support for system-wide power transitions in generic power domains Rafael J. Wysocki
2011-05-09 22:10     ` Rafael J. Wysocki [this message]
2011-05-10 21:19       ` [Update 2x][PATCH 3/5] PM: System-wide power transitions support for " Rafael J. Wysocki
2011-05-11 17:17     ` [PATCH 3/5] PM: Support for system-wide power transitions in Jonathan Corbet
2011-05-11 19:11       ` [PATCH 3/5] PM: Support for system-wide power transitions in generic power domains Rafael J. Wysocki
2011-05-08 21:25   ` [PATCH 4/5] ARM / shmobile: Support for I/O power domains for SH7372 (v4) Rafael J. Wysocki
2011-05-08 21:25   ` [PATCH 5/5] ARM / shmobile: Support for power domain A4MP on SH7372 Rafael J. Wysocki
2011-05-15 23:17   ` [PATCH 0/6] PM: Support for generic I/O power domains (v3) Rafael J. Wysocki
2011-05-15 23:30     ` [PATCH 1/6] PM: Introduce generic prepare and complete callbacks for subsystems Rafael J. Wysocki
2011-05-15 23:31     ` [PATCH 2/6] PM / Runtime: Support for generic I/O power domains (v4) Rafael J. Wysocki
2011-05-15 23:31     ` [PATCH 3/6] PM: System-wide transitions support for generic power domains (v2) Rafael J. Wysocki
2011-05-15 23:32     ` [PATCH 4/6] ARM / shmobile: Support for I/O power domains for SH7372 (v5) Rafael J. Wysocki
2011-05-15 23:33     ` [PATCH 5/6] ARM / shmobile: Support for power domain A4MP on SH7372 Rafael J. Wysocki
2011-05-15 23:34     ` [PATCH 6/6][RFC] PM / Domains: Support for multiple generic power domain states R. J. Wysocki
2011-05-15 23:38     ` Rafael J. Wysocki
2011-05-16 10:07       ` Kevin Hilman
2011-05-16 18:29         ` Rafael J. Wysocki
2011-05-27 23:15     ` [PATCH 0/5] PM: Support for generic I/O power domains (v4) Rafael J. Wysocki
2011-05-27 23:17       ` [PATCH 1/5] PM / Runtime: " Rafael J. Wysocki
2011-06-02  7:29         ` [PATCH 1/5] PM / Runtime: Support for generic I/O power domains Guennadi Liakhovetski
2011-06-06 18:48           ` [PATCH 1/5] PM / Runtime: Support for generic I/O power domains (v4) Rafael J. Wysocki
2011-05-27 23:17       ` [PATCH 2/5] PM: System-wide transitions support for generic power domains (v2) Rafael J. Wysocki
2011-05-27 23:18       ` [PATCH 3/5] ARM / shmobile: Support for I/O power domains for SH7372 (v5) Rafael J. Wysocki
2011-05-27 23:18       ` [PATCH 4/5] PM / Domains: Support for multiple generic power domain states Rafael J. Wysocki
2011-05-27 23:19       ` [PATCH 5/5] ARM / shmobile: Support for power domain A4MP on SH7372 Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201105100010.28810.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=g.liakhovetski@gmx.de \
    --cc=grant.likely@secretlab.ca \
    --cc=gregkh@suse.de \
    --cc=khilman@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=linux-sh@vger.kernel.org \
    --cc=magnus.damm@gmail.com \
    --cc=myungjoo.ham@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).