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.
18 * dev_pm_get_subsys_data - Create or refcount power.subsys_data for device.
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.
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.
87 * The @dev may only be attached to a single PM domain. By iterating through
89 * As attachment succeeds, the ->detach() callback in the struct dev_pm_domain
93 * the probe phase. Especially for those that holds devices which requires
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.
122 * As @dev may only be attached to a single PM domain, the backend PM domain
124 * the ->detach() callback in the struct dev_pm_domain are assigned by the
128 * This function should typically be invoked by a driver during the probe phase,
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
141 * dev_pm_domain_detach() on it, typically during the remove phase.
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.
187 * dev_pm_domain_detach_list(), typically during the remove phase.
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.
286 * it will be invoked during the remove phase from drivers implicitly if driver
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.
303 * you during remove phase.
327 * dev_pm_domain_detach - Detach a device from its PM domain.
334 * remove phase, either from subsystem level code or from drivers.
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.
351 * Typically it should be invoked during the remove phase from drivers.
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()