From: ulf.hansson@linaro.org (Ulf Hansson)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3 2/9] PM / Domains: Enable genpd to support ->get|put() callbacks
Date: Mon, 13 Oct 2014 16:02:03 +0200 [thread overview]
Message-ID: <1413208930-26019-3-git-send-email-ulf.hansson@linaro.org> (raw)
In-Reply-To: <1413208930-26019-1-git-send-email-ulf.hansson@linaro.org>
To provide users control over whether the power should be maintained,
implement the ->get|put() callbacks for genpd's PM domain.
A usage count variable keeps track of the number of users. A positive
value tells genpd to keep supplying power and also to power up if it's
the first user.
Do note, the above applies no matter of CONFIG_PM_RUNTIME. That's
because we allows a PM domain to be initialized in power off state and
thus we need a way to power it up.
Once the usage count reaches zero, genpd tries to power off its PM
domain. Although for !CONFIG_PM_RUNTIME we need to maintain the power
once it's been enabled, since drivers can't use runtime PM to restore
it dynamically.
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
drivers/base/power/domain.c | 26 +++++++++++++++++++++++++-
include/linux/pm_domain.h | 1 +
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index 40bc2f4..96fe72e 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -451,10 +451,12 @@ static int pm_genpd_poweroff(struct generic_pm_domain *genpd)
* (2) The domain is waiting for its master to power up.
* (3) One of the domain's devices is being resumed right now.
* (4) System suspend is in progress.
+ * (5) The usage_count > 0, since it tells us to stay powered.
*/
if (genpd->status == GPD_STATE_POWER_OFF
|| genpd->status == GPD_STATE_WAIT_MASTER
- || genpd->resume_count > 0 || genpd->prepared_count > 0)
+ || genpd->resume_count > 0 || genpd->prepared_count > 0
+ || atomic_read(&genpd->usage_count) > 0)
return 0;
if (atomic_read(&genpd->sd_count) > 0)
@@ -1358,6 +1360,25 @@ EXPORT_SYMBOL_GPL(pm_genpd_syscore_poweron);
#endif /* CONFIG_PM_SLEEP */
+static int pm_genpd_get(struct dev_pm_domain *domain)
+{
+ struct generic_pm_domain *genpd = pd_to_genpd(domain);
+
+ atomic_inc(&genpd->usage_count);
+
+ return pm_genpd_poweron(genpd);
+}
+
+static void pm_genpd_put(struct dev_pm_domain *domain)
+{
+ struct generic_pm_domain *genpd = pd_to_genpd(domain);
+
+ if (!atomic_dec_and_test(&genpd->usage_count))
+ return;
+
+ genpd_queue_power_off_work(genpd);
+}
+
static struct generic_pm_domain_data *__pm_genpd_alloc_dev_data(struct device *dev)
{
struct generic_pm_domain_data *gpd_data;
@@ -1875,10 +1896,13 @@ void pm_genpd_init(struct generic_pm_domain *genpd,
genpd->status = is_off ? GPD_STATE_POWER_OFF : GPD_STATE_ACTIVE;
init_waitqueue_head(&genpd->status_wait_queue);
genpd->poweroff_task = NULL;
+ atomic_set(&genpd->usage_count, 0);
genpd->resume_count = 0;
genpd->device_count = 0;
genpd->max_off_time_ns = -1;
genpd->max_off_time_changed = true;
+ genpd->domain.get = pm_genpd_get;
+ genpd->domain.put = pm_genpd_put;
genpd->domain.ops.runtime_suspend = pm_genpd_runtime_suspend;
genpd->domain.ops.runtime_resume = pm_genpd_runtime_resume;
genpd->domain.ops.prepare = pm_genpd_prepare;
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index 8e2806f..7b3cba2 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -58,6 +58,7 @@ struct generic_pm_domain {
enum gpd_status status; /* Current state of the domain */
wait_queue_head_t status_wait_queue;
struct task_struct *poweroff_task; /* Powering off task */
+ atomic_t usage_count; /* Number of users of the domain */
unsigned int resume_count; /* Number of devices being resumed */
unsigned int device_count; /* Number of devices */
unsigned int suspended_count; /* System suspend device counter */
--
1.9.1
next prev parent reply other threads:[~2014-10-13 14:02 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-13 14:02 [PATCH v3 0/9] PM / Domains: Fix race conditions during boot Ulf Hansson
2014-10-13 14:02 ` [PATCH v3 1/9] PM / Domains: Add dev_pm_domain_get|put() APIs Ulf Hansson
2014-10-13 14:02 ` Ulf Hansson [this message]
2014-10-13 14:02 ` [PATCH v3 3/9] amba: Keep PM domain powered during ->probe() Ulf Hansson
2014-10-13 14:02 ` [PATCH v3 4/9] drivercore / platform: " Ulf Hansson
2014-10-30 20:47 ` Kevin Hilman
2014-10-31 0:07 ` Dmitry Torokhov
2014-10-31 9:23 ` Ulf Hansson
2014-11-01 0:21 ` Rafael J. Wysocki
2014-10-31 9:19 ` Ulf Hansson
2014-10-13 14:02 ` [PATCH v3 5/9] i2c: core: " Ulf Hansson
2014-10-13 14:02 ` [PATCH v3 6/9] spi: " Ulf Hansson
2014-10-13 14:02 ` [PATCH v3 7/9] mmc: core: Attach PM domain prior probing of SDIO func driver Ulf Hansson
2014-10-13 14:02 ` [PATCH v3 8/9] mmmc: core: Keep PM domain powered during ->probe() " Ulf Hansson
2014-10-13 14:02 ` [PATCH v3 9/9] PM / Domains: Remove pm_genpd_dev_need_restore() API Ulf Hansson
2014-10-24 16:12 ` [PATCH v3 0/9] PM / Domains: Fix race conditions during boot Kevin Hilman
2014-10-24 16:18 ` Mark Brown
2014-10-30 20:46 ` Kevin Hilman
2014-10-30 23:56 ` Mark Brown
2014-10-31 9:16 ` Ulf Hansson
2014-11-01 0:20 ` Rafael J. Wysocki
2014-11-01 1:08 ` pm_runtime_enable() in ->probe() (was: Re: [PATCH v3 0/9] PM / Domains: Fix race conditions during boot) Rafael J. Wysocki
2014-11-01 1:14 ` Rafael J. Wysocki
2014-11-03 17:00 ` pm_runtime_enable() in ->probe() Kevin Hilman
2014-11-03 23:55 ` Rafael J. Wysocki
2014-11-03 14:03 ` [PATCH v3 0/9] PM / Domains: Fix race conditions during boot Ulf Hansson
2014-11-04 1:43 ` Rafael J. Wysocki
2014-11-04 8:20 ` Geert Uytterhoeven
2014-11-04 13:32 ` Rafael J. Wysocki
2014-11-04 8:54 ` Ulf Hansson
2014-11-04 9:05 ` Dmitry Torokhov
2014-11-04 9:24 ` Ulf Hansson
2014-11-04 13:56 ` Rafael J. Wysocki
2014-11-04 17:01 ` Ulf Hansson
2014-11-04 18:29 ` Dmitry Torokhov
2014-11-04 21:38 ` Rafael J. Wysocki
2014-11-05 8:17 ` Ulf Hansson
2014-11-04 13:52 ` Rafael J. Wysocki
2014-11-04 13:51 ` Rafael J. Wysocki
2014-11-04 16:42 ` Ulf Hansson
2014-11-07 17:25 ` Grygorii Strashko
2014-11-11 11:05 ` Ulf Hansson
2014-11-12 18:01 ` Grygorii Strashko
2014-11-13 2:07 ` Rafael J. Wysocki
2014-11-13 20:13 ` Grygorii Strashko
2014-11-13 14:05 ` Pavel Machek
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=1413208930-26019-3-git-send-email-ulf.hansson@linaro.org \
--to=ulf.hansson@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
/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).