blob: 3c9451b104270142e3249677581042415268e39c [file] [log] [blame]
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001/*
2 * drivers/base/power/domain.c - Common code related to device power domains.
3 *
4 * Copyright (C) 2011 Rafael J. Wysocki <rjw@sisk.pl>, Renesas Electronics Corp.
5 *
6 * This file is released under the GPLv2.
7 */
8
9#include <linux/init.h>
10#include <linux/kernel.h>
11#include <linux/io.h>
12#include <linux/pm_runtime.h>
13#include <linux/pm_domain.h>
14#include <linux/slab.h>
15#include <linux/err.h>
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +020016#include <linux/sched.h>
17#include <linux/suspend.h>
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +010018#include <linux/export.h>
19
20#define GENPD_DEV_CALLBACK(genpd, type, callback, dev) \
21({ \
22 type (*__routine)(struct device *__d); \
23 type __ret = (type)0; \
24 \
25 __routine = genpd->dev_ops.callback; \
26 if (__routine) { \
27 __ret = __routine(dev); \
28 } else { \
29 __routine = dev_gpd_data(dev)->ops.callback; \
30 if (__routine) \
31 __ret = __routine(dev); \
32 } \
33 __ret; \
34})
Rafael J. Wysockif7218892011-07-01 22:12:45 +020035
Rafael J. Wysocki5125bbf382011-07-13 12:31:52 +020036static LIST_HEAD(gpd_list);
37static DEFINE_MUTEX(gpd_list_lock);
38
Rafael J. Wysocki52480512011-07-01 22:13:10 +020039#ifdef CONFIG_PM
40
41static struct generic_pm_domain *dev_to_genpd(struct device *dev)
42{
43 if (IS_ERR_OR_NULL(dev->pm_domain))
44 return ERR_PTR(-EINVAL);
45
Rafael J. Wysocki596ba342011-07-01 22:13:19 +020046 return pd_to_genpd(dev->pm_domain);
Rafael J. Wysocki52480512011-07-01 22:13:10 +020047}
Rafael J. Wysockif7218892011-07-01 22:12:45 +020048
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +010049static int genpd_stop_dev(struct generic_pm_domain *genpd, struct device *dev)
50{
51 return GENPD_DEV_CALLBACK(genpd, int, stop, dev);
52}
53
54static int genpd_start_dev(struct generic_pm_domain *genpd, struct device *dev)
55{
56 return GENPD_DEV_CALLBACK(genpd, int, start, dev);
57}
58
Rafael J. Wysockiecf00472011-11-27 13:11:44 +010059static int genpd_save_dev(struct generic_pm_domain *genpd, struct device *dev)
60{
61 return GENPD_DEV_CALLBACK(genpd, int, save_state, dev);
62}
63
64static int genpd_restore_dev(struct generic_pm_domain *genpd, struct device *dev)
65{
66 return GENPD_DEV_CALLBACK(genpd, int, restore_state, dev);
67}
68
Rafael J. Wysockic4bb3162011-08-08 23:43:04 +020069static bool genpd_sd_counter_dec(struct generic_pm_domain *genpd)
Rafael J. Wysockif7218892011-07-01 22:12:45 +020070{
Rafael J. Wysockic4bb3162011-08-08 23:43:04 +020071 bool ret = false;
72
73 if (!WARN_ON(atomic_read(&genpd->sd_count) == 0))
74 ret = !!atomic_dec_and_test(&genpd->sd_count);
75
76 return ret;
77}
78
79static void genpd_sd_counter_inc(struct generic_pm_domain *genpd)
80{
81 atomic_inc(&genpd->sd_count);
82 smp_mb__after_atomic_inc();
Rafael J. Wysockif7218892011-07-01 22:12:45 +020083}
84
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +020085static void genpd_acquire_lock(struct generic_pm_domain *genpd)
86{
87 DEFINE_WAIT(wait);
88
89 mutex_lock(&genpd->lock);
90 /*
91 * Wait for the domain to transition into either the active,
92 * or the power off state.
93 */
94 for (;;) {
95 prepare_to_wait(&genpd->status_wait_queue, &wait,
96 TASK_UNINTERRUPTIBLE);
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +020097 if (genpd->status == GPD_STATE_ACTIVE
98 || genpd->status == GPD_STATE_POWER_OFF)
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +020099 break;
100 mutex_unlock(&genpd->lock);
101
102 schedule();
103
104 mutex_lock(&genpd->lock);
105 }
106 finish_wait(&genpd->status_wait_queue, &wait);
107}
108
109static void genpd_release_lock(struct generic_pm_domain *genpd)
110{
111 mutex_unlock(&genpd->lock);
112}
113
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +0200114static void genpd_set_active(struct generic_pm_domain *genpd)
115{
116 if (genpd->resume_count == 0)
117 genpd->status = GPD_STATE_ACTIVE;
118}
119
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200120/**
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +0200121 * __pm_genpd_poweron - Restore power to a given PM domain and its masters.
Rafael J. Wysocki52480512011-07-01 22:13:10 +0200122 * @genpd: PM domain to power up.
123 *
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +0200124 * Restore power to @genpd and all of its masters so that it is possible to
Rafael J. Wysocki52480512011-07-01 22:13:10 +0200125 * resume a device belonging to it.
126 */
Rafael J. Wysocki3f241772011-08-08 23:43:29 +0200127int __pm_genpd_poweron(struct generic_pm_domain *genpd)
128 __releases(&genpd->lock) __acquires(&genpd->lock)
Rafael J. Wysocki52480512011-07-01 22:13:10 +0200129{
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +0200130 struct gpd_link *link;
Rafael J. Wysocki3f241772011-08-08 23:43:29 +0200131 DEFINE_WAIT(wait);
Rafael J. Wysocki52480512011-07-01 22:13:10 +0200132 int ret = 0;
133
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +0200134 /* If the domain's master is being waited for, we have to wait too. */
Rafael J. Wysocki3f241772011-08-08 23:43:29 +0200135 for (;;) {
136 prepare_to_wait(&genpd->status_wait_queue, &wait,
137 TASK_UNINTERRUPTIBLE);
Rafael J. Wysocki17877eb2011-08-08 23:43:50 +0200138 if (genpd->status != GPD_STATE_WAIT_MASTER)
Rafael J. Wysocki3f241772011-08-08 23:43:29 +0200139 break;
140 mutex_unlock(&genpd->lock);
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200141
Rafael J. Wysocki3f241772011-08-08 23:43:29 +0200142 schedule();
Rafael J. Wysocki9e08cf42011-08-08 23:43:22 +0200143
Rafael J. Wysocki3f241772011-08-08 23:43:29 +0200144 mutex_lock(&genpd->lock);
145 }
146 finish_wait(&genpd->status_wait_queue, &wait);
147
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200148 if (genpd->status == GPD_STATE_ACTIVE
Rafael J. Wysocki596ba342011-07-01 22:13:19 +0200149 || (genpd->prepared_count > 0 && genpd->suspend_power_off))
Rafael J. Wysocki3f241772011-08-08 23:43:29 +0200150 return 0;
Rafael J. Wysocki52480512011-07-01 22:13:10 +0200151
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +0200152 if (genpd->status != GPD_STATE_POWER_OFF) {
153 genpd_set_active(genpd);
Rafael J. Wysocki3f241772011-08-08 23:43:29 +0200154 return 0;
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +0200155 }
156
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +0200157 /*
158 * The list is guaranteed not to change while the loop below is being
159 * executed, unless one of the masters' .power_on() callbacks fiddles
160 * with it.
161 */
162 list_for_each_entry(link, &genpd->slave_links, slave_node) {
163 genpd_sd_counter_inc(link->master);
Rafael J. Wysocki17877eb2011-08-08 23:43:50 +0200164 genpd->status = GPD_STATE_WAIT_MASTER;
Rafael J. Wysocki3c07cbc2011-08-08 23:43:14 +0200165
Rafael J. Wysocki52480512011-07-01 22:13:10 +0200166 mutex_unlock(&genpd->lock);
Rafael J. Wysocki52480512011-07-01 22:13:10 +0200167
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +0200168 ret = pm_genpd_poweron(link->master);
Rafael J. Wysocki9e08cf42011-08-08 23:43:22 +0200169
170 mutex_lock(&genpd->lock);
171
Rafael J. Wysocki3f241772011-08-08 23:43:29 +0200172 /*
173 * The "wait for parent" status is guaranteed not to change
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +0200174 * while the master is powering on.
Rafael J. Wysocki3f241772011-08-08 23:43:29 +0200175 */
176 genpd->status = GPD_STATE_POWER_OFF;
177 wake_up_all(&genpd->status_wait_queue);
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +0200178 if (ret) {
179 genpd_sd_counter_dec(link->master);
Rafael J. Wysocki9e08cf42011-08-08 23:43:22 +0200180 goto err;
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +0200181 }
Rafael J. Wysocki52480512011-07-01 22:13:10 +0200182 }
183
Rafael J. Wysocki9e08cf42011-08-08 23:43:22 +0200184 if (genpd->power_on) {
Rafael J. Wysockife202fd2011-08-05 21:45:11 +0200185 ret = genpd->power_on(genpd);
Rafael J. Wysocki9e08cf42011-08-08 23:43:22 +0200186 if (ret)
187 goto err;
Rafael J. Wysocki3c07cbc2011-08-08 23:43:14 +0200188 }
Rafael J. Wysocki52480512011-07-01 22:13:10 +0200189
Rafael J. Wysocki9e08cf42011-08-08 23:43:22 +0200190 genpd_set_active(genpd);
191
Rafael J. Wysocki3f241772011-08-08 23:43:29 +0200192 return 0;
Rafael J. Wysocki9e08cf42011-08-08 23:43:22 +0200193
194 err:
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +0200195 list_for_each_entry_continue_reverse(link, &genpd->slave_links, slave_node)
196 genpd_sd_counter_dec(link->master);
Rafael J. Wysocki9e08cf42011-08-08 23:43:22 +0200197
Rafael J. Wysocki3f241772011-08-08 23:43:29 +0200198 return ret;
199}
200
201/**
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +0200202 * pm_genpd_poweron - Restore power to a given PM domain and its masters.
Rafael J. Wysocki3f241772011-08-08 23:43:29 +0200203 * @genpd: PM domain to power up.
204 */
205int pm_genpd_poweron(struct generic_pm_domain *genpd)
206{
207 int ret;
208
209 mutex_lock(&genpd->lock);
210 ret = __pm_genpd_poweron(genpd);
211 mutex_unlock(&genpd->lock);
212 return ret;
Rafael J. Wysocki52480512011-07-01 22:13:10 +0200213}
214
215#endif /* CONFIG_PM */
216
217#ifdef CONFIG_PM_RUNTIME
218
219/**
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200220 * __pm_genpd_save_device - Save the pre-suspend state of a device.
Rafael J. Wysocki4605ab62011-08-25 15:34:12 +0200221 * @pdd: Domain data of the device to save the state of.
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200222 * @genpd: PM domain the device belongs to.
223 */
Rafael J. Wysocki4605ab62011-08-25 15:34:12 +0200224static int __pm_genpd_save_device(struct pm_domain_data *pdd,
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200225 struct generic_pm_domain *genpd)
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200226 __releases(&genpd->lock) __acquires(&genpd->lock)
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200227{
Rafael J. Wysockicd0ea672011-09-26 20:22:02 +0200228 struct generic_pm_domain_data *gpd_data = to_gpd_data(pdd);
Rafael J. Wysocki4605ab62011-08-25 15:34:12 +0200229 struct device *dev = pdd->dev;
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200230 int ret = 0;
231
Rafael J. Wysockicd0ea672011-09-26 20:22:02 +0200232 if (gpd_data->need_restore)
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200233 return 0;
234
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200235 mutex_unlock(&genpd->lock);
236
Rafael J. Wysockiecf00472011-11-27 13:11:44 +0100237 genpd_start_dev(genpd, dev);
238 ret = genpd_save_dev(genpd, dev);
239 genpd_stop_dev(genpd, dev);
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200240
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200241 mutex_lock(&genpd->lock);
242
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200243 if (!ret)
Rafael J. Wysockicd0ea672011-09-26 20:22:02 +0200244 gpd_data->need_restore = true;
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200245
246 return ret;
247}
248
249/**
250 * __pm_genpd_restore_device - Restore the pre-suspend state of a device.
Rafael J. Wysocki4605ab62011-08-25 15:34:12 +0200251 * @pdd: Domain data of the device to restore the state of.
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200252 * @genpd: PM domain the device belongs to.
253 */
Rafael J. Wysocki4605ab62011-08-25 15:34:12 +0200254static void __pm_genpd_restore_device(struct pm_domain_data *pdd,
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200255 struct generic_pm_domain *genpd)
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200256 __releases(&genpd->lock) __acquires(&genpd->lock)
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200257{
Rafael J. Wysockicd0ea672011-09-26 20:22:02 +0200258 struct generic_pm_domain_data *gpd_data = to_gpd_data(pdd);
Rafael J. Wysocki4605ab62011-08-25 15:34:12 +0200259 struct device *dev = pdd->dev;
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200260
Rafael J. Wysockicd0ea672011-09-26 20:22:02 +0200261 if (!gpd_data->need_restore)
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200262 return;
263
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200264 mutex_unlock(&genpd->lock);
265
Rafael J. Wysockiecf00472011-11-27 13:11:44 +0100266 genpd_start_dev(genpd, dev);
267 genpd_restore_dev(genpd, dev);
268 genpd_stop_dev(genpd, dev);
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200269
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200270 mutex_lock(&genpd->lock);
271
Rafael J. Wysockicd0ea672011-09-26 20:22:02 +0200272 gpd_data->need_restore = false;
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200273}
274
275/**
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +0200276 * genpd_abort_poweroff - Check if a PM domain power off should be aborted.
277 * @genpd: PM domain to check.
278 *
279 * Return true if a PM domain's status changed to GPD_STATE_ACTIVE during
280 * a "power off" operation, which means that a "power on" has occured in the
281 * meantime, or if its resume_count field is different from zero, which means
282 * that one of its devices has been resumed in the meantime.
283 */
284static bool genpd_abort_poweroff(struct generic_pm_domain *genpd)
285{
Rafael J. Wysocki17877eb2011-08-08 23:43:50 +0200286 return genpd->status == GPD_STATE_WAIT_MASTER
Rafael J. Wysocki3f241772011-08-08 23:43:29 +0200287 || genpd->status == GPD_STATE_ACTIVE || genpd->resume_count > 0;
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +0200288}
289
290/**
Rafael J. Wysocki56375fd2011-07-12 00:40:03 +0200291 * genpd_queue_power_off_work - Queue up the execution of pm_genpd_poweroff().
292 * @genpd: PM domait to power off.
293 *
294 * Queue up the execution of pm_genpd_poweroff() unless it's already been done
295 * before.
296 */
Rafael J. Wysocki0bc5b2d2011-07-14 20:59:07 +0200297void genpd_queue_power_off_work(struct generic_pm_domain *genpd)
Rafael J. Wysocki56375fd2011-07-12 00:40:03 +0200298{
299 if (!work_pending(&genpd->power_off_work))
300 queue_work(pm_wq, &genpd->power_off_work);
301}
302
303/**
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200304 * pm_genpd_poweroff - Remove power from a given PM domain.
305 * @genpd: PM domain to power down.
306 *
307 * If all of the @genpd's devices have been suspended and all of its subdomains
308 * have been powered down, run the runtime suspend callbacks provided by all of
309 * the @genpd's devices' drivers and remove power from @genpd.
310 */
311static int pm_genpd_poweroff(struct generic_pm_domain *genpd)
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200312 __releases(&genpd->lock) __acquires(&genpd->lock)
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200313{
Rafael J. Wysocki4605ab62011-08-25 15:34:12 +0200314 struct pm_domain_data *pdd;
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +0200315 struct gpd_link *link;
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200316 unsigned int not_suspended;
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +0200317 int ret = 0;
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200318
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +0200319 start:
320 /*
321 * Do not try to power off the domain in the following situations:
322 * (1) The domain is already in the "power off" state.
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +0200323 * (2) The domain is waiting for its master to power up.
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +0200324 * (3) One of the domain's devices is being resumed right now.
Rafael J. Wysocki3f241772011-08-08 23:43:29 +0200325 * (4) System suspend is in progress.
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +0200326 */
Rafael J. Wysocki3f241772011-08-08 23:43:29 +0200327 if (genpd->status == GPD_STATE_POWER_OFF
Rafael J. Wysocki17877eb2011-08-08 23:43:50 +0200328 || genpd->status == GPD_STATE_WAIT_MASTER
Rafael J. Wysocki3f241772011-08-08 23:43:29 +0200329 || genpd->resume_count > 0 || genpd->prepared_count > 0)
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200330 return 0;
331
Rafael J. Wysockic4bb3162011-08-08 23:43:04 +0200332 if (atomic_read(&genpd->sd_count) > 0)
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200333 return -EBUSY;
334
335 not_suspended = 0;
Rafael J. Wysocki4605ab62011-08-25 15:34:12 +0200336 list_for_each_entry(pdd, &genpd->dev_list, list_node)
Rafael J. Wysocki0aa2a222011-08-25 15:37:04 +0200337 if (pdd->dev->driver && (!pm_runtime_suspended(pdd->dev)
338 || pdd->dev->power.irq_safe))
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200339 not_suspended++;
340
341 if (not_suspended > genpd->in_progress)
342 return -EBUSY;
343
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +0200344 if (genpd->poweroff_task) {
345 /*
346 * Another instance of pm_genpd_poweroff() is executing
347 * callbacks, so tell it to start over and return.
348 */
349 genpd->status = GPD_STATE_REPEAT;
350 return 0;
351 }
352
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200353 if (genpd->gov && genpd->gov->power_down_ok) {
354 if (!genpd->gov->power_down_ok(&genpd->domain))
355 return -EAGAIN;
356 }
357
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200358 genpd->status = GPD_STATE_BUSY;
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +0200359 genpd->poweroff_task = current;
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200360
Rafael J. Wysocki4605ab62011-08-25 15:34:12 +0200361 list_for_each_entry_reverse(pdd, &genpd->dev_list, list_node) {
Rafael J. Wysocki3c07cbc2011-08-08 23:43:14 +0200362 ret = atomic_read(&genpd->sd_count) == 0 ?
Rafael J. Wysocki4605ab62011-08-25 15:34:12 +0200363 __pm_genpd_save_device(pdd, genpd) : -EBUSY;
Rafael J. Wysocki3f241772011-08-08 23:43:29 +0200364
365 if (genpd_abort_poweroff(genpd))
366 goto out;
367
Rafael J. Wysocki697a7f32011-07-12 00:39:48 +0200368 if (ret) {
369 genpd_set_active(genpd);
370 goto out;
371 }
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200372
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +0200373 if (genpd->status == GPD_STATE_REPEAT) {
374 genpd->poweroff_task = NULL;
375 goto start;
376 }
377 }
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200378
Rafael J. Wysocki3c07cbc2011-08-08 23:43:14 +0200379 if (genpd->power_off) {
380 if (atomic_read(&genpd->sd_count) > 0) {
381 ret = -EBUSY;
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +0200382 goto out;
383 }
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200384
Rafael J. Wysocki3c07cbc2011-08-08 23:43:14 +0200385 /*
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +0200386 * If sd_count > 0 at this point, one of the subdomains hasn't
387 * managed to call pm_genpd_poweron() for the master yet after
Rafael J. Wysocki3c07cbc2011-08-08 23:43:14 +0200388 * incrementing it. In that case pm_genpd_poweron() will wait
389 * for us to drop the lock, so we can call .power_off() and let
390 * the pm_genpd_poweron() restore power for us (this shouldn't
391 * happen very often).
392 */
Rafael J. Wysockid2805402011-07-14 20:59:20 +0200393 ret = genpd->power_off(genpd);
394 if (ret == -EBUSY) {
395 genpd_set_active(genpd);
Rafael J. Wysockid2805402011-07-14 20:59:20 +0200396 goto out;
397 }
398 }
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200399
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200400 genpd->status = GPD_STATE_POWER_OFF;
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200401
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +0200402 list_for_each_entry(link, &genpd->slave_links, slave_node) {
403 genpd_sd_counter_dec(link->master);
404 genpd_queue_power_off_work(link->master);
405 }
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200406
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +0200407 out:
408 genpd->poweroff_task = NULL;
409 wake_up_all(&genpd->status_wait_queue);
410 return ret;
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200411}
412
413/**
414 * genpd_power_off_work_fn - Power off PM domain whose subdomain count is 0.
415 * @work: Work structure used for scheduling the execution of this function.
416 */
417static void genpd_power_off_work_fn(struct work_struct *work)
418{
419 struct generic_pm_domain *genpd;
420
421 genpd = container_of(work, struct generic_pm_domain, power_off_work);
422
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200423 genpd_acquire_lock(genpd);
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200424 pm_genpd_poweroff(genpd);
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200425 genpd_release_lock(genpd);
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200426}
427
428/**
429 * pm_genpd_runtime_suspend - Suspend a device belonging to I/O PM domain.
430 * @dev: Device to suspend.
431 *
432 * Carry out a runtime suspend of a device under the assumption that its
433 * pm_domain field points to the domain member of an object of type
434 * struct generic_pm_domain representing a PM domain consisting of I/O devices.
435 */
436static int pm_genpd_runtime_suspend(struct device *dev)
437{
438 struct generic_pm_domain *genpd;
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +0100439 int ret;
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200440
441 dev_dbg(dev, "%s()\n", __func__);
442
Rafael J. Wysocki52480512011-07-01 22:13:10 +0200443 genpd = dev_to_genpd(dev);
444 if (IS_ERR(genpd))
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200445 return -EINVAL;
446
Rafael J. Wysocki0aa2a222011-08-25 15:37:04 +0200447 might_sleep_if(!genpd->dev_irq_safe);
448
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +0100449 ret = genpd_stop_dev(genpd, dev);
450 if (ret)
451 return ret;
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200452
Rafael J. Wysocki0aa2a222011-08-25 15:37:04 +0200453 /*
454 * If power.irq_safe is set, this routine will be run with interrupts
455 * off, so it can't use mutexes.
456 */
457 if (dev->power.irq_safe)
458 return 0;
459
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +0200460 mutex_lock(&genpd->lock);
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200461 genpd->in_progress++;
462 pm_genpd_poweroff(genpd);
463 genpd->in_progress--;
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +0200464 mutex_unlock(&genpd->lock);
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200465
466 return 0;
467}
468
469/**
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200470 * pm_genpd_runtime_resume - Resume a device belonging to I/O PM domain.
471 * @dev: Device to resume.
472 *
473 * Carry out a runtime resume of a device under the assumption that its
474 * pm_domain field points to the domain member of an object of type
475 * struct generic_pm_domain representing a PM domain consisting of I/O devices.
476 */
477static int pm_genpd_runtime_resume(struct device *dev)
478{
479 struct generic_pm_domain *genpd;
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +0200480 DEFINE_WAIT(wait);
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200481 int ret;
482
483 dev_dbg(dev, "%s()\n", __func__);
484
Rafael J. Wysocki52480512011-07-01 22:13:10 +0200485 genpd = dev_to_genpd(dev);
486 if (IS_ERR(genpd))
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200487 return -EINVAL;
488
Rafael J. Wysocki0aa2a222011-08-25 15:37:04 +0200489 might_sleep_if(!genpd->dev_irq_safe);
490
491 /* If power.irq_safe, the PM domain is never powered off. */
492 if (dev->power.irq_safe)
493 goto out;
494
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +0200495 mutex_lock(&genpd->lock);
Rafael J. Wysocki3f241772011-08-08 23:43:29 +0200496 ret = __pm_genpd_poweron(genpd);
497 if (ret) {
498 mutex_unlock(&genpd->lock);
499 return ret;
500 }
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200501 genpd->status = GPD_STATE_BUSY;
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +0200502 genpd->resume_count++;
503 for (;;) {
504 prepare_to_wait(&genpd->status_wait_queue, &wait,
505 TASK_UNINTERRUPTIBLE);
506 /*
507 * If current is the powering off task, we have been called
508 * reentrantly from one of the device callbacks, so we should
509 * not wait.
510 */
511 if (!genpd->poweroff_task || genpd->poweroff_task == current)
512 break;
513 mutex_unlock(&genpd->lock);
514
515 schedule();
516
517 mutex_lock(&genpd->lock);
518 }
519 finish_wait(&genpd->status_wait_queue, &wait);
Rafael J. Wysockicd0ea672011-09-26 20:22:02 +0200520 __pm_genpd_restore_device(dev->power.subsys_data->domain_data, genpd);
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +0200521 genpd->resume_count--;
522 genpd_set_active(genpd);
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200523 wake_up_all(&genpd->status_wait_queue);
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +0200524 mutex_unlock(&genpd->lock);
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200525
Rafael J. Wysocki0aa2a222011-08-25 15:37:04 +0200526 out:
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +0100527 genpd_start_dev(genpd, dev);
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200528
529 return 0;
530}
531
Rafael J. Wysocki17f2ae72011-08-14 13:34:31 +0200532/**
533 * pm_genpd_poweroff_unused - Power off all PM domains with no devices in use.
534 */
535void pm_genpd_poweroff_unused(void)
536{
537 struct generic_pm_domain *genpd;
538
539 mutex_lock(&gpd_list_lock);
540
541 list_for_each_entry(genpd, &gpd_list, gpd_list_node)
542 genpd_queue_power_off_work(genpd);
543
544 mutex_unlock(&gpd_list_lock);
545}
546
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200547#else
548
549static inline void genpd_power_off_work_fn(struct work_struct *work) {}
550
551#define pm_genpd_runtime_suspend NULL
552#define pm_genpd_runtime_resume NULL
553
554#endif /* CONFIG_PM_RUNTIME */
555
Rafael J. Wysocki596ba342011-07-01 22:13:19 +0200556#ifdef CONFIG_PM_SLEEP
557
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +0100558static bool genpd_dev_active_wakeup(struct generic_pm_domain *genpd,
559 struct device *dev)
560{
561 return GENPD_DEV_CALLBACK(genpd, bool, active_wakeup, dev);
562}
563
Rafael J. Wysocki596ba342011-07-01 22:13:19 +0200564/**
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +0200565 * pm_genpd_sync_poweroff - Synchronously power off a PM domain and its masters.
Rafael J. Wysocki596ba342011-07-01 22:13:19 +0200566 * @genpd: PM domain to power off, if possible.
567 *
568 * Check if the given PM domain can be powered off (during system suspend or
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +0200569 * hibernation) and do that if so. Also, in that case propagate to its masters.
Rafael J. Wysocki596ba342011-07-01 22:13:19 +0200570 *
571 * This function is only called in "noirq" stages of system power transitions,
572 * so it need not acquire locks (all of the "noirq" callbacks are executed
573 * sequentially, so it is guaranteed that it will never run twice in parallel).
574 */
575static void pm_genpd_sync_poweroff(struct generic_pm_domain *genpd)
576{
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +0200577 struct gpd_link *link;
Rafael J. Wysocki596ba342011-07-01 22:13:19 +0200578
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200579 if (genpd->status == GPD_STATE_POWER_OFF)
Rafael J. Wysocki596ba342011-07-01 22:13:19 +0200580 return;
581
Rafael J. Wysockic4bb3162011-08-08 23:43:04 +0200582 if (genpd->suspended_count != genpd->device_count
583 || atomic_read(&genpd->sd_count) > 0)
Rafael J. Wysocki596ba342011-07-01 22:13:19 +0200584 return;
585
586 if (genpd->power_off)
587 genpd->power_off(genpd);
588
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200589 genpd->status = GPD_STATE_POWER_OFF;
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +0200590
591 list_for_each_entry(link, &genpd->slave_links, slave_node) {
592 genpd_sd_counter_dec(link->master);
593 pm_genpd_sync_poweroff(link->master);
Rafael J. Wysocki596ba342011-07-01 22:13:19 +0200594 }
595}
596
597/**
Rafael J. Wysocki4ecd6e62011-07-12 00:39:57 +0200598 * resume_needed - Check whether to resume a device before system suspend.
599 * @dev: Device to check.
600 * @genpd: PM domain the device belongs to.
601 *
602 * There are two cases in which a device that can wake up the system from sleep
603 * states should be resumed by pm_genpd_prepare(): (1) if the device is enabled
604 * to wake up the system and it has to remain active for this purpose while the
605 * system is in the sleep state and (2) if the device is not enabled to wake up
606 * the system from sleep states and it generally doesn't generate wakeup signals
607 * by itself (those signals are generated on its behalf by other parts of the
608 * system). In the latter case it may be necessary to reconfigure the device's
609 * wakeup settings during system suspend, because it may have been set up to
610 * signal remote wakeup from the system's working state as needed by runtime PM.
611 * Return 'true' in either of the above cases.
612 */
613static bool resume_needed(struct device *dev, struct generic_pm_domain *genpd)
614{
615 bool active_wakeup;
616
617 if (!device_can_wakeup(dev))
618 return false;
619
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +0100620 active_wakeup = genpd_dev_active_wakeup(genpd, dev);
Rafael J. Wysocki4ecd6e62011-07-12 00:39:57 +0200621 return device_may_wakeup(dev) ? active_wakeup : !active_wakeup;
622}
623
624/**
Rafael J. Wysocki596ba342011-07-01 22:13:19 +0200625 * pm_genpd_prepare - Start power transition of a device in a PM domain.
626 * @dev: Device to start the transition of.
627 *
628 * Start a power transition of a device (during a system-wide power transition)
629 * under the assumption that its pm_domain field points to the domain member of
630 * an object of type struct generic_pm_domain representing a PM domain
631 * consisting of I/O devices.
632 */
633static int pm_genpd_prepare(struct device *dev)
634{
635 struct generic_pm_domain *genpd;
Rafael J. Wysockib6c10c82011-07-12 00:39:21 +0200636 int ret;
Rafael J. Wysocki596ba342011-07-01 22:13:19 +0200637
638 dev_dbg(dev, "%s()\n", __func__);
639
640 genpd = dev_to_genpd(dev);
641 if (IS_ERR(genpd))
642 return -EINVAL;
643
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200644 /*
645 * If a wakeup request is pending for the device, it should be woken up
646 * at this point and a system wakeup event should be reported if it's
647 * set up to wake up the system from sleep states.
648 */
649 pm_runtime_get_noresume(dev);
650 if (pm_runtime_barrier(dev) && device_may_wakeup(dev))
651 pm_wakeup_event(dev, 0);
652
653 if (pm_wakeup_pending()) {
654 pm_runtime_put_sync(dev);
655 return -EBUSY;
656 }
657
Rafael J. Wysocki4ecd6e62011-07-12 00:39:57 +0200658 if (resume_needed(dev, genpd))
659 pm_runtime_resume(dev);
660
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200661 genpd_acquire_lock(genpd);
Rafael J. Wysocki596ba342011-07-01 22:13:19 +0200662
663 if (genpd->prepared_count++ == 0)
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200664 genpd->suspend_power_off = genpd->status == GPD_STATE_POWER_OFF;
665
666 genpd_release_lock(genpd);
Rafael J. Wysocki596ba342011-07-01 22:13:19 +0200667
668 if (genpd->suspend_power_off) {
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200669 pm_runtime_put_noidle(dev);
Rafael J. Wysocki596ba342011-07-01 22:13:19 +0200670 return 0;
671 }
672
673 /*
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200674 * The PM domain must be in the GPD_STATE_ACTIVE state at this point,
675 * so pm_genpd_poweron() will return immediately, but if the device
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +0100676 * is suspended (e.g. it's been stopped by genpd_stop_dev()), we need
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200677 * to make it operational.
Rafael J. Wysocki596ba342011-07-01 22:13:19 +0200678 */
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200679 pm_runtime_resume(dev);
Rafael J. Wysocki596ba342011-07-01 22:13:19 +0200680 __pm_runtime_disable(dev, false);
681
Rafael J. Wysockib6c10c82011-07-12 00:39:21 +0200682 ret = pm_generic_prepare(dev);
683 if (ret) {
684 mutex_lock(&genpd->lock);
685
686 if (--genpd->prepared_count == 0)
687 genpd->suspend_power_off = false;
688
689 mutex_unlock(&genpd->lock);
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200690 pm_runtime_enable(dev);
Rafael J. Wysockib6c10c82011-07-12 00:39:21 +0200691 }
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +0200692
693 pm_runtime_put_sync(dev);
Rafael J. Wysockib6c10c82011-07-12 00:39:21 +0200694 return ret;
Rafael J. Wysocki596ba342011-07-01 22:13:19 +0200695}
696
697/**
698 * pm_genpd_suspend - Suspend a device belonging to an I/O PM domain.
699 * @dev: Device to suspend.
700 *
701 * Suspend a device under the assumption that its pm_domain field points to the
702 * domain member of an object of type struct generic_pm_domain representing
703 * a PM domain consisting of I/O devices.
704 */
705static int pm_genpd_suspend(struct device *dev)
706{
707 struct generic_pm_domain *genpd;
708
709 dev_dbg(dev, "%s()\n", __func__);
710
711 genpd = dev_to_genpd(dev);
712 if (IS_ERR(genpd))
713 return -EINVAL;
714
715 return genpd->suspend_power_off ? 0 : pm_generic_suspend(dev);
716}
717
718/**
719 * pm_genpd_suspend_noirq - Late suspend of a device from an I/O PM domain.
720 * @dev: Device to suspend.
721 *
722 * Carry out a late suspend of a device under the assumption that its
723 * pm_domain field points to the domain member of an object of type
724 * struct generic_pm_domain representing a PM domain consisting of I/O devices.
725 */
726static int pm_genpd_suspend_noirq(struct device *dev)
727{
728 struct generic_pm_domain *genpd;
729 int ret;
730
731 dev_dbg(dev, "%s()\n", __func__);
732
733 genpd = dev_to_genpd(dev);
734 if (IS_ERR(genpd))
735 return -EINVAL;
736
737 if (genpd->suspend_power_off)
738 return 0;
739
740 ret = pm_generic_suspend_noirq(dev);
741 if (ret)
742 return ret;
743
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +0100744 if (dev->power.wakeup_path && genpd_dev_active_wakeup(genpd, dev))
Rafael J. Wysockid4f2d872011-07-01 22:13:29 +0200745 return 0;
746
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +0100747 genpd_stop_dev(genpd, dev);
Rafael J. Wysocki596ba342011-07-01 22:13:19 +0200748
749 /*
750 * Since all of the "noirq" callbacks are executed sequentially, it is
751 * guaranteed that this function will never run twice in parallel for
752 * the same PM domain, so it is not necessary to use locking here.
753 */
754 genpd->suspended_count++;
755 pm_genpd_sync_poweroff(genpd);
756
757 return 0;
758}
759
760/**
761 * pm_genpd_resume_noirq - Early resume of a device from an I/O power domain.
762 * @dev: Device to resume.
763 *
764 * Carry out an early resume of a device under the assumption that its
765 * pm_domain field points to the domain member of an object of type
766 * struct generic_pm_domain representing a power domain consisting of I/O
767 * devices.
768 */
769static int pm_genpd_resume_noirq(struct device *dev)
770{
771 struct generic_pm_domain *genpd;
772
773 dev_dbg(dev, "%s()\n", __func__);
774
775 genpd = dev_to_genpd(dev);
776 if (IS_ERR(genpd))
777 return -EINVAL;
778
779 if (genpd->suspend_power_off)
780 return 0;
781
782 /*
783 * Since all of the "noirq" callbacks are executed sequentially, it is
784 * guaranteed that this function will never run twice in parallel for
785 * the same PM domain, so it is not necessary to use locking here.
786 */
787 pm_genpd_poweron(genpd);
788 genpd->suspended_count--;
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +0100789 genpd_start_dev(genpd, dev);
Rafael J. Wysocki596ba342011-07-01 22:13:19 +0200790
791 return pm_generic_resume_noirq(dev);
792}
793
794/**
795 * pm_genpd_resume - Resume a device belonging to an I/O power domain.
796 * @dev: Device to resume.
797 *
798 * Resume a device under the assumption that its pm_domain field points to the
799 * domain member of an object of type struct generic_pm_domain representing
800 * a power domain consisting of I/O devices.
801 */
802static int pm_genpd_resume(struct device *dev)
803{
804 struct generic_pm_domain *genpd;
805
806 dev_dbg(dev, "%s()\n", __func__);
807
808 genpd = dev_to_genpd(dev);
809 if (IS_ERR(genpd))
810 return -EINVAL;
811
812 return genpd->suspend_power_off ? 0 : pm_generic_resume(dev);
813}
814
815/**
816 * pm_genpd_freeze - Freeze a device belonging to an I/O power domain.
817 * @dev: Device to freeze.
818 *
819 * Freeze a device under the assumption that its pm_domain field points to the
820 * domain member of an object of type struct generic_pm_domain representing
821 * a power domain consisting of I/O devices.
822 */
823static int pm_genpd_freeze(struct device *dev)
824{
825 struct generic_pm_domain *genpd;
826
827 dev_dbg(dev, "%s()\n", __func__);
828
829 genpd = dev_to_genpd(dev);
830 if (IS_ERR(genpd))
831 return -EINVAL;
832
833 return genpd->suspend_power_off ? 0 : pm_generic_freeze(dev);
834}
835
836/**
837 * pm_genpd_freeze_noirq - Late freeze of a device from an I/O power domain.
838 * @dev: Device to freeze.
839 *
840 * Carry out a late freeze of a device under the assumption that its
841 * pm_domain field points to the domain member of an object of type
842 * struct generic_pm_domain representing a power domain consisting of I/O
843 * devices.
844 */
845static int pm_genpd_freeze_noirq(struct device *dev)
846{
847 struct generic_pm_domain *genpd;
848 int ret;
849
850 dev_dbg(dev, "%s()\n", __func__);
851
852 genpd = dev_to_genpd(dev);
853 if (IS_ERR(genpd))
854 return -EINVAL;
855
856 if (genpd->suspend_power_off)
857 return 0;
858
859 ret = pm_generic_freeze_noirq(dev);
860 if (ret)
861 return ret;
862
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +0100863 genpd_stop_dev(genpd, dev);
Rafael J. Wysocki596ba342011-07-01 22:13:19 +0200864
865 return 0;
866}
867
868/**
869 * pm_genpd_thaw_noirq - Early thaw of a device from an I/O power domain.
870 * @dev: Device to thaw.
871 *
872 * Carry out an early thaw of a device under the assumption that its
873 * pm_domain field points to the domain member of an object of type
874 * struct generic_pm_domain representing a power domain consisting of I/O
875 * devices.
876 */
877static int pm_genpd_thaw_noirq(struct device *dev)
878{
879 struct generic_pm_domain *genpd;
880
881 dev_dbg(dev, "%s()\n", __func__);
882
883 genpd = dev_to_genpd(dev);
884 if (IS_ERR(genpd))
885 return -EINVAL;
886
887 if (genpd->suspend_power_off)
888 return 0;
889
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +0100890 genpd_start_dev(genpd, dev);
Rafael J. Wysocki596ba342011-07-01 22:13:19 +0200891
892 return pm_generic_thaw_noirq(dev);
893}
894
895/**
896 * pm_genpd_thaw - Thaw a device belonging to an I/O power domain.
897 * @dev: Device to thaw.
898 *
899 * Thaw a device under the assumption that its pm_domain field points to the
900 * domain member of an object of type struct generic_pm_domain representing
901 * a power domain consisting of I/O devices.
902 */
903static int pm_genpd_thaw(struct device *dev)
904{
905 struct generic_pm_domain *genpd;
906
907 dev_dbg(dev, "%s()\n", __func__);
908
909 genpd = dev_to_genpd(dev);
910 if (IS_ERR(genpd))
911 return -EINVAL;
912
913 return genpd->suspend_power_off ? 0 : pm_generic_thaw(dev);
914}
915
916/**
917 * pm_genpd_dev_poweroff - Power off a device belonging to an I/O PM domain.
918 * @dev: Device to suspend.
919 *
920 * Power off a device under the assumption that its pm_domain field points to
921 * the domain member of an object of type struct generic_pm_domain representing
922 * a PM domain consisting of I/O devices.
923 */
924static int pm_genpd_dev_poweroff(struct device *dev)
925{
926 struct generic_pm_domain *genpd;
927
928 dev_dbg(dev, "%s()\n", __func__);
929
930 genpd = dev_to_genpd(dev);
931 if (IS_ERR(genpd))
932 return -EINVAL;
933
934 return genpd->suspend_power_off ? 0 : pm_generic_poweroff(dev);
935}
936
937/**
938 * pm_genpd_dev_poweroff_noirq - Late power off of a device from a PM domain.
939 * @dev: Device to suspend.
940 *
941 * Carry out a late powering off of a device under the assumption that its
942 * pm_domain field points to the domain member of an object of type
943 * struct generic_pm_domain representing a PM domain consisting of I/O devices.
944 */
945static int pm_genpd_dev_poweroff_noirq(struct device *dev)
946{
947 struct generic_pm_domain *genpd;
948 int ret;
949
950 dev_dbg(dev, "%s()\n", __func__);
951
952 genpd = dev_to_genpd(dev);
953 if (IS_ERR(genpd))
954 return -EINVAL;
955
956 if (genpd->suspend_power_off)
957 return 0;
958
959 ret = pm_generic_poweroff_noirq(dev);
960 if (ret)
961 return ret;
962
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +0100963 if (dev->power.wakeup_path && genpd_dev_active_wakeup(genpd, dev))
Rafael J. Wysockid4f2d872011-07-01 22:13:29 +0200964 return 0;
965
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +0100966 genpd_stop_dev(genpd, dev);
Rafael J. Wysocki596ba342011-07-01 22:13:19 +0200967
968 /*
969 * Since all of the "noirq" callbacks are executed sequentially, it is
970 * guaranteed that this function will never run twice in parallel for
971 * the same PM domain, so it is not necessary to use locking here.
972 */
973 genpd->suspended_count++;
974 pm_genpd_sync_poweroff(genpd);
975
976 return 0;
977}
978
979/**
980 * pm_genpd_restore_noirq - Early restore of a device from an I/O power domain.
981 * @dev: Device to resume.
982 *
983 * Carry out an early restore of a device under the assumption that its
984 * pm_domain field points to the domain member of an object of type
985 * struct generic_pm_domain representing a power domain consisting of I/O
986 * devices.
987 */
988static int pm_genpd_restore_noirq(struct device *dev)
989{
990 struct generic_pm_domain *genpd;
991
992 dev_dbg(dev, "%s()\n", __func__);
993
994 genpd = dev_to_genpd(dev);
995 if (IS_ERR(genpd))
996 return -EINVAL;
997
998 /*
999 * Since all of the "noirq" callbacks are executed sequentially, it is
1000 * guaranteed that this function will never run twice in parallel for
1001 * the same PM domain, so it is not necessary to use locking here.
1002 */
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +02001003 genpd->status = GPD_STATE_POWER_OFF;
Rafael J. Wysocki596ba342011-07-01 22:13:19 +02001004 if (genpd->suspend_power_off) {
1005 /*
1006 * The boot kernel might put the domain into the power on state,
1007 * so make sure it really is powered off.
1008 */
1009 if (genpd->power_off)
1010 genpd->power_off(genpd);
1011 return 0;
1012 }
1013
1014 pm_genpd_poweron(genpd);
1015 genpd->suspended_count--;
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +01001016 genpd_start_dev(genpd, dev);
Rafael J. Wysocki596ba342011-07-01 22:13:19 +02001017
1018 return pm_generic_restore_noirq(dev);
1019}
1020
1021/**
1022 * pm_genpd_restore - Restore a device belonging to an I/O power domain.
1023 * @dev: Device to resume.
1024 *
1025 * Restore a device under the assumption that its pm_domain field points to the
1026 * domain member of an object of type struct generic_pm_domain representing
1027 * a power domain consisting of I/O devices.
1028 */
1029static int pm_genpd_restore(struct device *dev)
1030{
1031 struct generic_pm_domain *genpd;
1032
1033 dev_dbg(dev, "%s()\n", __func__);
1034
1035 genpd = dev_to_genpd(dev);
1036 if (IS_ERR(genpd))
1037 return -EINVAL;
1038
1039 return genpd->suspend_power_off ? 0 : pm_generic_restore(dev);
1040}
1041
1042/**
1043 * pm_genpd_complete - Complete power transition of a device in a power domain.
1044 * @dev: Device to complete the transition of.
1045 *
1046 * Complete a power transition of a device (during a system-wide power
1047 * transition) under the assumption that its pm_domain field points to the
1048 * domain member of an object of type struct generic_pm_domain representing
1049 * a power domain consisting of I/O devices.
1050 */
1051static void pm_genpd_complete(struct device *dev)
1052{
1053 struct generic_pm_domain *genpd;
1054 bool run_complete;
1055
1056 dev_dbg(dev, "%s()\n", __func__);
1057
1058 genpd = dev_to_genpd(dev);
1059 if (IS_ERR(genpd))
1060 return;
1061
1062 mutex_lock(&genpd->lock);
1063
1064 run_complete = !genpd->suspend_power_off;
1065 if (--genpd->prepared_count == 0)
1066 genpd->suspend_power_off = false;
1067
1068 mutex_unlock(&genpd->lock);
1069
1070 if (run_complete) {
1071 pm_generic_complete(dev);
Rafael J. Wysocki6f00ff72011-07-12 00:39:10 +02001072 pm_runtime_set_active(dev);
Rafael J. Wysocki596ba342011-07-01 22:13:19 +02001073 pm_runtime_enable(dev);
Rafael J. Wysocki6f00ff72011-07-12 00:39:10 +02001074 pm_runtime_idle(dev);
Rafael J. Wysocki596ba342011-07-01 22:13:19 +02001075 }
1076}
1077
1078#else
1079
1080#define pm_genpd_prepare NULL
1081#define pm_genpd_suspend NULL
1082#define pm_genpd_suspend_noirq NULL
1083#define pm_genpd_resume_noirq NULL
1084#define pm_genpd_resume NULL
1085#define pm_genpd_freeze NULL
1086#define pm_genpd_freeze_noirq NULL
1087#define pm_genpd_thaw_noirq NULL
1088#define pm_genpd_thaw NULL
1089#define pm_genpd_dev_poweroff_noirq NULL
1090#define pm_genpd_dev_poweroff NULL
1091#define pm_genpd_restore_noirq NULL
1092#define pm_genpd_restore NULL
1093#define pm_genpd_complete NULL
1094
1095#endif /* CONFIG_PM_SLEEP */
1096
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001097/**
1098 * pm_genpd_add_device - Add a device to an I/O PM domain.
1099 * @genpd: PM domain to add the device to.
1100 * @dev: Device to be added.
1101 */
1102int pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev)
1103{
Rafael J. Wysockicd0ea672011-09-26 20:22:02 +02001104 struct generic_pm_domain_data *gpd_data;
Rafael J. Wysocki4605ab62011-08-25 15:34:12 +02001105 struct pm_domain_data *pdd;
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001106 int ret = 0;
1107
1108 dev_dbg(dev, "%s()\n", __func__);
1109
1110 if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(dev))
1111 return -EINVAL;
1112
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +02001113 genpd_acquire_lock(genpd);
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001114
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +02001115 if (genpd->status == GPD_STATE_POWER_OFF) {
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001116 ret = -EINVAL;
1117 goto out;
1118 }
1119
Rafael J. Wysocki596ba342011-07-01 22:13:19 +02001120 if (genpd->prepared_count > 0) {
1121 ret = -EAGAIN;
1122 goto out;
1123 }
1124
Rafael J. Wysocki4605ab62011-08-25 15:34:12 +02001125 list_for_each_entry(pdd, &genpd->dev_list, list_node)
1126 if (pdd->dev == dev) {
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001127 ret = -EINVAL;
1128 goto out;
1129 }
1130
Rafael J. Wysockicd0ea672011-09-26 20:22:02 +02001131 gpd_data = kzalloc(sizeof(*gpd_data), GFP_KERNEL);
1132 if (!gpd_data) {
1133 ret = -ENOMEM;
1134 goto out;
1135 }
1136
Rafael J. Wysocki596ba342011-07-01 22:13:19 +02001137 genpd->device_count++;
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001138
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001139 dev->pm_domain = &genpd->domain;
Rafael J. Wysocki4605ab62011-08-25 15:34:12 +02001140 dev_pm_get_subsys_data(dev);
Rafael J. Wysockicd0ea672011-09-26 20:22:02 +02001141 dev->power.subsys_data->domain_data = &gpd_data->base;
1142 gpd_data->base.dev = dev;
1143 gpd_data->need_restore = false;
1144 list_add_tail(&gpd_data->base.list_node, &genpd->dev_list);
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001145
1146 out:
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +02001147 genpd_release_lock(genpd);
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001148
1149 return ret;
1150}
1151
1152/**
1153 * pm_genpd_remove_device - Remove a device from an I/O PM domain.
1154 * @genpd: PM domain to remove the device from.
1155 * @dev: Device to be removed.
1156 */
1157int pm_genpd_remove_device(struct generic_pm_domain *genpd,
1158 struct device *dev)
1159{
Rafael J. Wysocki4605ab62011-08-25 15:34:12 +02001160 struct pm_domain_data *pdd;
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001161 int ret = -EINVAL;
1162
1163 dev_dbg(dev, "%s()\n", __func__);
1164
1165 if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(dev))
1166 return -EINVAL;
1167
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +02001168 genpd_acquire_lock(genpd);
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001169
Rafael J. Wysocki596ba342011-07-01 22:13:19 +02001170 if (genpd->prepared_count > 0) {
1171 ret = -EAGAIN;
1172 goto out;
1173 }
1174
Rafael J. Wysocki4605ab62011-08-25 15:34:12 +02001175 list_for_each_entry(pdd, &genpd->dev_list, list_node) {
1176 if (pdd->dev != dev)
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001177 continue;
1178
Rafael J. Wysocki4605ab62011-08-25 15:34:12 +02001179 list_del_init(&pdd->list_node);
1180 pdd->dev = NULL;
1181 dev_pm_put_subsys_data(dev);
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001182 dev->pm_domain = NULL;
Rafael J. Wysockicd0ea672011-09-26 20:22:02 +02001183 kfree(to_gpd_data(pdd));
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001184
Rafael J. Wysocki596ba342011-07-01 22:13:19 +02001185 genpd->device_count--;
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001186
1187 ret = 0;
1188 break;
1189 }
1190
Rafael J. Wysocki596ba342011-07-01 22:13:19 +02001191 out:
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +02001192 genpd_release_lock(genpd);
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001193
1194 return ret;
1195}
1196
1197/**
1198 * pm_genpd_add_subdomain - Add a subdomain to an I/O PM domain.
1199 * @genpd: Master PM domain to add the subdomain to.
Rafael J. Wysockibc0403f2011-08-08 23:43:59 +02001200 * @subdomain: Subdomain to be added.
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001201 */
1202int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
Rafael J. Wysockibc0403f2011-08-08 23:43:59 +02001203 struct generic_pm_domain *subdomain)
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001204{
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +02001205 struct gpd_link *link;
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001206 int ret = 0;
1207
Rafael J. Wysockibc0403f2011-08-08 23:43:59 +02001208 if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(subdomain))
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001209 return -EINVAL;
1210
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +02001211 start:
1212 genpd_acquire_lock(genpd);
Rafael J. Wysockibc0403f2011-08-08 23:43:59 +02001213 mutex_lock_nested(&subdomain->lock, SINGLE_DEPTH_NESTING);
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001214
Rafael J. Wysockibc0403f2011-08-08 23:43:59 +02001215 if (subdomain->status != GPD_STATE_POWER_OFF
1216 && subdomain->status != GPD_STATE_ACTIVE) {
1217 mutex_unlock(&subdomain->lock);
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +02001218 genpd_release_lock(genpd);
1219 goto start;
1220 }
1221
1222 if (genpd->status == GPD_STATE_POWER_OFF
Rafael J. Wysockibc0403f2011-08-08 23:43:59 +02001223 && subdomain->status != GPD_STATE_POWER_OFF) {
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001224 ret = -EINVAL;
1225 goto out;
1226 }
1227
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +02001228 list_for_each_entry(link, &genpd->slave_links, slave_node) {
Rafael J. Wysockibc0403f2011-08-08 23:43:59 +02001229 if (link->slave == subdomain && link->master == genpd) {
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001230 ret = -EINVAL;
1231 goto out;
1232 }
1233 }
1234
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +02001235 link = kzalloc(sizeof(*link), GFP_KERNEL);
1236 if (!link) {
1237 ret = -ENOMEM;
1238 goto out;
1239 }
1240 link->master = genpd;
1241 list_add_tail(&link->master_node, &genpd->master_links);
Rafael J. Wysockibc0403f2011-08-08 23:43:59 +02001242 link->slave = subdomain;
1243 list_add_tail(&link->slave_node, &subdomain->slave_links);
1244 if (subdomain->status != GPD_STATE_POWER_OFF)
Rafael J. Wysockic4bb3162011-08-08 23:43:04 +02001245 genpd_sd_counter_inc(genpd);
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001246
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001247 out:
Rafael J. Wysockibc0403f2011-08-08 23:43:59 +02001248 mutex_unlock(&subdomain->lock);
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +02001249 genpd_release_lock(genpd);
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001250
1251 return ret;
1252}
1253
1254/**
1255 * pm_genpd_remove_subdomain - Remove a subdomain from an I/O PM domain.
1256 * @genpd: Master PM domain to remove the subdomain from.
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +02001257 * @subdomain: Subdomain to be removed.
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001258 */
1259int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +02001260 struct generic_pm_domain *subdomain)
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001261{
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +02001262 struct gpd_link *link;
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001263 int ret = -EINVAL;
1264
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +02001265 if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(subdomain))
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001266 return -EINVAL;
1267
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +02001268 start:
1269 genpd_acquire_lock(genpd);
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001270
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +02001271 list_for_each_entry(link, &genpd->master_links, master_node) {
1272 if (link->slave != subdomain)
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001273 continue;
1274
1275 mutex_lock_nested(&subdomain->lock, SINGLE_DEPTH_NESTING);
1276
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +02001277 if (subdomain->status != GPD_STATE_POWER_OFF
1278 && subdomain->status != GPD_STATE_ACTIVE) {
1279 mutex_unlock(&subdomain->lock);
1280 genpd_release_lock(genpd);
1281 goto start;
1282 }
1283
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +02001284 list_del(&link->master_node);
1285 list_del(&link->slave_node);
1286 kfree(link);
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +02001287 if (subdomain->status != GPD_STATE_POWER_OFF)
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001288 genpd_sd_counter_dec(genpd);
1289
1290 mutex_unlock(&subdomain->lock);
1291
1292 ret = 0;
1293 break;
1294 }
1295
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +02001296 genpd_release_lock(genpd);
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001297
1298 return ret;
1299}
1300
1301/**
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +01001302 * pm_genpd_add_callbacks - Add PM domain callbacks to a given device.
1303 * @dev: Device to add the callbacks to.
1304 * @ops: Set of callbacks to add.
1305 */
1306int pm_genpd_add_callbacks(struct device *dev, struct gpd_dev_ops *ops)
1307{
1308 struct pm_domain_data *pdd;
1309 int ret = 0;
1310
1311 if (!(dev && dev->power.subsys_data && ops))
1312 return -EINVAL;
1313
1314 pm_runtime_disable(dev);
1315 device_pm_lock();
1316
1317 pdd = dev->power.subsys_data->domain_data;
1318 if (pdd) {
1319 struct generic_pm_domain_data *gpd_data = to_gpd_data(pdd);
1320
1321 gpd_data->ops = *ops;
1322 } else {
1323 ret = -EINVAL;
1324 }
1325
1326 device_pm_unlock();
1327 pm_runtime_enable(dev);
1328
1329 return ret;
1330}
1331EXPORT_SYMBOL_GPL(pm_genpd_add_callbacks);
1332
1333/**
1334 * pm_genpd_remove_callbacks - Remove PM domain callbacks from a given device.
1335 * @dev: Device to remove the callbacks from.
1336 */
1337int pm_genpd_remove_callbacks(struct device *dev)
1338{
1339 struct pm_domain_data *pdd;
1340 int ret = 0;
1341
1342 if (!(dev && dev->power.subsys_data))
1343 return -EINVAL;
1344
1345 pm_runtime_disable(dev);
1346 device_pm_lock();
1347
1348 pdd = dev->power.subsys_data->domain_data;
1349 if (pdd) {
1350 struct generic_pm_domain_data *gpd_data = to_gpd_data(pdd);
1351
1352 gpd_data->ops = (struct gpd_dev_ops){ 0 };
1353 } else {
1354 ret = -EINVAL;
1355 }
1356
1357 device_pm_unlock();
1358 pm_runtime_enable(dev);
1359
1360 return ret;
1361}
1362EXPORT_SYMBOL_GPL(pm_genpd_remove_callbacks);
1363
1364/**
Rafael J. Wysockiecf00472011-11-27 13:11:44 +01001365 * pm_genpd_default_save_state - Default "save device state" for PM domians.
1366 * @dev: Device to handle.
1367 */
1368static int pm_genpd_default_save_state(struct device *dev)
1369{
1370 int (*cb)(struct device *__dev);
1371 struct device_driver *drv = dev->driver;
1372
1373 cb = dev_gpd_data(dev)->ops.save_state;
1374 if (cb)
1375 return cb(dev);
1376
1377 if (drv && drv->pm && drv->pm->runtime_suspend)
1378 return drv->pm->runtime_suspend(dev);
1379
1380 return 0;
1381}
1382
1383/**
1384 * pm_genpd_default_restore_state - Default PM domians "restore device state".
1385 * @dev: Device to handle.
1386 */
1387static int pm_genpd_default_restore_state(struct device *dev)
1388{
1389 int (*cb)(struct device *__dev);
1390 struct device_driver *drv = dev->driver;
1391
1392 cb = dev_gpd_data(dev)->ops.restore_state;
1393 if (cb)
1394 return cb(dev);
1395
1396 if (drv && drv->pm && drv->pm->runtime_resume)
1397 return drv->pm->runtime_resume(dev);
1398
1399 return 0;
1400}
1401
1402/**
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001403 * pm_genpd_init - Initialize a generic I/O PM domain object.
1404 * @genpd: PM domain object to initialize.
1405 * @gov: PM domain governor to associate with the domain (may be NULL).
1406 * @is_off: Initial value of the domain's power_is_off field.
1407 */
1408void pm_genpd_init(struct generic_pm_domain *genpd,
1409 struct dev_power_governor *gov, bool is_off)
1410{
1411 if (IS_ERR_OR_NULL(genpd))
1412 return;
1413
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +02001414 INIT_LIST_HEAD(&genpd->master_links);
1415 INIT_LIST_HEAD(&genpd->slave_links);
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001416 INIT_LIST_HEAD(&genpd->dev_list);
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001417 mutex_init(&genpd->lock);
1418 genpd->gov = gov;
1419 INIT_WORK(&genpd->power_off_work, genpd_power_off_work_fn);
1420 genpd->in_progress = 0;
Rafael J. Wysockic4bb3162011-08-08 23:43:04 +02001421 atomic_set(&genpd->sd_count, 0);
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +02001422 genpd->status = is_off ? GPD_STATE_POWER_OFF : GPD_STATE_ACTIVE;
1423 init_waitqueue_head(&genpd->status_wait_queue);
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +02001424 genpd->poweroff_task = NULL;
1425 genpd->resume_count = 0;
Rafael J. Wysocki596ba342011-07-01 22:13:19 +02001426 genpd->device_count = 0;
1427 genpd->suspended_count = 0;
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001428 genpd->domain.ops.runtime_suspend = pm_genpd_runtime_suspend;
1429 genpd->domain.ops.runtime_resume = pm_genpd_runtime_resume;
1430 genpd->domain.ops.runtime_idle = pm_generic_runtime_idle;
Rafael J. Wysocki596ba342011-07-01 22:13:19 +02001431 genpd->domain.ops.prepare = pm_genpd_prepare;
1432 genpd->domain.ops.suspend = pm_genpd_suspend;
1433 genpd->domain.ops.suspend_noirq = pm_genpd_suspend_noirq;
1434 genpd->domain.ops.resume_noirq = pm_genpd_resume_noirq;
1435 genpd->domain.ops.resume = pm_genpd_resume;
1436 genpd->domain.ops.freeze = pm_genpd_freeze;
1437 genpd->domain.ops.freeze_noirq = pm_genpd_freeze_noirq;
1438 genpd->domain.ops.thaw_noirq = pm_genpd_thaw_noirq;
1439 genpd->domain.ops.thaw = pm_genpd_thaw;
1440 genpd->domain.ops.poweroff = pm_genpd_dev_poweroff;
1441 genpd->domain.ops.poweroff_noirq = pm_genpd_dev_poweroff_noirq;
1442 genpd->domain.ops.restore_noirq = pm_genpd_restore_noirq;
1443 genpd->domain.ops.restore = pm_genpd_restore;
1444 genpd->domain.ops.complete = pm_genpd_complete;
Rafael J. Wysockiecf00472011-11-27 13:11:44 +01001445 genpd->dev_ops.save_state = pm_genpd_default_save_state;
1446 genpd->dev_ops.restore_state = pm_genpd_default_restore_state;
Rafael J. Wysocki5125bbf382011-07-13 12:31:52 +02001447 mutex_lock(&gpd_list_lock);
1448 list_add(&genpd->gpd_list_node, &gpd_list);
1449 mutex_unlock(&gpd_list_lock);
1450}