i2c-eg20t: change timeout value 50msec to 1000msec
[zen-stable.git] / drivers / base / power / domain.c
blob58c8b4def2f74ff6157ab7d45268a09d713333b4
1 /*
2 * drivers/base/power/domain.c - Common code related to device power domains.
4 * Copyright (C) 2011 Rafael J. Wysocki <rjw@sisk.pl>, Renesas Electronics Corp.
6 * This file is released under the GPLv2.
7 */
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>
16 #include <linux/sched.h>
17 #include <linux/suspend.h>
18 #include <linux/export.h>
20 #define GENPD_DEV_CALLBACK(genpd, type, callback, dev) \
21 ({ \
22 type (*__routine)(struct device *__d); \
23 type __ret = (type)0; \
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; \
36 #define GENPD_DEV_TIMED_CALLBACK(genpd, type, callback, dev, field, name) \
37 ({ \
38 ktime_t __start = ktime_get(); \
39 type __retval = GENPD_DEV_CALLBACK(genpd, type, callback, dev); \
40 s64 __elapsed = ktime_to_ns(ktime_sub(ktime_get(), __start)); \
41 struct generic_pm_domain_data *__gpd_data = dev_gpd_data(dev); \
42 if (__elapsed > __gpd_data->td.field) { \
43 __gpd_data->td.field = __elapsed; \
44 dev_warn(dev, name " latency exceeded, new value %lld ns\n", \
45 __elapsed); \
46 } \
47 __retval; \
50 static LIST_HEAD(gpd_list);
51 static DEFINE_MUTEX(gpd_list_lock);
53 #ifdef CONFIG_PM
55 struct generic_pm_domain *dev_to_genpd(struct device *dev)
57 if (IS_ERR_OR_NULL(dev->pm_domain))
58 return ERR_PTR(-EINVAL);
60 return pd_to_genpd(dev->pm_domain);
63 static int genpd_stop_dev(struct generic_pm_domain *genpd, struct device *dev)
65 return GENPD_DEV_TIMED_CALLBACK(genpd, int, stop, dev,
66 stop_latency_ns, "stop");
69 static int genpd_start_dev(struct generic_pm_domain *genpd, struct device *dev)
71 return GENPD_DEV_TIMED_CALLBACK(genpd, int, start, dev,
72 start_latency_ns, "start");
75 static int genpd_save_dev(struct generic_pm_domain *genpd, struct device *dev)
77 return GENPD_DEV_TIMED_CALLBACK(genpd, int, save_state, dev,
78 save_state_latency_ns, "state save");
81 static int genpd_restore_dev(struct generic_pm_domain *genpd, struct device *dev)
83 return GENPD_DEV_TIMED_CALLBACK(genpd, int, restore_state, dev,
84 restore_state_latency_ns,
85 "state restore");
88 static bool genpd_sd_counter_dec(struct generic_pm_domain *genpd)
90 bool ret = false;
92 if (!WARN_ON(atomic_read(&genpd->sd_count) == 0))
93 ret = !!atomic_dec_and_test(&genpd->sd_count);
95 return ret;
98 static void genpd_sd_counter_inc(struct generic_pm_domain *genpd)
100 atomic_inc(&genpd->sd_count);
101 smp_mb__after_atomic_inc();
104 static void genpd_acquire_lock(struct generic_pm_domain *genpd)
106 DEFINE_WAIT(wait);
108 mutex_lock(&genpd->lock);
110 * Wait for the domain to transition into either the active,
111 * or the power off state.
113 for (;;) {
114 prepare_to_wait(&genpd->status_wait_queue, &wait,
115 TASK_UNINTERRUPTIBLE);
116 if (genpd->status == GPD_STATE_ACTIVE
117 || genpd->status == GPD_STATE_POWER_OFF)
118 break;
119 mutex_unlock(&genpd->lock);
121 schedule();
123 mutex_lock(&genpd->lock);
125 finish_wait(&genpd->status_wait_queue, &wait);
128 static void genpd_release_lock(struct generic_pm_domain *genpd)
130 mutex_unlock(&genpd->lock);
133 static void genpd_set_active(struct generic_pm_domain *genpd)
135 if (genpd->resume_count == 0)
136 genpd->status = GPD_STATE_ACTIVE;
140 * __pm_genpd_poweron - Restore power to a given PM domain and its masters.
141 * @genpd: PM domain to power up.
143 * Restore power to @genpd and all of its masters so that it is possible to
144 * resume a device belonging to it.
146 int __pm_genpd_poweron(struct generic_pm_domain *genpd)
147 __releases(&genpd->lock) __acquires(&genpd->lock)
149 struct gpd_link *link;
150 DEFINE_WAIT(wait);
151 int ret = 0;
153 /* If the domain's master is being waited for, we have to wait too. */
154 for (;;) {
155 prepare_to_wait(&genpd->status_wait_queue, &wait,
156 TASK_UNINTERRUPTIBLE);
157 if (genpd->status != GPD_STATE_WAIT_MASTER)
158 break;
159 mutex_unlock(&genpd->lock);
161 schedule();
163 mutex_lock(&genpd->lock);
165 finish_wait(&genpd->status_wait_queue, &wait);
167 if (genpd->status == GPD_STATE_ACTIVE
168 || (genpd->prepared_count > 0 && genpd->suspend_power_off))
169 return 0;
171 if (genpd->status != GPD_STATE_POWER_OFF) {
172 genpd_set_active(genpd);
173 return 0;
177 * The list is guaranteed not to change while the loop below is being
178 * executed, unless one of the masters' .power_on() callbacks fiddles
179 * with it.
181 list_for_each_entry(link, &genpd->slave_links, slave_node) {
182 genpd_sd_counter_inc(link->master);
183 genpd->status = GPD_STATE_WAIT_MASTER;
185 mutex_unlock(&genpd->lock);
187 ret = pm_genpd_poweron(link->master);
189 mutex_lock(&genpd->lock);
192 * The "wait for parent" status is guaranteed not to change
193 * while the master is powering on.
195 genpd->status = GPD_STATE_POWER_OFF;
196 wake_up_all(&genpd->status_wait_queue);
197 if (ret) {
198 genpd_sd_counter_dec(link->master);
199 goto err;
203 if (genpd->power_on) {
204 ktime_t time_start = ktime_get();
205 s64 elapsed_ns;
207 ret = genpd->power_on(genpd);
208 if (ret)
209 goto err;
211 elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start));
212 if (elapsed_ns > genpd->power_on_latency_ns) {
213 genpd->power_on_latency_ns = elapsed_ns;
214 if (genpd->name)
215 pr_warning("%s: Power-on latency exceeded, "
216 "new value %lld ns\n", genpd->name,
217 elapsed_ns);
221 genpd_set_active(genpd);
223 return 0;
225 err:
226 list_for_each_entry_continue_reverse(link, &genpd->slave_links, slave_node)
227 genpd_sd_counter_dec(link->master);
229 return ret;
233 * pm_genpd_poweron - Restore power to a given PM domain and its masters.
234 * @genpd: PM domain to power up.
236 int pm_genpd_poweron(struct generic_pm_domain *genpd)
238 int ret;
240 mutex_lock(&genpd->lock);
241 ret = __pm_genpd_poweron(genpd);
242 mutex_unlock(&genpd->lock);
243 return ret;
246 #endif /* CONFIG_PM */
248 #ifdef CONFIG_PM_RUNTIME
251 * __pm_genpd_save_device - Save the pre-suspend state of a device.
252 * @pdd: Domain data of the device to save the state of.
253 * @genpd: PM domain the device belongs to.
255 static int __pm_genpd_save_device(struct pm_domain_data *pdd,
256 struct generic_pm_domain *genpd)
257 __releases(&genpd->lock) __acquires(&genpd->lock)
259 struct generic_pm_domain_data *gpd_data = to_gpd_data(pdd);
260 struct device *dev = pdd->dev;
261 int ret = 0;
263 if (gpd_data->need_restore)
264 return 0;
266 mutex_unlock(&genpd->lock);
268 genpd_start_dev(genpd, dev);
269 ret = genpd_save_dev(genpd, dev);
270 genpd_stop_dev(genpd, dev);
272 mutex_lock(&genpd->lock);
274 if (!ret)
275 gpd_data->need_restore = true;
277 return ret;
281 * __pm_genpd_restore_device - Restore the pre-suspend state of a device.
282 * @pdd: Domain data of the device to restore the state of.
283 * @genpd: PM domain the device belongs to.
285 static void __pm_genpd_restore_device(struct pm_domain_data *pdd,
286 struct generic_pm_domain *genpd)
287 __releases(&genpd->lock) __acquires(&genpd->lock)
289 struct generic_pm_domain_data *gpd_data = to_gpd_data(pdd);
290 struct device *dev = pdd->dev;
292 if (!gpd_data->need_restore)
293 return;
295 mutex_unlock(&genpd->lock);
297 genpd_start_dev(genpd, dev);
298 genpd_restore_dev(genpd, dev);
299 genpd_stop_dev(genpd, dev);
301 mutex_lock(&genpd->lock);
303 gpd_data->need_restore = false;
307 * genpd_abort_poweroff - Check if a PM domain power off should be aborted.
308 * @genpd: PM domain to check.
310 * Return true if a PM domain's status changed to GPD_STATE_ACTIVE during
311 * a "power off" operation, which means that a "power on" has occured in the
312 * meantime, or if its resume_count field is different from zero, which means
313 * that one of its devices has been resumed in the meantime.
315 static bool genpd_abort_poweroff(struct generic_pm_domain *genpd)
317 return genpd->status == GPD_STATE_WAIT_MASTER
318 || genpd->status == GPD_STATE_ACTIVE || genpd->resume_count > 0;
322 * genpd_queue_power_off_work - Queue up the execution of pm_genpd_poweroff().
323 * @genpd: PM domait to power off.
325 * Queue up the execution of pm_genpd_poweroff() unless it's already been done
326 * before.
328 void genpd_queue_power_off_work(struct generic_pm_domain *genpd)
330 if (!work_pending(&genpd->power_off_work))
331 queue_work(pm_wq, &genpd->power_off_work);
335 * pm_genpd_poweroff - Remove power from a given PM domain.
336 * @genpd: PM domain to power down.
338 * If all of the @genpd's devices have been suspended and all of its subdomains
339 * have been powered down, run the runtime suspend callbacks provided by all of
340 * the @genpd's devices' drivers and remove power from @genpd.
342 static int pm_genpd_poweroff(struct generic_pm_domain *genpd)
343 __releases(&genpd->lock) __acquires(&genpd->lock)
345 struct pm_domain_data *pdd;
346 struct gpd_link *link;
347 unsigned int not_suspended;
348 int ret = 0;
350 start:
352 * Do not try to power off the domain in the following situations:
353 * (1) The domain is already in the "power off" state.
354 * (2) The domain is waiting for its master to power up.
355 * (3) One of the domain's devices is being resumed right now.
356 * (4) System suspend is in progress.
358 if (genpd->status == GPD_STATE_POWER_OFF
359 || genpd->status == GPD_STATE_WAIT_MASTER
360 || genpd->resume_count > 0 || genpd->prepared_count > 0)
361 return 0;
363 if (atomic_read(&genpd->sd_count) > 0)
364 return -EBUSY;
366 not_suspended = 0;
367 list_for_each_entry(pdd, &genpd->dev_list, list_node)
368 if (pdd->dev->driver && (!pm_runtime_suspended(pdd->dev)
369 || pdd->dev->power.irq_safe || to_gpd_data(pdd)->always_on))
370 not_suspended++;
372 if (not_suspended > genpd->in_progress)
373 return -EBUSY;
375 if (genpd->poweroff_task) {
377 * Another instance of pm_genpd_poweroff() is executing
378 * callbacks, so tell it to start over and return.
380 genpd->status = GPD_STATE_REPEAT;
381 return 0;
384 if (genpd->gov && genpd->gov->power_down_ok) {
385 if (!genpd->gov->power_down_ok(&genpd->domain))
386 return -EAGAIN;
389 genpd->status = GPD_STATE_BUSY;
390 genpd->poweroff_task = current;
392 list_for_each_entry_reverse(pdd, &genpd->dev_list, list_node) {
393 ret = atomic_read(&genpd->sd_count) == 0 ?
394 __pm_genpd_save_device(pdd, genpd) : -EBUSY;
396 if (genpd_abort_poweroff(genpd))
397 goto out;
399 if (ret) {
400 genpd_set_active(genpd);
401 goto out;
404 if (genpd->status == GPD_STATE_REPEAT) {
405 genpd->poweroff_task = NULL;
406 goto start;
410 if (genpd->power_off) {
411 ktime_t time_start;
412 s64 elapsed_ns;
414 if (atomic_read(&genpd->sd_count) > 0) {
415 ret = -EBUSY;
416 goto out;
419 time_start = ktime_get();
422 * If sd_count > 0 at this point, one of the subdomains hasn't
423 * managed to call pm_genpd_poweron() for the master yet after
424 * incrementing it. In that case pm_genpd_poweron() will wait
425 * for us to drop the lock, so we can call .power_off() and let
426 * the pm_genpd_poweron() restore power for us (this shouldn't
427 * happen very often).
429 ret = genpd->power_off(genpd);
430 if (ret == -EBUSY) {
431 genpd_set_active(genpd);
432 goto out;
435 elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start));
436 if (elapsed_ns > genpd->power_off_latency_ns) {
437 genpd->power_off_latency_ns = elapsed_ns;
438 if (genpd->name)
439 pr_warning("%s: Power-off latency exceeded, "
440 "new value %lld ns\n", genpd->name,
441 elapsed_ns);
445 genpd->status = GPD_STATE_POWER_OFF;
446 genpd->power_off_time = ktime_get();
448 /* Update PM QoS information for devices in the domain. */
449 list_for_each_entry_reverse(pdd, &genpd->dev_list, list_node) {
450 struct gpd_timing_data *td = &to_gpd_data(pdd)->td;
452 pm_runtime_update_max_time_suspended(pdd->dev,
453 td->start_latency_ns +
454 td->restore_state_latency_ns +
455 genpd->power_on_latency_ns);
458 list_for_each_entry(link, &genpd->slave_links, slave_node) {
459 genpd_sd_counter_dec(link->master);
460 genpd_queue_power_off_work(link->master);
463 out:
464 genpd->poweroff_task = NULL;
465 wake_up_all(&genpd->status_wait_queue);
466 return ret;
470 * genpd_power_off_work_fn - Power off PM domain whose subdomain count is 0.
471 * @work: Work structure used for scheduling the execution of this function.
473 static void genpd_power_off_work_fn(struct work_struct *work)
475 struct generic_pm_domain *genpd;
477 genpd = container_of(work, struct generic_pm_domain, power_off_work);
479 genpd_acquire_lock(genpd);
480 pm_genpd_poweroff(genpd);
481 genpd_release_lock(genpd);
485 * pm_genpd_runtime_suspend - Suspend a device belonging to I/O PM domain.
486 * @dev: Device to suspend.
488 * Carry out a runtime suspend of a device under the assumption that its
489 * pm_domain field points to the domain member of an object of type
490 * struct generic_pm_domain representing a PM domain consisting of I/O devices.
492 static int pm_genpd_runtime_suspend(struct device *dev)
494 struct generic_pm_domain *genpd;
495 bool (*stop_ok)(struct device *__dev);
496 int ret;
498 dev_dbg(dev, "%s()\n", __func__);
500 genpd = dev_to_genpd(dev);
501 if (IS_ERR(genpd))
502 return -EINVAL;
504 might_sleep_if(!genpd->dev_irq_safe);
506 if (dev_gpd_data(dev)->always_on)
507 return -EBUSY;
509 stop_ok = genpd->gov ? genpd->gov->stop_ok : NULL;
510 if (stop_ok && !stop_ok(dev))
511 return -EBUSY;
513 ret = genpd_stop_dev(genpd, dev);
514 if (ret)
515 return ret;
517 pm_runtime_update_max_time_suspended(dev,
518 dev_gpd_data(dev)->td.start_latency_ns);
521 * If power.irq_safe is set, this routine will be run with interrupts
522 * off, so it can't use mutexes.
524 if (dev->power.irq_safe)
525 return 0;
527 mutex_lock(&genpd->lock);
528 genpd->in_progress++;
529 pm_genpd_poweroff(genpd);
530 genpd->in_progress--;
531 mutex_unlock(&genpd->lock);
533 return 0;
537 * pm_genpd_runtime_resume - Resume a device belonging to I/O PM domain.
538 * @dev: Device to resume.
540 * Carry out a runtime resume of a device under the assumption that its
541 * pm_domain field points to the domain member of an object of type
542 * struct generic_pm_domain representing a PM domain consisting of I/O devices.
544 static int pm_genpd_runtime_resume(struct device *dev)
546 struct generic_pm_domain *genpd;
547 DEFINE_WAIT(wait);
548 int ret;
550 dev_dbg(dev, "%s()\n", __func__);
552 genpd = dev_to_genpd(dev);
553 if (IS_ERR(genpd))
554 return -EINVAL;
556 might_sleep_if(!genpd->dev_irq_safe);
558 /* If power.irq_safe, the PM domain is never powered off. */
559 if (dev->power.irq_safe)
560 goto out;
562 mutex_lock(&genpd->lock);
563 ret = __pm_genpd_poweron(genpd);
564 if (ret) {
565 mutex_unlock(&genpd->lock);
566 return ret;
568 genpd->status = GPD_STATE_BUSY;
569 genpd->resume_count++;
570 for (;;) {
571 prepare_to_wait(&genpd->status_wait_queue, &wait,
572 TASK_UNINTERRUPTIBLE);
574 * If current is the powering off task, we have been called
575 * reentrantly from one of the device callbacks, so we should
576 * not wait.
578 if (!genpd->poweroff_task || genpd->poweroff_task == current)
579 break;
580 mutex_unlock(&genpd->lock);
582 schedule();
584 mutex_lock(&genpd->lock);
586 finish_wait(&genpd->status_wait_queue, &wait);
587 __pm_genpd_restore_device(dev->power.subsys_data->domain_data, genpd);
588 genpd->resume_count--;
589 genpd_set_active(genpd);
590 wake_up_all(&genpd->status_wait_queue);
591 mutex_unlock(&genpd->lock);
593 out:
594 genpd_start_dev(genpd, dev);
596 return 0;
600 * pm_genpd_poweroff_unused - Power off all PM domains with no devices in use.
602 void pm_genpd_poweroff_unused(void)
604 struct generic_pm_domain *genpd;
606 mutex_lock(&gpd_list_lock);
608 list_for_each_entry(genpd, &gpd_list, gpd_list_node)
609 genpd_queue_power_off_work(genpd);
611 mutex_unlock(&gpd_list_lock);
614 #else
616 static inline void genpd_power_off_work_fn(struct work_struct *work) {}
618 #define pm_genpd_runtime_suspend NULL
619 #define pm_genpd_runtime_resume NULL
621 #endif /* CONFIG_PM_RUNTIME */
623 #ifdef CONFIG_PM_SLEEP
625 static bool genpd_dev_active_wakeup(struct generic_pm_domain *genpd,
626 struct device *dev)
628 return GENPD_DEV_CALLBACK(genpd, bool, active_wakeup, dev);
631 static int genpd_suspend_dev(struct generic_pm_domain *genpd, struct device *dev)
633 return GENPD_DEV_CALLBACK(genpd, int, suspend, dev);
636 static int genpd_suspend_late(struct generic_pm_domain *genpd, struct device *dev)
638 return GENPD_DEV_CALLBACK(genpd, int, suspend_late, dev);
641 static int genpd_resume_early(struct generic_pm_domain *genpd, struct device *dev)
643 return GENPD_DEV_CALLBACK(genpd, int, resume_early, dev);
646 static int genpd_resume_dev(struct generic_pm_domain *genpd, struct device *dev)
648 return GENPD_DEV_CALLBACK(genpd, int, resume, dev);
651 static int genpd_freeze_dev(struct generic_pm_domain *genpd, struct device *dev)
653 return GENPD_DEV_CALLBACK(genpd, int, freeze, dev);
656 static int genpd_freeze_late(struct generic_pm_domain *genpd, struct device *dev)
658 return GENPD_DEV_CALLBACK(genpd, int, freeze_late, dev);
661 static int genpd_thaw_early(struct generic_pm_domain *genpd, struct device *dev)
663 return GENPD_DEV_CALLBACK(genpd, int, thaw_early, dev);
666 static int genpd_thaw_dev(struct generic_pm_domain *genpd, struct device *dev)
668 return GENPD_DEV_CALLBACK(genpd, int, thaw, dev);
672 * pm_genpd_sync_poweroff - Synchronously power off a PM domain and its masters.
673 * @genpd: PM domain to power off, if possible.
675 * Check if the given PM domain can be powered off (during system suspend or
676 * hibernation) and do that if so. Also, in that case propagate to its masters.
678 * This function is only called in "noirq" stages of system power transitions,
679 * so it need not acquire locks (all of the "noirq" callbacks are executed
680 * sequentially, so it is guaranteed that it will never run twice in parallel).
682 static void pm_genpd_sync_poweroff(struct generic_pm_domain *genpd)
684 struct gpd_link *link;
686 if (genpd->status == GPD_STATE_POWER_OFF)
687 return;
689 if (genpd->suspended_count != genpd->device_count
690 || atomic_read(&genpd->sd_count) > 0)
691 return;
693 if (genpd->power_off)
694 genpd->power_off(genpd);
696 genpd->status = GPD_STATE_POWER_OFF;
698 list_for_each_entry(link, &genpd->slave_links, slave_node) {
699 genpd_sd_counter_dec(link->master);
700 pm_genpd_sync_poweroff(link->master);
705 * resume_needed - Check whether to resume a device before system suspend.
706 * @dev: Device to check.
707 * @genpd: PM domain the device belongs to.
709 * There are two cases in which a device that can wake up the system from sleep
710 * states should be resumed by pm_genpd_prepare(): (1) if the device is enabled
711 * to wake up the system and it has to remain active for this purpose while the
712 * system is in the sleep state and (2) if the device is not enabled to wake up
713 * the system from sleep states and it generally doesn't generate wakeup signals
714 * by itself (those signals are generated on its behalf by other parts of the
715 * system). In the latter case it may be necessary to reconfigure the device's
716 * wakeup settings during system suspend, because it may have been set up to
717 * signal remote wakeup from the system's working state as needed by runtime PM.
718 * Return 'true' in either of the above cases.
720 static bool resume_needed(struct device *dev, struct generic_pm_domain *genpd)
722 bool active_wakeup;
724 if (!device_can_wakeup(dev))
725 return false;
727 active_wakeup = genpd_dev_active_wakeup(genpd, dev);
728 return device_may_wakeup(dev) ? active_wakeup : !active_wakeup;
732 * pm_genpd_prepare - Start power transition of a device in a PM domain.
733 * @dev: Device to start the transition of.
735 * Start a power transition of a device (during a system-wide power transition)
736 * under the assumption that its pm_domain field points to the domain member of
737 * an object of type struct generic_pm_domain representing a PM domain
738 * consisting of I/O devices.
740 static int pm_genpd_prepare(struct device *dev)
742 struct generic_pm_domain *genpd;
743 int ret;
745 dev_dbg(dev, "%s()\n", __func__);
747 genpd = dev_to_genpd(dev);
748 if (IS_ERR(genpd))
749 return -EINVAL;
752 * If a wakeup request is pending for the device, it should be woken up
753 * at this point and a system wakeup event should be reported if it's
754 * set up to wake up the system from sleep states.
756 pm_runtime_get_noresume(dev);
757 if (pm_runtime_barrier(dev) && device_may_wakeup(dev))
758 pm_wakeup_event(dev, 0);
760 if (pm_wakeup_pending()) {
761 pm_runtime_put_sync(dev);
762 return -EBUSY;
765 if (resume_needed(dev, genpd))
766 pm_runtime_resume(dev);
768 genpd_acquire_lock(genpd);
770 if (genpd->prepared_count++ == 0) {
771 genpd->suspended_count = 0;
772 genpd->suspend_power_off = genpd->status == GPD_STATE_POWER_OFF;
775 genpd_release_lock(genpd);
777 if (genpd->suspend_power_off) {
778 pm_runtime_put_noidle(dev);
779 return 0;
783 * The PM domain must be in the GPD_STATE_ACTIVE state at this point,
784 * so pm_genpd_poweron() will return immediately, but if the device
785 * is suspended (e.g. it's been stopped by genpd_stop_dev()), we need
786 * to make it operational.
788 pm_runtime_resume(dev);
789 __pm_runtime_disable(dev, false);
791 ret = pm_generic_prepare(dev);
792 if (ret) {
793 mutex_lock(&genpd->lock);
795 if (--genpd->prepared_count == 0)
796 genpd->suspend_power_off = false;
798 mutex_unlock(&genpd->lock);
799 pm_runtime_enable(dev);
802 pm_runtime_put_sync(dev);
803 return ret;
807 * pm_genpd_suspend - Suspend a device belonging to an I/O PM domain.
808 * @dev: Device to suspend.
810 * Suspend a device under the assumption that its pm_domain field points to the
811 * domain member of an object of type struct generic_pm_domain representing
812 * a PM domain consisting of I/O devices.
814 static int pm_genpd_suspend(struct device *dev)
816 struct generic_pm_domain *genpd;
818 dev_dbg(dev, "%s()\n", __func__);
820 genpd = dev_to_genpd(dev);
821 if (IS_ERR(genpd))
822 return -EINVAL;
824 return genpd->suspend_power_off ? 0 : genpd_suspend_dev(genpd, dev);
828 * pm_genpd_suspend_noirq - Late suspend of a device from an I/O PM domain.
829 * @dev: Device to suspend.
831 * Carry out a late suspend of a device under the assumption that its
832 * pm_domain field points to the domain member of an object of type
833 * struct generic_pm_domain representing a PM domain consisting of I/O devices.
835 static int pm_genpd_suspend_noirq(struct device *dev)
837 struct generic_pm_domain *genpd;
838 int ret;
840 dev_dbg(dev, "%s()\n", __func__);
842 genpd = dev_to_genpd(dev);
843 if (IS_ERR(genpd))
844 return -EINVAL;
846 if (genpd->suspend_power_off)
847 return 0;
849 ret = genpd_suspend_late(genpd, dev);
850 if (ret)
851 return ret;
853 if (dev_gpd_data(dev)->always_on
854 || (dev->power.wakeup_path && genpd_dev_active_wakeup(genpd, dev)))
855 return 0;
857 genpd_stop_dev(genpd, dev);
860 * Since all of the "noirq" callbacks are executed sequentially, it is
861 * guaranteed that this function will never run twice in parallel for
862 * the same PM domain, so it is not necessary to use locking here.
864 genpd->suspended_count++;
865 pm_genpd_sync_poweroff(genpd);
867 return 0;
871 * pm_genpd_resume_noirq - Early resume of a device from an I/O power domain.
872 * @dev: Device to resume.
874 * Carry out an early resume of a device under the assumption that its
875 * pm_domain field points to the domain member of an object of type
876 * struct generic_pm_domain representing a power domain consisting of I/O
877 * devices.
879 static int pm_genpd_resume_noirq(struct device *dev)
881 struct generic_pm_domain *genpd;
883 dev_dbg(dev, "%s()\n", __func__);
885 genpd = dev_to_genpd(dev);
886 if (IS_ERR(genpd))
887 return -EINVAL;
889 if (genpd->suspend_power_off || dev_gpd_data(dev)->always_on
890 || (dev->power.wakeup_path && genpd_dev_active_wakeup(genpd, dev)))
891 return 0;
894 * Since all of the "noirq" callbacks are executed sequentially, it is
895 * guaranteed that this function will never run twice in parallel for
896 * the same PM domain, so it is not necessary to use locking here.
898 pm_genpd_poweron(genpd);
899 genpd->suspended_count--;
900 genpd_start_dev(genpd, dev);
902 return genpd_resume_early(genpd, dev);
906 * pm_genpd_resume - Resume a device belonging to an I/O power domain.
907 * @dev: Device to resume.
909 * Resume a device under the assumption that its pm_domain field points to the
910 * domain member of an object of type struct generic_pm_domain representing
911 * a power domain consisting of I/O devices.
913 static int pm_genpd_resume(struct device *dev)
915 struct generic_pm_domain *genpd;
917 dev_dbg(dev, "%s()\n", __func__);
919 genpd = dev_to_genpd(dev);
920 if (IS_ERR(genpd))
921 return -EINVAL;
923 return genpd->suspend_power_off ? 0 : genpd_resume_dev(genpd, dev);
927 * pm_genpd_freeze - Freeze a device belonging to an I/O power domain.
928 * @dev: Device to freeze.
930 * Freeze a device under the assumption that its pm_domain field points to the
931 * domain member of an object of type struct generic_pm_domain representing
932 * a power domain consisting of I/O devices.
934 static int pm_genpd_freeze(struct device *dev)
936 struct generic_pm_domain *genpd;
938 dev_dbg(dev, "%s()\n", __func__);
940 genpd = dev_to_genpd(dev);
941 if (IS_ERR(genpd))
942 return -EINVAL;
944 return genpd->suspend_power_off ? 0 : genpd_freeze_dev(genpd, dev);
948 * pm_genpd_freeze_noirq - Late freeze of a device from an I/O power domain.
949 * @dev: Device to freeze.
951 * Carry out a late freeze of a device under the assumption that its
952 * pm_domain field points to the domain member of an object of type
953 * struct generic_pm_domain representing a power domain consisting of I/O
954 * devices.
956 static int pm_genpd_freeze_noirq(struct device *dev)
958 struct generic_pm_domain *genpd;
959 int ret;
961 dev_dbg(dev, "%s()\n", __func__);
963 genpd = dev_to_genpd(dev);
964 if (IS_ERR(genpd))
965 return -EINVAL;
967 if (genpd->suspend_power_off || dev_gpd_data(dev)->always_on)
968 return 0;
970 ret = genpd_freeze_late(genpd, dev);
971 if (ret)
972 return ret;
974 genpd_stop_dev(genpd, dev);
976 return 0;
980 * pm_genpd_thaw_noirq - Early thaw of a device from an I/O power domain.
981 * @dev: Device to thaw.
983 * Carry out an early thaw 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.
988 static int pm_genpd_thaw_noirq(struct device *dev)
990 struct generic_pm_domain *genpd;
992 dev_dbg(dev, "%s()\n", __func__);
994 genpd = dev_to_genpd(dev);
995 if (IS_ERR(genpd))
996 return -EINVAL;
998 if (genpd->suspend_power_off || dev_gpd_data(dev)->always_on)
999 return 0;
1001 genpd_start_dev(genpd, dev);
1003 return genpd_thaw_early(genpd, dev);
1007 * pm_genpd_thaw - Thaw a device belonging to an I/O power domain.
1008 * @dev: Device to thaw.
1010 * Thaw a device under the assumption that its pm_domain field points to the
1011 * domain member of an object of type struct generic_pm_domain representing
1012 * a power domain consisting of I/O devices.
1014 static int pm_genpd_thaw(struct device *dev)
1016 struct generic_pm_domain *genpd;
1018 dev_dbg(dev, "%s()\n", __func__);
1020 genpd = dev_to_genpd(dev);
1021 if (IS_ERR(genpd))
1022 return -EINVAL;
1024 return genpd->suspend_power_off ? 0 : genpd_thaw_dev(genpd, dev);
1028 * pm_genpd_restore_noirq - Early restore of a device from an I/O power domain.
1029 * @dev: Device to resume.
1031 * Carry out an early restore of a device under the assumption that its
1032 * pm_domain field points to the domain member of an object of type
1033 * struct generic_pm_domain representing a power domain consisting of I/O
1034 * devices.
1036 static int pm_genpd_restore_noirq(struct device *dev)
1038 struct generic_pm_domain *genpd;
1040 dev_dbg(dev, "%s()\n", __func__);
1042 genpd = dev_to_genpd(dev);
1043 if (IS_ERR(genpd))
1044 return -EINVAL;
1047 * Since all of the "noirq" callbacks are executed sequentially, it is
1048 * guaranteed that this function will never run twice in parallel for
1049 * the same PM domain, so it is not necessary to use locking here.
1051 * At this point suspended_count == 0 means we are being run for the
1052 * first time for the given domain in the present cycle.
1054 if (genpd->suspended_count++ == 0) {
1056 * The boot kernel might put the domain into arbitrary state,
1057 * so make it appear as powered off to pm_genpd_poweron(), so
1058 * that it tries to power it on in case it was really off.
1060 genpd->status = GPD_STATE_POWER_OFF;
1061 if (genpd->suspend_power_off) {
1063 * If the domain was off before the hibernation, make
1064 * sure it will be off going forward.
1066 if (genpd->power_off)
1067 genpd->power_off(genpd);
1071 if (genpd->suspend_power_off || dev_gpd_data(dev)->always_on)
1072 return 0;
1074 pm_genpd_poweron(genpd);
1075 genpd_start_dev(genpd, dev);
1077 return genpd_resume_early(genpd, dev);
1081 * pm_genpd_complete - Complete power transition of a device in a power domain.
1082 * @dev: Device to complete the transition of.
1084 * Complete a power transition of a device (during a system-wide power
1085 * transition) under the assumption that its pm_domain field points to the
1086 * domain member of an object of type struct generic_pm_domain representing
1087 * a power domain consisting of I/O devices.
1089 static void pm_genpd_complete(struct device *dev)
1091 struct generic_pm_domain *genpd;
1092 bool run_complete;
1094 dev_dbg(dev, "%s()\n", __func__);
1096 genpd = dev_to_genpd(dev);
1097 if (IS_ERR(genpd))
1098 return;
1100 mutex_lock(&genpd->lock);
1102 run_complete = !genpd->suspend_power_off;
1103 if (--genpd->prepared_count == 0)
1104 genpd->suspend_power_off = false;
1106 mutex_unlock(&genpd->lock);
1108 if (run_complete) {
1109 pm_generic_complete(dev);
1110 pm_runtime_set_active(dev);
1111 pm_runtime_enable(dev);
1112 pm_runtime_idle(dev);
1116 #else
1118 #define pm_genpd_prepare NULL
1119 #define pm_genpd_suspend NULL
1120 #define pm_genpd_suspend_noirq NULL
1121 #define pm_genpd_resume_noirq NULL
1122 #define pm_genpd_resume NULL
1123 #define pm_genpd_freeze NULL
1124 #define pm_genpd_freeze_noirq NULL
1125 #define pm_genpd_thaw_noirq NULL
1126 #define pm_genpd_thaw NULL
1127 #define pm_genpd_restore_noirq NULL
1128 #define pm_genpd_complete NULL
1130 #endif /* CONFIG_PM_SLEEP */
1133 * __pm_genpd_add_device - Add a device to an I/O PM domain.
1134 * @genpd: PM domain to add the device to.
1135 * @dev: Device to be added.
1136 * @td: Set of PM QoS timing parameters to attach to the device.
1138 int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev,
1139 struct gpd_timing_data *td)
1141 struct generic_pm_domain_data *gpd_data;
1142 struct pm_domain_data *pdd;
1143 int ret = 0;
1145 dev_dbg(dev, "%s()\n", __func__);
1147 if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(dev))
1148 return -EINVAL;
1150 genpd_acquire_lock(genpd);
1152 if (genpd->status == GPD_STATE_POWER_OFF) {
1153 ret = -EINVAL;
1154 goto out;
1157 if (genpd->prepared_count > 0) {
1158 ret = -EAGAIN;
1159 goto out;
1162 list_for_each_entry(pdd, &genpd->dev_list, list_node)
1163 if (pdd->dev == dev) {
1164 ret = -EINVAL;
1165 goto out;
1168 gpd_data = kzalloc(sizeof(*gpd_data), GFP_KERNEL);
1169 if (!gpd_data) {
1170 ret = -ENOMEM;
1171 goto out;
1174 genpd->device_count++;
1176 dev->pm_domain = &genpd->domain;
1177 dev_pm_get_subsys_data(dev);
1178 dev->power.subsys_data->domain_data = &gpd_data->base;
1179 gpd_data->base.dev = dev;
1180 gpd_data->need_restore = false;
1181 list_add_tail(&gpd_data->base.list_node, &genpd->dev_list);
1182 if (td)
1183 gpd_data->td = *td;
1185 out:
1186 genpd_release_lock(genpd);
1188 return ret;
1192 * pm_genpd_remove_device - Remove a device from an I/O PM domain.
1193 * @genpd: PM domain to remove the device from.
1194 * @dev: Device to be removed.
1196 int pm_genpd_remove_device(struct generic_pm_domain *genpd,
1197 struct device *dev)
1199 struct pm_domain_data *pdd;
1200 int ret = -EINVAL;
1202 dev_dbg(dev, "%s()\n", __func__);
1204 if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(dev))
1205 return -EINVAL;
1207 genpd_acquire_lock(genpd);
1209 if (genpd->prepared_count > 0) {
1210 ret = -EAGAIN;
1211 goto out;
1214 list_for_each_entry(pdd, &genpd->dev_list, list_node) {
1215 if (pdd->dev != dev)
1216 continue;
1218 list_del_init(&pdd->list_node);
1219 pdd->dev = NULL;
1220 dev_pm_put_subsys_data(dev);
1221 dev->pm_domain = NULL;
1222 kfree(to_gpd_data(pdd));
1224 genpd->device_count--;
1226 ret = 0;
1227 break;
1230 out:
1231 genpd_release_lock(genpd);
1233 return ret;
1237 * pm_genpd_dev_always_on - Set/unset the "always on" flag for a given device.
1238 * @dev: Device to set/unset the flag for.
1239 * @val: The new value of the device's "always on" flag.
1241 void pm_genpd_dev_always_on(struct device *dev, bool val)
1243 struct pm_subsys_data *psd;
1244 unsigned long flags;
1246 spin_lock_irqsave(&dev->power.lock, flags);
1248 psd = dev_to_psd(dev);
1249 if (psd && psd->domain_data)
1250 to_gpd_data(psd->domain_data)->always_on = val;
1252 spin_unlock_irqrestore(&dev->power.lock, flags);
1254 EXPORT_SYMBOL_GPL(pm_genpd_dev_always_on);
1257 * pm_genpd_add_subdomain - Add a subdomain to an I/O PM domain.
1258 * @genpd: Master PM domain to add the subdomain to.
1259 * @subdomain: Subdomain to be added.
1261 int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
1262 struct generic_pm_domain *subdomain)
1264 struct gpd_link *link;
1265 int ret = 0;
1267 if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(subdomain))
1268 return -EINVAL;
1270 start:
1271 genpd_acquire_lock(genpd);
1272 mutex_lock_nested(&subdomain->lock, SINGLE_DEPTH_NESTING);
1274 if (subdomain->status != GPD_STATE_POWER_OFF
1275 && subdomain->status != GPD_STATE_ACTIVE) {
1276 mutex_unlock(&subdomain->lock);
1277 genpd_release_lock(genpd);
1278 goto start;
1281 if (genpd->status == GPD_STATE_POWER_OFF
1282 && subdomain->status != GPD_STATE_POWER_OFF) {
1283 ret = -EINVAL;
1284 goto out;
1287 list_for_each_entry(link, &genpd->slave_links, slave_node) {
1288 if (link->slave == subdomain && link->master == genpd) {
1289 ret = -EINVAL;
1290 goto out;
1294 link = kzalloc(sizeof(*link), GFP_KERNEL);
1295 if (!link) {
1296 ret = -ENOMEM;
1297 goto out;
1299 link->master = genpd;
1300 list_add_tail(&link->master_node, &genpd->master_links);
1301 link->slave = subdomain;
1302 list_add_tail(&link->slave_node, &subdomain->slave_links);
1303 if (subdomain->status != GPD_STATE_POWER_OFF)
1304 genpd_sd_counter_inc(genpd);
1306 out:
1307 mutex_unlock(&subdomain->lock);
1308 genpd_release_lock(genpd);
1310 return ret;
1314 * pm_genpd_remove_subdomain - Remove a subdomain from an I/O PM domain.
1315 * @genpd: Master PM domain to remove the subdomain from.
1316 * @subdomain: Subdomain to be removed.
1318 int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
1319 struct generic_pm_domain *subdomain)
1321 struct gpd_link *link;
1322 int ret = -EINVAL;
1324 if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(subdomain))
1325 return -EINVAL;
1327 start:
1328 genpd_acquire_lock(genpd);
1330 list_for_each_entry(link, &genpd->master_links, master_node) {
1331 if (link->slave != subdomain)
1332 continue;
1334 mutex_lock_nested(&subdomain->lock, SINGLE_DEPTH_NESTING);
1336 if (subdomain->status != GPD_STATE_POWER_OFF
1337 && subdomain->status != GPD_STATE_ACTIVE) {
1338 mutex_unlock(&subdomain->lock);
1339 genpd_release_lock(genpd);
1340 goto start;
1343 list_del(&link->master_node);
1344 list_del(&link->slave_node);
1345 kfree(link);
1346 if (subdomain->status != GPD_STATE_POWER_OFF)
1347 genpd_sd_counter_dec(genpd);
1349 mutex_unlock(&subdomain->lock);
1351 ret = 0;
1352 break;
1355 genpd_release_lock(genpd);
1357 return ret;
1361 * pm_genpd_add_callbacks - Add PM domain callbacks to a given device.
1362 * @dev: Device to add the callbacks to.
1363 * @ops: Set of callbacks to add.
1364 * @td: Timing data to add to the device along with the callbacks (optional).
1366 int pm_genpd_add_callbacks(struct device *dev, struct gpd_dev_ops *ops,
1367 struct gpd_timing_data *td)
1369 struct pm_domain_data *pdd;
1370 int ret = 0;
1372 if (!(dev && dev->power.subsys_data && ops))
1373 return -EINVAL;
1375 pm_runtime_disable(dev);
1376 device_pm_lock();
1378 pdd = dev->power.subsys_data->domain_data;
1379 if (pdd) {
1380 struct generic_pm_domain_data *gpd_data = to_gpd_data(pdd);
1382 gpd_data->ops = *ops;
1383 if (td)
1384 gpd_data->td = *td;
1385 } else {
1386 ret = -EINVAL;
1389 device_pm_unlock();
1390 pm_runtime_enable(dev);
1392 return ret;
1394 EXPORT_SYMBOL_GPL(pm_genpd_add_callbacks);
1397 * __pm_genpd_remove_callbacks - Remove PM domain callbacks from a given device.
1398 * @dev: Device to remove the callbacks from.
1399 * @clear_td: If set, clear the device's timing data too.
1401 int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
1403 struct pm_domain_data *pdd;
1404 int ret = 0;
1406 if (!(dev && dev->power.subsys_data))
1407 return -EINVAL;
1409 pm_runtime_disable(dev);
1410 device_pm_lock();
1412 pdd = dev->power.subsys_data->domain_data;
1413 if (pdd) {
1414 struct generic_pm_domain_data *gpd_data = to_gpd_data(pdd);
1416 gpd_data->ops = (struct gpd_dev_ops){ 0 };
1417 if (clear_td)
1418 gpd_data->td = (struct gpd_timing_data){ 0 };
1419 } else {
1420 ret = -EINVAL;
1423 device_pm_unlock();
1424 pm_runtime_enable(dev);
1426 return ret;
1428 EXPORT_SYMBOL_GPL(__pm_genpd_remove_callbacks);
1430 /* Default device callbacks for generic PM domains. */
1433 * pm_genpd_default_save_state - Default "save device state" for PM domians.
1434 * @dev: Device to handle.
1436 static int pm_genpd_default_save_state(struct device *dev)
1438 int (*cb)(struct device *__dev);
1439 struct device_driver *drv = dev->driver;
1441 cb = dev_gpd_data(dev)->ops.save_state;
1442 if (cb)
1443 return cb(dev);
1445 if (drv && drv->pm && drv->pm->runtime_suspend)
1446 return drv->pm->runtime_suspend(dev);
1448 return 0;
1452 * pm_genpd_default_restore_state - Default PM domians "restore device state".
1453 * @dev: Device to handle.
1455 static int pm_genpd_default_restore_state(struct device *dev)
1457 int (*cb)(struct device *__dev);
1458 struct device_driver *drv = dev->driver;
1460 cb = dev_gpd_data(dev)->ops.restore_state;
1461 if (cb)
1462 return cb(dev);
1464 if (drv && drv->pm && drv->pm->runtime_resume)
1465 return drv->pm->runtime_resume(dev);
1467 return 0;
1470 #ifdef CONFIG_PM_SLEEP
1473 * pm_genpd_default_suspend - Default "device suspend" for PM domians.
1474 * @dev: Device to handle.
1476 static int pm_genpd_default_suspend(struct device *dev)
1478 int (*cb)(struct device *__dev) = dev_gpd_data(dev)->ops.suspend;
1480 return cb ? cb(dev) : pm_generic_suspend(dev);
1484 * pm_genpd_default_suspend_late - Default "late device suspend" for PM domians.
1485 * @dev: Device to handle.
1487 static int pm_genpd_default_suspend_late(struct device *dev)
1489 int (*cb)(struct device *__dev) = dev_gpd_data(dev)->ops.suspend_late;
1491 return cb ? cb(dev) : pm_generic_suspend_noirq(dev);
1495 * pm_genpd_default_resume_early - Default "early device resume" for PM domians.
1496 * @dev: Device to handle.
1498 static int pm_genpd_default_resume_early(struct device *dev)
1500 int (*cb)(struct device *__dev) = dev_gpd_data(dev)->ops.resume_early;
1502 return cb ? cb(dev) : pm_generic_resume_noirq(dev);
1506 * pm_genpd_default_resume - Default "device resume" for PM domians.
1507 * @dev: Device to handle.
1509 static int pm_genpd_default_resume(struct device *dev)
1511 int (*cb)(struct device *__dev) = dev_gpd_data(dev)->ops.resume;
1513 return cb ? cb(dev) : pm_generic_resume(dev);
1517 * pm_genpd_default_freeze - Default "device freeze" for PM domians.
1518 * @dev: Device to handle.
1520 static int pm_genpd_default_freeze(struct device *dev)
1522 int (*cb)(struct device *__dev) = dev_gpd_data(dev)->ops.freeze;
1524 return cb ? cb(dev) : pm_generic_freeze(dev);
1528 * pm_genpd_default_freeze_late - Default "late device freeze" for PM domians.
1529 * @dev: Device to handle.
1531 static int pm_genpd_default_freeze_late(struct device *dev)
1533 int (*cb)(struct device *__dev) = dev_gpd_data(dev)->ops.freeze_late;
1535 return cb ? cb(dev) : pm_generic_freeze_noirq(dev);
1539 * pm_genpd_default_thaw_early - Default "early device thaw" for PM domians.
1540 * @dev: Device to handle.
1542 static int pm_genpd_default_thaw_early(struct device *dev)
1544 int (*cb)(struct device *__dev) = dev_gpd_data(dev)->ops.thaw_early;
1546 return cb ? cb(dev) : pm_generic_thaw_noirq(dev);
1550 * pm_genpd_default_thaw - Default "device thaw" for PM domians.
1551 * @dev: Device to handle.
1553 static int pm_genpd_default_thaw(struct device *dev)
1555 int (*cb)(struct device *__dev) = dev_gpd_data(dev)->ops.thaw;
1557 return cb ? cb(dev) : pm_generic_thaw(dev);
1560 #else /* !CONFIG_PM_SLEEP */
1562 #define pm_genpd_default_suspend NULL
1563 #define pm_genpd_default_suspend_late NULL
1564 #define pm_genpd_default_resume_early NULL
1565 #define pm_genpd_default_resume NULL
1566 #define pm_genpd_default_freeze NULL
1567 #define pm_genpd_default_freeze_late NULL
1568 #define pm_genpd_default_thaw_early NULL
1569 #define pm_genpd_default_thaw NULL
1571 #endif /* !CONFIG_PM_SLEEP */
1574 * pm_genpd_init - Initialize a generic I/O PM domain object.
1575 * @genpd: PM domain object to initialize.
1576 * @gov: PM domain governor to associate with the domain (may be NULL).
1577 * @is_off: Initial value of the domain's power_is_off field.
1579 void pm_genpd_init(struct generic_pm_domain *genpd,
1580 struct dev_power_governor *gov, bool is_off)
1582 if (IS_ERR_OR_NULL(genpd))
1583 return;
1585 INIT_LIST_HEAD(&genpd->master_links);
1586 INIT_LIST_HEAD(&genpd->slave_links);
1587 INIT_LIST_HEAD(&genpd->dev_list);
1588 mutex_init(&genpd->lock);
1589 genpd->gov = gov;
1590 INIT_WORK(&genpd->power_off_work, genpd_power_off_work_fn);
1591 genpd->in_progress = 0;
1592 atomic_set(&genpd->sd_count, 0);
1593 genpd->status = is_off ? GPD_STATE_POWER_OFF : GPD_STATE_ACTIVE;
1594 init_waitqueue_head(&genpd->status_wait_queue);
1595 genpd->poweroff_task = NULL;
1596 genpd->resume_count = 0;
1597 genpd->device_count = 0;
1598 genpd->max_off_time_ns = -1;
1599 genpd->domain.ops.runtime_suspend = pm_genpd_runtime_suspend;
1600 genpd->domain.ops.runtime_resume = pm_genpd_runtime_resume;
1601 genpd->domain.ops.runtime_idle = pm_generic_runtime_idle;
1602 genpd->domain.ops.prepare = pm_genpd_prepare;
1603 genpd->domain.ops.suspend = pm_genpd_suspend;
1604 genpd->domain.ops.suspend_noirq = pm_genpd_suspend_noirq;
1605 genpd->domain.ops.resume_noirq = pm_genpd_resume_noirq;
1606 genpd->domain.ops.resume = pm_genpd_resume;
1607 genpd->domain.ops.freeze = pm_genpd_freeze;
1608 genpd->domain.ops.freeze_noirq = pm_genpd_freeze_noirq;
1609 genpd->domain.ops.thaw_noirq = pm_genpd_thaw_noirq;
1610 genpd->domain.ops.thaw = pm_genpd_thaw;
1611 genpd->domain.ops.poweroff = pm_genpd_suspend;
1612 genpd->domain.ops.poweroff_noirq = pm_genpd_suspend_noirq;
1613 genpd->domain.ops.restore_noirq = pm_genpd_restore_noirq;
1614 genpd->domain.ops.restore = pm_genpd_resume;
1615 genpd->domain.ops.complete = pm_genpd_complete;
1616 genpd->dev_ops.save_state = pm_genpd_default_save_state;
1617 genpd->dev_ops.restore_state = pm_genpd_default_restore_state;
1618 genpd->dev_ops.suspend = pm_genpd_default_suspend;
1619 genpd->dev_ops.suspend_late = pm_genpd_default_suspend_late;
1620 genpd->dev_ops.resume_early = pm_genpd_default_resume_early;
1621 genpd->dev_ops.resume = pm_genpd_default_resume;
1622 genpd->dev_ops.freeze = pm_genpd_default_freeze;
1623 genpd->dev_ops.freeze_late = pm_genpd_default_freeze_late;
1624 genpd->dev_ops.thaw_early = pm_genpd_default_thaw_early;
1625 genpd->dev_ops.thaw = pm_genpd_default_thaw;
1626 mutex_lock(&gpd_list_lock);
1627 list_add(&genpd->gpd_list_node, &gpd_list);
1628 mutex_unlock(&gpd_list_lock);