Lines Matching +full:power +full:- +full:domain
1 // SPDX-License-Identifier: GPL-2.0
3 * drivers/base/power/common.c - Common device power management code.
16 #include "power.h"
19 * dev_pm_get_subsys_data - Create or refcount power.subsys_data for device.
22 * If power.subsys_data is NULL, point it to a new object, otherwise increment
32 return -ENOMEM; in dev_pm_get_subsys_data()
34 spin_lock_irq(&dev->power.lock); in dev_pm_get_subsys_data()
36 if (dev->power.subsys_data) { in dev_pm_get_subsys_data()
37 dev->power.subsys_data->refcount++; in dev_pm_get_subsys_data()
39 spin_lock_init(&psd->lock); in dev_pm_get_subsys_data()
40 psd->refcount = 1; in dev_pm_get_subsys_data()
41 dev->power.subsys_data = psd; in dev_pm_get_subsys_data()
46 spin_unlock_irq(&dev->power.lock); in dev_pm_get_subsys_data()
56 * dev_pm_put_subsys_data - Drop reference to power.subsys_data.
59 * If the reference counter of power.subsys_data is zero after dropping the
60 * reference, power.subsys_data is removed.
66 spin_lock_irq(&dev->power.lock); in dev_pm_put_subsys_data()
72 if (--psd->refcount == 0) in dev_pm_put_subsys_data()
73 dev->power.subsys_data = NULL; in dev_pm_put_subsys_data()
78 spin_unlock_irq(&dev->power.lock); in dev_pm_put_subsys_data()
84 * dev_pm_domain_attach - Attach a device to its PM domain.
86 * @power_on: Used to indicate whether we should power on the device.
88 * The @dev may only be attached to a single PM domain. By iterating through
89 * the available alternatives we try to find a valid PM domain for the device.
90 * As attachment succeeds, the ->detach() callback in the struct dev_pm_domain
95 * power management through PM domains.
97 * Callers must ensure proper synchronization of this function with power
100 * Returns 0 on successfully attached PM domain, or when it is found that the
101 * device doesn't need a PM domain, else a negative error code.
107 if (dev->pm_domain) in dev_pm_domain_attach()
119 * dev_pm_domain_attach_by_id - Associate a device with one of its PM domains.
120 * @dev: The device used to lookup the PM domain.
121 * @index: The index of the PM domain.
123 * As @dev may only be attached to a single PM domain, the backend PM domain
125 * the ->detach() callback in the struct dev_pm_domain are assigned by the
130 * in case its device requires power management through multiple PM domains. The
131 * driver may benefit from using the received device, to configure device-links
132 * towards its original device. Depending on the use-case and if needed, the
134 * the power to the PM domains independently from each other.
136 * Callers must ensure proper synchronization of this function with power
140 * domain, NULL in case @dev don't need a PM domain, else an ERR_PTR().
147 if (dev->pm_domain) in dev_pm_domain_attach_by_id()
148 return ERR_PTR(-EEXIST); in dev_pm_domain_attach_by_id()
155 * dev_pm_domain_attach_by_name - Associate a device with one of its PM domains.
156 * @dev: The device used to lookup the PM domain.
157 * @name: The name of the PM domain.
164 if (dev->pm_domain) in dev_pm_domain_attach_by_name()
165 return ERR_PTR(-EEXIST); in dev_pm_domain_attach_by_name()
172 * dev_pm_domain_attach_list - Associate a device with its PM domains.
175 * @list: An out-parameter with an allocated list of attached PM domains.
183 * Callers must ensure proper synchronization of this function with power
194 struct device_node *np = dev->of_node; in dev_pm_domain_attach_list()
200 u32 pd_flags = data ? data->pd_flags : 0; in dev_pm_domain_attach_list()
204 if (dev->pm_domain) in dev_pm_domain_attach_list()
205 return -EEXIST; in dev_pm_domain_attach_list()
211 if (data && data->pd_names) { in dev_pm_domain_attach_list()
212 num_pds = data->num_pd_names; in dev_pm_domain_attach_list()
215 num_pds = of_count_phandle_with_args(np, "power-domains", in dev_pm_domain_attach_list()
216 "#power-domain-cells"); in dev_pm_domain_attach_list()
224 return -ENOMEM; in dev_pm_domain_attach_list()
226 size = sizeof(*pds->pd_devs) + sizeof(*pds->pd_links) + in dev_pm_domain_attach_list()
227 sizeof(*pds->opp_tokens); in dev_pm_domain_attach_list()
228 pds->pd_devs = kcalloc(num_pds, size, GFP_KERNEL); in dev_pm_domain_attach_list()
229 if (!pds->pd_devs) { in dev_pm_domain_attach_list()
230 ret = -ENOMEM; in dev_pm_domain_attach_list()
233 pds->pd_links = (void *)(pds->pd_devs + num_pds); in dev_pm_domain_attach_list()
234 pds->opp_tokens = (void *)(pds->pd_links + num_pds); in dev_pm_domain_attach_list()
244 data->pd_names[i]); in dev_pm_domain_attach_list()
246 ret = pd_dev ? PTR_ERR(pd_dev) : -ENODEV; in dev_pm_domain_attach_list()
260 pds->opp_tokens[i] = ret; in dev_pm_domain_attach_list()
268 ret = -ENODEV; in dev_pm_domain_attach_list()
272 pds->pd_links[i] = link; in dev_pm_domain_attach_list()
275 pds->pd_devs[i] = pd_dev; in dev_pm_domain_attach_list()
278 pds->num_pds = num_pds; in dev_pm_domain_attach_list()
283 dev_pm_opp_clear_config(pds->opp_tokens[i]); in dev_pm_domain_attach_list()
286 while (--i >= 0) { in dev_pm_domain_attach_list()
287 dev_pm_opp_clear_config(pds->opp_tokens[i]); in dev_pm_domain_attach_list()
288 if (pds->pd_links[i]) in dev_pm_domain_attach_list()
289 device_link_del(pds->pd_links[i]); in dev_pm_domain_attach_list()
290 dev_pm_domain_detach(pds->pd_devs[i], true); in dev_pm_domain_attach_list()
292 kfree(pds->pd_devs); in dev_pm_domain_attach_list()
300 * devm_pm_domain_detach_list - devres-enabled version of dev_pm_domain_detach_list.
315 * devm_pm_domain_attach_list - devres-enabled version of dev_pm_domain_attach_list
318 * @list: An out-parameter with an allocated list of attached PM domains.
345 * dev_pm_domain_detach - Detach a device from its PM domain.
347 * @power_off: Used to indicate whether we should power off the device.
351 * detaches @dev from its PM domain. Typically it should be invoked during the
354 * Callers must ensure proper synchronization of this function with power
359 if (dev->pm_domain && dev->pm_domain->detach) in dev_pm_domain_detach()
360 dev->pm_domain->detach(dev, power_off); in dev_pm_domain_detach()
365 * dev_pm_domain_detach_list - Detach a list of PM domains.
371 * Callers must ensure proper synchronization of this function with power
381 for (i = 0; i < list->num_pds; i++) { in dev_pm_domain_detach_list()
382 dev_pm_opp_clear_config(list->opp_tokens[i]); in dev_pm_domain_detach_list()
383 if (list->pd_links[i]) in dev_pm_domain_detach_list()
384 device_link_del(list->pd_links[i]); in dev_pm_domain_detach_list()
385 dev_pm_domain_detach(list->pd_devs[i], true); in dev_pm_domain_detach_list()
388 kfree(list->pd_devs); in dev_pm_domain_detach_list()
394 * dev_pm_domain_start - Start the device through its PM domain.
398 * when it needs to start its device from the PM domain's perspective. Note
399 * that, it's assumed that the PM domain is already powered on when this
406 if (dev->pm_domain && dev->pm_domain->start) in dev_pm_domain_start()
407 return dev->pm_domain->start(dev); in dev_pm_domain_start()
414 * dev_pm_domain_set - Set PM domain of a device.
415 * @dev: Device whose PM domain is to be set.
416 * @pd: PM domain to be set, or NULL.
418 * Sets the PM domain the device belongs to. The PM domain of a device needs
425 if (dev->pm_domain == pd) in dev_pm_domain_set()
430 dev->pm_domain = pd; in dev_pm_domain_set()
436 * dev_pm_domain_set_performance_state - Request a new performance state.
441 * requested for a device that is attached to a PM domain. Note that, the
449 if (dev->pm_domain && dev->pm_domain->set_performance_state) in dev_pm_domain_set_performance_state()
450 return dev->pm_domain->set_performance_state(dev, state); in dev_pm_domain_set_performance_state()