Lines Matching +full:p +full:- +full:states

1 // SPDX-License-Identifier: GPL-2.0
3 * drivers/base/power/domain.c - Common code related to device power domains.
37 __routine = genpd->dev_ops.callback; \
56 mutex_lock(&genpd->mlock); in genpd_lock_mtx()
62 mutex_lock_nested(&genpd->mlock, depth); in genpd_lock_nested_mtx()
67 return mutex_lock_interruptible(&genpd->mlock); in genpd_lock_interruptible_mtx()
72 return mutex_unlock(&genpd->mlock); in genpd_unlock_mtx()
83 __acquires(&genpd->slock) in genpd_lock_spin()
87 spin_lock_irqsave(&genpd->slock, flags); in genpd_lock_spin()
88 genpd->lock_flags = flags; in genpd_lock_spin()
93 __acquires(&genpd->slock) in genpd_lock_nested_spin()
97 spin_lock_irqsave_nested(&genpd->slock, flags, depth); in genpd_lock_nested_spin()
98 genpd->lock_flags = flags; in genpd_lock_nested_spin()
102 __acquires(&genpd->slock) in genpd_lock_interruptible_spin()
106 spin_lock_irqsave(&genpd->slock, flags); in genpd_lock_interruptible_spin()
107 genpd->lock_flags = flags; in genpd_lock_interruptible_spin()
112 __releases(&genpd->slock) in genpd_unlock_spin()
114 spin_unlock_irqrestore(&genpd->slock, genpd->lock_flags); in genpd_unlock_spin()
125 __acquires(&genpd->raw_slock) in genpd_lock_raw_spin()
129 raw_spin_lock_irqsave(&genpd->raw_slock, flags); in genpd_lock_raw_spin()
130 genpd->raw_lock_flags = flags; in genpd_lock_raw_spin()
135 __acquires(&genpd->raw_slock) in genpd_lock_nested_raw_spin()
139 raw_spin_lock_irqsave_nested(&genpd->raw_slock, flags, depth); in genpd_lock_nested_raw_spin()
140 genpd->raw_lock_flags = flags; in genpd_lock_nested_raw_spin()
144 __acquires(&genpd->raw_slock) in genpd_lock_interruptible_raw_spin()
148 raw_spin_lock_irqsave(&genpd->raw_slock, flags); in genpd_lock_interruptible_raw_spin()
149 genpd->raw_lock_flags = flags; in genpd_lock_interruptible_raw_spin()
154 __releases(&genpd->raw_slock) in genpd_unlock_raw_spin()
156 raw_spin_unlock_irqrestore(&genpd->raw_slock, genpd->raw_lock_flags); in genpd_unlock_raw_spin()
166 #define genpd_lock(p) p->lock_ops->lock(p) argument
167 #define genpd_lock_nested(p, d) p->lock_ops->lock_nested(p, d) argument
168 #define genpd_lock_interruptible(p) p->lock_ops->lock_interruptible(p) argument
169 #define genpd_unlock(p) p->lock_ops->unlock(p) argument
171 #define genpd_status_on(genpd) (genpd->status == GENPD_STATE_ON)
172 #define genpd_is_irq_safe(genpd) (genpd->flags & GENPD_FLAG_IRQ_SAFE)
173 #define genpd_is_always_on(genpd) (genpd->flags & GENPD_FLAG_ALWAYS_ON)
174 #define genpd_is_active_wakeup(genpd) (genpd->flags & GENPD_FLAG_ACTIVE_WAKEUP)
175 #define genpd_is_cpu_domain(genpd) (genpd->flags & GENPD_FLAG_CPU_DOMAIN)
176 #define genpd_is_rpm_always_on(genpd) (genpd->flags & GENPD_FLAG_RPM_ALWAYS_ON)
177 #define genpd_is_opp_table_fw(genpd) (genpd->flags & GENPD_FLAG_OPP_TABLE_FW)
178 #define genpd_is_dev_name_fw(genpd) (genpd->flags & GENPD_FLAG_DEV_NAME_FW)
197 dev_name(&genpd->dev)); in irq_safe_dev_in_sleep_domain()
212 if (IS_ERR_OR_NULL(dev) || IS_ERR_OR_NULL(dev->pm_domain)) in dev_to_genpd_safe()
215 /* A genpd's always have its ->runtime_suspend() callback assigned. */ in dev_to_genpd_safe()
216 if (dev->pm_domain->ops.runtime_suspend == genpd_runtime_suspend) in dev_to_genpd_safe()
217 return pd_to_genpd(dev->pm_domain); in dev_to_genpd_safe()
228 if (IS_ERR_OR_NULL(dev->pm_domain)) in dev_to_genpd()
229 return ERR_PTR(-EINVAL); in dev_to_genpd()
231 return pd_to_genpd(dev->pm_domain); in dev_to_genpd()
241 return &genpd->dev; in dev_to_genpd_dev()
260 if (!WARN_ON(atomic_read(&genpd->sd_count) == 0)) in genpd_sd_counter_dec()
261 ret = !!atomic_dec_and_test(&genpd->sd_count); in genpd_sd_counter_dec()
268 atomic_inc(&genpd->sd_count); in genpd_sd_counter_inc()
282 debugfs_lookup_and_remove(dev_name(&genpd->dev), genpd_debugfs_dir); in genpd_debug_remove()
290 if (now <= genpd->accounting_time) in genpd_update_accounting()
293 delta = now - genpd->accounting_time; in genpd_update_accounting()
296 * If genpd->status is active, it means we are just in genpd_update_accounting()
300 if (genpd->status == GENPD_STATE_ON) in genpd_update_accounting()
301 genpd->states[genpd->state_idx].idle_time += delta; in genpd_update_accounting()
303 genpd->on_time += delta; in genpd_update_accounting()
305 genpd->accounting_time = now; in genpd_update_accounting()
321 if (state == genpd->performance_state) in _genpd_reeval_performance_state()
325 if (state > genpd->performance_state) in _genpd_reeval_performance_state()
329 list_for_each_entry(pdd, &genpd->dev_list, list_node) { in _genpd_reeval_performance_state()
332 if (pd_data->performance_state > state) in _genpd_reeval_performance_state()
333 state = pd_data->performance_state; in _genpd_reeval_performance_state()
337 * Traverse all sub-domains within the domain. This can be in _genpd_reeval_performance_state()
338 * done without any additional locking as the link->performance_state in _genpd_reeval_performance_state()
339 * field is protected by the parent genpd->lock, which is already taken. in _genpd_reeval_performance_state()
341 * Also note that link->performance_state (subdomain's performance state in _genpd_reeval_performance_state()
343 * link->child->performance_state (current performance state requirement in _genpd_reeval_performance_state()
344 * of the devices/sub-domains of the subdomain) and so can have a in _genpd_reeval_performance_state()
347 * Note that we also take vote from powered-off sub-domains into account in _genpd_reeval_performance_state()
350 list_for_each_entry(link, &genpd->parent_links, parent_node) { in _genpd_reeval_performance_state()
351 if (link->performance_state > state) in _genpd_reeval_performance_state()
352 state = link->performance_state; in _genpd_reeval_performance_state()
362 if (!parent->set_performance_state) in genpd_xlate_performance_state()
365 return dev_pm_opp_xlate_performance_state(genpd->opp_table, in genpd_xlate_performance_state()
366 parent->opp_table, in genpd_xlate_performance_state()
375 struct generic_pm_domain *parent = link->parent; in _genpd_rollback_parent_state()
380 parent_state = link->prev_performance_state; in _genpd_rollback_parent_state()
381 link->performance_state = parent_state; in _genpd_rollback_parent_state()
386 parent->name, parent_state); in _genpd_rollback_parent_state()
396 struct generic_pm_domain *parent = link->parent; in _genpd_set_parent_state()
408 link->prev_performance_state = link->performance_state; in _genpd_set_parent_state()
409 link->performance_state = parent_state; in _genpd_set_parent_state()
414 link->performance_state = link->prev_performance_state; in _genpd_set_parent_state()
427 if (state == genpd->performance_state) in _genpd_set_performance_state()
431 if (state > genpd->performance_state) { in _genpd_set_performance_state()
432 list_for_each_entry(link, &genpd->child_links, child_node) { in _genpd_set_performance_state()
439 if (genpd->set_performance_state) { in _genpd_set_performance_state()
440 ret = genpd->set_performance_state(genpd, state); in _genpd_set_performance_state()
449 if (state < genpd->performance_state) { in _genpd_set_performance_state()
450 list_for_each_entry_reverse(link, &genpd->child_links, child_node) { in _genpd_set_performance_state()
457 genpd->performance_state = state; in _genpd_set_performance_state()
461 list_for_each_entry_continue_reverse(link, &genpd->child_links, child_node) in _genpd_set_performance_state()
465 list_for_each_entry_continue(link, &genpd->child_links, child_node) in _genpd_set_performance_state()
477 prev_state = gpd_data->performance_state; in genpd_set_performance_state()
481 gpd_data->performance_state = state; in genpd_set_performance_state()
486 gpd_data->performance_state = prev_state; in genpd_set_performance_state()
493 unsigned int prev_state = dev_gpd_data(dev)->performance_state; in genpd_drop_performance_state()
516 dev_gpd_data(dev)->rpm_pstate = state; in genpd_dev_pm_set_performance_state()
520 dev_gpd_data(dev)->rpm_pstate = 0; in genpd_dev_pm_set_performance_state()
528 * dev_pm_genpd_set_performance_state- Set performance state of device's power
531 * @dev: Device for which the performance-state needs to be set.
548 return -ENODEV; in dev_pm_genpd_set_performance_state()
550 if (WARN_ON(!dev->power.subsys_data || in dev_pm_genpd_set_performance_state()
551 !dev->power.subsys_data->domain_data)) in dev_pm_genpd_set_performance_state()
552 return -EINVAL; in dev_pm_genpd_set_performance_state()
559 * dev_pm_genpd_set_next_wakeup - Notify PM framework of an impending wakeup.
582 td = to_gpd_data(dev->power.subsys_data->domain_data)->td; in dev_pm_genpd_set_next_wakeup()
584 td->next_wakeup = next; in dev_pm_genpd_set_next_wakeup()
589 * dev_pm_genpd_get_next_hrtimer - Return the next_hrtimer for the genpd
606 if (genpd->gd) in dev_pm_genpd_get_next_hrtimer()
607 return genpd->gd->next_hrtimer; in dev_pm_genpd_get_next_hrtimer()
614 * dev_pm_genpd_synced_poweroff - Next power off should be synchronous
633 genpd->synced_poweroff = true; in dev_pm_genpd_synced_poweroff()
639 * dev_pm_genpd_set_hwmode() - Set the HW mode for the device and its PM domain.
641 * @dev: Device for which the HW-mode should be changed.
642 * @enable: Value to set or unset the HW-mode.
661 return -ENODEV; in dev_pm_genpd_set_hwmode()
663 if (!genpd->set_hwmode_dev) in dev_pm_genpd_set_hwmode()
664 return -EOPNOTSUPP; in dev_pm_genpd_set_hwmode()
668 if (dev_gpd_data(dev)->hw_mode == enable) in dev_pm_genpd_set_hwmode()
671 ret = genpd->set_hwmode_dev(genpd, dev, enable); in dev_pm_genpd_set_hwmode()
673 dev_gpd_data(dev)->hw_mode = enable; in dev_pm_genpd_set_hwmode()
682 * dev_pm_genpd_get_hwmode() - Get the HW mode setting for the device.
684 * @dev: Device for which the current HW-mode setting should be fetched.
696 return dev_gpd_data(dev)->hw_mode; in dev_pm_genpd_get_hwmode()
702 unsigned int state_idx = genpd->state_idx; in _genpd_power_on()
708 ret = raw_notifier_call_chain_robust(&genpd->power_notifiers, in _genpd_power_on()
715 if (!genpd->power_on) in _genpd_power_on()
718 timed = timed && genpd->gd && !genpd->states[state_idx].fwnode; in _genpd_power_on()
720 ret = genpd->power_on(genpd); in _genpd_power_on()
728 ret = genpd->power_on(genpd); in _genpd_power_on()
733 if (elapsed_ns <= genpd->states[state_idx].power_on_latency_ns) in _genpd_power_on()
736 genpd->states[state_idx].power_on_latency_ns = elapsed_ns; in _genpd_power_on()
737 genpd->gd->max_off_time_changed = true; in _genpd_power_on()
738 pr_debug("%s: Power-%s latency exceeded, new value %lld ns\n", in _genpd_power_on()
739 dev_name(&genpd->dev), "on", elapsed_ns); in _genpd_power_on()
742 raw_notifier_call_chain(&genpd->power_notifiers, GENPD_NOTIFY_ON, NULL); in _genpd_power_on()
743 genpd->synced_poweroff = false; in _genpd_power_on()
746 raw_notifier_call_chain(&genpd->power_notifiers, GENPD_NOTIFY_OFF, in _genpd_power_on()
753 unsigned int state_idx = genpd->state_idx; in _genpd_power_off()
759 ret = raw_notifier_call_chain_robust(&genpd->power_notifiers, in _genpd_power_off()
766 if (!genpd->power_off) in _genpd_power_off()
769 timed = timed && genpd->gd && !genpd->states[state_idx].fwnode; in _genpd_power_off()
771 ret = genpd->power_off(genpd); in _genpd_power_off()
779 ret = genpd->power_off(genpd); in _genpd_power_off()
784 if (elapsed_ns <= genpd->states[state_idx].power_off_latency_ns) in _genpd_power_off()
787 genpd->states[state_idx].power_off_latency_ns = elapsed_ns; in _genpd_power_off()
788 genpd->gd->max_off_time_changed = true; in _genpd_power_off()
789 pr_debug("%s: Power-%s latency exceeded, new value %lld ns\n", in _genpd_power_off()
790 dev_name(&genpd->dev), "off", elapsed_ns); in _genpd_power_off()
793 raw_notifier_call_chain(&genpd->power_notifiers, GENPD_NOTIFY_OFF, in _genpd_power_off()
797 raw_notifier_call_chain(&genpd->power_notifiers, GENPD_NOTIFY_ON, NULL); in _genpd_power_off()
802 * genpd_queue_power_off_work - Queue up the execution of genpd_power_off().
810 queue_work(pm_wq, &genpd->power_off_work); in genpd_queue_power_off_work()
814 * genpd_power_off - Remove power from a given PM domain.
816 * @one_dev_on: If invoked from genpd's ->runtime_suspend|resume() callback, the
838 if (!genpd_status_on(genpd) || genpd->prepared_count > 0) in genpd_power_off()
848 atomic_read(&genpd->sd_count) > 0) in genpd_power_off()
849 return -EBUSY; in genpd_power_off()
852 * The children must be in their deepest (powered-off) states to allow in genpd_power_off()
857 list_for_each_entry(link, &genpd->parent_links, parent_node) { in genpd_power_off()
858 struct generic_pm_domain *child = link->child; in genpd_power_off()
859 if (child->state_idx < child->state_count - 1) in genpd_power_off()
860 return -EBUSY; in genpd_power_off()
863 list_for_each_entry(pdd, &genpd->dev_list, list_node) { in genpd_power_off()
866 * device is part of a non-IRQ safe domain. in genpd_power_off()
868 if (!pm_runtime_suspended(pdd->dev) || in genpd_power_off()
869 irq_safe_dev_in_sleep_domain(pdd->dev, genpd)) in genpd_power_off()
874 return -EBUSY; in genpd_power_off()
876 if (genpd->gov && genpd->gov->power_down_ok) { in genpd_power_off()
877 if (!genpd->gov->power_down_ok(&genpd->domain)) in genpd_power_off()
878 return -EAGAIN; in genpd_power_off()
882 if (!genpd->gov) in genpd_power_off()
883 genpd->state_idx = 0; in genpd_power_off()
886 if (atomic_read(&genpd->sd_count) > 0) in genpd_power_off()
887 return -EBUSY; in genpd_power_off()
891 genpd->states[genpd->state_idx].rejected++; in genpd_power_off()
895 genpd->status = GENPD_STATE_OFF; in genpd_power_off()
897 genpd->states[genpd->state_idx].usage++; in genpd_power_off()
899 list_for_each_entry(link, &genpd->child_links, child_node) { in genpd_power_off()
900 genpd_sd_counter_dec(link->parent); in genpd_power_off()
901 genpd_lock_nested(link->parent, depth + 1); in genpd_power_off()
902 genpd_power_off(link->parent, false, depth + 1); in genpd_power_off()
903 genpd_unlock(link->parent); in genpd_power_off()
910 * genpd_power_on - Restore power to a given PM domain and its parents.
930 list_for_each_entry(link, &genpd->child_links, child_node) { in genpd_power_on()
931 struct generic_pm_domain *parent = link->parent; in genpd_power_on()
949 genpd->status = GENPD_STATE_ON; in genpd_power_on()
956 &genpd->child_links, in genpd_power_on()
958 genpd_sd_counter_dec(link->parent); in genpd_power_on()
959 genpd_lock_nested(link->parent, depth + 1); in genpd_power_on()
960 genpd_power_off(link->parent, false, depth + 1); in genpd_power_on()
961 genpd_unlock(link->parent); in genpd_power_on()
981 dev = gpd_data->base.dev; in genpd_dev_pm_qos_notifier()
984 struct generic_pm_domain *genpd = ERR_PTR(-ENODATA); in genpd_dev_pm_qos_notifier()
988 spin_lock_irq(&dev->power.lock); in genpd_dev_pm_qos_notifier()
990 pdd = dev->power.subsys_data ? in genpd_dev_pm_qos_notifier()
991 dev->power.subsys_data->domain_data : NULL; in genpd_dev_pm_qos_notifier()
993 td = to_gpd_data(pdd)->td; in genpd_dev_pm_qos_notifier()
995 td->constraint_changed = true; in genpd_dev_pm_qos_notifier()
1000 spin_unlock_irq(&dev->power.lock); in genpd_dev_pm_qos_notifier()
1004 genpd->gd->max_off_time_changed = true; in genpd_dev_pm_qos_notifier()
1008 dev = dev->parent; in genpd_dev_pm_qos_notifier()
1009 if (!dev || dev->power.ignore_children) in genpd_dev_pm_qos_notifier()
1017 * genpd_power_off_work_fn - Power off PM domain whose subdomain count is 0.
1032 * __genpd_runtime_suspend - walk the hierarchy of ->runtime_suspend() callbacks
1039 if (dev->type && dev->type->pm) in __genpd_runtime_suspend()
1040 cb = dev->type->pm->runtime_suspend; in __genpd_runtime_suspend()
1041 else if (dev->class && dev->class->pm) in __genpd_runtime_suspend()
1042 cb = dev->class->pm->runtime_suspend; in __genpd_runtime_suspend()
1043 else if (dev->bus && dev->bus->pm) in __genpd_runtime_suspend()
1044 cb = dev->bus->pm->runtime_suspend; in __genpd_runtime_suspend()
1048 if (!cb && dev->driver && dev->driver->pm) in __genpd_runtime_suspend()
1049 cb = dev->driver->pm->runtime_suspend; in __genpd_runtime_suspend()
1055 * __genpd_runtime_resume - walk the hierarchy of ->runtime_resume() callbacks
1062 if (dev->type && dev->type->pm) in __genpd_runtime_resume()
1063 cb = dev->type->pm->runtime_resume; in __genpd_runtime_resume()
1064 else if (dev->class && dev->class->pm) in __genpd_runtime_resume()
1065 cb = dev->class->pm->runtime_resume; in __genpd_runtime_resume()
1066 else if (dev->bus && dev->bus->pm) in __genpd_runtime_resume()
1067 cb = dev->bus->pm->runtime_resume; in __genpd_runtime_resume()
1071 if (!cb && dev->driver && dev->driver->pm) in __genpd_runtime_resume()
1072 cb = dev->driver->pm->runtime_resume; in __genpd_runtime_resume()
1078 * genpd_runtime_suspend - Suspend a device belonging to I/O PM domain.
1090 struct gpd_timing_data *td = gpd_data->td; in genpd_runtime_suspend()
1100 return -EINVAL; in genpd_runtime_suspend()
1103 * A runtime PM centric subsystem/driver may re-use the runtime PM in genpd_runtime_suspend()
1108 suspend_ok = genpd->gov ? genpd->gov->suspend_ok : NULL; in genpd_runtime_suspend()
1110 return -EBUSY; in genpd_runtime_suspend()
1129 if (elapsed_ns > td->suspend_latency_ns) { in genpd_runtime_suspend()
1130 td->suspend_latency_ns = elapsed_ns; in genpd_runtime_suspend()
1133 genpd->gd->max_off_time_changed = true; in genpd_runtime_suspend()
1134 td->constraint_changed = true; in genpd_runtime_suspend()
1147 gpd_data->rpm_pstate = genpd_drop_performance_state(dev); in genpd_runtime_suspend()
1154 * genpd_runtime_resume - Resume a device belonging to I/O PM domain.
1165 struct gpd_timing_data *td = gpd_data->td; in genpd_runtime_resume()
1175 return -EINVAL; in genpd_runtime_resume()
1185 genpd_restore_performance_state(dev, gpd_data->rpm_pstate); in genpd_runtime_resume()
1208 if (elapsed_ns > td->resume_latency_ns) { in genpd_runtime_resume()
1209 td->resume_latency_ns = elapsed_ns; in genpd_runtime_resume()
1212 genpd->gd->max_off_time_changed = true; in genpd_runtime_resume()
1213 td->constraint_changed = true; in genpd_runtime_resume()
1225 gpd_data->rpm_pstate = genpd_drop_performance_state(dev); in genpd_runtime_resume()
1241 * genpd_power_off_unused - Power off all PM domains with no devices in use.
1267 * genpd_sync_power_off - Synchronously power off a PM domain and its parents.
1287 if (genpd->suspended_count != genpd->device_count in genpd_sync_power_off()
1288 || atomic_read(&genpd->sd_count) > 0) in genpd_sync_power_off()
1291 /* Check that the children are in their deepest (powered-off) state. */ in genpd_sync_power_off()
1292 list_for_each_entry(link, &genpd->parent_links, parent_node) { in genpd_sync_power_off()
1293 struct generic_pm_domain *child = link->child; in genpd_sync_power_off()
1294 if (child->state_idx < child->state_count - 1) in genpd_sync_power_off()
1299 genpd->state_idx = genpd->state_count - 1; in genpd_sync_power_off()
1301 genpd->states[genpd->state_idx].rejected++; in genpd_sync_power_off()
1304 genpd->states[genpd->state_idx].usage++; in genpd_sync_power_off()
1307 genpd->status = GENPD_STATE_OFF; in genpd_sync_power_off()
1309 list_for_each_entry(link, &genpd->child_links, child_node) { in genpd_sync_power_off()
1310 genpd_sd_counter_dec(link->parent); in genpd_sync_power_off()
1313 genpd_lock_nested(link->parent, depth + 1); in genpd_sync_power_off()
1315 genpd_sync_power_off(link->parent, use_lock, depth + 1); in genpd_sync_power_off()
1318 genpd_unlock(link->parent); in genpd_sync_power_off()
1323 * genpd_sync_power_on - Synchronously power on a PM domain and its parents.
1340 list_for_each_entry(link, &genpd->child_links, child_node) { in genpd_sync_power_on()
1341 genpd_sd_counter_inc(link->parent); in genpd_sync_power_on()
1344 genpd_lock_nested(link->parent, depth + 1); in genpd_sync_power_on()
1346 genpd_sync_power_on(link->parent, use_lock, depth + 1); in genpd_sync_power_on()
1349 genpd_unlock(link->parent); in genpd_sync_power_on()
1353 genpd->status = GENPD_STATE_ON; in genpd_sync_power_on()
1357 * genpd_prepare - Start power transition of a device in a PM domain.
1360 * Start a power transition of a device (during a system-wide power transition)
1374 return -EINVAL; in genpd_prepare()
1377 genpd->prepared_count++; in genpd_prepare()
1384 genpd->prepared_count--; in genpd_prepare()
1394 * genpd_finish_suspend - Completion of suspend or hibernation of device in an
1412 return -EINVAL; in genpd_finish_suspend()
1421 if (genpd->dev_ops.stop && genpd->dev_ops.start && in genpd_finish_suspend()
1431 genpd->suspended_count++; in genpd_finish_suspend()
1439 * genpd_suspend_noirq - Completion of suspend of device in an I/O PM domain.
1455 * genpd_finish_resume - Completion of resume of device in an I/O PM domain.
1471 return -EINVAL; in genpd_finish_resume()
1478 genpd->suspended_count--; in genpd_finish_resume()
1481 if (genpd->dev_ops.stop && genpd->dev_ops.start && in genpd_finish_resume()
1492 * genpd_resume_noirq - Start of resume of device in an I/O PM domain.
1505 * genpd_freeze_noirq - Completion of freezing a device in an I/O PM domain.
1523 * genpd_thaw_noirq - Early thaw of device in an I/O PM domain.
1537 * genpd_poweroff_noirq - Completion of hibernation of device in an
1554 * genpd_restore_noirq - Start of restore of device in an I/O PM domain.
1568 * genpd_complete - Complete power transition of a device in a power domain.
1571 * Complete a power transition of a device (during a system-wide power
1590 genpd->prepared_count--; in genpd_complete()
1591 if (!genpd->prepared_count) in genpd_complete()
1612 genpd->suspended_count++; in genpd_switch_state()
1616 genpd->suspended_count--; in genpd_switch_state()
1624 * dev_pm_genpd_suspend - Synchronously try to suspend the genpd for @dev
1629 * suspend-to-idle to suspend a corresponding CPU device that is attached to a
1639 * dev_pm_genpd_resume - Synchronously try to resume the genpd for @dev
1643 * during the syscore resume phase. It may also be called during suspend-to-idle
1678 ret = -ENOMEM; in genpd_alloc_dev_data()
1682 gpd_data->base.dev = dev; in genpd_alloc_dev_data()
1683 gpd_data->nb.notifier_call = genpd_dev_pm_qos_notifier; in genpd_alloc_dev_data()
1689 ret = -ENOMEM; in genpd_alloc_dev_data()
1693 td->constraint_changed = true; in genpd_alloc_dev_data()
1694 td->effective_constraint_ns = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT_NS; in genpd_alloc_dev_data()
1695 td->next_wakeup = KTIME_MAX; in genpd_alloc_dev_data()
1696 gpd_data->td = td; in genpd_alloc_dev_data()
1699 spin_lock_irq(&dev->power.lock); in genpd_alloc_dev_data()
1701 if (dev->power.subsys_data->domain_data) in genpd_alloc_dev_data()
1702 ret = -EINVAL; in genpd_alloc_dev_data()
1704 dev->power.subsys_data->domain_data = &gpd_data->base; in genpd_alloc_dev_data()
1706 spin_unlock_irq(&dev->power.lock); in genpd_alloc_dev_data()
1714 kfree(gpd_data->td); in genpd_alloc_dev_data()
1724 spin_lock_irq(&dev->power.lock); in genpd_free_dev_data()
1726 dev->power.subsys_data->domain_data = NULL; in genpd_free_dev_data()
1728 spin_unlock_irq(&dev->power.lock); in genpd_free_dev_data()
1730 dev_pm_opp_clear_config(gpd_data->opp_token); in genpd_free_dev_data()
1731 kfree(gpd_data->td); in genpd_free_dev_data()
1744 list_for_each_entry(link, &genpd->child_links, child_node) { in genpd_update_cpumask()
1745 struct generic_pm_domain *parent = link->parent; in genpd_update_cpumask()
1753 cpumask_set_cpu(cpu, genpd->cpus); in genpd_update_cpumask()
1755 cpumask_clear_cpu(cpu, genpd->cpus); in genpd_update_cpumask()
1775 return -1; in genpd_get_cpu()
1782 return -1; in genpd_get_cpu()
1788 struct genpd_governor_data *gd = genpd->gd; in genpd_add_device()
1798 gpd_data->cpu = genpd_get_cpu(genpd, base_dev); in genpd_add_device()
1800 gpd_data->hw_mode = genpd->get_hwmode_dev ? genpd->get_hwmode_dev(genpd, dev) : false; in genpd_add_device()
1802 ret = genpd->attach_dev ? genpd->attach_dev(genpd, dev) : 0; in genpd_add_device()
1808 genpd_set_cpumask(genpd, gpd_data->cpu); in genpd_add_device()
1810 genpd->device_count++; in genpd_add_device()
1812 gd->max_off_time_changed = true; in genpd_add_device()
1814 list_add_tail(&gpd_data->base.list_node, &genpd->dev_list); in genpd_add_device()
1817 dev_pm_domain_set(dev, &genpd->domain); in genpd_add_device()
1822 dev_pm_qos_add_notifier(dev, &gpd_data->nb, in genpd_add_device()
1829 * pm_genpd_add_device - Add a device to an I/O PM domain.
1838 return -EINVAL; in pm_genpd_add_device()
1857 pdd = dev->power.subsys_data->domain_data; in genpd_remove_device()
1859 dev_pm_qos_remove_notifier(dev, &gpd_data->nb, in genpd_remove_device()
1864 if (genpd->prepared_count > 0) { in genpd_remove_device()
1865 ret = -EAGAIN; in genpd_remove_device()
1869 genpd->device_count--; in genpd_remove_device()
1870 if (genpd->gd) in genpd_remove_device()
1871 genpd->gd->max_off_time_changed = true; in genpd_remove_device()
1873 genpd_clear_cpumask(genpd, gpd_data->cpu); in genpd_remove_device()
1875 list_del_init(&pdd->list_node); in genpd_remove_device()
1881 if (genpd->detach_dev) in genpd_remove_device()
1882 genpd->detach_dev(genpd, dev); in genpd_remove_device()
1890 dev_pm_qos_add_notifier(dev, &gpd_data->nb, DEV_PM_QOS_RESUME_LATENCY); in genpd_remove_device()
1896 * pm_genpd_remove_device - Remove a device from an I/O PM domain.
1904 return -EINVAL; in pm_genpd_remove_device()
1911 * dev_pm_genpd_add_notifier - Add a genpd power on/off notifier for @dev
1933 return -ENODEV; in dev_pm_genpd_add_notifier()
1935 if (WARN_ON(!dev->power.subsys_data || in dev_pm_genpd_add_notifier()
1936 !dev->power.subsys_data->domain_data)) in dev_pm_genpd_add_notifier()
1937 return -EINVAL; in dev_pm_genpd_add_notifier()
1939 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data); in dev_pm_genpd_add_notifier()
1940 if (gpd_data->power_nb) in dev_pm_genpd_add_notifier()
1941 return -EEXIST; in dev_pm_genpd_add_notifier()
1944 ret = raw_notifier_chain_register(&genpd->power_notifiers, nb); in dev_pm_genpd_add_notifier()
1949 dev_name(&genpd->dev)); in dev_pm_genpd_add_notifier()
1953 gpd_data->power_nb = nb; in dev_pm_genpd_add_notifier()
1959 * dev_pm_genpd_remove_notifier - Remove a genpd power on/off notifier for @dev
1979 return -ENODEV; in dev_pm_genpd_remove_notifier()
1981 if (WARN_ON(!dev->power.subsys_data || in dev_pm_genpd_remove_notifier()
1982 !dev->power.subsys_data->domain_data)) in dev_pm_genpd_remove_notifier()
1983 return -EINVAL; in dev_pm_genpd_remove_notifier()
1985 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data); in dev_pm_genpd_remove_notifier()
1986 if (!gpd_data->power_nb) in dev_pm_genpd_remove_notifier()
1987 return -ENODEV; in dev_pm_genpd_remove_notifier()
1990 ret = raw_notifier_chain_unregister(&genpd->power_notifiers, in dev_pm_genpd_remove_notifier()
1991 gpd_data->power_nb); in dev_pm_genpd_remove_notifier()
1996 dev_name(&genpd->dev)); in dev_pm_genpd_remove_notifier()
2000 gpd_data->power_nb = NULL; in dev_pm_genpd_remove_notifier()
2013 return -EINVAL; in genpd_add_subdomain()
2022 dev_name(&genpd->dev), subdomain->name); in genpd_add_subdomain()
2023 return -EINVAL; in genpd_add_subdomain()
2028 return -ENOMEM; in genpd_add_subdomain()
2034 ret = -EINVAL; in genpd_add_subdomain()
2038 list_for_each_entry(itr, &genpd->parent_links, parent_node) { in genpd_add_subdomain()
2039 if (itr->child == subdomain && itr->parent == genpd) { in genpd_add_subdomain()
2040 ret = -EINVAL; in genpd_add_subdomain()
2045 link->parent = genpd; in genpd_add_subdomain()
2046 list_add_tail(&link->parent_node, &genpd->parent_links); in genpd_add_subdomain()
2047 link->child = subdomain; in genpd_add_subdomain()
2048 list_add_tail(&link->child_node, &subdomain->child_links); in genpd_add_subdomain()
2061 * pm_genpd_add_subdomain - Add a subdomain to an I/O PM domain.
2079 * pm_genpd_remove_subdomain - Remove a subdomain from an I/O PM domain.
2087 int ret = -EINVAL; in pm_genpd_remove_subdomain()
2090 return -EINVAL; in pm_genpd_remove_subdomain()
2095 if (!list_empty(&subdomain->parent_links) || subdomain->device_count) { in pm_genpd_remove_subdomain()
2097 dev_name(&genpd->dev), subdomain->name); in pm_genpd_remove_subdomain()
2098 ret = -EBUSY; in pm_genpd_remove_subdomain()
2102 list_for_each_entry_safe(link, l, &genpd->parent_links, parent_node) { in pm_genpd_remove_subdomain()
2103 if (link->child != subdomain) in pm_genpd_remove_subdomain()
2106 list_del(&link->parent_node); in pm_genpd_remove_subdomain()
2107 list_del(&link->child_node); in pm_genpd_remove_subdomain()
2124 static void genpd_free_default_power_state(struct genpd_power_state *states, in genpd_free_default_power_state() argument
2127 kfree(states); in genpd_free_default_power_state()
2136 return -ENOMEM; in genpd_set_default_power_state()
2138 genpd->states = state; in genpd_set_default_power_state()
2139 genpd->state_count = 1; in genpd_set_default_power_state()
2140 genpd->free_states = genpd_free_default_power_state; in genpd_set_default_power_state()
2156 !zalloc_cpumask_var(&genpd->cpus, GFP_KERNEL)) in genpd_alloc_data()
2157 return -ENOMEM; in genpd_alloc_data()
2159 if (genpd->gov) { in genpd_alloc_data()
2162 ret = -ENOMEM; in genpd_alloc_data()
2166 gd->max_off_time_ns = -1; in genpd_alloc_data()
2167 gd->max_off_time_changed = true; in genpd_alloc_data()
2168 gd->next_wakeup = KTIME_MAX; in genpd_alloc_data()
2169 gd->next_hrtimer = KTIME_MAX; in genpd_alloc_data()
2172 /* Use only one "off" state if there were no states declared */ in genpd_alloc_data()
2173 if (genpd->state_count == 0) { in genpd_alloc_data()
2179 genpd->gd = gd; in genpd_alloc_data()
2180 device_initialize(&genpd->dev); in genpd_alloc_data()
2181 genpd->dev.release = genpd_provider_release; in genpd_alloc_data()
2184 dev_set_name(&genpd->dev, "%s", genpd->name); in genpd_alloc_data()
2190 genpd->device_id = ret; in genpd_alloc_data()
2191 dev_set_name(&genpd->dev, "%s_%u", genpd->name, genpd->device_id); in genpd_alloc_data()
2196 put_device(&genpd->dev); in genpd_alloc_data()
2197 if (genpd->free_states == genpd_free_default_power_state) in genpd_alloc_data()
2198 kfree(genpd->states); in genpd_alloc_data()
2201 free_cpumask_var(genpd->cpus); in genpd_alloc_data()
2208 put_device(&genpd->dev); in genpd_free_data()
2209 if (genpd->device_id != -ENXIO) in genpd_free_data()
2210 ida_free(&genpd_ida, genpd->device_id); in genpd_free_data()
2212 free_cpumask_var(genpd->cpus); in genpd_free_data()
2213 if (genpd->free_states) in genpd_free_data()
2214 genpd->free_states(genpd->states, genpd->state_count); in genpd_free_data()
2215 kfree(genpd->gd); in genpd_free_data()
2221 raw_spin_lock_init(&genpd->raw_slock); in genpd_lock_init()
2222 genpd->lock_ops = &genpd_raw_spin_ops; in genpd_lock_init()
2224 spin_lock_init(&genpd->slock); in genpd_lock_init()
2225 genpd->lock_ops = &genpd_spin_ops; in genpd_lock_init()
2227 mutex_init(&genpd->mlock); in genpd_lock_init()
2228 genpd->lock_ops = &genpd_mtx_ops; in genpd_lock_init()
2233 * pm_genpd_init - Initialize a generic I/O PM domain object.
2246 return -EINVAL; in pm_genpd_init()
2248 INIT_LIST_HEAD(&genpd->parent_links); in pm_genpd_init()
2249 INIT_LIST_HEAD(&genpd->child_links); in pm_genpd_init()
2250 INIT_LIST_HEAD(&genpd->dev_list); in pm_genpd_init()
2251 RAW_INIT_NOTIFIER_HEAD(&genpd->power_notifiers); in pm_genpd_init()
2253 genpd->gov = gov; in pm_genpd_init()
2254 INIT_WORK(&genpd->power_off_work, genpd_power_off_work_fn); in pm_genpd_init()
2255 atomic_set(&genpd->sd_count, 0); in pm_genpd_init()
2256 genpd->status = is_off ? GENPD_STATE_OFF : GENPD_STATE_ON; in pm_genpd_init()
2257 genpd->device_count = 0; in pm_genpd_init()
2258 genpd->provider = NULL; in pm_genpd_init()
2259 genpd->device_id = -ENXIO; in pm_genpd_init()
2260 genpd->has_provider = false; in pm_genpd_init()
2261 genpd->accounting_time = ktime_get_mono_fast_ns(); in pm_genpd_init()
2262 genpd->domain.ops.runtime_suspend = genpd_runtime_suspend; in pm_genpd_init()
2263 genpd->domain.ops.runtime_resume = genpd_runtime_resume; in pm_genpd_init()
2264 genpd->domain.ops.prepare = genpd_prepare; in pm_genpd_init()
2265 genpd->domain.ops.suspend_noirq = genpd_suspend_noirq; in pm_genpd_init()
2266 genpd->domain.ops.resume_noirq = genpd_resume_noirq; in pm_genpd_init()
2267 genpd->domain.ops.freeze_noirq = genpd_freeze_noirq; in pm_genpd_init()
2268 genpd->domain.ops.thaw_noirq = genpd_thaw_noirq; in pm_genpd_init()
2269 genpd->domain.ops.poweroff_noirq = genpd_poweroff_noirq; in pm_genpd_init()
2270 genpd->domain.ops.restore_noirq = genpd_restore_noirq; in pm_genpd_init()
2271 genpd->domain.ops.complete = genpd_complete; in pm_genpd_init()
2272 genpd->domain.start = genpd_dev_pm_start; in pm_genpd_init()
2273 genpd->domain.set_performance_state = genpd_dev_pm_set_performance_state; in pm_genpd_init()
2275 if (genpd->flags & GENPD_FLAG_PM_CLK) { in pm_genpd_init()
2276 genpd->dev_ops.stop = pm_clk_suspend; in pm_genpd_init()
2277 genpd->dev_ops.start = pm_clk_resume; in pm_genpd_init()
2280 /* The always-on governor works better with the corresponding flag. */ in pm_genpd_init()
2282 genpd->flags |= GENPD_FLAG_RPM_ALWAYS_ON; in pm_genpd_init()
2284 /* Always-on domains must be powered on at initialization. */ in pm_genpd_init()
2287 pr_err("always-on PM domain %s is not on\n", genpd->name); in pm_genpd_init()
2288 return -EINVAL; in pm_genpd_init()
2291 /* Multiple states but no governor doesn't make sense. */ in pm_genpd_init()
2292 if (!gov && genpd->state_count > 1) in pm_genpd_init()
2293 pr_warn("%s: no governor for states\n", genpd->name); in pm_genpd_init()
2300 list_add(&genpd->gpd_list_node, &gpd_list); in pm_genpd_init()
2313 return -EINVAL; in genpd_remove()
2317 if (genpd->has_provider) { in genpd_remove()
2319 pr_err("Provider present, unable to remove %s\n", dev_name(&genpd->dev)); in genpd_remove()
2320 return -EBUSY; in genpd_remove()
2323 if (!list_empty(&genpd->parent_links) || genpd->device_count) { in genpd_remove()
2325 pr_err("%s: unable to remove %s\n", __func__, dev_name(&genpd->dev)); in genpd_remove()
2326 return -EBUSY; in genpd_remove()
2329 list_for_each_entry_safe(link, l, &genpd->child_links, child_node) { in genpd_remove()
2330 list_del(&link->parent_node); in genpd_remove()
2331 list_del(&link->child_node); in genpd_remove()
2335 list_del(&genpd->gpd_list_node); in genpd_remove()
2338 cancel_work_sync(&genpd->power_off_work); in genpd_remove()
2341 pr_debug("%s: removed %s\n", __func__, dev_name(&genpd->dev)); in genpd_remove()
2347 * pm_genpd_remove - Remove a generic I/O PM domain
2351 * - Removes the PM domain as a subdomain to any parent domains,
2353 * - Removes the PM domain from the list of registered PM domains.
2384 * - genpd_xlate_simple() for 1:1 device tree node to PM domain mapping.
2385 * - genpd_xlate_onecell() for mapping of multiple PM domains per node by
2390 * struct of_genpd_provider - PM domain provider registration structure
2393 * @xlate: Provider-specific xlate callback mapping a set of specifier cells
2410 * genpd_xlate_simple() - Xlate function for direct node-domain mapping
2412 * @data: xlate function private data - pointer to struct generic_pm_domain
2426 * genpd_xlate_onecell() - Xlate function using a single index.
2428 * @data: xlate function private data - pointer to struct genpd_onecell_data
2440 unsigned int idx = genpdspec->args[0]; in genpd_xlate_onecell()
2442 if (genpdspec->args_count != 1) in genpd_xlate_onecell()
2443 return ERR_PTR(-EINVAL); in genpd_xlate_onecell()
2445 if (idx >= genpd_data->num_domains) { in genpd_xlate_onecell()
2447 return ERR_PTR(-EINVAL); in genpd_xlate_onecell()
2450 if (!genpd_data->domains[idx]) in genpd_xlate_onecell()
2451 return ERR_PTR(-ENOENT); in genpd_xlate_onecell()
2453 return genpd_data->domains[idx]; in genpd_xlate_onecell()
2457 * genpd_add_provider() - Register a PM domain provider for a node
2469 return -ENOMEM; in genpd_add_provider()
2471 cp->node = of_node_get(np); in genpd_add_provider()
2472 cp->data = data; in genpd_add_provider()
2473 cp->xlate = xlate; in genpd_add_provider()
2474 fwnode_dev_initialized(&np->fwnode, true); in genpd_add_provider()
2477 list_add(&cp->link, &of_genpd_providers); in genpd_add_provider()
2502 * of_genpd_add_provider_simple() - Register a simple PM domain provider
2512 return -EINVAL; in of_genpd_add_provider_simple()
2515 return -EINVAL; in of_genpd_add_provider_simple()
2517 genpd->dev.of_node = np; in of_genpd_add_provider_simple()
2520 if (!genpd_is_opp_table_fw(genpd) && genpd->set_performance_state) { in of_genpd_add_provider_simple()
2521 ret = dev_pm_opp_of_add_table(&genpd->dev); in of_genpd_add_provider_simple()
2523 return dev_err_probe(&genpd->dev, ret, "Failed to add OPP table\n"); in of_genpd_add_provider_simple()
2529 genpd->opp_table = dev_pm_opp_get_opp_table(&genpd->dev); in of_genpd_add_provider_simple()
2530 WARN_ON(IS_ERR(genpd->opp_table)); in of_genpd_add_provider_simple()
2535 if (!genpd_is_opp_table_fw(genpd) && genpd->set_performance_state) { in of_genpd_add_provider_simple()
2536 dev_pm_opp_put_opp_table(genpd->opp_table); in of_genpd_add_provider_simple()
2537 dev_pm_opp_of_remove_table(&genpd->dev); in of_genpd_add_provider_simple()
2543 genpd->provider = &np->fwnode; in of_genpd_add_provider_simple()
2544 genpd->has_provider = true; in of_genpd_add_provider_simple()
2551 * of_genpd_add_provider_onecell() - Register a onecell PM domain provider
2560 int ret = -EINVAL; in of_genpd_add_provider_onecell()
2563 return -EINVAL; in of_genpd_add_provider_onecell()
2565 if (!data->xlate) in of_genpd_add_provider_onecell()
2566 data->xlate = genpd_xlate_onecell; in of_genpd_add_provider_onecell()
2568 for (i = 0; i < data->num_domains; i++) { in of_genpd_add_provider_onecell()
2569 genpd = data->domains[i]; in of_genpd_add_provider_onecell()
2576 genpd->dev.of_node = np; in of_genpd_add_provider_onecell()
2579 if (!genpd_is_opp_table_fw(genpd) && genpd->set_performance_state) { in of_genpd_add_provider_onecell()
2580 ret = dev_pm_opp_of_add_table_indexed(&genpd->dev, i); in of_genpd_add_provider_onecell()
2582 dev_err_probe(&genpd->dev, ret, in of_genpd_add_provider_onecell()
2591 genpd->opp_table = dev_pm_opp_get_opp_table(&genpd->dev); in of_genpd_add_provider_onecell()
2592 WARN_ON(IS_ERR(genpd->opp_table)); in of_genpd_add_provider_onecell()
2595 genpd->provider = &np->fwnode; in of_genpd_add_provider_onecell()
2596 genpd->has_provider = true; in of_genpd_add_provider_onecell()
2599 ret = genpd_add_provider(np, data->xlate, data); in of_genpd_add_provider_onecell()
2606 while (i--) { in of_genpd_add_provider_onecell()
2607 genpd = data->domains[i]; in of_genpd_add_provider_onecell()
2612 genpd->provider = NULL; in of_genpd_add_provider_onecell()
2613 genpd->has_provider = false; in of_genpd_add_provider_onecell()
2615 if (!genpd_is_opp_table_fw(genpd) && genpd->set_performance_state) { in of_genpd_add_provider_onecell()
2616 dev_pm_opp_put_opp_table(genpd->opp_table); in of_genpd_add_provider_onecell()
2617 dev_pm_opp_of_remove_table(&genpd->dev); in of_genpd_add_provider_onecell()
2626 * of_genpd_del_provider() - Remove a previously registered PM domain provider
2637 if (cp->node == np) { in of_genpd_del_provider()
2644 if (gpd->provider == &np->fwnode) { in of_genpd_del_provider()
2645 gpd->has_provider = false; in of_genpd_del_provider()
2647 if (genpd_is_opp_table_fw(gpd) || !gpd->set_performance_state) in of_genpd_del_provider()
2650 dev_pm_opp_put_opp_table(gpd->opp_table); in of_genpd_del_provider()
2651 dev_pm_opp_of_remove_table(&gpd->dev); in of_genpd_del_provider()
2655 fwnode_dev_initialized(&cp->node->fwnode, false); in of_genpd_del_provider()
2656 list_del(&cp->link); in of_genpd_del_provider()
2657 of_node_put(cp->node); in of_genpd_del_provider()
2668 * genpd_get_from_provider() - Look-up PM domain
2669 * @genpdspec: OF phandle args to use for look-up
2681 struct generic_pm_domain *genpd = ERR_PTR(-ENOENT); in genpd_get_from_provider()
2685 return ERR_PTR(-EINVAL); in genpd_get_from_provider()
2691 if (provider->node == genpdspec->np) in genpd_get_from_provider()
2692 genpd = provider->xlate(genpdspec, provider->data); in genpd_get_from_provider()
2703 * of_genpd_add_device() - Add a device to an I/O PM domain
2704 * @genpdspec: OF phandle args to use for look-up PM domain
2707 * Looks-up an I/O PM domain based upon phandle args provided and adds
2716 return -EINVAL; in of_genpd_add_device()
2736 * of_genpd_add_subdomain - Add a subdomain to an I/O PM domain.
2737 * @parent_spec: OF phandle args to use for parent PM domain look-up
2738 * @subdomain_spec: OF phandle args to use for subdomain look-up
2740 * Looks-up a parent PM domain and subdomain based upon phandle args
2769 return ret == -ENOENT ? -EPROBE_DEFER : ret; in of_genpd_add_subdomain()
2774 * of_genpd_remove_subdomain - Remove a subdomain from an I/O PM domain.
2775 * @parent_spec: OF phandle args to use for parent PM domain look-up
2776 * @subdomain_spec: OF phandle args to use for subdomain look-up
2778 * Looks-up a parent PM domain and subdomain based upon phandle args
2812 * of_genpd_remove_last - Remove the last PM domain registered for a provider
2826 struct generic_pm_domain *gpd, *tmp, *genpd = ERR_PTR(-ENOENT); in of_genpd_remove_last()
2830 return ERR_PTR(-EINVAL); in of_genpd_remove_last()
2834 if (gpd->provider == &np->fwnode) { in of_genpd_remove_last()
2848 of_node_put(dev->of_node); in genpd_release_dev()
2857 * genpd_dev_pm_detach - Detach a device from its PM domain.
2874 dev_dbg(dev, "removing from PM domain %s\n", pd->name); in genpd_dev_pm_detach()
2877 if (dev_gpd_data(dev)->default_pstate) { in genpd_dev_pm_detach()
2879 dev_gpd_data(dev)->default_pstate = 0; in genpd_dev_pm_detach()
2884 if (ret != -EAGAIN) in genpd_dev_pm_detach()
2893 pd->name, ret); in genpd_dev_pm_detach()
2901 if (dev->bus == &genpd_bus_type) in genpd_dev_pm_detach()
2924 /* Limit support to non-providers for now. */ in genpd_set_required_opp_dev()
2925 if (of_property_present(base_dev->of_node, "#power-domain-cells")) in genpd_set_required_opp_dev()
2935 dev_gpd_data(dev)->opp_token = ret; in genpd_set_required_opp_dev()
2944 pstate = of_get_required_opp_performance_state(dev->of_node, index); in genpd_set_required_opp()
2945 if (pstate < 0 && pstate != -ENODEV && pstate != -EOPNOTSUPP) { in genpd_set_required_opp()
2952 dev_gpd_data(dev)->default_pstate = pstate; in genpd_set_required_opp()
2957 dev_err(dev, "failed to set required performance state for power-domain %s: %d\n", in genpd_set_required_opp()
2958 dev_to_genpd(dev)->name, ret); in genpd_set_required_opp()
2970 ret = of_parse_phandle_with_args(dev->of_node, "power-domains", in __genpd_dev_pm_attach()
2971 "#power-domain-cells", index, &pd_args); in __genpd_dev_pm_attach()
2985 dev_dbg(dev, "adding to PM domain %s\n", pd->name); in __genpd_dev_pm_attach()
2991 return dev_err_probe(dev, ret, "failed to add to PM domain %s\n", pd->name); in __genpd_dev_pm_attach()
2993 dev->pm_domain->detach = genpd_dev_pm_detach; in __genpd_dev_pm_attach()
2994 dev->pm_domain->sync = genpd_dev_pm_sync; in __genpd_dev_pm_attach()
3019 if (dev_gpd_data(dev)->default_pstate) { in __genpd_dev_pm_attach()
3021 dev_gpd_data(dev)->default_pstate = 0; in __genpd_dev_pm_attach()
3025 return -EPROBE_DEFER; in __genpd_dev_pm_attach()
3036 * genpd_dev_pm_attach - Attach a device to its PM domain using DT.
3043 * PM domain or when multiple power-domains exists for it, else a negative error
3044 * code. Note that if a power-domain exists for the device, but it cannot be
3045 * found or turned on, then return -EPROBE_DEFER to ensure that the device is
3046 * not probed and to re-try again later.
3050 if (!dev->of_node) in genpd_dev_pm_attach()
3057 if (of_count_phandle_with_args(dev->of_node, "power-domains", in genpd_dev_pm_attach()
3058 "#power-domain-cells") != 1) in genpd_dev_pm_attach()
3066 * genpd_dev_pm_attach_by_id - Associate a device with one of its PM domains.
3072 * pm_domain ops. To deal with detaching of the virtual device, the ->detach()
3077 * failures. If a power-domain exists for the device, but cannot be found or
3078 * turned on, then ERR_PTR(-EPROBE_DEFER) is returned to ensure that the device
3079 * is not probed and to re-try again later.
3088 if (!dev->of_node) in genpd_dev_pm_attach_by_id()
3092 num_domains = of_count_phandle_with_args(dev->of_node, "power-domains", in genpd_dev_pm_attach_by_id()
3093 "#power-domain-cells"); in genpd_dev_pm_attach_by_id()
3100 return ERR_PTR(-ENOMEM); in genpd_dev_pm_attach_by_id()
3103 virt_dev->bus = &genpd_bus_type; in genpd_dev_pm_attach_by_id()
3104 virt_dev->release = genpd_release_dev; in genpd_dev_pm_attach_by_id()
3105 virt_dev->of_node = of_node_get(dev->of_node); in genpd_dev_pm_attach_by_id()
3128 * genpd_dev_pm_attach_by_name - Associate a device with one of its PM domains.
3133 * power-domain-names DT property. For further description see
3140 if (!dev->of_node) in genpd_dev_pm_attach_by_name()
3143 index = of_property_match_string(dev->of_node, "power-domain-names", in genpd_dev_pm_attach_by_name()
3152 { .compatible = "domain-idle-state", },
3163 err = of_property_read_u32(state_node, "entry-latency-us", in genpd_parse_state()
3166 pr_debug(" * %pOF missing entry-latency-us property\n", in genpd_parse_state()
3168 return -EINVAL; in genpd_parse_state()
3171 err = of_property_read_u32(state_node, "exit-latency-us", in genpd_parse_state()
3174 pr_debug(" * %pOF missing exit-latency-us property\n", in genpd_parse_state()
3176 return -EINVAL; in genpd_parse_state()
3179 err = of_property_read_u32(state_node, "min-residency-us", &residency); in genpd_parse_state()
3181 genpd_state->residency_ns = 1000LL * residency; in genpd_parse_state()
3183 genpd_state->power_on_latency_ns = 1000LL * exit_latency; in genpd_parse_state()
3184 genpd_state->power_off_latency_ns = 1000LL * entry_latency; in genpd_parse_state()
3185 genpd_state->fwnode = &state_node->fwnode; in genpd_parse_state()
3191 struct genpd_power_state *states) in genpd_iterate_idle_states() argument
3198 ret = of_count_phandle_with_args(dn, "domain-idle-states", NULL); in genpd_iterate_idle_states()
3200 return ret == -ENOENT ? 0 : ret; in genpd_iterate_idle_states()
3203 of_for_each_phandle(&it, ret, dn, "domain-idle-states", NULL, 0) { in genpd_iterate_idle_states()
3211 if (states) { in genpd_iterate_idle_states()
3212 ret = genpd_parse_state(&states[i], np); in genpd_iterate_idle_states()
3227 * of_genpd_parse_idle_states: Return array of idle states for the genpd.
3230 * @states: The pointer to which the state array will be saved.
3233 * Returns the device states parsed from the OF node. The memory for the states
3235 * free the memory after use. If any or zero compatible domain idle states is
3239 struct genpd_power_state **states, int *n) in of_genpd_parse_idle_states() argument
3249 *states = NULL; in of_genpd_parse_idle_states()
3256 return -ENOMEM; in of_genpd_parse_idle_states()
3261 return ret < 0 ? ret : -EINVAL; in of_genpd_parse_idle_states()
3264 *states = st; in of_genpd_parse_idle_states()
3295 const char *p = ""; in rtpm_status_str() local
3297 if (dev->power.runtime_error) in rtpm_status_str()
3298 p = "error"; in rtpm_status_str()
3299 else if (dev->power.disable_depth) in rtpm_status_str()
3300 p = "unsupported"; in rtpm_status_str()
3301 else if (dev->power.runtime_status < ARRAY_SIZE(status_lookup)) in rtpm_status_str()
3302 p = status_lookup[dev->power.runtime_status]; in rtpm_status_str()
3306 seq_printf(s, "%-26s ", p); in rtpm_status_str()
3313 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data); in perf_status_str()
3315 seq_printf(s, "%-10u ", gpd_data->performance_state); in perf_status_str()
3322 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data); in mode_status_str()
3324 seq_printf(s, "%2s", gpd_data->hw_mode ? "HW" : "SW"); in mode_status_str()
3341 return -ERESTARTSYS; in genpd_summary_one()
3343 if (WARN_ON(genpd->status >= ARRAY_SIZE(status_lookup))) in genpd_summary_one()
3346 snprintf(state, sizeof(state), "%s-%u", in genpd_summary_one()
3347 status_lookup[genpd->status], genpd->state_idx); in genpd_summary_one()
3350 status_lookup[genpd->status]); in genpd_summary_one()
3351 seq_printf(s, "%-30s %-30s %u", dev_name(&genpd->dev), state, genpd->performance_state); in genpd_summary_one()
3358 list_for_each_entry(link, &genpd->parent_links, parent_node) { in genpd_summary_one()
3359 if (list_is_first(&link->parent_node, &genpd->parent_links)) in genpd_summary_one()
3361 seq_printf(s, "%s", link->child->name); in genpd_summary_one()
3362 if (!list_is_last(&link->parent_node, &genpd->parent_links)) in genpd_summary_one()
3366 list_for_each_entry(pm_data, &genpd->dev_list, list_node) { in genpd_summary_one()
3367 seq_printf(s, "\n %-30s ", dev_name(pm_data->dev)); in genpd_summary_one()
3368 rtpm_status_str(s, pm_data->dev); in genpd_summary_one()
3369 perf_status_str(s, pm_data->dev); in genpd_summary_one()
3370 mode_status_str(s, pm_data->dev); in genpd_summary_one()
3387 seq_puts(s, "------------------------------------------------------------------------------\n"); in summary_show()
3391 return -ERESTARTSYS; in summary_show()
3410 struct generic_pm_domain *genpd = s->private; in status_show()
3415 return -ERESTARTSYS; in status_show()
3417 if (WARN_ON_ONCE(genpd->status >= ARRAY_SIZE(status_lookup))) in status_show()
3420 if (genpd->status == GENPD_STATE_OFF) in status_show()
3421 seq_printf(s, "%s-%u\n", status_lookup[genpd->status], in status_show()
3422 genpd->state_idx); in status_show()
3424 seq_printf(s, "%s\n", status_lookup[genpd->status]); in status_show()
3432 struct generic_pm_domain *genpd = s->private; in sub_domains_show()
3438 return -ERESTARTSYS; in sub_domains_show()
3440 list_for_each_entry(link, &genpd->parent_links, parent_node) in sub_domains_show()
3441 seq_printf(s, "%s\n", link->child->name); in sub_domains_show()
3449 struct generic_pm_domain *genpd = s->private; in idle_states_show()
3456 return -ERESTARTSYS; in idle_states_show()
3460 for (i = 0; i < genpd->state_count; i++) { in idle_states_show()
3461 idle_time += genpd->states[i].idle_time; in idle_states_show()
3463 if (genpd->status == GENPD_STATE_OFF && genpd->state_idx == i) { in idle_states_show()
3465 if (now > genpd->accounting_time) { in idle_states_show()
3466 delta = now - genpd->accounting_time; in idle_states_show()
3472 seq_printf(s, "S%-13i %-14llu %-14llu %llu\n", i, idle_time, in idle_states_show()
3473 genpd->states[i].usage, genpd->states[i].rejected); in idle_states_show()
3482 struct generic_pm_domain *genpd = s->private; in active_time_show()
3488 return -ERESTARTSYS; in active_time_show()
3490 if (genpd->status == GENPD_STATE_ON) { in active_time_show()
3492 if (now > genpd->accounting_time) in active_time_show()
3493 delta = now - genpd->accounting_time; in active_time_show()
3496 on_time = genpd->on_time + delta; in active_time_show()
3506 struct generic_pm_domain *genpd = s->private; in total_idle_time_show()
3513 return -ERESTARTSYS; in total_idle_time_show()
3515 for (i = 0; i < genpd->state_count; i++) { in total_idle_time_show()
3516 total += genpd->states[i].idle_time; in total_idle_time_show()
3518 if (genpd->status == GENPD_STATE_OFF && genpd->state_idx == i) { in total_idle_time_show()
3520 if (now > genpd->accounting_time) { in total_idle_time_show()
3521 delta = now - genpd->accounting_time; in total_idle_time_show()
3537 struct generic_pm_domain *genpd = s->private; in devices_show()
3543 return -ERESTARTSYS; in devices_show()
3545 list_for_each_entry(pm_data, &genpd->dev_list, list_node) in devices_show()
3546 seq_printf(s, "%s\n", dev_name(pm_data->dev)); in devices_show()
3554 struct generic_pm_domain *genpd = s->private; in perf_state_show()
3557 return -ERESTARTSYS; in perf_state_show()
3559 seq_printf(s, "%u\n", genpd->performance_state); in perf_state_show()
3581 d = debugfs_create_dir(dev_name(&genpd->dev), genpd_debugfs_dir); in genpd_debug_add()
3595 if (genpd->set_performance_state) in genpd_debug_add()