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.
9 #include <linux/init.h>
10 #include <linux/kernel.h>
12 #include <linux/pm_runtime.h>
13 #include <linux/pm_domain.h>
14 #include <linux/slab.h>
15 #include <linux/err.h>
19 static struct generic_pm_domain *dev_to_genpd(struct device *dev)
21 if (IS_ERR_OR_NULL(dev->pm_domain))
22 return ERR_PTR(-EINVAL);
24 return pd_to_genpd(dev->pm_domain);
27 static void genpd_sd_counter_dec(struct generic_pm_domain *genpd)
29 if (!WARN_ON(genpd->sd_count == 0))
34 * pm_genpd_poweron - Restore power to a given PM domain and its parents.
35 * @genpd: PM domain to power up.
37 * Restore power to @genpd and all of its parents so that it is possible to
38 * resume a device belonging to it.
40 int pm_genpd_poweron(struct generic_pm_domain *genpd)
46 mutex_lock(&genpd->parent->lock);
47 mutex_lock_nested(&genpd->lock, SINGLE_DEPTH_NESTING);
49 if (!genpd->power_is_off
50 || (genpd->prepared_count > 0 && genpd->suspend_power_off))
53 if (genpd->parent && genpd->parent->power_is_off) {
54 mutex_unlock(&genpd->lock);
55 mutex_unlock(&genpd->parent->lock);
57 ret = pm_genpd_poweron(genpd->parent);
64 if (genpd->power_on) {
65 int ret = genpd->power_on(genpd);
70 genpd->power_is_off = false;
72 genpd->parent->sd_count++;
75 mutex_unlock(&genpd->lock);
77 mutex_unlock(&genpd->parent->lock);
82 #endif /* CONFIG_PM */
84 #ifdef CONFIG_PM_RUNTIME
87 * __pm_genpd_save_device - Save the pre-suspend state of a device.
88 * @dle: Device list entry of the device to save the state of.
89 * @genpd: PM domain the device belongs to.
91 static int __pm_genpd_save_device(struct dev_list_entry *dle,
92 struct generic_pm_domain *genpd)
94 struct device *dev = dle->dev;
95 struct device_driver *drv = dev->driver;
98 if (dle->need_restore)
101 if (drv && drv->pm && drv->pm->runtime_suspend) {
102 if (genpd->start_device)
103 genpd->start_device(dev);
105 ret = drv->pm->runtime_suspend(dev);
107 if (genpd->stop_device)
108 genpd->stop_device(dev);
112 dle->need_restore = true;
118 * __pm_genpd_restore_device - Restore the pre-suspend state of a device.
119 * @dle: Device list entry of the device to restore the state of.
120 * @genpd: PM domain the device belongs to.
122 static void __pm_genpd_restore_device(struct dev_list_entry *dle,
123 struct generic_pm_domain *genpd)
125 struct device *dev = dle->dev;
126 struct device_driver *drv = dev->driver;
128 if (!dle->need_restore)
131 if (drv && drv->pm && drv->pm->runtime_resume) {
132 if (genpd->start_device)
133 genpd->start_device(dev);
135 drv->pm->runtime_resume(dev);
137 if (genpd->stop_device)
138 genpd->stop_device(dev);
141 dle->need_restore = false;
145 * pm_genpd_poweroff - Remove power from a given PM domain.
146 * @genpd: PM domain to power down.
148 * If all of the @genpd's devices have been suspended and all of its subdomains
149 * have been powered down, run the runtime suspend callbacks provided by all of
150 * the @genpd's devices' drivers and remove power from @genpd.
152 static int pm_genpd_poweroff(struct generic_pm_domain *genpd)
154 struct generic_pm_domain *parent;
155 struct dev_list_entry *dle;
156 unsigned int not_suspended;
159 if (genpd->power_is_off || genpd->prepared_count > 0)
162 if (genpd->sd_count > 0)
166 list_for_each_entry(dle, &genpd->dev_list, node)
167 if (dle->dev->driver && !pm_runtime_suspended(dle->dev))
170 if (not_suspended > genpd->in_progress)
173 if (genpd->gov && genpd->gov->power_down_ok) {
174 if (!genpd->gov->power_down_ok(&genpd->domain))
178 list_for_each_entry_reverse(dle, &genpd->dev_list, node) {
179 ret = __pm_genpd_save_device(dle, genpd);
184 if (genpd->power_off)
185 genpd->power_off(genpd);
187 genpd->power_is_off = true;
189 parent = genpd->parent;
191 genpd_sd_counter_dec(parent);
192 if (parent->sd_count == 0)
193 queue_work(pm_wq, &parent->power_off_work);
199 list_for_each_entry_continue(dle, &genpd->dev_list, node)
200 __pm_genpd_restore_device(dle, genpd);
206 * genpd_power_off_work_fn - Power off PM domain whose subdomain count is 0.
207 * @work: Work structure used for scheduling the execution of this function.
209 static void genpd_power_off_work_fn(struct work_struct *work)
211 struct generic_pm_domain *genpd;
213 genpd = container_of(work, struct generic_pm_domain, power_off_work);
216 mutex_lock(&genpd->parent->lock);
217 mutex_lock_nested(&genpd->lock, SINGLE_DEPTH_NESTING);
218 pm_genpd_poweroff(genpd);
219 mutex_unlock(&genpd->lock);
221 mutex_unlock(&genpd->parent->lock);
225 * pm_genpd_runtime_suspend - Suspend a device belonging to I/O PM domain.
226 * @dev: Device to suspend.
228 * Carry out a runtime suspend of a device under the assumption that its
229 * pm_domain field points to the domain member of an object of type
230 * struct generic_pm_domain representing a PM domain consisting of I/O devices.
232 static int pm_genpd_runtime_suspend(struct device *dev)
234 struct generic_pm_domain *genpd;
236 dev_dbg(dev, "%s()\n", __func__);
238 genpd = dev_to_genpd(dev);
243 mutex_lock(&genpd->parent->lock);
244 mutex_lock_nested(&genpd->lock, SINGLE_DEPTH_NESTING);
246 if (genpd->stop_device) {
247 int ret = genpd->stop_device(dev);
251 genpd->in_progress++;
252 pm_genpd_poweroff(genpd);
253 genpd->in_progress--;
256 mutex_unlock(&genpd->lock);
258 mutex_unlock(&genpd->parent->lock);
264 * __pm_genpd_runtime_resume - Resume a device belonging to I/O PM domain.
265 * @dev: Device to resume.
266 * @genpd: PM domain the device belongs to.
268 static void __pm_genpd_runtime_resume(struct device *dev,
269 struct generic_pm_domain *genpd)
271 struct dev_list_entry *dle;
273 list_for_each_entry(dle, &genpd->dev_list, node) {
274 if (dle->dev == dev) {
275 __pm_genpd_restore_device(dle, genpd);
280 if (genpd->start_device)
281 genpd->start_device(dev);
285 * pm_genpd_runtime_resume - Resume a device belonging to I/O PM domain.
286 * @dev: Device to resume.
288 * Carry out a runtime resume of a device under the assumption that its
289 * pm_domain field points to the domain member of an object of type
290 * struct generic_pm_domain representing a PM domain consisting of I/O devices.
292 static int pm_genpd_runtime_resume(struct device *dev)
294 struct generic_pm_domain *genpd;
297 dev_dbg(dev, "%s()\n", __func__);
299 genpd = dev_to_genpd(dev);
303 ret = pm_genpd_poweron(genpd);
307 mutex_lock(&genpd->lock);
308 __pm_genpd_runtime_resume(dev, genpd);
309 mutex_unlock(&genpd->lock);
316 static inline void genpd_power_off_work_fn(struct work_struct *work) {}
317 static inline void __pm_genpd_runtime_resume(struct device *dev,
318 struct generic_pm_domain *genpd) {}
320 #define pm_genpd_runtime_suspend NULL
321 #define pm_genpd_runtime_resume NULL
323 #endif /* CONFIG_PM_RUNTIME */
325 #ifdef CONFIG_PM_SLEEP
328 * pm_genpd_sync_poweroff - Synchronously power off a PM domain and its parents.
329 * @genpd: PM domain to power off, if possible.
331 * Check if the given PM domain can be powered off (during system suspend or
332 * hibernation) and do that if so. Also, in that case propagate to its parent.
334 * This function is only called in "noirq" stages of system power transitions,
335 * so it need not acquire locks (all of the "noirq" callbacks are executed
336 * sequentially, so it is guaranteed that it will never run twice in parallel).
338 static void pm_genpd_sync_poweroff(struct generic_pm_domain *genpd)
340 struct generic_pm_domain *parent = genpd->parent;
342 if (genpd->power_is_off)
345 if (genpd->suspended_count != genpd->device_count || genpd->sd_count > 0)
348 if (genpd->power_off)
349 genpd->power_off(genpd);
351 genpd->power_is_off = true;
353 genpd_sd_counter_dec(parent);
354 pm_genpd_sync_poweroff(parent);
359 * pm_genpd_prepare - Start power transition of a device in a PM domain.
360 * @dev: Device to start the transition of.
362 * Start a power transition of a device (during a system-wide power transition)
363 * under the assumption that its pm_domain field points to the domain member of
364 * an object of type struct generic_pm_domain representing a PM domain
365 * consisting of I/O devices.
367 static int pm_genpd_prepare(struct device *dev)
369 struct generic_pm_domain *genpd;
372 dev_dbg(dev, "%s()\n", __func__);
374 genpd = dev_to_genpd(dev);
378 mutex_lock(&genpd->lock);
380 if (genpd->prepared_count++ == 0)
381 genpd->suspend_power_off = genpd->power_is_off;
383 if (genpd->suspend_power_off) {
384 mutex_unlock(&genpd->lock);
389 * If the device is in the (runtime) "suspended" state, call
390 * .start_device() for it, if defined.
392 if (pm_runtime_suspended(dev))
393 __pm_genpd_runtime_resume(dev, genpd);
396 * Do not check if runtime resume is pending at this point, because it
397 * has been taken care of already and if pm_genpd_poweron() ran at this
398 * point as a result of the check, it would deadlock.
400 __pm_runtime_disable(dev, false);
402 mutex_unlock(&genpd->lock);
404 ret = pm_generic_prepare(dev);
406 mutex_lock(&genpd->lock);
408 if (--genpd->prepared_count == 0)
409 genpd->suspend_power_off = false;
411 mutex_unlock(&genpd->lock);
417 * pm_genpd_suspend - Suspend a device belonging to an I/O PM domain.
418 * @dev: Device to suspend.
420 * Suspend a device under the assumption that its pm_domain field points to the
421 * domain member of an object of type struct generic_pm_domain representing
422 * a PM domain consisting of I/O devices.
424 static int pm_genpd_suspend(struct device *dev)
426 struct generic_pm_domain *genpd;
428 dev_dbg(dev, "%s()\n", __func__);
430 genpd = dev_to_genpd(dev);
434 return genpd->suspend_power_off ? 0 : pm_generic_suspend(dev);
438 * pm_genpd_suspend_noirq - Late suspend of a device from an I/O PM domain.
439 * @dev: Device to suspend.
441 * Carry out a late suspend of a device under the assumption that its
442 * pm_domain field points to the domain member of an object of type
443 * struct generic_pm_domain representing a PM domain consisting of I/O devices.
445 static int pm_genpd_suspend_noirq(struct device *dev)
447 struct generic_pm_domain *genpd;
450 dev_dbg(dev, "%s()\n", __func__);
452 genpd = dev_to_genpd(dev);
456 if (genpd->suspend_power_off)
459 ret = pm_generic_suspend_noirq(dev);
463 if (device_may_wakeup(dev)
464 && genpd->active_wakeup && genpd->active_wakeup(dev))
467 if (genpd->stop_device)
468 genpd->stop_device(dev);
471 * Since all of the "noirq" callbacks are executed sequentially, it is
472 * guaranteed that this function will never run twice in parallel for
473 * the same PM domain, so it is not necessary to use locking here.
475 genpd->suspended_count++;
476 pm_genpd_sync_poweroff(genpd);
482 * pm_genpd_resume_noirq - Early resume of a device from an I/O power domain.
483 * @dev: Device to resume.
485 * Carry out an early resume of a device under the assumption that its
486 * pm_domain field points to the domain member of an object of type
487 * struct generic_pm_domain representing a power domain consisting of I/O
490 static int pm_genpd_resume_noirq(struct device *dev)
492 struct generic_pm_domain *genpd;
494 dev_dbg(dev, "%s()\n", __func__);
496 genpd = dev_to_genpd(dev);
500 if (genpd->suspend_power_off)
504 * Since all of the "noirq" callbacks are executed sequentially, it is
505 * guaranteed that this function will never run twice in parallel for
506 * the same PM domain, so it is not necessary to use locking here.
508 pm_genpd_poweron(genpd);
509 genpd->suspended_count--;
510 if (genpd->start_device)
511 genpd->start_device(dev);
513 return pm_generic_resume_noirq(dev);
517 * pm_genpd_resume - Resume a device belonging to an I/O power domain.
518 * @dev: Device to resume.
520 * Resume a device under the assumption that its pm_domain field points to the
521 * domain member of an object of type struct generic_pm_domain representing
522 * a power domain consisting of I/O devices.
524 static int pm_genpd_resume(struct device *dev)
526 struct generic_pm_domain *genpd;
528 dev_dbg(dev, "%s()\n", __func__);
530 genpd = dev_to_genpd(dev);
534 return genpd->suspend_power_off ? 0 : pm_generic_resume(dev);
538 * pm_genpd_freeze - Freeze a device belonging to an I/O power domain.
539 * @dev: Device to freeze.
541 * Freeze a device under the assumption that its pm_domain field points to the
542 * domain member of an object of type struct generic_pm_domain representing
543 * a power domain consisting of I/O devices.
545 static int pm_genpd_freeze(struct device *dev)
547 struct generic_pm_domain *genpd;
549 dev_dbg(dev, "%s()\n", __func__);
551 genpd = dev_to_genpd(dev);
555 return genpd->suspend_power_off ? 0 : pm_generic_freeze(dev);
559 * pm_genpd_freeze_noirq - Late freeze of a device from an I/O power domain.
560 * @dev: Device to freeze.
562 * Carry out a late freeze of a device under the assumption that its
563 * pm_domain field points to the domain member of an object of type
564 * struct generic_pm_domain representing a power domain consisting of I/O
567 static int pm_genpd_freeze_noirq(struct device *dev)
569 struct generic_pm_domain *genpd;
572 dev_dbg(dev, "%s()\n", __func__);
574 genpd = dev_to_genpd(dev);
578 if (genpd->suspend_power_off)
581 ret = pm_generic_freeze_noirq(dev);
585 if (genpd->stop_device)
586 genpd->stop_device(dev);
592 * pm_genpd_thaw_noirq - Early thaw of a device from an I/O power domain.
593 * @dev: Device to thaw.
595 * Carry out an early thaw of a device under the assumption that its
596 * pm_domain field points to the domain member of an object of type
597 * struct generic_pm_domain representing a power domain consisting of I/O
600 static int pm_genpd_thaw_noirq(struct device *dev)
602 struct generic_pm_domain *genpd;
604 dev_dbg(dev, "%s()\n", __func__);
606 genpd = dev_to_genpd(dev);
610 if (genpd->suspend_power_off)
613 if (genpd->start_device)
614 genpd->start_device(dev);
616 return pm_generic_thaw_noirq(dev);
620 * pm_genpd_thaw - Thaw a device belonging to an I/O power domain.
621 * @dev: Device to thaw.
623 * Thaw a device under the assumption that its pm_domain field points to the
624 * domain member of an object of type struct generic_pm_domain representing
625 * a power domain consisting of I/O devices.
627 static int pm_genpd_thaw(struct device *dev)
629 struct generic_pm_domain *genpd;
631 dev_dbg(dev, "%s()\n", __func__);
633 genpd = dev_to_genpd(dev);
637 return genpd->suspend_power_off ? 0 : pm_generic_thaw(dev);
641 * pm_genpd_dev_poweroff - Power off a device belonging to an I/O PM domain.
642 * @dev: Device to suspend.
644 * Power off a device under the assumption that its pm_domain field points to
645 * the domain member of an object of type struct generic_pm_domain representing
646 * a PM domain consisting of I/O devices.
648 static int pm_genpd_dev_poweroff(struct device *dev)
650 struct generic_pm_domain *genpd;
652 dev_dbg(dev, "%s()\n", __func__);
654 genpd = dev_to_genpd(dev);
658 return genpd->suspend_power_off ? 0 : pm_generic_poweroff(dev);
662 * pm_genpd_dev_poweroff_noirq - Late power off of a device from a PM domain.
663 * @dev: Device to suspend.
665 * Carry out a late powering off of a device under the assumption that its
666 * pm_domain field points to the domain member of an object of type
667 * struct generic_pm_domain representing a PM domain consisting of I/O devices.
669 static int pm_genpd_dev_poweroff_noirq(struct device *dev)
671 struct generic_pm_domain *genpd;
674 dev_dbg(dev, "%s()\n", __func__);
676 genpd = dev_to_genpd(dev);
680 if (genpd->suspend_power_off)
683 ret = pm_generic_poweroff_noirq(dev);
687 if (device_may_wakeup(dev)
688 && genpd->active_wakeup && genpd->active_wakeup(dev))
691 if (genpd->stop_device)
692 genpd->stop_device(dev);
695 * Since all of the "noirq" callbacks are executed sequentially, it is
696 * guaranteed that this function will never run twice in parallel for
697 * the same PM domain, so it is not necessary to use locking here.
699 genpd->suspended_count++;
700 pm_genpd_sync_poweroff(genpd);
706 * pm_genpd_restore_noirq - Early restore of a device from an I/O power domain.
707 * @dev: Device to resume.
709 * Carry out an early restore of a device under the assumption that its
710 * pm_domain field points to the domain member of an object of type
711 * struct generic_pm_domain representing a power domain consisting of I/O
714 static int pm_genpd_restore_noirq(struct device *dev)
716 struct generic_pm_domain *genpd;
718 dev_dbg(dev, "%s()\n", __func__);
720 genpd = dev_to_genpd(dev);
725 * Since all of the "noirq" callbacks are executed sequentially, it is
726 * guaranteed that this function will never run twice in parallel for
727 * the same PM domain, so it is not necessary to use locking here.
729 genpd->power_is_off = true;
730 if (genpd->suspend_power_off) {
732 * The boot kernel might put the domain into the power on state,
733 * so make sure it really is powered off.
735 if (genpd->power_off)
736 genpd->power_off(genpd);
740 pm_genpd_poweron(genpd);
741 genpd->suspended_count--;
742 if (genpd->start_device)
743 genpd->start_device(dev);
745 return pm_generic_restore_noirq(dev);
749 * pm_genpd_restore - Restore a device belonging to an I/O power domain.
750 * @dev: Device to resume.
752 * Restore a device under the assumption that its pm_domain field points to the
753 * domain member of an object of type struct generic_pm_domain representing
754 * a power domain consisting of I/O devices.
756 static int pm_genpd_restore(struct device *dev)
758 struct generic_pm_domain *genpd;
760 dev_dbg(dev, "%s()\n", __func__);
762 genpd = dev_to_genpd(dev);
766 return genpd->suspend_power_off ? 0 : pm_generic_restore(dev);
770 * pm_genpd_complete - Complete power transition of a device in a power domain.
771 * @dev: Device to complete the transition of.
773 * Complete a power transition of a device (during a system-wide power
774 * transition) under the assumption that its pm_domain field points to the
775 * domain member of an object of type struct generic_pm_domain representing
776 * a power domain consisting of I/O devices.
778 static void pm_genpd_complete(struct device *dev)
780 struct generic_pm_domain *genpd;
783 dev_dbg(dev, "%s()\n", __func__);
785 genpd = dev_to_genpd(dev);
789 mutex_lock(&genpd->lock);
791 run_complete = !genpd->suspend_power_off;
792 if (--genpd->prepared_count == 0)
793 genpd->suspend_power_off = false;
795 mutex_unlock(&genpd->lock);
798 pm_generic_complete(dev);
799 pm_runtime_set_active(dev);
800 pm_runtime_enable(dev);
801 pm_runtime_idle(dev);
807 #define pm_genpd_prepare NULL
808 #define pm_genpd_suspend NULL
809 #define pm_genpd_suspend_noirq NULL
810 #define pm_genpd_resume_noirq NULL
811 #define pm_genpd_resume NULL
812 #define pm_genpd_freeze NULL
813 #define pm_genpd_freeze_noirq NULL
814 #define pm_genpd_thaw_noirq NULL
815 #define pm_genpd_thaw NULL
816 #define pm_genpd_dev_poweroff_noirq NULL
817 #define pm_genpd_dev_poweroff NULL
818 #define pm_genpd_restore_noirq NULL
819 #define pm_genpd_restore NULL
820 #define pm_genpd_complete NULL
822 #endif /* CONFIG_PM_SLEEP */
825 * pm_genpd_add_device - Add a device to an I/O PM domain.
826 * @genpd: PM domain to add the device to.
827 * @dev: Device to be added.
829 int pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev)
831 struct dev_list_entry *dle;
834 dev_dbg(dev, "%s()\n", __func__);
836 if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(dev))
839 mutex_lock(&genpd->lock);
841 if (genpd->power_is_off) {
846 if (genpd->prepared_count > 0) {
851 list_for_each_entry(dle, &genpd->dev_list, node)
852 if (dle->dev == dev) {
857 dle = kzalloc(sizeof(*dle), GFP_KERNEL);
864 dle->need_restore = false;
865 list_add_tail(&dle->node, &genpd->dev_list);
866 genpd->device_count++;
868 spin_lock_irq(&dev->power.lock);
869 dev->pm_domain = &genpd->domain;
870 spin_unlock_irq(&dev->power.lock);
873 mutex_unlock(&genpd->lock);
879 * pm_genpd_remove_device - Remove a device from an I/O PM domain.
880 * @genpd: PM domain to remove the device from.
881 * @dev: Device to be removed.
883 int pm_genpd_remove_device(struct generic_pm_domain *genpd,
886 struct dev_list_entry *dle;
889 dev_dbg(dev, "%s()\n", __func__);
891 if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(dev))
894 mutex_lock(&genpd->lock);
896 if (genpd->prepared_count > 0) {
901 list_for_each_entry(dle, &genpd->dev_list, node) {
905 spin_lock_irq(&dev->power.lock);
906 dev->pm_domain = NULL;
907 spin_unlock_irq(&dev->power.lock);
909 genpd->device_count--;
910 list_del(&dle->node);
918 mutex_unlock(&genpd->lock);
924 * pm_genpd_add_subdomain - Add a subdomain to an I/O PM domain.
925 * @genpd: Master PM domain to add the subdomain to.
926 * @new_subdomain: Subdomain to be added.
928 int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
929 struct generic_pm_domain *new_subdomain)
931 struct generic_pm_domain *subdomain;
934 if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(new_subdomain))
937 mutex_lock(&genpd->lock);
939 if (genpd->power_is_off && !new_subdomain->power_is_off) {
944 list_for_each_entry(subdomain, &genpd->sd_list, sd_node) {
945 if (subdomain == new_subdomain) {
951 mutex_lock_nested(&new_subdomain->lock, SINGLE_DEPTH_NESTING);
953 list_add_tail(&new_subdomain->sd_node, &genpd->sd_list);
954 new_subdomain->parent = genpd;
955 if (!subdomain->power_is_off)
958 mutex_unlock(&new_subdomain->lock);
961 mutex_unlock(&genpd->lock);
967 * pm_genpd_remove_subdomain - Remove a subdomain from an I/O PM domain.
968 * @genpd: Master PM domain to remove the subdomain from.
969 * @target: Subdomain to be removed.
971 int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
972 struct generic_pm_domain *target)
974 struct generic_pm_domain *subdomain;
977 if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(target))
980 mutex_lock(&genpd->lock);
982 list_for_each_entry(subdomain, &genpd->sd_list, sd_node) {
983 if (subdomain != target)
986 mutex_lock_nested(&subdomain->lock, SINGLE_DEPTH_NESTING);
988 list_del(&subdomain->sd_node);
989 subdomain->parent = NULL;
990 if (!subdomain->power_is_off)
991 genpd_sd_counter_dec(genpd);
993 mutex_unlock(&subdomain->lock);
999 mutex_unlock(&genpd->lock);
1005 * pm_genpd_init - Initialize a generic I/O PM domain object.
1006 * @genpd: PM domain object to initialize.
1007 * @gov: PM domain governor to associate with the domain (may be NULL).
1008 * @is_off: Initial value of the domain's power_is_off field.
1010 void pm_genpd_init(struct generic_pm_domain *genpd,
1011 struct dev_power_governor *gov, bool is_off)
1013 if (IS_ERR_OR_NULL(genpd))
1016 INIT_LIST_HEAD(&genpd->sd_node);
1017 genpd->parent = NULL;
1018 INIT_LIST_HEAD(&genpd->dev_list);
1019 INIT_LIST_HEAD(&genpd->sd_list);
1020 mutex_init(&genpd->lock);
1022 INIT_WORK(&genpd->power_off_work, genpd_power_off_work_fn);
1023 genpd->in_progress = 0;
1024 genpd->sd_count = 0;
1025 genpd->power_is_off = is_off;
1026 genpd->device_count = 0;
1027 genpd->suspended_count = 0;
1028 genpd->domain.ops.runtime_suspend = pm_genpd_runtime_suspend;
1029 genpd->domain.ops.runtime_resume = pm_genpd_runtime_resume;
1030 genpd->domain.ops.runtime_idle = pm_generic_runtime_idle;
1031 genpd->domain.ops.prepare = pm_genpd_prepare;
1032 genpd->domain.ops.suspend = pm_genpd_suspend;
1033 genpd->domain.ops.suspend_noirq = pm_genpd_suspend_noirq;
1034 genpd->domain.ops.resume_noirq = pm_genpd_resume_noirq;
1035 genpd->domain.ops.resume = pm_genpd_resume;
1036 genpd->domain.ops.freeze = pm_genpd_freeze;
1037 genpd->domain.ops.freeze_noirq = pm_genpd_freeze_noirq;
1038 genpd->domain.ops.thaw_noirq = pm_genpd_thaw_noirq;
1039 genpd->domain.ops.thaw = pm_genpd_thaw;
1040 genpd->domain.ops.poweroff = pm_genpd_dev_poweroff;
1041 genpd->domain.ops.poweroff_noirq = pm_genpd_dev_poweroff_noirq;
1042 genpd->domain.ops.restore_noirq = pm_genpd_restore_noirq;
1043 genpd->domain.ops.restore = pm_genpd_restore;
1044 genpd->domain.ops.complete = pm_genpd_complete;