linux-sh.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Linux-sh list <linux-sh@vger.kernel.org>,
	Linux PM list <linux-pm@vger.kernel.org>,
	Magnus Damm <magnus.damm@gmail.com>,
	Paul Mundt <lethal@linux-sh.org>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: [RFC][PATCH 2/6] PM / Domains: Add power off/on function for system core suspend stage
Date: Sun, 29 Jul 2012 14:14:19 +0000	[thread overview]
Message-ID: <201207291614.19792.rjw@sisk.pl> (raw)
In-Reply-To: <201207291612.43138.rjw@sisk.pl>


Introduce function pm_genpd_syscore_switch() and two wrappers around
it, pm_genpd_syscore_poweroff() and pm_genpd_syscore_poweron(),
allowing the callers to let the generic PM domains framework know
that the given device is not necessary any more and its PM domain
can be turned off (the former) or that the given device will be
required immediately, so its PM domain has to be turned on (the
latter) during the system core (syscore) stage of system suspend
(or hibernation) and resume.

These functions will be used for handling devices registered as
clock sources and clock event devices that belong to PM domains.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 drivers/base/power/domain.c |   60 +++++++++++++++++++++++++++++++++++++++-----
 include/linux/pm_domain.h   |   13 +++++++++
 2 files changed, 67 insertions(+), 6 deletions(-)

Index: linux/drivers/base/power/domain.c
=================================--- linux.orig/drivers/base/power/domain.c
+++ linux/drivers/base/power/domain.c
@@ -63,6 +63,24 @@ struct generic_pm_domain *dev_to_genpd(s
 	return pd_to_genpd(dev->pm_domain);
 }
 
