Lines Matching +full:power +full:- +full:power +full:- +full:management
1 // SPDX-License-Identifier: GPL-2.0
3 * drivers/base/power/common.c - Common device power management code.
15 #include "power.h"
18 * dev_pm_get_subsys_data - Create or refcount power.subsys_data for device.
21 * If power.subsys_data is NULL, point it to a new object, otherwise increment
31 return -ENOMEM; in dev_pm_get_subsys_data()
33 spin_lock_irq(&dev->power.lock); in dev_pm_get_subsys_data()
35 if (dev->power.subsys_data) { in dev_pm_get_subsys_data()
36 dev->power.subsys_data->refcount++; in dev_pm_get_subsys_data()
38 spin_lock_init(&psd->lock); in dev_pm_get_subsys_data()
39 psd->refcount = 1; in dev_pm_get_subsys_data()
40 dev->power.subsys_data = psd; in dev_pm_get_subsys_data()
45 spin_unlock_irq(&dev->power.lock); in dev_pm_get_subsys_data()
55 * dev_pm_put_subsys_data - Drop reference to power.subsys_data.
58 * If the reference counter of power.subsys_data is zero after dropping the
59 * reference, power.subsys_data is removed.
65 spin_lock_irq(&dev->power.lock); in dev_pm_put_subsys_data()
71 if (--psd->refcount == 0) in dev_pm_put_subsys_data()
72 dev->power.subsys_data = NULL; in dev_pm_put_subsys_data()
77 spin_unlock_irq(&dev->power.lock); in dev_pm_put_subsys_data()
83 * dev_pm_domain_attach - Attach a device to its PM domain.
85 * @power_on: Used to indicate whether we should power on the device.
89 * As attachment succeeds, the ->detach() callback in the struct dev_pm_domain
94 * power management through PM domains.
96 * Callers must ensure proper synchronization of this function with power
97 * management callbacks.
106 if (dev->pm_domain) in dev_pm_domain_attach()
118 * dev_pm_domain_attach_by_id - Associate a device with one of its PM domains.
124 * the ->detach() callback in the struct dev_pm_domain are assigned by the
129 * in case its device requires power management through multiple PM domains. The
130 * driver may benefit from using the received device, to configure device-links
131 * towards its original device. Depending on the use-case and if needed, the
133 * the power to the PM domains independently from each other.
135 * Callers must ensure proper synchronization of this function with power
136 * management callbacks.
146 if (dev->pm_domain) in dev_pm_domain_attach_by_id()
147 return ERR_PTR(-EEXIST); in dev_pm_domain_attach_by_id()
154 * dev_pm_domain_attach_by_name - Associate a device with one of its PM domains.
163 if (dev->pm_domain) in dev_pm_domain_attach_by_name()
164 return ERR_PTR(-EEXIST); in dev_pm_domain_attach_by_name()
171 * dev_pm_domain_attach_list - Associate a device with its PM domains.
174 * @list: An out-parameter with an allocated list of attached PM domains.
182 * Callers must ensure proper synchronization of this function with power
183 * management callbacks.
193 struct device_node *np = dev->of_node; in dev_pm_domain_attach_list()
199 u32 pd_flags = data ? data->pd_flags : 0; in dev_pm_domain_attach_list()
203 if (dev->pm_domain) in dev_pm_domain_attach_list()
204 return -EEXIST; in dev_pm_domain_attach_list()
210 if (data && data->pd_names) { in dev_pm_domain_attach_list()
211 num_pds = data->num_pd_names; in dev_pm_domain_attach_list()
214 num_pds = of_count_phandle_with_args(np, "power-domains", in dev_pm_domain_attach_list()
215 "#power-domain-cells"); in dev_pm_domain_attach_list()
223 return -ENOMEM; in dev_pm_domain_attach_list()
225 size = sizeof(*pds->pd_devs) + sizeof(*pds->pd_links); in dev_pm_domain_attach_list()
226 pds->pd_devs = kcalloc(num_pds, size, GFP_KERNEL); in dev_pm_domain_attach_list()
227 if (!pds->pd_devs) { in dev_pm_domain_attach_list()
228 ret = -ENOMEM; in dev_pm_domain_attach_list()
231 pds->pd_links = (void *)(pds->pd_devs + num_pds); in dev_pm_domain_attach_list()
241 data->pd_names[i]); in dev_pm_domain_attach_list()
243 ret = pd_dev ? PTR_ERR(pd_dev) : -ENODEV; in dev_pm_domain_attach_list()
252 ret = -ENODEV; in dev_pm_domain_attach_list()
256 pds->pd_links[i] = link; in dev_pm_domain_attach_list()
259 pds->pd_devs[i] = pd_dev; in dev_pm_domain_attach_list()
262 pds->num_pds = num_pds; in dev_pm_domain_attach_list()
269 while (--i >= 0) { in dev_pm_domain_attach_list()
270 if (pds->pd_links[i]) in dev_pm_domain_attach_list()
271 device_link_del(pds->pd_links[i]); in dev_pm_domain_attach_list()
272 dev_pm_domain_detach(pds->pd_devs[i], true); in dev_pm_domain_attach_list()
274 kfree(pds->pd_devs); in dev_pm_domain_attach_list()
282 * devm_pm_domain_detach_list - devres-enabled version of dev_pm_domain_detach_list.
297 * devm_pm_domain_attach_list - devres-enabled version of dev_pm_domain_attach_list
300 * @list: An out-parameter with an allocated list of attached PM domains.
327 * dev_pm_domain_detach - Detach a device from its PM domain.
329 * @power_off: Used to indicate whether we should power off the device.
336 * Callers must ensure proper synchronization of this function with power
337 * management callbacks.
341 if (dev->pm_domain && dev->pm_domain->detach) in dev_pm_domain_detach()
342 dev->pm_domain->detach(dev, power_off); in dev_pm_domain_detach()
347 * dev_pm_domain_detach_list - Detach a list of PM domains.
353 * Callers must ensure proper synchronization of this function with power
354 * management callbacks.
363 for (i = 0; i < list->num_pds; i++) { in dev_pm_domain_detach_list()
364 if (list->pd_links[i]) in dev_pm_domain_detach_list()
365 device_link_del(list->pd_links[i]); in dev_pm_domain_detach_list()
366 dev_pm_domain_detach(list->pd_devs[i], true); in dev_pm_domain_detach_list()
369 kfree(list->pd_devs); in dev_pm_domain_detach_list()
375 * dev_pm_domain_start - Start the device through its PM domain.
387 if (dev->pm_domain && dev->pm_domain->start) in dev_pm_domain_start()
388 return dev->pm_domain->start(dev); in dev_pm_domain_start()
395 * dev_pm_domain_set - Set PM domain of a device.
406 if (dev->pm_domain == pd) in dev_pm_domain_set()
411 dev->pm_domain = pd; in dev_pm_domain_set()
417 * dev_pm_domain_set_performance_state - Request a new performance state.
430 if (dev->pm_domain && dev->pm_domain->set_performance_state) in dev_pm_domain_set_performance_state()
431 return dev->pm_domain->set_performance_state(dev, state); in dev_pm_domain_set_performance_state()