Lines Matching +full:single +full:- +full:phase
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
90 * As attachment succeeds, the ->detach() callback in the struct dev_pm_domain
94 * the probe phase. Especially for those that holds devices which requires
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.
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
129 * This function should typically be invoked by a driver during the probe phase,
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
142 * dev_pm_domain_detach() on it, typically during the remove phase.
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.
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.
188 * dev_pm_domain_detach_list(), typically during the remove phase.
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.
304 * it will be invoked during the remove phase from drivers implicitly if driver
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.
321 * you during remove phase.
345 * dev_pm_domain_detach - Detach a device from its PM domain.
352 * remove phase, either from subsystem level code or from drivers.
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.
369 * Typically it should be invoked during the remove phase from drivers.
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.
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.
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.
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()