+/**
+ * pm_genpd_present - Check if the given PM domain has been initialized.
+ * @genpd: PM domain to check.
+ */
+static bool pm_genpd_present(struct generic_pm_domain *genpd)
+{
+	struct generic_pm_domain *gpd;
+
+	if (IS_ERR_OR_NULL(genpd))
+		return false;
+
+	list_for_each_entry(gpd, &gpd_list, gpd_list_node)
+		if (gpd = genpd)
+			return true;
+
+	return false;
+}
+
 static int genpd_stop_dev(struct generic_pm_domain *genpd, struct device *dev)
 {
 	return GENPD_DEV_TIMED_CALLBACK(genpd, int, stop, dev,
@@ -750,9 +768,10 @@ static int genpd_thaw_dev(struct generic
  * Check if the given PM domain can be powered off (during system suspend or
  * hibernation) and do that if so.  Also, in that case propagate to its masters.
  *
- * This function is only called in "noirq" stages of system power transitions,
- * so it need not acquire locks (all of the "noirq" callbacks are executed
- * sequentially, so it is guaranteed that it will never run twice in parallel).
+ * This function is only called in "noirq" and "syscore" stages of system power
+ * transitions, so it need not acquire locks (all of the "noirq" callbacks are
+ * executed sequentially, so it is guaranteed that it will never run twice in
+ * parallel).
  */
 static void pm_genpd_sync_poweroff(struct generic_pm_domain *genpd)
 {
@@ -780,9 +799,10 @@ static void pm_genpd_sync_poweroff(struc
  * pm_genpd_sync_poweron - Synchronously power on a PM domain and its masters.
  * @genpd: PM domain to power on.
  *
- * This function is only called in "noirq" stage of system power transitions, so
- * it need not acquire locks (all of the "noirq" callbacks are executed
- * sequentially, so it is guaranteed that it will never run twice in parallel).
+ * This function is only called in "noirq" and "syscore" stages of system power
+ * transitions, so it need not acquire locks (all of the "noirq" callbacks are
+ * executed sequentially, so it is guaranteed that it will never run twice in
+ * parallel).
  */
 static void pm_genpd_sync_poweron(struct generic_pm_domain *genpd)
 {
@@ -1272,6 +1292,34 @@ static void pm_genpd_complete(struct dev
 	}
 }
 
+/**
+ * pm_genpd_syscore_switch - Switch power during system core suspend or resume.
+ * @dev: Device that normally is marked as "always on" to switch power for.
+ *
+ * This routine may only be called during the system core (syscore) suspend or
+ * resume phase for devices whose "always on" flags are set.
+ */
+void pm_genpd_syscore_switch(struct device *dev, bool suspend)
+{
+	struct generic_pm_domain *genpd;
+
+	genpd = dev_to_genpd(dev);
+	if (!pm_genpd_present(genpd))
+		return;
+
+	if (!dev_gpd_data(dev)->always_on)
+		return;
+
+	if (suspend) {
+		genpd->suspended_count++;
+		pm_genpd_sync_poweroff(genpd);
+	} else {
+		pm_genpd_sync_poweron(genpd);
+		genpd->suspended_count--;
+	}
+}
+EXPORT_SYMBOL_GPL(pm_genpd_syscore_switch);
+
 #else
 
 #define pm_genpd_prepare		NULL
Index: linux/include/linux/pm_domain.h
=================================--- linux.orig/include/linux/pm_domain.h
+++ linux/include/linux/pm_domain.h
@@ -172,6 +172,8 @@ extern int pm_genpd_poweron(struct gener
 
 extern bool default_stop_ok(struct device *dev);
 
+extern void pm_genpd_syscore_switch(struct device *dev, bool suspend);
+
 extern struct dev_power_governor pm_domain_always_on_gov;
 #else
 
@@ -241,6 +243,7 @@ static inline bool default_stop_ok(struc
 {
 	return false;
 }
+static inline void pm_genpd_syscore_switch(struct device *dev, bool suspend) {}
 #define simple_qos_governor NULL
 #define pm_domain_always_on_gov NULL
 #endif
@@ -250,6 +253,16 @@ static inline int pm_genpd_remove_callba
 	return __pm_genpd_remove_callbacks(dev, true);
 }
 
+static inline void pm_genpd_syscore_poweroff(struct device *dev)
+{
+	pm_genpd_syscore_switch(dev, true);
+}
+
+static inline void pm_genpd_syscore_poweron(struct device *dev)
+{
+	pm_genpd_syscore_switch(dev, false);
+}
+
 #ifdef CONFIG_PM_GENERIC_DOMAINS_RUNTIME
 extern void genpd_queue_power_off_work(struct generic_pm_domain *genpd);
 extern void pm_genpd_poweroff_unused(void);


  parent reply	other threads:[~2012-07-29 14:14 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-29 14:12 [RFC][PATCH 0/6] PM: Suspend/resume for clock sources/clock event devices in PM domains Rafael J. Wysocki
2012-07-29 14:13 ` [RFC][PATCH 1/6] PM / Domains: Introduce simplified power on routine for system resume Rafael J. Wysocki
2012-07-29 14:14 ` Rafael J. Wysocki [this message]
2012-07-29 14:15 ` [RFC][PATCH 3/6] timekeeping: Add suspend and resume of clock event devices Rafael J. Wysocki
2012-07-29 14:16 ` [RFC][PATCH 4/6] sh: TMU: Introduce clocksource/clock events suspend/resume routines Rafael J. Wysocki
2012-07-29 14:16 ` [RFC][PATCH 5/6] sh: CMT: " Rafael J. Wysocki
2012-07-29 14:17 ` [RFC][PATCH 6/6] sh: MTU2: Introduce clock " Rafael J. Wysocki
2012-08-05 23:38 ` [PATCH 0/15] PM: Suspend/resume and runtime PM for clock sources/clock event devices in PM domains Rafael J. Wysocki
2012-08-05 23:39   ` [PATCH 1/15] PM / Domains: Introduce simplified power on routine for system resume Rafael J. Wysocki
2012-08-05 23:39   ` [PATCH 2/15] PM / Domains: Add power off/on function for system core suspend stage Rafael J. Wysocki
2012-08-05 23:40   ` [PATCH 3/15] timekeeping: Add suspend and resume of clock event devices Rafael J. Wysocki
2012-08-05 23:41   ` [PATCH 4/15] sh: TMU: Introduce clocksource/clock events suspend/resume routines Rafael J. Wysocki
2012-08-05 23:43   ` [PATCH 5/15] sh: CMT: " Rafael J. Wysocki
2012-08-05 23:43   ` [PATCH 6/15] sh: MTU2: Introduce clock " Rafael J. Wysocki
2012-08-05 23:44   ` [PATCH 7/15] PM: Reorganize device PM initialization Rafael J. Wysocki
2012-08-05 23:45   ` [PATCH 8/15] PM / Runtime: Allow helpers to be called by early platform drivers Rafael J. Wysocki
2012-08-05 23:45   ` [PATCH 9/15] PM / Domains: Rename the always_on device flag to syscore Rafael J. Wysocki
2012-08-05 23:46   ` [PATCH 10/15] PM / Domains: Move syscore flag from subsys data to struct device Rafael J. Wysocki
2012-08-05 23:47   ` [PATCH 11/15] PM / Domains: Do not measure start time for "irq safe" devices Rafael J. Wysocki
2012-08-05 23:48   ` [PATCH 12/15] sh: TMU: Basic runtime PM support Rafael J. Wysocki
2012-08-05 23:48   ` [PATCH 13/15] sh: CMT: " Rafael J. Wysocki
2012-08-05 23:49   ` [PATCH 14/15] sh: MTU2: " Rafael J. Wysocki
2012-08-11  9:39     ` Geert Uytterhoeven
2012-08-11 22:29       ` Rafael J. Wysocki
2012-08-05 23:53   ` [PATCH 15/15] PM: Do not use the syscore flag for runtime PM 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=201207291614.19792.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=lethal@linux-sh.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-sh@vger.kernel.org \
    --cc=magnus.damm@gmail.com \
    --cc=tglx@linutronix.de \
    /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).