Lines Matching +full:pm +full:- +full:domains
1 // SPDX-License-Identifier: GPL-2.0
3 * drivers/base/power/common.c - Common device power management code.
19 * dev_pm_get_subsys_data - Create or refcount power.subsys_data for device.
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.
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.
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.
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()
114 if (dev->pm_domain) in dev_pm_domain_attach()
115 dev->power.detach_power_off = !!(flags & PD_FLAG_DETACH_POWER_OFF); in dev_pm_domain_attach()
122 * dev_pm_domain_attach_by_id - Associate a device with one of its PM domains.
123 * @dev: The device used to lookup the PM domain.
124 * @index: The index of the PM domain.
126 * As @dev may only be attached to a single PM domain, the backend PM domain
128 * the ->detach() callback in the struct dev_pm_domain are assigned by the
133 * in case its device requires power management through multiple PM domains. The
134 * driver may benefit from using the received device, to configure device-links
135 * towards its original device. Depending on the use-case and if needed, the
137 * the power to the PM domains independently from each other.
142 * Returns the virtual created device when successfully attached to its PM
143 * domain, NULL in case @dev don't need a PM domain, else an ERR_PTR().
150 if (dev->pm_domain) in dev_pm_domain_attach_by_id()
151 return ERR_PTR(-EEXIST); in dev_pm_domain_attach_by_id()
158 * dev_pm_domain_attach_by_name - Associate a device with one of its PM domains.
159 * @dev: The device used to lookup the PM domain.
160 * @name: The name of the PM domain.
167 if (dev->pm_domain) in dev_pm_domain_attach_by_name()
168 return ERR_PTR(-EEXIST); in dev_pm_domain_attach_by_name()
175 * dev_pm_domain_attach_list - Associate a device with its PM domains.
176 * @dev: The device used to lookup the PM domains for.
177 * @data: The data used for attaching to the PM domains.
178 * @list: An out-parameter with an allocated list of attached PM domains.
180 * This function helps to attach a device to its multiple PM domains. The
182 * names for the PM domains that we should try to attach the device to, but it
184 * the available PM domains.
189 * Returns the number of attached PM domains or a negative error code in case of
190 * a failure. Note that, to detach the list of PM domains, the driver shall call
197 struct device_node *np = dev->of_node; in dev_pm_domain_attach_list()
203 u32 pd_flags = data ? data->pd_flags : 0; in dev_pm_domain_attach_list()
207 if (dev->pm_domain) in dev_pm_domain_attach_list()
208 return -EEXIST; in dev_pm_domain_attach_list()
214 if (data && data->pd_names) { in dev_pm_domain_attach_list()
215 num_pds = data->num_pd_names; in dev_pm_domain_attach_list()
218 num_pds = of_count_phandle_with_args(np, "power-domains", in dev_pm_domain_attach_list()
219 "#power-domain-cells"); in dev_pm_domain_attach_list()
227 return -ENOMEM; in dev_pm_domain_attach_list()
229 size = sizeof(*pds->pd_devs) + sizeof(*pds->pd_links) + in dev_pm_domain_attach_list()
230 sizeof(*pds->opp_tokens); in dev_pm_domain_attach_list()
231 pds->pd_devs = kcalloc(num_pds, size, GFP_KERNEL); in dev_pm_domain_attach_list()
232 if (!pds->pd_devs) { in dev_pm_domain_attach_list()
233 ret = -ENOMEM; in dev_pm_domain_attach_list()
236 pds->pd_links = (void *)(pds->pd_devs + num_pds); in dev_pm_domain_attach_list()
237 pds->opp_tokens = (void *)(pds->pd_links + num_pds); in dev_pm_domain_attach_list()
247 data->pd_names[i]); in dev_pm_domain_attach_list()
249 ret = pd_dev ? PTR_ERR(pd_dev) : -ENODEV; in dev_pm_domain_attach_list()
263 pds->opp_tokens[i] = ret; in dev_pm_domain_attach_list()
271 ret = -ENODEV; in dev_pm_domain_attach_list()
275 pds->pd_links[i] = link; in dev_pm_domain_attach_list()
278 pds->pd_devs[i] = pd_dev; in dev_pm_domain_attach_list()
281 pds->num_pds = num_pds; in dev_pm_domain_attach_list()
286 dev_pm_opp_clear_config(pds->opp_tokens[i]); in dev_pm_domain_attach_list()
289 while (--i >= 0) { in dev_pm_domain_attach_list()
290 dev_pm_opp_clear_config(pds->opp_tokens[i]); in dev_pm_domain_attach_list()
291 if (pds->pd_links[i]) in dev_pm_domain_attach_list()
292 device_link_del(pds->pd_links[i]); in dev_pm_domain_attach_list()
293 dev_pm_domain_detach(pds->pd_devs[i], true); in dev_pm_domain_attach_list()
295 kfree(pds->pd_devs); in dev_pm_domain_attach_list()
303 * devm_pm_domain_detach_list - devres-enabled version of dev_pm_domain_detach_list.
304 * @_list: The list of PM domains to detach.
308 * uses devm_pm_domain_attach_list() to attach the PM domains.
318 * devm_pm_domain_attach_list - devres-enabled version of dev_pm_domain_attach_list
319 * @dev: The device used to lookup the PM domains for.
320 * @data: The data used for attaching to the PM domains.
321 * @list: An out-parameter with an allocated list of attached PM domains.
326 * Returns the number of attached PM domains or a negative error code in case of
348 * dev_pm_domain_detach - Detach a device from its PM domain.
354 * detaches @dev from its PM domain. Typically it should be invoked during the
362 if (dev->pm_domain && dev->pm_domain->detach) in dev_pm_domain_detach()
363 dev->pm_domain->detach(dev, power_off); in dev_pm_domain_detach()
368 * dev_pm_domain_detach_list - Detach a list of PM domains.
369 * @list: The list of PM domains to detach.
384 for (i = 0; i < list->num_pds; i++) { in dev_pm_domain_detach_list()
385 dev_pm_opp_clear_config(list->opp_tokens[i]); in dev_pm_domain_detach_list()
386 if (list->pd_links[i]) in dev_pm_domain_detach_list()
387 device_link_del(list->pd_links[i]); in dev_pm_domain_detach_list()
388 dev_pm_domain_detach(list->pd_devs[i], true); in dev_pm_domain_detach_list()
391 kfree(list->pd_devs); in dev_pm_domain_detach_list()
397 * dev_pm_domain_start - Start the device through its PM domain.
401 * when it needs to start its device from the PM domain's perspective. Note
402 * that, it's assumed that the PM domain is already powered on when this
409 if (dev->pm_domain && dev->pm_domain->start) in dev_pm_domain_start()
410 return dev->pm_domain->start(dev); in dev_pm_domain_start()
417 * dev_pm_domain_set - Set PM domain of a device.
418 * @dev: Device whose PM domain is to be set.
419 * @pd: PM domain to be set, or NULL.
421 * Sets the PM domain the device belongs to. The PM domain of a device needs
428 if (dev->pm_domain == pd) in dev_pm_domain_set()
432 "PM domains can only be changed for unbound devices\n"); in dev_pm_domain_set()
433 dev->pm_domain = pd; in dev_pm_domain_set()
439 * dev_pm_domain_set_performance_state - Request a new performance state.
444 * requested for a device that is attached to a PM domain. Note that, the
445 * support for performance scaling for PM domains is optional.
452 if (dev->pm_domain && dev->pm_domain->set_performance_state) in dev_pm_domain_set_performance_state()
453 return dev->pm_domain->set_performance_state(dev, state); in dev_pm_domain_set_performance_state()