aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/power/domain.c
diff options
context:
space:
mode:
authorRafael J. Wysocki <rjw@sisk.pl>2011-07-01 16:13:10 -0400
committerRafael J. Wysocki <rjw@sisk.pl>2011-07-02 08:29:55 -0400
commit5248051b9afb6684cd817b2fbdaefa5063761dab (patch)
tree44782bb3ae2330f676e053d1b3a8aad4d2abb6e7 /drivers/base/power/domain.c
parente5291928839877f8e73c2643ee1d3fe0bcdcaf5c (diff)
PM / Domains: Move code from under #ifdef CONFIG_PM_RUNTIME (v2)
There is some code in drivers/base/power/domain.c that will be useful for both runtime PM and system-wide power transitions, so make it depend on CONFIG_PM instead of CONFIG_PM_RUNTIME. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Reviewed-by: Kevin Hilman <khilman@ti.com>
Diffstat (limited to 'drivers/base/power/domain.c')
-rw-r--r--drivers/base/power/domain.c120
1 files changed, 65 insertions, 55 deletions
diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index fd31be3be404..f14ba32818dc 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -14,7 +14,15 @@
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/err.h> 15#include <linux/err.h>
16 16
17#ifdef CONFIG_PM_RUNTIME 17#ifdef CONFIG_PM
18
19static struct generic_pm_domain *dev_to_genpd(struct device *dev)
20{
21 if (IS_ERR_OR_NULL(dev->pm_domain))
22 return ERR_PTR(-EINVAL);
23
24 return container_of(dev->pm_domain, struct generic_pm_domain, domain);
25}
18 26
19static void genpd_sd_counter_dec(struct generic_pm_domain *genpd) 27static void genpd_sd_counter_dec(struct generic_pm_domain *genpd)
20{ 28{
@@ -23,6 +31,58 @@ static void genpd_sd_counter_dec(struct generic_pm_domain *genpd)
23} 31}
24 32
25/** 33/**
34 * pm_genpd_poweron - Restore power to a given PM domain and its parents.
35 * @genpd: PM domain to power up.
36 *
37 * Restore power to @genpd and all of its parents so that it is possible to
38 * resume a device belonging to it.
39 */
40static int pm_genpd_poweron(struct generic_pm_domain *genpd)
41{
42 int ret = 0;
43
44 start:
45 if (genpd->parent)
46 mutex_lock(&genpd->parent->lock);
47 mutex_lock_nested(&genpd->lock, SINGLE_DEPTH_NESTING);
48
49 if (!genpd->power_is_off)
50 goto out;
51
52 if (genpd->parent && genpd->parent->power_is_off) {
53 mutex_unlock(&genpd->lock);
54 mutex_unlock(&genpd->parent->lock);
55
56 ret = pm_genpd_poweron(genpd->parent);
57 if (ret)
58 return ret;
59
60 goto start;
61 }
62
63 if (genpd->power_on) {
64 int ret = genpd->power_on(genpd);
65 if (ret)
66 goto out;
67 }
68
69 genpd->power_is_off = false;
70 if (genpd->parent)
71 genpd->parent->sd_count++;
72
73 out:
74 mutex_unlock(&genpd->lock);
75 if (genpd->parent)
76 mutex_unlock(&genpd->parent->lock);
77
78 return ret;
79}
80
81#endif /* CONFIG_PM */
82
83#ifdef CONFIG_PM_RUNTIME
84
85/**
26 * __pm_genpd_save_device - Save the pre-suspend state of a device. 86 * __pm_genpd_save_device - Save the pre-suspend state of a device.
27 * @dle: Device list entry of the device to save the state of. 87 * @dle: Device list entry of the device to save the state of.
28 * @genpd: PM domain the device belongs to. 88 * @genpd: PM domain the device belongs to.
@@ -174,11 +234,10 @@ static int pm_genpd_runtime_suspend(struct device *dev)
174 234
175 dev_dbg(dev, "%s()\n", __func__); 235 dev_dbg(dev, "%s()\n", __func__);
176 236
177 if (IS_ERR_OR_NULL(dev->pm_domain)) 237 genpd = dev_to_genpd(dev);
238 if (IS_ERR(genpd))
178 return -EINVAL; 239 return -EINVAL;
179 240
180 genpd = container_of(dev->pm_domain, struct generic_pm_domain, domain);
181
182 if (genpd->parent) 241 if (genpd->parent)
183 mutex_lock(&genpd->parent->lock); 242 mutex_lock(&genpd->parent->lock);
184 mutex_lock_nested(&genpd->lock, SINGLE_DEPTH_NESTING); 243 mutex_lock_nested(&genpd->lock, SINGLE_DEPTH_NESTING);
@@ -201,54 +260,6 @@ static int pm_genpd_runtime_suspend(struct device *dev)
201} 260}
202 261
203/** 262/**
204 * pm_genpd_poweron - Restore power to a given PM domain and its parents.
205 * @genpd: PM domain to power up.
206 *
207 * Restore power to @genpd and all of its parents so that it is possible to
208 * resume a device belonging to it.
209 */
210static int pm_genpd_poweron(struct generic_pm_domain *genpd)
211{
212 int ret = 0;
213
214 start:
215 if (genpd->parent)
216 mutex_lock(&genpd->parent->lock);
217 mutex_lock_nested(&genpd->lock, SINGLE_DEPTH_NESTING);
218
219 if (!genpd->power_is_off)
220 goto out;
221
222 if (genpd->parent && genpd->parent->power_is_off) {
223 mutex_unlock(&genpd->lock);
224 mutex_unlock(&genpd->parent->lock);
225
226 ret = pm_genpd_poweron(genpd->parent);
227 if (ret)
228 return ret;
229
230 goto start;
231 }
232
233 if (genpd->power_on) {
234 int ret = genpd->power_on(genpd);
235 if (ret)
236 goto out;
237 }
238
239 genpd->power_is_off = false;
240 if (genpd->parent)
241 genpd->parent->sd_count++;
242
243 out:
244 mutex_unlock(&genpd->lock);
245 if (genpd->parent)
246 mutex_unlock(&genpd->parent->lock);
247
248 return ret;
249}
250
251/**
252 * pm_genpd_runtime_resume - Resume a device belonging to I/O PM domain. 263 * pm_genpd_runtime_resume - Resume a device belonging to I/O PM domain.
253 * @dev: Device to resume. 264 * @dev: Device to resume.
254 * 265 *
@@ -264,11 +275,10 @@ static int pm_genpd_runtime_resume(struct device *dev)
264 275
265 dev_dbg(dev, "%s()\n", __func__); 276 dev_dbg(dev, "%s()\n", __func__);
266 277
267 if (IS_ERR_OR_NULL(dev->pm_domain)) 278 genpd = dev_to_genpd(dev);
279 if (IS_ERR(genpd))
268 return -EINVAL; 280 return -EINVAL;
269 281
270 genpd = container_of(dev->pm_domain, struct generic_pm_domain, domain);
271
272 ret = pm_genpd_poweron(genpd); 282 ret = pm_genpd_poweron(genpd);
273 if (ret) 283 if (ret)
274 return ret; 284 return ret;