1 // SPDX-License-Identifier: GPL-2.0
3 * drivers/base/power/domain.c - Common code related to device power domains.
7 #define pr_fmt(fmt) "PM: " fmt
9 #include <linux/delay.h>
10 #include <linux/kernel.h>
12 #include <linux/platform_device.h>
13 #include <linux/pm_opp.h>
14 #include <linux/pm_runtime.h>
15 #include <linux/pm_domain.h>
16 #include <linux/pm_qos.h>
17 #include <linux/pm_clock.h>
18 #include <linux/slab.h>
19 #include <linux/err.h>
20 #include <linux/sched.h>
21 #include <linux/suspend.h>
22 #include <linux/export.h>
23 #include <linux/cpu.h>
24 #include <linux/debugfs.h>
26 #define GENPD_RETRY_MAX_MS 250 /* Approximate */
28 #define GENPD_DEV_CALLBACK(genpd, type, callback, dev) \
30 type (*__routine)(struct device *__d); \
31 type __ret = (type)0; \
33 __routine = genpd->dev_ops.callback; \
35 __ret = __routine(dev); \
40 static LIST_HEAD(gpd_list);
41 static DEFINE_MUTEX(gpd_list_lock);
43 struct genpd_lock_ops {
44 void (*lock)(struct generic_pm_domain *genpd);
45 void (*lock_nested)(struct generic_pm_domain *genpd, int depth);
46 int (*lock_interruptible)(struct generic_pm_domain *genpd);
47 void (*unlock)(struct generic_pm_domain *genpd);
50 static void genpd_lock_mtx(struct generic_pm_domain *genpd)
52 mutex_lock(&genpd->mlock);
55 static void genpd_lock_nested_mtx(struct generic_pm_domain *genpd,
58 mutex_lock_nested(&genpd->mlock, depth);
61 static int genpd_lock_interruptible_mtx(struct generic_pm_domain *genpd)
63 return mutex_lock_interruptible(&genpd->mlock);
66 static void genpd_unlock_mtx(struct generic_pm_domain *genpd)
68 return mutex_unlock(&genpd->mlock);
71 static const struct genpd_lock_ops genpd_mtx_ops = {
72 .lock = genpd_lock_mtx,
73 .lock_nested = genpd_lock_nested_mtx,
74 .lock_interruptible = genpd_lock_interruptible_mtx,
75 .unlock = genpd_unlock_mtx,
78 static void genpd_lock_spin(struct generic_pm_domain *genpd)
79 __acquires(&genpd->slock)
83 spin_lock_irqsave(&genpd->slock, flags);
84 genpd->lock_flags = flags;
87 static void genpd_lock_nested_spin(struct generic_pm_domain *genpd,
89 __acquires(&genpd->slock)
93 spin_lock_irqsave_nested(&genpd->slock, flags, depth);
94 genpd->lock_flags = flags;
97 static int genpd_lock_interruptible_spin(struct generic_pm_domain *genpd)
98 __acquires(&genpd->slock)
102 spin_lock_irqsave(&genpd->slock, flags);
103 genpd->lock_flags = flags;
107 static void genpd_unlock_spin(struct generic_pm_domain *genpd)
108 __releases(&genpd->slock)
110 spin_unlock_irqrestore(&genpd->slock, genpd->lock_flags);
113 static const struct genpd_lock_ops genpd_spin_ops = {
114 .lock = genpd_lock_spin,
115 .lock_nested = genpd_lock_nested_spin,
116 .lock_interruptible = genpd_lock_interruptible_spin,
117 .unlock = genpd_unlock_spin,
120 static void genpd_lock_raw_spin(struct generic_pm_domain *genpd)
121 __acquires(&genpd->raw_slock)
125 raw_spin_lock_irqsave(&genpd->raw_slock, flags);
126 genpd->raw_lock_flags = flags;
129 static void genpd_lock_nested_raw_spin(struct generic_pm_domain *genpd,
131 __acquires(&genpd->raw_slock)
135 raw_spin_lock_irqsave_nested(&genpd->raw_slock, flags, depth);
136 genpd->raw_lock_flags = flags;
139 static int genpd_lock_interruptible_raw_spin(struct generic_pm_domain *genpd)
140 __acquires(&genpd->raw_slock)
144 raw_spin_lock_irqsave(&genpd->raw_slock, flags);
145 genpd->raw_lock_flags = flags;
149 static void genpd_unlock_raw_spin(struct generic_pm_domain *genpd)
150 __releases(&genpd->raw_slock)
152 raw_spin_unlock_irqrestore(&genpd->raw_slock, genpd->raw_lock_flags);
155 static const struct genpd_lock_ops genpd_raw_spin_ops = {
156 .lock = genpd_lock_raw_spin,
157 .lock_nested = genpd_lock_nested_raw_spin,
158 .lock_interruptible = genpd_lock_interruptible_raw_spin,
159 .unlock = genpd_unlock_raw_spin,
162 #define genpd_lock(p) p->lock_ops->lock(p)
163 #define genpd_lock_nested(p, d) p->lock_ops->lock_nested(p, d)
164 #define genpd_lock_interruptible(p) p->lock_ops->lock_interruptible(p)
165 #define genpd_unlock(p) p->lock_ops->unlock(p)
167 #define genpd_status_on(genpd) (genpd->status == GENPD_STATE_ON)
168 #define genpd_is_irq_safe(genpd) (genpd->flags & GENPD_FLAG_IRQ_SAFE)
169 #define genpd_is_always_on(genpd) (genpd->flags & GENPD_FLAG_ALWAYS_ON)
170 #define genpd_is_active_wakeup(genpd) (genpd->flags & GENPD_FLAG_ACTIVE_WAKEUP)
171 #define genpd_is_cpu_domain(genpd) (genpd->flags & GENPD_FLAG_CPU_DOMAIN)
172 #define genpd_is_rpm_always_on(genpd) (genpd->flags & GENPD_FLAG_RPM_ALWAYS_ON)
173 #define genpd_is_opp_table_fw(genpd) (genpd->flags & GENPD_FLAG_OPP_TABLE_FW)
175 static inline bool irq_safe_dev_in_sleep_domain(struct device *dev,
176 const struct generic_pm_domain *genpd)
180 ret = pm_runtime_is_irq_safe(dev) && !genpd_is_irq_safe(genpd);
183 * Warn once if an IRQ safe device is attached to a domain, which
184 * callbacks are allowed to sleep. This indicates a suboptimal
185 * configuration for PM, but it doesn't matter for an always on domain.
187 if (genpd_is_always_on(genpd) || genpd_is_rpm_always_on(genpd))
191 dev_warn_once(dev, "PM domain %s will not be powered off\n",
197 static int genpd_runtime_suspend(struct device *dev);
200 * Get the generic PM domain for a particular struct device.
201 * This validates the struct device pointer, the PM domain pointer,
202 * and checks that the PM domain pointer is a real generic PM domain.
203 * Any failure results in NULL being returned.
205 static struct generic_pm_domain *dev_to_genpd_safe(struct device *dev)
207 if (IS_ERR_OR_NULL(dev) || IS_ERR_OR_NULL(dev->pm_domain))
210 /* A genpd's always have its ->runtime_suspend() callback assigned. */
211 if (dev->pm_domain->ops.runtime_suspend == genpd_runtime_suspend)
212 return pd_to_genpd(dev->pm_domain);
218 * This should only be used where we are certain that the pm_domain
219 * attached to the device is a genpd domain.
221 static struct generic_pm_domain *dev_to_genpd(struct device *dev)
223 if (IS_ERR_OR_NULL(dev->pm_domain))
224 return ERR_PTR(-EINVAL);
226 return pd_to_genpd(dev->pm_domain);
229 struct device *dev_to_genpd_dev(struct device *dev)
231 struct generic_pm_domain *genpd = dev_to_genpd(dev);
234 return ERR_CAST(genpd);
239 static int genpd_stop_dev(const struct generic_pm_domain *genpd,
242 return GENPD_DEV_CALLBACK(genpd, int, stop, dev);
245 static int genpd_start_dev(const struct generic_pm_domain *genpd,
248 return GENPD_DEV_CALLBACK(genpd, int, start, dev);
251 static bool genpd_sd_counter_dec(struct generic_pm_domain *genpd)
255 if (!WARN_ON(atomic_read(&genpd->sd_count) == 0))
256 ret = !!atomic_dec_and_test(&genpd->sd_count);
261 static void genpd_sd_counter_inc(struct generic_pm_domain *genpd)
263 atomic_inc(&genpd->sd_count);
264 smp_mb__after_atomic();
267 #ifdef CONFIG_DEBUG_FS
268 static struct dentry *genpd_debugfs_dir;
270 static void genpd_debug_add(struct generic_pm_domain *genpd);
272 static void genpd_debug_remove(struct generic_pm_domain *genpd)
274 if (!genpd_debugfs_dir)
277 debugfs_lookup_and_remove(genpd->name, genpd_debugfs_dir);
280 static void genpd_update_accounting(struct generic_pm_domain *genpd)
284 now = ktime_get_mono_fast_ns();
285 if (now <= genpd->accounting_time)
288 delta = now - genpd->accounting_time;
291 * If genpd->status is active, it means we are just
292 * out of off and so update the idle time and vice
295 if (genpd->status == GENPD_STATE_ON)
296 genpd->states[genpd->state_idx].idle_time += delta;
298 genpd->on_time += delta;
300 genpd->accounting_time = now;
303 static inline void genpd_debug_add(struct generic_pm_domain *genpd) {}
304 static inline void genpd_debug_remove(struct generic_pm_domain *genpd) {}
305 static inline void genpd_update_accounting(struct generic_pm_domain *genpd) {}
308 static int _genpd_reeval_performance_state(struct generic_pm_domain *genpd,
311 struct generic_pm_domain_data *pd_data;
312 struct pm_domain_data *pdd;
313 struct gpd_link *link;
315 /* New requested state is same as Max requested state */
316 if (state == genpd->performance_state)
319 /* New requested state is higher than Max requested state */
320 if (state > genpd->performance_state)
323 /* Traverse all devices within the domain */
324 list_for_each_entry(pdd, &genpd->dev_list, list_node) {
325 pd_data = to_gpd_data(pdd);
327 if (pd_data->performance_state > state)
328 state = pd_data->performance_state;
332 * Traverse all sub-domains within the domain. This can be
333 * done without any additional locking as the link->performance_state
334 * field is protected by the parent genpd->lock, which is already taken.
336 * Also note that link->performance_state (subdomain's performance state
337 * requirement to parent domain) is different from
338 * link->child->performance_state (current performance state requirement
339 * of the devices/sub-domains of the subdomain) and so can have a
342 * Note that we also take vote from powered-off sub-domains into account
343 * as the same is done for devices right now.
345 list_for_each_entry(link, &genpd->parent_links, parent_node) {
346 if (link->performance_state > state)
347 state = link->performance_state;
353 static int genpd_xlate_performance_state(struct generic_pm_domain *genpd,
354 struct generic_pm_domain *parent,
357 if (!parent->set_performance_state)
360 return dev_pm_opp_xlate_performance_state(genpd->opp_table,
365 static int _genpd_set_performance_state(struct generic_pm_domain *genpd,
366 unsigned int state, int depth);
368 static void _genpd_rollback_parent_state(struct gpd_link *link, int depth)
370 struct generic_pm_domain *parent = link->parent;
373 genpd_lock_nested(parent, depth + 1);
375 parent_state = link->prev_performance_state;
376 link->performance_state = parent_state;
378 parent_state = _genpd_reeval_performance_state(parent, parent_state);
379 if (_genpd_set_performance_state(parent, parent_state, depth + 1)) {
380 pr_err("%s: Failed to roll back to %d performance state\n",
381 parent->name, parent_state);
384 genpd_unlock(parent);
387 static int _genpd_set_parent_state(struct generic_pm_domain *genpd,
388 struct gpd_link *link,
389 unsigned int state, int depth)
391 struct generic_pm_domain *parent = link->parent;
392 int parent_state, ret;
394 /* Find parent's performance state */
395 ret = genpd_xlate_performance_state(genpd, parent, state);
396 if (unlikely(ret < 0))
401 genpd_lock_nested(parent, depth + 1);
403 link->prev_performance_state = link->performance_state;
404 link->performance_state = parent_state;
406 parent_state = _genpd_reeval_performance_state(parent, parent_state);
407 ret = _genpd_set_performance_state(parent, parent_state, depth + 1);
409 link->performance_state = link->prev_performance_state;
411 genpd_unlock(parent);
416 static int _genpd_set_performance_state(struct generic_pm_domain *genpd,
417 unsigned int state, int depth)
419 struct gpd_link *link = NULL;
422 if (state == genpd->performance_state)
425 /* When scaling up, propagate to parents first in normal order */
426 if (state > genpd->performance_state) {
427 list_for_each_entry(link, &genpd->child_links, child_node) {
428 ret = _genpd_set_parent_state(genpd, link, state, depth);
430 goto rollback_parents_up;
434 if (genpd->set_performance_state) {
435 ret = genpd->set_performance_state(genpd, state);
438 goto rollback_parents_up;
443 /* When scaling down, propagate to parents last in reverse order */
444 if (state < genpd->performance_state) {
445 list_for_each_entry_reverse(link, &genpd->child_links, child_node) {
446 ret = _genpd_set_parent_state(genpd, link, state, depth);
448 goto rollback_parents_down;
452 genpd->performance_state = state;
456 list_for_each_entry_continue_reverse(link, &genpd->child_links, child_node)
457 _genpd_rollback_parent_state(link, depth);
459 rollback_parents_down:
460 list_for_each_entry_continue(link, &genpd->child_links, child_node)
461 _genpd_rollback_parent_state(link, depth);
465 static int genpd_set_performance_state(struct device *dev, unsigned int state)
467 struct generic_pm_domain *genpd = dev_to_genpd(dev);
468 struct generic_pm_domain_data *gpd_data = dev_gpd_data(dev);
469 unsigned int prev_state;
472 prev_state = gpd_data->performance_state;
473 if (prev_state == state)
476 gpd_data->performance_state = state;
477 state = _genpd_reeval_performance_state(genpd, state);
479 ret = _genpd_set_performance_state(genpd, state, 0);
481 gpd_data->performance_state = prev_state;
486 static int genpd_drop_performance_state(struct device *dev)
488 unsigned int prev_state = dev_gpd_data(dev)->performance_state;
490 if (!genpd_set_performance_state(dev, 0))
496 static void genpd_restore_performance_state(struct device *dev,
500 genpd_set_performance_state(dev, state);
503 static int genpd_dev_pm_set_performance_state(struct device *dev,
506 struct generic_pm_domain *genpd = dev_to_genpd(dev);
510 if (pm_runtime_suspended(dev)) {
511 dev_gpd_data(dev)->rpm_pstate = state;
513 ret = genpd_set_performance_state(dev, state);
515 dev_gpd_data(dev)->rpm_pstate = 0;
523 * dev_pm_genpd_set_performance_state- Set performance state of device's power
526 * @dev: Device for which the performance-state needs to be set.
527 * @state: Target performance state of the device. This can be set as 0 when the
528 * device doesn't have any performance state constraints left (And so
529 * the device wouldn't participate anymore to find the target
530 * performance state of the genpd).
532 * It is assumed that the users guarantee that the genpd wouldn't be detached
533 * while this routine is getting called.
535 * Returns 0 on success and negative error values on failures.
537 int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state)
539 struct generic_pm_domain *genpd;
541 genpd = dev_to_genpd_safe(dev);
545 if (WARN_ON(!dev->power.subsys_data ||
546 !dev->power.subsys_data->domain_data))
549 return genpd_dev_pm_set_performance_state(dev, state);
551 EXPORT_SYMBOL_GPL(dev_pm_genpd_set_performance_state);
554 * dev_pm_genpd_set_next_wakeup - Notify PM framework of an impending wakeup.
556 * @dev: Device to handle
557 * @next: impending interrupt/wakeup for the device
560 * Allow devices to inform of the next wakeup. It's assumed that the users
561 * guarantee that the genpd wouldn't be detached while this routine is getting
562 * called. Additionally, it's also assumed that @dev isn't runtime suspended
564 * Although devices are expected to update the next_wakeup after the end of
565 * their usecase as well, it is possible the devices themselves may not know
566 * about that, so stale @next will be ignored when powering off the domain.
568 void dev_pm_genpd_set_next_wakeup(struct device *dev, ktime_t next)
570 struct generic_pm_domain *genpd;
571 struct gpd_timing_data *td;
573 genpd = dev_to_genpd_safe(dev);
577 td = to_gpd_data(dev->power.subsys_data->domain_data)->td;
579 td->next_wakeup = next;
581 EXPORT_SYMBOL_GPL(dev_pm_genpd_set_next_wakeup);
584 * dev_pm_genpd_get_next_hrtimer - Return the next_hrtimer for the genpd
585 * @dev: A device that is attached to the genpd.
587 * This routine should typically be called for a device, at the point of when a
588 * GENPD_NOTIFY_PRE_OFF notification has been sent for it.
590 * Returns the aggregated value of the genpd's next hrtimer or KTIME_MAX if no
591 * valid value have been set.
593 ktime_t dev_pm_genpd_get_next_hrtimer(struct device *dev)
595 struct generic_pm_domain *genpd;
597 genpd = dev_to_genpd_safe(dev);
602 return genpd->gd->next_hrtimer;
606 EXPORT_SYMBOL_GPL(dev_pm_genpd_get_next_hrtimer);
609 * dev_pm_genpd_synced_poweroff - Next power off should be synchronous
611 * @dev: A device that is attached to the genpd.
613 * Allows a consumer of the genpd to notify the provider that the next power off
614 * should be synchronous.
616 * It is assumed that the users guarantee that the genpd wouldn't be detached
617 * while this routine is getting called.
619 void dev_pm_genpd_synced_poweroff(struct device *dev)
621 struct generic_pm_domain *genpd;
623 genpd = dev_to_genpd_safe(dev);
628 genpd->synced_poweroff = true;
631 EXPORT_SYMBOL_GPL(dev_pm_genpd_synced_poweroff);
634 * dev_pm_genpd_set_hwmode() - Set the HW mode for the device and its PM domain.
636 * @dev: Device for which the HW-mode should be changed.
637 * @enable: Value to set or unset the HW-mode.
639 * Some PM domains can rely on HW signals to control the power for a device. To
640 * allow a consumer driver to switch the behaviour for its device in runtime,
641 * which may be beneficial from a latency or energy point of view, this function
644 * It is assumed that the users guarantee that the genpd wouldn't be detached
645 * while this routine is getting called.
647 * Return: Returns 0 on success and negative error values on failures.
649 int dev_pm_genpd_set_hwmode(struct device *dev, bool enable)
651 struct generic_pm_domain *genpd;
654 genpd = dev_to_genpd_safe(dev);
658 if (!genpd->set_hwmode_dev)
663 if (dev_gpd_data(dev)->hw_mode == enable)
666 ret = genpd->set_hwmode_dev(genpd, dev, enable);
668 dev_gpd_data(dev)->hw_mode = enable;
674 EXPORT_SYMBOL_GPL(dev_pm_genpd_set_hwmode);
677 * dev_pm_genpd_get_hwmode() - Get the HW mode setting for the device.
679 * @dev: Device for which the current HW-mode setting should be fetched.
681 * This helper function allows consumer drivers to fetch the current HW mode
682 * setting of its the device.
684 * It is assumed that the users guarantee that the genpd wouldn't be detached
685 * while this routine is getting called.
687 * Return: Returns the HW mode setting of device from SW cached hw_mode.
689 bool dev_pm_genpd_get_hwmode(struct device *dev)
691 return dev_gpd_data(dev)->hw_mode;
693 EXPORT_SYMBOL_GPL(dev_pm_genpd_get_hwmode);
695 static int _genpd_power_on(struct generic_pm_domain *genpd, bool timed)
697 unsigned int state_idx = genpd->state_idx;
702 /* Notify consumers that we are about to power on. */
703 ret = raw_notifier_call_chain_robust(&genpd->power_notifiers,
705 GENPD_NOTIFY_OFF, NULL);
706 ret = notifier_to_errno(ret);
710 if (!genpd->power_on)
713 timed = timed && genpd->gd && !genpd->states[state_idx].fwnode;
715 ret = genpd->power_on(genpd);
722 time_start = ktime_get();
723 ret = genpd->power_on(genpd);
727 elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start));
728 if (elapsed_ns <= genpd->states[state_idx].power_on_latency_ns)
731 genpd->states[state_idx].power_on_latency_ns = elapsed_ns;
732 genpd->gd->max_off_time_changed = true;
733 pr_debug("%s: Power-%s latency exceeded, new value %lld ns\n",
734 genpd->name, "on", elapsed_ns);
737 raw_notifier_call_chain(&genpd->power_notifiers, GENPD_NOTIFY_ON, NULL);
738 genpd->synced_poweroff = false;
741 raw_notifier_call_chain(&genpd->power_notifiers, GENPD_NOTIFY_OFF,
746 static int _genpd_power_off(struct generic_pm_domain *genpd, bool timed)
748 unsigned int state_idx = genpd->state_idx;
753 /* Notify consumers that we are about to power off. */
754 ret = raw_notifier_call_chain_robust(&genpd->power_notifiers,
755 GENPD_NOTIFY_PRE_OFF,
756 GENPD_NOTIFY_ON, NULL);
757 ret = notifier_to_errno(ret);
761 if (!genpd->power_off)
764 timed = timed && genpd->gd && !genpd->states[state_idx].fwnode;
766 ret = genpd->power_off(genpd);
773 time_start = ktime_get();
774 ret = genpd->power_off(genpd);
778 elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start));
779 if (elapsed_ns <= genpd->states[state_idx].power_off_latency_ns)
782 genpd->states[state_idx].power_off_latency_ns = elapsed_ns;
783 genpd->gd->max_off_time_changed = true;
784 pr_debug("%s: Power-%s latency exceeded, new value %lld ns\n",
785 genpd->name, "off", elapsed_ns);
788 raw_notifier_call_chain(&genpd->power_notifiers, GENPD_NOTIFY_OFF,
792 raw_notifier_call_chain(&genpd->power_notifiers, GENPD_NOTIFY_ON, NULL);
797 * genpd_queue_power_off_work - Queue up the execution of genpd_power_off().
798 * @genpd: PM domain to power off.
800 * Queue up the execution of genpd_power_off() unless it's already been done
803 static void genpd_queue_power_off_work(struct generic_pm_domain *genpd)
805 queue_work(pm_wq, &genpd->power_off_work);
809 * genpd_power_off - Remove power from a given PM domain.
810 * @genpd: PM domain to power down.
811 * @one_dev_on: If invoked from genpd's ->runtime_suspend|resume() callback, the
812 * RPM status of the releated device is in an intermediate state, not yet turned
813 * into RPM_SUSPENDED. This means genpd_power_off() must allow one device to not
814 * be RPM_SUSPENDED, while it tries to power off the PM domain.
815 * @depth: nesting count for lockdep.
817 * If all of the @genpd's devices have been suspended and all of its subdomains
818 * have been powered down, remove power from @genpd.
820 static int genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on,
823 struct pm_domain_data *pdd;
824 struct gpd_link *link;
825 unsigned int not_suspended = 0;
829 * Do not try to power off the domain in the following situations:
830 * (1) The domain is already in the "power off" state.
831 * (2) System suspend is in progress.
833 if (!genpd_status_on(genpd) || genpd->prepared_count > 0)
837 * Abort power off for the PM domain in the following situations:
838 * (1) The domain is configured as always on.
839 * (2) When the domain has a subdomain being powered on.
841 if (genpd_is_always_on(genpd) ||
842 genpd_is_rpm_always_on(genpd) ||
843 atomic_read(&genpd->sd_count) > 0)
847 * The children must be in their deepest (powered-off) states to allow
848 * the parent to be powered off. Note that, there's no need for
849 * additional locking, as powering on a child, requires the parent's
850 * lock to be acquired first.
852 list_for_each_entry(link, &genpd->parent_links, parent_node) {
853 struct generic_pm_domain *child = link->child;
854 if (child->state_idx < child->state_count - 1)
858 list_for_each_entry(pdd, &genpd->dev_list, list_node) {
860 * Do not allow PM domain to be powered off, when an IRQ safe
861 * device is part of a non-IRQ safe domain.
863 if (!pm_runtime_suspended(pdd->dev) ||
864 irq_safe_dev_in_sleep_domain(pdd->dev, genpd))
868 if (not_suspended > 1 || (not_suspended == 1 && !one_dev_on))
871 if (genpd->gov && genpd->gov->power_down_ok) {
872 if (!genpd->gov->power_down_ok(&genpd->domain))
876 /* Default to shallowest state. */
878 genpd->state_idx = 0;
880 /* Don't power off, if a child domain is waiting to power on. */
881 if (atomic_read(&genpd->sd_count) > 0)
884 ret = _genpd_power_off(genpd, true);
886 genpd->states[genpd->state_idx].rejected++;
890 genpd->status = GENPD_STATE_OFF;
891 genpd_update_accounting(genpd);
892 genpd->states[genpd->state_idx].usage++;
894 list_for_each_entry(link, &genpd->child_links, child_node) {
895 genpd_sd_counter_dec(link->parent);
896 genpd_lock_nested(link->parent, depth + 1);
897 genpd_power_off(link->parent, false, depth + 1);
898 genpd_unlock(link->parent);
905 * genpd_power_on - Restore power to a given PM domain and its parents.
906 * @genpd: PM domain to power up.
907 * @depth: nesting count for lockdep.
909 * Restore power to @genpd and all of its parents so that it is possible to
910 * resume a device belonging to it.
912 static int genpd_power_on(struct generic_pm_domain *genpd, unsigned int depth)
914 struct gpd_link *link;
917 if (genpd_status_on(genpd))
921 * The list is guaranteed not to change while the loop below is being
922 * executed, unless one of the parents' .power_on() callbacks fiddles
925 list_for_each_entry(link, &genpd->child_links, child_node) {
926 struct generic_pm_domain *parent = link->parent;
928 genpd_sd_counter_inc(parent);
930 genpd_lock_nested(parent, depth + 1);
931 ret = genpd_power_on(parent, depth + 1);
932 genpd_unlock(parent);
935 genpd_sd_counter_dec(parent);
940 ret = _genpd_power_on(genpd, true);
944 genpd->status = GENPD_STATE_ON;
945 genpd_update_accounting(genpd);
950 list_for_each_entry_continue_reverse(link,
953 genpd_sd_counter_dec(link->parent);
954 genpd_lock_nested(link->parent, depth + 1);
955 genpd_power_off(link->parent, false, depth + 1);
956 genpd_unlock(link->parent);
962 static int genpd_dev_pm_start(struct device *dev)
964 struct generic_pm_domain *genpd = dev_to_genpd(dev);
966 return genpd_start_dev(genpd, dev);
969 static int genpd_dev_pm_qos_notifier(struct notifier_block *nb,
970 unsigned long val, void *ptr)
972 struct generic_pm_domain_data *gpd_data;
975 gpd_data = container_of(nb, struct generic_pm_domain_data, nb);
976 dev = gpd_data->base.dev;
979 struct generic_pm_domain *genpd = ERR_PTR(-ENODATA);
980 struct pm_domain_data *pdd;
981 struct gpd_timing_data *td;
983 spin_lock_irq(&dev->power.lock);
985 pdd = dev->power.subsys_data ?
986 dev->power.subsys_data->domain_data : NULL;
988 td = to_gpd_data(pdd)->td;
990 td->constraint_changed = true;
991 genpd = dev_to_genpd(dev);
995 spin_unlock_irq(&dev->power.lock);
997 if (!IS_ERR(genpd)) {
999 genpd->gd->max_off_time_changed = true;
1000 genpd_unlock(genpd);
1004 if (!dev || dev->power.ignore_children)
1012 * genpd_power_off_work_fn - Power off PM domain whose subdomain count is 0.
1013 * @work: Work structure used for scheduling the execution of this function.
1015 static void genpd_power_off_work_fn(struct work_struct *work)
1017 struct generic_pm_domain *genpd;
1019 genpd = container_of(work, struct generic_pm_domain, power_off_work);
1022 genpd_power_off(genpd, false, 0);
1023 genpd_unlock(genpd);
1027 * __genpd_runtime_suspend - walk the hierarchy of ->runtime_suspend() callbacks
1028 * @dev: Device to handle.
1030 static int __genpd_runtime_suspend(struct device *dev)
1032 int (*cb)(struct device *__dev);
1034 if (dev->type && dev->type->pm)
1035 cb = dev->type->pm->runtime_suspend;
1036 else if (dev->class && dev->class->pm)
1037 cb = dev->class->pm->runtime_suspend;
1038 else if (dev->bus && dev->bus->pm)
1039 cb = dev->bus->pm->runtime_suspend;
1043 if (!cb && dev->driver && dev->driver->pm)
1044 cb = dev->driver->pm->runtime_suspend;
1046 return cb ? cb(dev) : 0;
1050 * __genpd_runtime_resume - walk the hierarchy of ->runtime_resume() callbacks
1051 * @dev: Device to handle.
1053 static int __genpd_runtime_resume(struct device *dev)
1055 int (*cb)(struct device *__dev);
1057 if (dev->type && dev->type->pm)
1058 cb = dev->type->pm->runtime_resume;
1059 else if (dev->class && dev->class->pm)
1060 cb = dev->class->pm->runtime_resume;
1061 else if (dev->bus && dev->bus->pm)
1062 cb = dev->bus->pm->runtime_resume;
1066 if (!cb && dev->driver && dev->driver->pm)
1067 cb = dev->driver->pm->runtime_resume;
1069 return cb ? cb(dev) : 0;
1073 * genpd_runtime_suspend - Suspend a device belonging to I/O PM domain.
1074 * @dev: Device to suspend.
1076 * Carry out a runtime suspend of a device under the assumption that its
1077 * pm_domain field points to the domain member of an object of type
1078 * struct generic_pm_domain representing a PM domain consisting of I/O devices.
1080 static int genpd_runtime_suspend(struct device *dev)
1082 struct generic_pm_domain *genpd;
1083 bool (*suspend_ok)(struct device *__dev);
1084 struct generic_pm_domain_data *gpd_data = dev_gpd_data(dev);
1085 struct gpd_timing_data *td = gpd_data->td;
1086 bool runtime_pm = pm_runtime_enabled(dev);
1087 ktime_t time_start = 0;
1091 dev_dbg(dev, "%s()\n", __func__);
1093 genpd = dev_to_genpd(dev);
1098 * A runtime PM centric subsystem/driver may re-use the runtime PM
1099 * callbacks for other purposes than runtime PM. In those scenarios
1100 * runtime PM is disabled. Under these circumstances, we shall skip
1101 * validating/measuring the PM QoS latency.
1103 suspend_ok = genpd->gov ? genpd->gov->suspend_ok : NULL;
1104 if (runtime_pm && suspend_ok && !suspend_ok(dev))
1107 /* Measure suspend latency. */
1108 if (td && runtime_pm)
1109 time_start = ktime_get();
1111 ret = __genpd_runtime_suspend(dev);
1115 ret = genpd_stop_dev(genpd, dev);
1117 __genpd_runtime_resume(dev);
1121 /* Update suspend latency value if the measured time exceeds it. */
1122 if (td && runtime_pm) {
1123 elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start));
1124 if (elapsed_ns > td->suspend_latency_ns) {
1125 td->suspend_latency_ns = elapsed_ns;
1126 dev_dbg(dev, "suspend latency exceeded, %lld ns\n",
1128 genpd->gd->max_off_time_changed = true;
1129 td->constraint_changed = true;
1134 * If power.irq_safe is set, this routine may be run with
1135 * IRQs disabled, so suspend only if the PM domain also is irq_safe.
1137 if (irq_safe_dev_in_sleep_domain(dev, genpd))
1141 genpd_power_off(genpd, true, 0);
1142 gpd_data->rpm_pstate = genpd_drop_performance_state(dev);
1143 genpd_unlock(genpd);
1149 * genpd_runtime_resume - Resume a device belonging to I/O PM domain.
1150 * @dev: Device to resume.
1152 * Carry out a runtime resume of a device under the assumption that its
1153 * pm_domain field points to the domain member of an object of type
1154 * struct generic_pm_domain representing a PM domain consisting of I/O devices.
1156 static int genpd_runtime_resume(struct device *dev)
1158 struct generic_pm_domain *genpd;
1159 struct generic_pm_domain_data *gpd_data = dev_gpd_data(dev);
1160 struct gpd_timing_data *td = gpd_data->td;
1161 bool timed = td && pm_runtime_enabled(dev);
1162 ktime_t time_start = 0;
1166 dev_dbg(dev, "%s()\n", __func__);
1168 genpd = dev_to_genpd(dev);
1173 * As we don't power off a non IRQ safe domain, which holds
1174 * an IRQ safe device, we don't need to restore power to it.
1176 if (irq_safe_dev_in_sleep_domain(dev, genpd))
1180 genpd_restore_performance_state(dev, gpd_data->rpm_pstate);
1181 ret = genpd_power_on(genpd, 0);
1182 genpd_unlock(genpd);
1188 /* Measure resume latency. */
1190 time_start = ktime_get();
1192 ret = genpd_start_dev(genpd, dev);
1196 ret = __genpd_runtime_resume(dev);
1200 /* Update resume latency value if the measured time exceeds it. */
1202 elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start));
1203 if (elapsed_ns > td->resume_latency_ns) {
1204 td->resume_latency_ns = elapsed_ns;
1205 dev_dbg(dev, "resume latency exceeded, %lld ns\n",
1207 genpd->gd->max_off_time_changed = true;
1208 td->constraint_changed = true;
1215 genpd_stop_dev(genpd, dev);
1217 if (!pm_runtime_is_irq_safe(dev) || genpd_is_irq_safe(genpd)) {
1219 genpd_power_off(genpd, true, 0);
1220 gpd_data->rpm_pstate = genpd_drop_performance_state(dev);
1221 genpd_unlock(genpd);
1227 static bool pd_ignore_unused;
1228 static int __init pd_ignore_unused_setup(char *__unused)
1230 pd_ignore_unused = true;
1233 __setup("pd_ignore_unused", pd_ignore_unused_setup);
1236 * genpd_power_off_unused - Power off all PM domains with no devices in use.
1238 static int __init genpd_power_off_unused(void)
1240 struct generic_pm_domain *genpd;
1242 if (pd_ignore_unused) {
1243 pr_warn("genpd: Not disabling unused power domains\n");
1247 pr_info("genpd: Disabling unused power domains\n");
1248 mutex_lock(&gpd_list_lock);
1250 list_for_each_entry(genpd, &gpd_list, gpd_list_node)
1251 genpd_queue_power_off_work(genpd);
1253 mutex_unlock(&gpd_list_lock);
1257 late_initcall_sync(genpd_power_off_unused);
1259 #ifdef CONFIG_PM_SLEEP
1262 * genpd_sync_power_off - Synchronously power off a PM domain and its parents.
1263 * @genpd: PM domain to power off, if possible.
1264 * @use_lock: use the lock.
1265 * @depth: nesting count for lockdep.
1267 * Check if the given PM domain can be powered off (during system suspend or
1268 * hibernation) and do that if so. Also, in that case propagate to its parents.
1270 * This function is only called in "noirq" and "syscore" stages of system power
1271 * transitions. The "noirq" callbacks may be executed asynchronously, thus in
1272 * these cases the lock must be held.
1274 static void genpd_sync_power_off(struct generic_pm_domain *genpd, bool use_lock,
1277 struct gpd_link *link;
1279 if (!genpd_status_on(genpd) || genpd_is_always_on(genpd))
1282 if (genpd->suspended_count != genpd->device_count
1283 || atomic_read(&genpd->sd_count) > 0)
1286 /* Check that the children are in their deepest (powered-off) state. */
1287 list_for_each_entry(link, &genpd->parent_links, parent_node) {
1288 struct generic_pm_domain *child = link->child;
1289 if (child->state_idx < child->state_count - 1)
1293 /* Choose the deepest state when suspending */
1294 genpd->state_idx = genpd->state_count - 1;
1295 if (_genpd_power_off(genpd, false)) {
1296 genpd->states[genpd->state_idx].rejected++;
1299 genpd->states[genpd->state_idx].usage++;
1302 genpd->status = GENPD_STATE_OFF;
1304 list_for_each_entry(link, &genpd->child_links, child_node) {
1305 genpd_sd_counter_dec(link->parent);
1308 genpd_lock_nested(link->parent, depth + 1);
1310 genpd_sync_power_off(link->parent, use_lock, depth + 1);
1313 genpd_unlock(link->parent);
1318 * genpd_sync_power_on - Synchronously power on a PM domain and its parents.
1319 * @genpd: PM domain to power on.
1320 * @use_lock: use the lock.
1321 * @depth: nesting count for lockdep.
1323 * This function is only called in "noirq" and "syscore" stages of system power
1324 * transitions. The "noirq" callbacks may be executed asynchronously, thus in
1325 * these cases the lock must be held.
1327 static void genpd_sync_power_on(struct generic_pm_domain *genpd, bool use_lock,
1330 struct gpd_link *link;
1332 if (genpd_status_on(genpd))
1335 list_for_each_entry(link, &genpd->child_links, child_node) {
1336 genpd_sd_counter_inc(link->parent);
1339 genpd_lock_nested(link->parent, depth + 1);
1341 genpd_sync_power_on(link->parent, use_lock, depth + 1);
1344 genpd_unlock(link->parent);
1347 _genpd_power_on(genpd, false);
1348 genpd->status = GENPD_STATE_ON;
1352 * genpd_prepare - Start power transition of a device in a PM domain.
1353 * @dev: Device to start the transition of.
1355 * Start a power transition of a device (during a system-wide power transition)
1356 * under the assumption that its pm_domain field points to the domain member of
1357 * an object of type struct generic_pm_domain representing a PM domain
1358 * consisting of I/O devices.
1360 static int genpd_prepare(struct device *dev)
1362 struct generic_pm_domain *genpd;
1365 dev_dbg(dev, "%s()\n", __func__);
1367 genpd = dev_to_genpd(dev);
1372 genpd->prepared_count++;
1373 genpd_unlock(genpd);
1375 ret = pm_generic_prepare(dev);
1379 genpd->prepared_count--;
1381 genpd_unlock(genpd);
1384 /* Never return 1, as genpd don't cope with the direct_complete path. */
1385 return ret >= 0 ? 0 : ret;
1389 * genpd_finish_suspend - Completion of suspend or hibernation of device in an
1391 * @dev: Device to suspend.
1392 * @suspend_noirq: Generic suspend_noirq callback.
1393 * @resume_noirq: Generic resume_noirq callback.
1395 * Stop the device and remove power from the domain if all devices in it have
1398 static int genpd_finish_suspend(struct device *dev,
1399 int (*suspend_noirq)(struct device *dev),
1400 int (*resume_noirq)(struct device *dev))
1402 struct generic_pm_domain *genpd;
1405 genpd = dev_to_genpd(dev);
1409 ret = suspend_noirq(dev);
1413 if (device_wakeup_path(dev) && genpd_is_active_wakeup(genpd))
1416 if (genpd->dev_ops.stop && genpd->dev_ops.start &&
1417 !pm_runtime_status_suspended(dev)) {
1418 ret = genpd_stop_dev(genpd, dev);
1426 genpd->suspended_count++;
1427 genpd_sync_power_off(genpd, true, 0);
1428 genpd_unlock(genpd);
1434 * genpd_suspend_noirq - Completion of suspend of device in an I/O PM domain.
1435 * @dev: Device to suspend.
1437 * Stop the device and remove power from the domain if all devices in it have
1440 static int genpd_suspend_noirq(struct device *dev)
1442 dev_dbg(dev, "%s()\n", __func__);
1444 return genpd_finish_suspend(dev,
1445 pm_generic_suspend_noirq,
1446 pm_generic_resume_noirq);
1450 * genpd_finish_resume - Completion of resume of device in an I/O PM domain.
1451 * @dev: Device to resume.
1452 * @resume_noirq: Generic resume_noirq callback.
1454 * Restore power to the device's PM domain, if necessary, and start the device.
1456 static int genpd_finish_resume(struct device *dev,
1457 int (*resume_noirq)(struct device *dev))
1459 struct generic_pm_domain *genpd;
1462 dev_dbg(dev, "%s()\n", __func__);
1464 genpd = dev_to_genpd(dev);
1468 if (device_wakeup_path(dev) && genpd_is_active_wakeup(genpd))
1469 return resume_noirq(dev);
1472 genpd_sync_power_on(genpd, true, 0);
1473 genpd->suspended_count--;
1474 genpd_unlock(genpd);
1476 if (genpd->dev_ops.stop && genpd->dev_ops.start &&
1477 !pm_runtime_status_suspended(dev)) {
1478 ret = genpd_start_dev(genpd, dev);
1483 return pm_generic_resume_noirq(dev);
1487 * genpd_resume_noirq - Start of resume of device in an I/O PM domain.
1488 * @dev: Device to resume.
1490 * Restore power to the device's PM domain, if necessary, and start the device.
1492 static int genpd_resume_noirq(struct device *dev)
1494 dev_dbg(dev, "%s()\n", __func__);
1496 return genpd_finish_resume(dev, pm_generic_resume_noirq);
1500 * genpd_freeze_noirq - Completion of freezing a device in an I/O PM domain.
1501 * @dev: Device to freeze.
1503 * Carry out a late freeze of a device under the assumption that its
1504 * pm_domain field points to the domain member of an object of type
1505 * struct generic_pm_domain representing a power domain consisting of I/O
1508 static int genpd_freeze_noirq(struct device *dev)
1510 dev_dbg(dev, "%s()\n", __func__);
1512 return genpd_finish_suspend(dev,
1513 pm_generic_freeze_noirq,
1514 pm_generic_thaw_noirq);
1518 * genpd_thaw_noirq - Early thaw of device in an I/O PM domain.
1519 * @dev: Device to thaw.
1521 * Start the device, unless power has been removed from the domain already
1522 * before the system transition.
1524 static int genpd_thaw_noirq(struct device *dev)
1526 dev_dbg(dev, "%s()\n", __func__);
1528 return genpd_finish_resume(dev, pm_generic_thaw_noirq);
1532 * genpd_poweroff_noirq - Completion of hibernation of device in an
1534 * @dev: Device to poweroff.
1536 * Stop the device and remove power from the domain if all devices in it have
1539 static int genpd_poweroff_noirq(struct device *dev)
1541 dev_dbg(dev, "%s()\n", __func__);
1543 return genpd_finish_suspend(dev,
1544 pm_generic_poweroff_noirq,
1545 pm_generic_restore_noirq);
1549 * genpd_restore_noirq - Start of restore of device in an I/O PM domain.
1550 * @dev: Device to resume.
1552 * Make sure the domain will be in the same power state as before the
1553 * hibernation the system is resuming from and start the device if necessary.
1555 static int genpd_restore_noirq(struct device *dev)
1557 dev_dbg(dev, "%s()\n", __func__);
1559 return genpd_finish_resume(dev, pm_generic_restore_noirq);
1563 * genpd_complete - Complete power transition of a device in a power domain.
1564 * @dev: Device to complete the transition of.
1566 * Complete a power transition of a device (during a system-wide power
1567 * transition) under the assumption that its pm_domain field points to the
1568 * domain member of an object of type struct generic_pm_domain representing
1569 * a power domain consisting of I/O devices.
1571 static void genpd_complete(struct device *dev)
1573 struct generic_pm_domain *genpd;
1575 dev_dbg(dev, "%s()\n", __func__);
1577 genpd = dev_to_genpd(dev);
1581 pm_generic_complete(dev);
1585 genpd->prepared_count--;
1586 if (!genpd->prepared_count)
1587 genpd_queue_power_off_work(genpd);
1589 genpd_unlock(genpd);
1592 static void genpd_switch_state(struct device *dev, bool suspend)
1594 struct generic_pm_domain *genpd;
1597 genpd = dev_to_genpd_safe(dev);
1601 use_lock = genpd_is_irq_safe(genpd);
1607 genpd->suspended_count++;
1608 genpd_sync_power_off(genpd, use_lock, 0);
1610 genpd_sync_power_on(genpd, use_lock, 0);
1611 genpd->suspended_count--;
1615 genpd_unlock(genpd);
1619 * dev_pm_genpd_suspend - Synchronously try to suspend the genpd for @dev
1620 * @dev: The device that is attached to the genpd, that can be suspended.
1622 * This routine should typically be called for a device that needs to be
1623 * suspended during the syscore suspend phase. It may also be called during
1624 * suspend-to-idle to suspend a corresponding CPU device that is attached to a
1627 void dev_pm_genpd_suspend(struct device *dev)
1629 genpd_switch_state(dev, true);
1631 EXPORT_SYMBOL_GPL(dev_pm_genpd_suspend);
1634 * dev_pm_genpd_resume - Synchronously try to resume the genpd for @dev
1635 * @dev: The device that is attached to the genpd, which needs to be resumed.
1637 * This routine should typically be called for a device that needs to be resumed
1638 * during the syscore resume phase. It may also be called during suspend-to-idle
1639 * to resume a corresponding CPU device that is attached to a genpd.
1641 void dev_pm_genpd_resume(struct device *dev)
1643 genpd_switch_state(dev, false);
1645 EXPORT_SYMBOL_GPL(dev_pm_genpd_resume);
1647 #else /* !CONFIG_PM_SLEEP */
1649 #define genpd_prepare NULL
1650 #define genpd_suspend_noirq NULL
1651 #define genpd_resume_noirq NULL
1652 #define genpd_freeze_noirq NULL
1653 #define genpd_thaw_noirq NULL
1654 #define genpd_poweroff_noirq NULL
1655 #define genpd_restore_noirq NULL
1656 #define genpd_complete NULL
1658 #endif /* CONFIG_PM_SLEEP */
1660 static struct generic_pm_domain_data *genpd_alloc_dev_data(struct device *dev,
1663 struct generic_pm_domain_data *gpd_data;
1664 struct gpd_timing_data *td;
1667 ret = dev_pm_get_subsys_data(dev);
1669 return ERR_PTR(ret);
1671 gpd_data = kzalloc(sizeof(*gpd_data), GFP_KERNEL);
1677 gpd_data->base.dev = dev;
1678 gpd_data->nb.notifier_call = genpd_dev_pm_qos_notifier;
1680 /* Allocate data used by a governor. */
1682 td = kzalloc(sizeof(*td), GFP_KERNEL);
1688 td->constraint_changed = true;
1689 td->effective_constraint_ns = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT_NS;
1690 td->next_wakeup = KTIME_MAX;
1694 spin_lock_irq(&dev->power.lock);
1696 if (dev->power.subsys_data->domain_data)
1699 dev->power.subsys_data->domain_data = &gpd_data->base;
1701 spin_unlock_irq(&dev->power.lock);
1709 kfree(gpd_data->td);
1712 dev_pm_put_subsys_data(dev);
1713 return ERR_PTR(ret);
1716 static void genpd_free_dev_data(struct device *dev,
1717 struct generic_pm_domain_data *gpd_data)
1719 spin_lock_irq(&dev->power.lock);
1721 dev->power.subsys_data->domain_data = NULL;
1723 spin_unlock_irq(&dev->power.lock);
1725 kfree(gpd_data->td);
1727 dev_pm_put_subsys_data(dev);
1730 static void genpd_update_cpumask(struct generic_pm_domain *genpd,
1731 int cpu, bool set, unsigned int depth)
1733 struct gpd_link *link;
1735 if (!genpd_is_cpu_domain(genpd))
1738 list_for_each_entry(link, &genpd->child_links, child_node) {
1739 struct generic_pm_domain *parent = link->parent;
1741 genpd_lock_nested(parent, depth + 1);
1742 genpd_update_cpumask(parent, cpu, set, depth + 1);
1743 genpd_unlock(parent);
1747 cpumask_set_cpu(cpu, genpd->cpus);
1749 cpumask_clear_cpu(cpu, genpd->cpus);
1752 static void genpd_set_cpumask(struct generic_pm_domain *genpd, int cpu)
1755 genpd_update_cpumask(genpd, cpu, true, 0);
1758 static void genpd_clear_cpumask(struct generic_pm_domain *genpd, int cpu)
1761 genpd_update_cpumask(genpd, cpu, false, 0);
1764 static int genpd_get_cpu(struct generic_pm_domain *genpd, struct device *dev)
1768 if (!genpd_is_cpu_domain(genpd))
1771 for_each_possible_cpu(cpu) {
1772 if (get_cpu_device(cpu) == dev)
1779 static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev,
1780 struct device *base_dev)
1782 struct genpd_governor_data *gd = genpd->gd;
1783 struct generic_pm_domain_data *gpd_data;
1786 dev_dbg(dev, "%s()\n", __func__);
1788 gpd_data = genpd_alloc_dev_data(dev, gd);
1789 if (IS_ERR(gpd_data))
1790 return PTR_ERR(gpd_data);
1792 gpd_data->cpu = genpd_get_cpu(genpd, base_dev);
1794 gpd_data->hw_mode = genpd->get_hwmode_dev ? genpd->get_hwmode_dev(genpd, dev) : false;
1796 ret = genpd->attach_dev ? genpd->attach_dev(genpd, dev) : 0;
1802 genpd_set_cpumask(genpd, gpd_data->cpu);
1804 genpd->device_count++;
1806 gd->max_off_time_changed = true;
1808 list_add_tail(&gpd_data->base.list_node, &genpd->dev_list);
1810 genpd_unlock(genpd);
1811 dev_pm_domain_set(dev, &genpd->domain);
1814 genpd_free_dev_data(dev, gpd_data);
1816 dev_pm_qos_add_notifier(dev, &gpd_data->nb,
1817 DEV_PM_QOS_RESUME_LATENCY);
1823 * pm_genpd_add_device - Add a device to an I/O PM domain.
1824 * @genpd: PM domain to add the device to.
1825 * @dev: Device to be added.
1827 int pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev)
1834 mutex_lock(&gpd_list_lock);
1835 ret = genpd_add_device(genpd, dev, dev);
1836 mutex_unlock(&gpd_list_lock);
1840 EXPORT_SYMBOL_GPL(pm_genpd_add_device);
1842 static int genpd_remove_device(struct generic_pm_domain *genpd,
1845 struct generic_pm_domain_data *gpd_data;
1846 struct pm_domain_data *pdd;
1849 dev_dbg(dev, "%s()\n", __func__);
1851 pdd = dev->power.subsys_data->domain_data;
1852 gpd_data = to_gpd_data(pdd);
1853 dev_pm_qos_remove_notifier(dev, &gpd_data->nb,
1854 DEV_PM_QOS_RESUME_LATENCY);
1858 if (genpd->prepared_count > 0) {
1863 genpd->device_count--;
1865 genpd->gd->max_off_time_changed = true;
1867 genpd_clear_cpumask(genpd, gpd_data->cpu);
1869 list_del_init(&pdd->list_node);
1871 genpd_unlock(genpd);
1873 dev_pm_domain_set(dev, NULL);
1875 if (genpd->detach_dev)
1876 genpd->detach_dev(genpd, dev);
1878 genpd_free_dev_data(dev, gpd_data);
1883 genpd_unlock(genpd);
1884 dev_pm_qos_add_notifier(dev, &gpd_data->nb, DEV_PM_QOS_RESUME_LATENCY);
1890 * pm_genpd_remove_device - Remove a device from an I/O PM domain.
1891 * @dev: Device to be removed.
1893 int pm_genpd_remove_device(struct device *dev)
1895 struct generic_pm_domain *genpd = dev_to_genpd_safe(dev);
1900 return genpd_remove_device(genpd, dev);
1902 EXPORT_SYMBOL_GPL(pm_genpd_remove_device);
1905 * dev_pm_genpd_add_notifier - Add a genpd power on/off notifier for @dev
1907 * @dev: Device that should be associated with the notifier
1908 * @nb: The notifier block to register
1910 * Users may call this function to add a genpd power on/off notifier for an
1911 * attached @dev. Only one notifier per device is allowed. The notifier is
1912 * sent when genpd is powering on/off the PM domain.
1914 * It is assumed that the user guarantee that the genpd wouldn't be detached
1915 * while this routine is getting called.
1917 * Returns 0 on success and negative error values on failures.
1919 int dev_pm_genpd_add_notifier(struct device *dev, struct notifier_block *nb)
1921 struct generic_pm_domain *genpd;
1922 struct generic_pm_domain_data *gpd_data;
1925 genpd = dev_to_genpd_safe(dev);
1929 if (WARN_ON(!dev->power.subsys_data ||
1930 !dev->power.subsys_data->domain_data))
1933 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
1934 if (gpd_data->power_nb)
1938 ret = raw_notifier_chain_register(&genpd->power_notifiers, nb);
1939 genpd_unlock(genpd);
1942 dev_warn(dev, "failed to add notifier for PM domain %s\n",
1947 gpd_data->power_nb = nb;
1950 EXPORT_SYMBOL_GPL(dev_pm_genpd_add_notifier);
1953 * dev_pm_genpd_remove_notifier - Remove a genpd power on/off notifier for @dev
1955 * @dev: Device that is associated with the notifier
1957 * Users may call this function to remove a genpd power on/off notifier for an
1960 * It is assumed that the user guarantee that the genpd wouldn't be detached
1961 * while this routine is getting called.
1963 * Returns 0 on success and negative error values on failures.
1965 int dev_pm_genpd_remove_notifier(struct device *dev)
1967 struct generic_pm_domain *genpd;
1968 struct generic_pm_domain_data *gpd_data;
1971 genpd = dev_to_genpd_safe(dev);
1975 if (WARN_ON(!dev->power.subsys_data ||
1976 !dev->power.subsys_data->domain_data))
1979 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
1980 if (!gpd_data->power_nb)
1984 ret = raw_notifier_chain_unregister(&genpd->power_notifiers,
1985 gpd_data->power_nb);
1986 genpd_unlock(genpd);
1989 dev_warn(dev, "failed to remove notifier for PM domain %s\n",
1994 gpd_data->power_nb = NULL;
1997 EXPORT_SYMBOL_GPL(dev_pm_genpd_remove_notifier);
1999 static int genpd_add_subdomain(struct generic_pm_domain *genpd,
2000 struct generic_pm_domain *subdomain)
2002 struct gpd_link *link, *itr;
2005 if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(subdomain)
2006 || genpd == subdomain)
2010 * If the domain can be powered on/off in an IRQ safe
2011 * context, ensure that the subdomain can also be
2012 * powered on/off in that context.
2014 if (!genpd_is_irq_safe(genpd) && genpd_is_irq_safe(subdomain)) {
2015 WARN(1, "Parent %s of subdomain %s must be IRQ safe\n",
2016 genpd->name, subdomain->name);
2020 link = kzalloc(sizeof(*link), GFP_KERNEL);
2024 genpd_lock(subdomain);
2025 genpd_lock_nested(genpd, SINGLE_DEPTH_NESTING);
2027 if (!genpd_status_on(genpd) && genpd_status_on(subdomain)) {
2032 list_for_each_entry(itr, &genpd->parent_links, parent_node) {
2033 if (itr->child == subdomain && itr->parent == genpd) {
2039 link->parent = genpd;
2040 list_add_tail(&link->parent_node, &genpd->parent_links);
2041 link->child = subdomain;
2042 list_add_tail(&link->child_node, &subdomain->child_links);
2043 if (genpd_status_on(subdomain))
2044 genpd_sd_counter_inc(genpd);
2047 genpd_unlock(genpd);
2048 genpd_unlock(subdomain);
2055 * pm_genpd_add_subdomain - Add a subdomain to an I/O PM domain.
2056 * @genpd: Leader PM domain to add the subdomain to.
2057 * @subdomain: Subdomain to be added.
2059 int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
2060 struct generic_pm_domain *subdomain)
2064 mutex_lock(&gpd_list_lock);
2065 ret = genpd_add_subdomain(genpd, subdomain);
2066 mutex_unlock(&gpd_list_lock);
2070 EXPORT_SYMBOL_GPL(pm_genpd_add_subdomain);
2073 * pm_genpd_remove_subdomain - Remove a subdomain from an I/O PM domain.
2074 * @genpd: Leader PM domain to remove the subdomain from.
2075 * @subdomain: Subdomain to be removed.
2077 int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
2078 struct generic_pm_domain *subdomain)
2080 struct gpd_link *l, *link;
2083 if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(subdomain))
2086 genpd_lock(subdomain);
2087 genpd_lock_nested(genpd, SINGLE_DEPTH_NESTING);
2089 if (!list_empty(&subdomain->parent_links) || subdomain->device_count) {
2090 pr_warn("%s: unable to remove subdomain %s\n",
2091 genpd->name, subdomain->name);
2096 list_for_each_entry_safe(link, l, &genpd->parent_links, parent_node) {
2097 if (link->child != subdomain)
2100 list_del(&link->parent_node);
2101 list_del(&link->child_node);
2103 if (genpd_status_on(subdomain))
2104 genpd_sd_counter_dec(genpd);
2111 genpd_unlock(genpd);
2112 genpd_unlock(subdomain);
2116 EXPORT_SYMBOL_GPL(pm_genpd_remove_subdomain);
2118 static void genpd_free_default_power_state(struct genpd_power_state *states,
2119 unsigned int state_count)
2124 static int genpd_set_default_power_state(struct generic_pm_domain *genpd)
2126 struct genpd_power_state *state;
2128 state = kzalloc(sizeof(*state), GFP_KERNEL);
2132 genpd->states = state;
2133 genpd->state_count = 1;
2134 genpd->free_states = genpd_free_default_power_state;
2139 static int genpd_alloc_data(struct generic_pm_domain *genpd)
2141 struct genpd_governor_data *gd = NULL;
2144 if (genpd_is_cpu_domain(genpd) &&
2145 !zalloc_cpumask_var(&genpd->cpus, GFP_KERNEL))
2149 gd = kzalloc(sizeof(*gd), GFP_KERNEL);
2155 gd->max_off_time_ns = -1;
2156 gd->max_off_time_changed = true;
2157 gd->next_wakeup = KTIME_MAX;
2158 gd->next_hrtimer = KTIME_MAX;
2161 /* Use only one "off" state if there were no states declared */
2162 if (genpd->state_count == 0) {
2163 ret = genpd_set_default_power_state(genpd);
2172 if (genpd_is_cpu_domain(genpd))
2173 free_cpumask_var(genpd->cpus);
2178 static void genpd_free_data(struct generic_pm_domain *genpd)
2180 if (genpd_is_cpu_domain(genpd))
2181 free_cpumask_var(genpd->cpus);
2182 if (genpd->free_states)
2183 genpd->free_states(genpd->states, genpd->state_count);
2187 static void genpd_lock_init(struct generic_pm_domain *genpd)
2189 if (genpd_is_cpu_domain(genpd)) {
2190 raw_spin_lock_init(&genpd->raw_slock);
2191 genpd->lock_ops = &genpd_raw_spin_ops;
2192 } else if (genpd_is_irq_safe(genpd)) {
2193 spin_lock_init(&genpd->slock);
2194 genpd->lock_ops = &genpd_spin_ops;
2196 mutex_init(&genpd->mlock);
2197 genpd->lock_ops = &genpd_mtx_ops;
2202 * pm_genpd_init - Initialize a generic I/O PM domain object.
2203 * @genpd: PM domain object to initialize.
2204 * @gov: PM domain governor to associate with the domain (may be NULL).
2205 * @is_off: Initial value of the domain's power_is_off field.
2207 * Returns 0 on successful initialization, else a negative error code.
2209 int pm_genpd_init(struct generic_pm_domain *genpd,
2210 struct dev_power_governor *gov, bool is_off)
2214 if (IS_ERR_OR_NULL(genpd))
2217 INIT_LIST_HEAD(&genpd->parent_links);
2218 INIT_LIST_HEAD(&genpd->child_links);
2219 INIT_LIST_HEAD(&genpd->dev_list);
2220 RAW_INIT_NOTIFIER_HEAD(&genpd->power_notifiers);
2221 genpd_lock_init(genpd);
2223 INIT_WORK(&genpd->power_off_work, genpd_power_off_work_fn);
2224 atomic_set(&genpd->sd_count, 0);
2225 genpd->status = is_off ? GENPD_STATE_OFF : GENPD_STATE_ON;
2226 genpd->device_count = 0;
2227 genpd->provider = NULL;
2228 genpd->has_provider = false;
2229 genpd->accounting_time = ktime_get_mono_fast_ns();
2230 genpd->domain.ops.runtime_suspend = genpd_runtime_suspend;
2231 genpd->domain.ops.runtime_resume = genpd_runtime_resume;
2232 genpd->domain.ops.prepare = genpd_prepare;
2233 genpd->domain.ops.suspend_noirq = genpd_suspend_noirq;
2234 genpd->domain.ops.resume_noirq = genpd_resume_noirq;
2235 genpd->domain.ops.freeze_noirq = genpd_freeze_noirq;
2236 genpd->domain.ops.thaw_noirq = genpd_thaw_noirq;
2237 genpd->domain.ops.poweroff_noirq = genpd_poweroff_noirq;
2238 genpd->domain.ops.restore_noirq = genpd_restore_noirq;
2239 genpd->domain.ops.complete = genpd_complete;
2240 genpd->domain.start = genpd_dev_pm_start;
2241 genpd->domain.set_performance_state = genpd_dev_pm_set_performance_state;
2243 if (genpd->flags & GENPD_FLAG_PM_CLK) {
2244 genpd->dev_ops.stop = pm_clk_suspend;
2245 genpd->dev_ops.start = pm_clk_resume;
2248 /* The always-on governor works better with the corresponding flag. */
2249 if (gov == &pm_domain_always_on_gov)
2250 genpd->flags |= GENPD_FLAG_RPM_ALWAYS_ON;
2252 /* Always-on domains must be powered on at initialization. */
2253 if ((genpd_is_always_on(genpd) || genpd_is_rpm_always_on(genpd)) &&
2254 !genpd_status_on(genpd)) {
2255 pr_err("always-on PM domain %s is not on\n", genpd->name);
2259 /* Multiple states but no governor doesn't make sense. */
2260 if (!gov && genpd->state_count > 1)
2261 pr_warn("%s: no governor for states\n", genpd->name);
2263 ret = genpd_alloc_data(genpd);
2267 device_initialize(&genpd->dev);
2268 dev_set_name(&genpd->dev, "%s", genpd->name);
2270 mutex_lock(&gpd_list_lock);
2271 list_add(&genpd->gpd_list_node, &gpd_list);
2272 mutex_unlock(&gpd_list_lock);
2273 genpd_debug_add(genpd);
2277 EXPORT_SYMBOL_GPL(pm_genpd_init);
2279 static int genpd_remove(struct generic_pm_domain *genpd)
2281 struct gpd_link *l, *link;
2283 if (IS_ERR_OR_NULL(genpd))
2288 if (genpd->has_provider) {
2289 genpd_unlock(genpd);
2290 pr_err("Provider present, unable to remove %s\n", genpd->name);
2294 if (!list_empty(&genpd->parent_links) || genpd->device_count) {
2295 genpd_unlock(genpd);
2296 pr_err("%s: unable to remove %s\n", __func__, genpd->name);
2300 list_for_each_entry_safe(link, l, &genpd->child_links, child_node) {
2301 list_del(&link->parent_node);
2302 list_del(&link->child_node);
2306 list_del(&genpd->gpd_list_node);
2307 genpd_unlock(genpd);
2308 genpd_debug_remove(genpd);
2309 cancel_work_sync(&genpd->power_off_work);
2310 genpd_free_data(genpd);
2312 pr_debug("%s: removed %s\n", __func__, genpd->name);
2318 * pm_genpd_remove - Remove a generic I/O PM domain
2319 * @genpd: Pointer to PM domain that is to be removed.
2321 * To remove the PM domain, this function:
2322 * - Removes the PM domain as a subdomain to any parent domains,
2324 * - Removes the PM domain from the list of registered PM domains.
2326 * The PM domain will only be removed, if the associated provider has
2327 * been removed, it is not a parent to any other PM domain and has no
2328 * devices associated with it.
2330 int pm_genpd_remove(struct generic_pm_domain *genpd)
2334 mutex_lock(&gpd_list_lock);
2335 ret = genpd_remove(genpd);
2336 mutex_unlock(&gpd_list_lock);
2340 EXPORT_SYMBOL_GPL(pm_genpd_remove);
2342 #ifdef CONFIG_PM_GENERIC_DOMAINS_OF
2345 * Device Tree based PM domain providers.
2347 * The code below implements generic device tree based PM domain providers that
2348 * bind device tree nodes with generic PM domains registered in the system.
2350 * Any driver that registers generic PM domains and needs to support binding of
2351 * devices to these domains is supposed to register a PM domain provider, which
2352 * maps a PM domain specifier retrieved from the device tree to a PM domain.
2354 * Two simple mapping functions have been provided for convenience:
2355 * - genpd_xlate_simple() for 1:1 device tree node to PM domain mapping.
2356 * - genpd_xlate_onecell() for mapping of multiple PM domains per node by
2361 * struct of_genpd_provider - PM domain provider registration structure
2362 * @link: Entry in global list of PM domain providers
2363 * @node: Pointer to device tree node of PM domain provider
2364 * @xlate: Provider-specific xlate callback mapping a set of specifier cells
2366 * @data: context pointer to be passed into @xlate callback
2368 struct of_genpd_provider {
2369 struct list_head link;
2370 struct device_node *node;
2371 genpd_xlate_t xlate;
2375 /* List of registered PM domain providers. */
2376 static LIST_HEAD(of_genpd_providers);
2377 /* Mutex to protect the list above. */
2378 static DEFINE_MUTEX(of_genpd_mutex);
2381 * genpd_xlate_simple() - Xlate function for direct node-domain mapping
2382 * @genpdspec: OF phandle args to map into a PM domain
2383 * @data: xlate function private data - pointer to struct generic_pm_domain
2385 * This is a generic xlate function that can be used to model PM domains that
2386 * have their own device tree nodes. The private data of xlate function needs
2387 * to be a valid pointer to struct generic_pm_domain.
2389 static struct generic_pm_domain *genpd_xlate_simple(
2390 const struct of_phandle_args *genpdspec,
2397 * genpd_xlate_onecell() - Xlate function using a single index.
2398 * @genpdspec: OF phandle args to map into a PM domain
2399 * @data: xlate function private data - pointer to struct genpd_onecell_data
2401 * This is a generic xlate function that can be used to model simple PM domain
2402 * controllers that have one device tree node and provide multiple PM domains.
2403 * A single cell is used as an index into an array of PM domains specified in
2404 * the genpd_onecell_data struct when registering the provider.
2406 static struct generic_pm_domain *genpd_xlate_onecell(
2407 const struct of_phandle_args *genpdspec,
2410 struct genpd_onecell_data *genpd_data = data;
2411 unsigned int idx = genpdspec->args[0];
2413 if (genpdspec->args_count != 1)
2414 return ERR_PTR(-EINVAL);
2416 if (idx >= genpd_data->num_domains) {
2417 pr_err("%s: invalid domain index %u\n", __func__, idx);
2418 return ERR_PTR(-EINVAL);
2421 if (!genpd_data->domains[idx])
2422 return ERR_PTR(-ENOENT);
2424 return genpd_data->domains[idx];
2428 * genpd_add_provider() - Register a PM domain provider for a node
2429 * @np: Device node pointer associated with the PM domain provider.
2430 * @xlate: Callback for decoding PM domain from phandle arguments.
2431 * @data: Context pointer for @xlate callback.
2433 static int genpd_add_provider(struct device_node *np, genpd_xlate_t xlate,
2436 struct of_genpd_provider *cp;
2438 cp = kzalloc(sizeof(*cp), GFP_KERNEL);
2442 cp->node = of_node_get(np);
2445 fwnode_dev_initialized(&np->fwnode, true);
2447 mutex_lock(&of_genpd_mutex);
2448 list_add(&cp->link, &of_genpd_providers);
2449 mutex_unlock(&of_genpd_mutex);
2450 pr_debug("Added domain provider from %pOF\n", np);
2455 static bool genpd_present(const struct generic_pm_domain *genpd)
2458 const struct generic_pm_domain *gpd;
2460 mutex_lock(&gpd_list_lock);
2461 list_for_each_entry(gpd, &gpd_list, gpd_list_node) {
2467 mutex_unlock(&gpd_list_lock);
2473 * of_genpd_add_provider_simple() - Register a simple PM domain provider
2474 * @np: Device node pointer associated with the PM domain provider.
2475 * @genpd: Pointer to PM domain associated with the PM domain provider.
2477 int of_genpd_add_provider_simple(struct device_node *np,
2478 struct generic_pm_domain *genpd)
2485 if (!genpd_present(genpd))
2488 genpd->dev.of_node = np;
2490 /* Parse genpd OPP table */
2491 if (!genpd_is_opp_table_fw(genpd) && genpd->set_performance_state) {
2492 ret = dev_pm_opp_of_add_table(&genpd->dev);
2494 return dev_err_probe(&genpd->dev, ret, "Failed to add OPP table\n");
2497 * Save table for faster processing while setting performance
2500 genpd->opp_table = dev_pm_opp_get_opp_table(&genpd->dev);
2501 WARN_ON(IS_ERR(genpd->opp_table));
2504 ret = genpd_add_provider(np, genpd_xlate_simple, genpd);
2506 if (!genpd_is_opp_table_fw(genpd) && genpd->set_performance_state) {
2507 dev_pm_opp_put_opp_table(genpd->opp_table);
2508 dev_pm_opp_of_remove_table(&genpd->dev);
2514 genpd->provider = &np->fwnode;
2515 genpd->has_provider = true;
2519 EXPORT_SYMBOL_GPL(of_genpd_add_provider_simple);
2522 * of_genpd_add_provider_onecell() - Register a onecell PM domain provider
2523 * @np: Device node pointer associated with the PM domain provider.
2524 * @data: Pointer to the data associated with the PM domain provider.
2526 int of_genpd_add_provider_onecell(struct device_node *np,
2527 struct genpd_onecell_data *data)
2529 struct generic_pm_domain *genpd;
2537 data->xlate = genpd_xlate_onecell;
2539 for (i = 0; i < data->num_domains; i++) {
2540 genpd = data->domains[i];
2544 if (!genpd_present(genpd))
2547 genpd->dev.of_node = np;
2549 /* Parse genpd OPP table */
2550 if (!genpd_is_opp_table_fw(genpd) && genpd->set_performance_state) {
2551 ret = dev_pm_opp_of_add_table_indexed(&genpd->dev, i);
2553 dev_err_probe(&genpd->dev, ret,
2554 "Failed to add OPP table for index %d\n", i);
2559 * Save table for faster processing while setting
2560 * performance state.
2562 genpd->opp_table = dev_pm_opp_get_opp_table(&genpd->dev);
2563 WARN_ON(IS_ERR(genpd->opp_table));
2566 genpd->provider = &np->fwnode;
2567 genpd->has_provider = true;
2570 ret = genpd_add_provider(np, data->xlate, data);
2578 genpd = data->domains[i];
2583 genpd->provider = NULL;
2584 genpd->has_provider = false;
2586 if (!genpd_is_opp_table_fw(genpd) && genpd->set_performance_state) {
2587 dev_pm_opp_put_opp_table(genpd->opp_table);
2588 dev_pm_opp_of_remove_table(&genpd->dev);
2594 EXPORT_SYMBOL_GPL(of_genpd_add_provider_onecell);
2597 * of_genpd_del_provider() - Remove a previously registered PM domain provider
2598 * @np: Device node pointer associated with the PM domain provider
2600 void of_genpd_del_provider(struct device_node *np)
2602 struct of_genpd_provider *cp, *tmp;
2603 struct generic_pm_domain *gpd;
2605 mutex_lock(&gpd_list_lock);
2606 mutex_lock(&of_genpd_mutex);
2607 list_for_each_entry_safe(cp, tmp, &of_genpd_providers, link) {
2608 if (cp->node == np) {
2610 * For each PM domain associated with the
2611 * provider, set the 'has_provider' to false
2612 * so that the PM domain can be safely removed.
2614 list_for_each_entry(gpd, &gpd_list, gpd_list_node) {
2615 if (gpd->provider == &np->fwnode) {
2616 gpd->has_provider = false;
2618 if (genpd_is_opp_table_fw(gpd) || !gpd->set_performance_state)
2621 dev_pm_opp_put_opp_table(gpd->opp_table);
2622 dev_pm_opp_of_remove_table(&gpd->dev);
2626 fwnode_dev_initialized(&cp->node->fwnode, false);
2627 list_del(&cp->link);
2628 of_node_put(cp->node);
2633 mutex_unlock(&of_genpd_mutex);
2634 mutex_unlock(&gpd_list_lock);
2636 EXPORT_SYMBOL_GPL(of_genpd_del_provider);
2639 * genpd_get_from_provider() - Look-up PM domain
2640 * @genpdspec: OF phandle args to use for look-up
2642 * Looks for a PM domain provider under the node specified by @genpdspec and if
2643 * found, uses xlate function of the provider to map phandle args to a PM
2646 * Returns a valid pointer to struct generic_pm_domain on success or ERR_PTR()
2649 static struct generic_pm_domain *genpd_get_from_provider(
2650 const struct of_phandle_args *genpdspec)
2652 struct generic_pm_domain *genpd = ERR_PTR(-ENOENT);
2653 struct of_genpd_provider *provider;
2656 return ERR_PTR(-EINVAL);
2658 mutex_lock(&of_genpd_mutex);
2660 /* Check if we have such a provider in our array */
2661 list_for_each_entry(provider, &of_genpd_providers, link) {
2662 if (provider->node == genpdspec->np)
2663 genpd = provider->xlate(genpdspec, provider->data);
2668 mutex_unlock(&of_genpd_mutex);
2674 * of_genpd_add_device() - Add a device to an I/O PM domain
2675 * @genpdspec: OF phandle args to use for look-up PM domain
2676 * @dev: Device to be added.
2678 * Looks-up an I/O PM domain based upon phandle args provided and adds
2679 * the device to the PM domain. Returns a negative error code on failure.
2681 int of_genpd_add_device(const struct of_phandle_args *genpdspec, struct device *dev)
2683 struct generic_pm_domain *genpd;
2689 mutex_lock(&gpd_list_lock);
2691 genpd = genpd_get_from_provider(genpdspec);
2692 if (IS_ERR(genpd)) {
2693 ret = PTR_ERR(genpd);
2697 ret = genpd_add_device(genpd, dev, dev);
2700 mutex_unlock(&gpd_list_lock);
2704 EXPORT_SYMBOL_GPL(of_genpd_add_device);
2707 * of_genpd_add_subdomain - Add a subdomain to an I/O PM domain.
2708 * @parent_spec: OF phandle args to use for parent PM domain look-up
2709 * @subdomain_spec: OF phandle args to use for subdomain look-up
2711 * Looks-up a parent PM domain and subdomain based upon phandle args
2712 * provided and adds the subdomain to the parent PM domain. Returns a
2713 * negative error code on failure.
2715 int of_genpd_add_subdomain(const struct of_phandle_args *parent_spec,
2716 const struct of_phandle_args *subdomain_spec)
2718 struct generic_pm_domain *parent, *subdomain;
2721 mutex_lock(&gpd_list_lock);
2723 parent = genpd_get_from_provider(parent_spec);
2724 if (IS_ERR(parent)) {
2725 ret = PTR_ERR(parent);
2729 subdomain = genpd_get_from_provider(subdomain_spec);
2730 if (IS_ERR(subdomain)) {
2731 ret = PTR_ERR(subdomain);
2735 ret = genpd_add_subdomain(parent, subdomain);
2738 mutex_unlock(&gpd_list_lock);
2740 return ret == -ENOENT ? -EPROBE_DEFER : ret;
2742 EXPORT_SYMBOL_GPL(of_genpd_add_subdomain);
2745 * of_genpd_remove_subdomain - Remove a subdomain from an I/O PM domain.
2746 * @parent_spec: OF phandle args to use for parent PM domain look-up
2747 * @subdomain_spec: OF phandle args to use for subdomain look-up
2749 * Looks-up a parent PM domain and subdomain based upon phandle args
2750 * provided and removes the subdomain from the parent PM domain. Returns a
2751 * negative error code on failure.
2753 int of_genpd_remove_subdomain(const struct of_phandle_args *parent_spec,
2754 const struct of_phandle_args *subdomain_spec)
2756 struct generic_pm_domain *parent, *subdomain;
2759 mutex_lock(&gpd_list_lock);
2761 parent = genpd_get_from_provider(parent_spec);
2762 if (IS_ERR(parent)) {
2763 ret = PTR_ERR(parent);
2767 subdomain = genpd_get_from_provider(subdomain_spec);
2768 if (IS_ERR(subdomain)) {
2769 ret = PTR_ERR(subdomain);
2773 ret = pm_genpd_remove_subdomain(parent, subdomain);
2776 mutex_unlock(&gpd_list_lock);
2780 EXPORT_SYMBOL_GPL(of_genpd_remove_subdomain);
2783 * of_genpd_remove_last - Remove the last PM domain registered for a provider
2784 * @np: Pointer to device node associated with provider
2786 * Find the last PM domain that was added by a particular provider and
2787 * remove this PM domain from the list of PM domains. The provider is
2788 * identified by the 'provider' device structure that is passed. The PM
2789 * domain will only be removed, if the provider associated with domain
2792 * Returns a valid pointer to struct generic_pm_domain on success or
2793 * ERR_PTR() on failure.
2795 struct generic_pm_domain *of_genpd_remove_last(struct device_node *np)
2797 struct generic_pm_domain *gpd, *tmp, *genpd = ERR_PTR(-ENOENT);
2800 if (IS_ERR_OR_NULL(np))
2801 return ERR_PTR(-EINVAL);
2803 mutex_lock(&gpd_list_lock);
2804 list_for_each_entry_safe(gpd, tmp, &gpd_list, gpd_list_node) {
2805 if (gpd->provider == &np->fwnode) {
2806 ret = genpd_remove(gpd);
2807 genpd = ret ? ERR_PTR(ret) : gpd;
2811 mutex_unlock(&gpd_list_lock);
2815 EXPORT_SYMBOL_GPL(of_genpd_remove_last);
2817 static void genpd_release_dev(struct device *dev)
2819 of_node_put(dev->of_node);
2823 static const struct bus_type genpd_bus_type = {
2828 * genpd_dev_pm_detach - Detach a device from its PM domain.
2829 * @dev: Device to detach.
2830 * @power_off: Currently not used
2832 * Try to locate a corresponding generic PM domain, which the device was
2833 * attached to previously. If such is found, the device is detached from it.
2835 static void genpd_dev_pm_detach(struct device *dev, bool power_off)
2837 struct generic_pm_domain *pd;
2841 pd = dev_to_genpd(dev);
2845 dev_dbg(dev, "removing from PM domain %s\n", pd->name);
2847 /* Drop the default performance state */
2848 if (dev_gpd_data(dev)->default_pstate) {
2849 dev_pm_genpd_set_performance_state(dev, 0);
2850 dev_gpd_data(dev)->default_pstate = 0;
2853 for (i = 1; i < GENPD_RETRY_MAX_MS; i <<= 1) {
2854 ret = genpd_remove_device(pd, dev);
2863 dev_err(dev, "failed to remove from PM domain %s: %d",
2868 /* Check if PM domain can be powered off after removing this device. */
2869 genpd_queue_power_off_work(pd);
2871 /* Unregister the device if it was created by genpd. */
2872 if (dev->bus == &genpd_bus_type)
2873 device_unregister(dev);
2876 static void genpd_dev_pm_sync(struct device *dev)
2878 struct generic_pm_domain *pd;
2880 pd = dev_to_genpd(dev);
2884 genpd_queue_power_off_work(pd);
2887 static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev,
2888 unsigned int index, bool power_on)
2890 struct of_phandle_args pd_args;
2891 struct generic_pm_domain *pd;
2895 ret = of_parse_phandle_with_args(dev->of_node, "power-domains",
2896 "#power-domain-cells", index, &pd_args);
2900 mutex_lock(&gpd_list_lock);
2901 pd = genpd_get_from_provider(&pd_args);
2902 of_node_put(pd_args.np);
2904 mutex_unlock(&gpd_list_lock);
2905 dev_dbg(dev, "%s() failed to find PM domain: %ld\n",
2906 __func__, PTR_ERR(pd));
2907 return driver_deferred_probe_check_state(base_dev);
2910 dev_dbg(dev, "adding to PM domain %s\n", pd->name);
2912 ret = genpd_add_device(pd, dev, base_dev);
2913 mutex_unlock(&gpd_list_lock);
2916 return dev_err_probe(dev, ret, "failed to add to PM domain %s\n", pd->name);
2918 dev->pm_domain->detach = genpd_dev_pm_detach;
2919 dev->pm_domain->sync = genpd_dev_pm_sync;
2921 /* Set the default performance state */
2922 pstate = of_get_required_opp_performance_state(dev->of_node, index);
2923 if (pstate < 0 && pstate != -ENODEV && pstate != -EOPNOTSUPP) {
2926 } else if (pstate > 0) {
2927 ret = dev_pm_genpd_set_performance_state(dev, pstate);
2930 dev_gpd_data(dev)->default_pstate = pstate;
2935 ret = genpd_power_on(pd, 0);
2940 /* Drop the default performance state */
2941 if (dev_gpd_data(dev)->default_pstate) {
2942 dev_pm_genpd_set_performance_state(dev, 0);
2943 dev_gpd_data(dev)->default_pstate = 0;
2946 genpd_remove_device(pd, dev);
2947 return -EPROBE_DEFER;
2953 dev_err(dev, "failed to set required performance state for power-domain %s: %d\n",
2955 genpd_remove_device(pd, dev);
2960 * genpd_dev_pm_attach - Attach a device to its PM domain using DT.
2961 * @dev: Device to attach.
2963 * Parse device's OF node to find a PM domain specifier. If such is found,
2964 * attaches the device to retrieved pm_domain ops.
2966 * Returns 1 on successfully attached PM domain, 0 when the device don't need a
2967 * PM domain or when multiple power-domains exists for it, else a negative error
2968 * code. Note that if a power-domain exists for the device, but it cannot be
2969 * found or turned on, then return -EPROBE_DEFER to ensure that the device is
2970 * not probed and to re-try again later.
2972 int genpd_dev_pm_attach(struct device *dev)
2978 * Devices with multiple PM domains must be attached separately, as we
2979 * can only attach one PM domain per device.
2981 if (of_count_phandle_with_args(dev->of_node, "power-domains",
2982 "#power-domain-cells") != 1)
2985 return __genpd_dev_pm_attach(dev, dev, 0, true);
2987 EXPORT_SYMBOL_GPL(genpd_dev_pm_attach);
2990 * genpd_dev_pm_attach_by_id - Associate a device with one of its PM domains.
2991 * @dev: The device used to lookup the PM domain.
2992 * @index: The index of the PM domain.
2994 * Parse device's OF node to find a PM domain specifier at the provided @index.
2995 * If such is found, creates a virtual device and attaches it to the retrieved
2996 * pm_domain ops. To deal with detaching of the virtual device, the ->detach()
2997 * callback in the struct dev_pm_domain are assigned to genpd_dev_pm_detach().
2999 * Returns the created virtual device if successfully attached PM domain, NULL
3000 * when the device don't need a PM domain, else an ERR_PTR() in case of
3001 * failures. If a power-domain exists for the device, but cannot be found or
3002 * turned on, then ERR_PTR(-EPROBE_DEFER) is returned to ensure that the device
3003 * is not probed and to re-try again later.
3005 struct device *genpd_dev_pm_attach_by_id(struct device *dev,
3008 struct device *virt_dev;
3015 /* Verify that the index is within a valid range. */
3016 num_domains = of_count_phandle_with_args(dev->of_node, "power-domains",
3017 "#power-domain-cells");
3018 if (index >= num_domains)
3021 /* Allocate and register device on the genpd bus. */
3022 virt_dev = kzalloc(sizeof(*virt_dev), GFP_KERNEL);
3024 return ERR_PTR(-ENOMEM);
3026 dev_set_name(virt_dev, "genpd:%u:%s", index, dev_name(dev));
3027 virt_dev->bus = &genpd_bus_type;
3028 virt_dev->release = genpd_release_dev;
3029 virt_dev->of_node = of_node_get(dev->of_node);
3031 ret = device_register(virt_dev);
3033 put_device(virt_dev);
3034 return ERR_PTR(ret);
3037 /* Try to attach the device to the PM domain at the specified index. */
3038 ret = __genpd_dev_pm_attach(virt_dev, dev, index, false);
3040 device_unregister(virt_dev);
3041 return ret ? ERR_PTR(ret) : NULL;
3044 pm_runtime_enable(virt_dev);
3045 genpd_queue_power_off_work(dev_to_genpd(virt_dev));
3049 EXPORT_SYMBOL_GPL(genpd_dev_pm_attach_by_id);
3052 * genpd_dev_pm_attach_by_name - Associate a device with one of its PM domains.
3053 * @dev: The device used to lookup the PM domain.
3054 * @name: The name of the PM domain.
3056 * Parse device's OF node to find a PM domain specifier using the
3057 * power-domain-names DT property. For further description see
3058 * genpd_dev_pm_attach_by_id().
3060 struct device *genpd_dev_pm_attach_by_name(struct device *dev, const char *name)
3067 index = of_property_match_string(dev->of_node, "power-domain-names",
3072 return genpd_dev_pm_attach_by_id(dev, index);
3075 static const struct of_device_id idle_state_match[] = {
3076 { .compatible = "domain-idle-state", },
3080 static int genpd_parse_state(struct genpd_power_state *genpd_state,
3081 struct device_node *state_node)
3085 u32 entry_latency, exit_latency;
3087 err = of_property_read_u32(state_node, "entry-latency-us",
3090 pr_debug(" * %pOF missing entry-latency-us property\n",
3095 err = of_property_read_u32(state_node, "exit-latency-us",
3098 pr_debug(" * %pOF missing exit-latency-us property\n",
3103 err = of_property_read_u32(state_node, "min-residency-us", &residency);
3105 genpd_state->residency_ns = 1000LL * residency;
3107 genpd_state->power_on_latency_ns = 1000LL * exit_latency;
3108 genpd_state->power_off_latency_ns = 1000LL * entry_latency;
3109 genpd_state->fwnode = &state_node->fwnode;
3114 static int genpd_iterate_idle_states(struct device_node *dn,
3115 struct genpd_power_state *states)
3118 struct of_phandle_iterator it;
3119 struct device_node *np;
3122 ret = of_count_phandle_with_args(dn, "domain-idle-states", NULL);
3124 return ret == -ENOENT ? 0 : ret;
3126 /* Loop over the phandles until all the requested entry is found */
3127 of_for_each_phandle(&it, ret, dn, "domain-idle-states", NULL, 0) {
3129 if (!of_match_node(idle_state_match, np))
3132 if (!of_device_is_available(np))
3136 ret = genpd_parse_state(&states[i], np);
3138 pr_err("Parsing idle state node %pOF failed with err %d\n",
3151 * of_genpd_parse_idle_states: Return array of idle states for the genpd.
3153 * @dn: The genpd device node
3154 * @states: The pointer to which the state array will be saved.
3155 * @n: The count of elements in the array returned from this function.
3157 * Returns the device states parsed from the OF node. The memory for the states
3158 * is allocated by this function and is the responsibility of the caller to
3159 * free the memory after use. If any or zero compatible domain idle states is
3160 * found it returns 0 and in case of errors, a negative error code is returned.
3162 int of_genpd_parse_idle_states(struct device_node *dn,
3163 struct genpd_power_state **states, int *n)
3165 struct genpd_power_state *st;
3168 ret = genpd_iterate_idle_states(dn, NULL);
3178 st = kcalloc(ret, sizeof(*st), GFP_KERNEL);
3182 ret = genpd_iterate_idle_states(dn, st);
3185 return ret < 0 ? ret : -EINVAL;
3193 EXPORT_SYMBOL_GPL(of_genpd_parse_idle_states);
3195 static int __init genpd_bus_init(void)
3197 return bus_register(&genpd_bus_type);
3199 core_initcall(genpd_bus_init);
3201 #endif /* CONFIG_PM_GENERIC_DOMAINS_OF */
3204 /*** debugfs support ***/
3206 #ifdef CONFIG_DEBUG_FS
3208 * TODO: This function is a slightly modified version of rtpm_status_show
3209 * from sysfs.c, so generalize it.
3211 static void rtpm_status_str(struct seq_file *s, struct device *dev)
3213 static const char * const status_lookup[] = {
3214 [RPM_ACTIVE] = "active",
3215 [RPM_RESUMING] = "resuming",
3216 [RPM_SUSPENDED] = "suspended",
3217 [RPM_SUSPENDING] = "suspending"
3221 if (dev->power.runtime_error)
3223 else if (dev->power.disable_depth)
3225 else if (dev->power.runtime_status < ARRAY_SIZE(status_lookup))
3226 p = status_lookup[dev->power.runtime_status];
3230 seq_printf(s, "%-26s ", p);
3233 static void perf_status_str(struct seq_file *s, struct device *dev)
3235 struct generic_pm_domain_data *gpd_data;
3237 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
3239 seq_printf(s, "%-10u ", gpd_data->performance_state);
3242 static void mode_status_str(struct seq_file *s, struct device *dev)
3244 struct generic_pm_domain_data *gpd_data;
3246 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
3248 seq_printf(s, "%2s", gpd_data->hw_mode ? "HW" : "SW");
3251 static int genpd_summary_one(struct seq_file *s,
3252 struct generic_pm_domain *genpd)
3254 static const char * const status_lookup[] = {
3255 [GENPD_STATE_ON] = "on",
3256 [GENPD_STATE_OFF] = "off"
3258 struct pm_domain_data *pm_data;
3259 struct gpd_link *link;
3263 ret = genpd_lock_interruptible(genpd);
3265 return -ERESTARTSYS;
3267 if (WARN_ON(genpd->status >= ARRAY_SIZE(status_lookup)))
3269 if (!genpd_status_on(genpd))
3270 snprintf(state, sizeof(state), "%s-%u",
3271 status_lookup[genpd->status], genpd->state_idx);
3273 snprintf(state, sizeof(state), "%s",
3274 status_lookup[genpd->status]);
3275 seq_printf(s, "%-30s %-30s %u", genpd->name, state, genpd->performance_state);
3278 * Modifications on the list require holding locks on both
3279 * parent and child, so we are safe.
3280 * Also genpd->name is immutable.
3282 list_for_each_entry(link, &genpd->parent_links, parent_node) {
3283 if (list_is_first(&link->parent_node, &genpd->parent_links))
3284 seq_printf(s, "\n%48s", " ");
3285 seq_printf(s, "%s", link->child->name);
3286 if (!list_is_last(&link->parent_node, &genpd->parent_links))
3290 list_for_each_entry(pm_data, &genpd->dev_list, list_node) {
3291 seq_printf(s, "\n %-30s ", dev_name(pm_data->dev));
3292 rtpm_status_str(s, pm_data->dev);
3293 perf_status_str(s, pm_data->dev);
3294 mode_status_str(s, pm_data->dev);
3299 genpd_unlock(genpd);
3304 static int summary_show(struct seq_file *s, void *data)
3306 struct generic_pm_domain *genpd;
3309 seq_puts(s, "domain status children performance\n");
3310 seq_puts(s, " /device runtime status managed by\n");
3311 seq_puts(s, "------------------------------------------------------------------------------\n");
3313 ret = mutex_lock_interruptible(&gpd_list_lock);
3315 return -ERESTARTSYS;
3317 list_for_each_entry(genpd, &gpd_list, gpd_list_node) {
3318 ret = genpd_summary_one(s, genpd);
3322 mutex_unlock(&gpd_list_lock);
3327 static int status_show(struct seq_file *s, void *data)
3329 static const char * const status_lookup[] = {
3330 [GENPD_STATE_ON] = "on",
3331 [GENPD_STATE_OFF] = "off"
3334 struct generic_pm_domain *genpd = s->private;
3337 ret = genpd_lock_interruptible(genpd);
3339 return -ERESTARTSYS;
3341 if (WARN_ON_ONCE(genpd->status >= ARRAY_SIZE(status_lookup)))
3344 if (genpd->status == GENPD_STATE_OFF)
3345 seq_printf(s, "%s-%u\n", status_lookup[genpd->status],
3348 seq_printf(s, "%s\n", status_lookup[genpd->status]);
3350 genpd_unlock(genpd);
3354 static int sub_domains_show(struct seq_file *s, void *data)
3356 struct generic_pm_domain *genpd = s->private;
3357 struct gpd_link *link;
3360 ret = genpd_lock_interruptible(genpd);
3362 return -ERESTARTSYS;
3364 list_for_each_entry(link, &genpd->parent_links, parent_node)
3365 seq_printf(s, "%s\n", link->child->name);
3367 genpd_unlock(genpd);
3371 static int idle_states_show(struct seq_file *s, void *data)
3373 struct generic_pm_domain *genpd = s->private;
3374 u64 now, delta, idle_time = 0;
3378 ret = genpd_lock_interruptible(genpd);
3380 return -ERESTARTSYS;
3382 seq_puts(s, "State Time Spent(ms) Usage Rejected\n");
3384 for (i = 0; i < genpd->state_count; i++) {
3385 idle_time += genpd->states[i].idle_time;
3387 if (genpd->status == GENPD_STATE_OFF && genpd->state_idx == i) {
3388 now = ktime_get_mono_fast_ns();
3389 if (now > genpd->accounting_time) {
3390 delta = now - genpd->accounting_time;
3395 do_div(idle_time, NSEC_PER_MSEC);
3396 seq_printf(s, "S%-13i %-14llu %-14llu %llu\n", i, idle_time,
3397 genpd->states[i].usage, genpd->states[i].rejected);
3400 genpd_unlock(genpd);
3404 static int active_time_show(struct seq_file *s, void *data)
3406 struct generic_pm_domain *genpd = s->private;
3407 u64 now, on_time, delta = 0;
3410 ret = genpd_lock_interruptible(genpd);
3412 return -ERESTARTSYS;
3414 if (genpd->status == GENPD_STATE_ON) {
3415 now = ktime_get_mono_fast_ns();
3416 if (now > genpd->accounting_time)
3417 delta = now - genpd->accounting_time;
3420 on_time = genpd->on_time + delta;
3421 do_div(on_time, NSEC_PER_MSEC);
3422 seq_printf(s, "%llu ms\n", on_time);
3424 genpd_unlock(genpd);
3428 static int total_idle_time_show(struct seq_file *s, void *data)
3430 struct generic_pm_domain *genpd = s->private;
3431 u64 now, delta, total = 0;
3435 ret = genpd_lock_interruptible(genpd);
3437 return -ERESTARTSYS;
3439 for (i = 0; i < genpd->state_count; i++) {
3440 total += genpd->states[i].idle_time;
3442 if (genpd->status == GENPD_STATE_OFF && genpd->state_idx == i) {
3443 now = ktime_get_mono_fast_ns();
3444 if (now > genpd->accounting_time) {
3445 delta = now - genpd->accounting_time;
3451 do_div(total, NSEC_PER_MSEC);
3452 seq_printf(s, "%llu ms\n", total);
3454 genpd_unlock(genpd);
3459 static int devices_show(struct seq_file *s, void *data)
3461 struct generic_pm_domain *genpd = s->private;
3462 struct pm_domain_data *pm_data;
3465 ret = genpd_lock_interruptible(genpd);
3467 return -ERESTARTSYS;
3469 list_for_each_entry(pm_data, &genpd->dev_list, list_node)
3470 seq_printf(s, "%s\n", dev_name(pm_data->dev));
3472 genpd_unlock(genpd);
3476 static int perf_state_show(struct seq_file *s, void *data)
3478 struct generic_pm_domain *genpd = s->private;
3480 if (genpd_lock_interruptible(genpd))
3481 return -ERESTARTSYS;
3483 seq_printf(s, "%u\n", genpd->performance_state);
3485 genpd_unlock(genpd);
3489 DEFINE_SHOW_ATTRIBUTE(summary);
3490 DEFINE_SHOW_ATTRIBUTE(status);
3491 DEFINE_SHOW_ATTRIBUTE(sub_domains);
3492 DEFINE_SHOW_ATTRIBUTE(idle_states);
3493 DEFINE_SHOW_ATTRIBUTE(active_time);
3494 DEFINE_SHOW_ATTRIBUTE(total_idle_time);
3495 DEFINE_SHOW_ATTRIBUTE(devices);
3496 DEFINE_SHOW_ATTRIBUTE(perf_state);
3498 static void genpd_debug_add(struct generic_pm_domain *genpd)
3502 if (!genpd_debugfs_dir)
3505 d = debugfs_create_dir(genpd->name, genpd_debugfs_dir);
3507 debugfs_create_file("current_state", 0444,
3508 d, genpd, &status_fops);
3509 debugfs_create_file("sub_domains", 0444,
3510 d, genpd, &sub_domains_fops);
3511 debugfs_create_file("idle_states", 0444,
3512 d, genpd, &idle_states_fops);
3513 debugfs_create_file("active_time", 0444,
3514 d, genpd, &active_time_fops);
3515 debugfs_create_file("total_idle_time", 0444,
3516 d, genpd, &total_idle_time_fops);
3517 debugfs_create_file("devices", 0444,
3518 d, genpd, &devices_fops);
3519 if (genpd->set_performance_state)
3520 debugfs_create_file("perf_state", 0444,
3521 d, genpd, &perf_state_fops);
3524 static int __init genpd_debug_init(void)
3526 struct generic_pm_domain *genpd;
3528 genpd_debugfs_dir = debugfs_create_dir("pm_genpd", NULL);
3530 debugfs_create_file("pm_genpd_summary", S_IRUGO, genpd_debugfs_dir,
3531 NULL, &summary_fops);
3533 list_for_each_entry(genpd, &gpd_list, gpd_list_node)
3534 genpd_debug_add(genpd);
3538 late_initcall(genpd_debug_init);
3540 static void __exit genpd_debug_exit(void)
3542 debugfs_remove_recursive(genpd_debugfs_dir);
3544 __exitcall(genpd_debug_exit);
3545 #endif /* CONFIG_DEBUG_FS */