Re: [PATCH 8/9] PM / Domains: Add support for multi PM domains per device to genpd

From: Rajendra Nayak
Date: Tue May 22 2018 - 23:57:56 EST




On 05/23/2018 02:25 AM, Jon Hunter wrote:
>
> On 22/05/18 15:47, Ulf Hansson wrote:
>> [...]
>>
>>>>
>>>> +/**
>>>> + * genpd_dev_pm_attach_by_id() - Attach a device to one of its PM domain.
>>>> + * @dev: Device to attach.
>>>> + * @index: The index of the PM domain.
>>>> + *
>>>> + * Parse device's OF node to find a PM domain specifier at the provided @index.
>>>> + * If such is found, allocates a new device and attaches it to retrieved
>>>> + * pm_domain ops.
>>>> + *
>>>> + * Returns the allocated device if successfully attached PM domain, NULL when
>>>> + * the device don't need a PM domain or have a single PM domain, else PTR_ERR()
>>>> + * in case of failures. Note that if a power-domain exists for the device, but
>>>> + * cannot be found or turned on, then return PTR_ERR(-EPROBE_DEFER) to ensure
>>>> + * that the device is not probed and to re-try again later.
>>>> + */
>>>> +struct device *genpd_dev_pm_attach_by_id(struct device *dev,
>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ unsigned int index)
>>>> +{
>>>> +ÂÂÂÂ struct device *genpd_dev;
>>>> +ÂÂÂÂ int num_domains;
>>>> +ÂÂÂÂ int ret;
>>>> +
>>>> +ÂÂÂÂ if (!dev->of_node)
>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂ return NULL;
>>>> +
>>>> +ÂÂÂÂ /* Deal only with devices using multiple PM domains. */
>>>> +ÂÂÂÂ num_domains = of_count_phandle_with_args(dev->of_node, "power-domains",
>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ "#power-domain-cells");
>>>> +ÂÂÂÂ if (num_domains < 2 || index >= num_domains)
>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂ return NULL;
>>>> +
>>>> +ÂÂÂÂ /* Allocate and register device on the genpd bus. */
>>>> +ÂÂÂÂ genpd_dev = kzalloc(sizeof(*genpd_dev), GFP_KERNEL);
>>>> +ÂÂÂÂ if (!genpd_dev)
>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂ return ERR_PTR(-ENOMEM);
>>>> +
>>>> +ÂÂÂÂ dev_set_name(genpd_dev, "genpd:%u:%s", index, dev_name(dev));
>>>> +ÂÂÂÂ genpd_dev->bus = &genpd_bus_type;
>>>> +ÂÂÂÂ genpd_dev->release = genpd_release_dev;
>>>> +
>>>> +ÂÂÂÂ ret = device_register(genpd_dev);
>>>> +ÂÂÂÂ if (ret) {
>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂ kfree(genpd_dev);
>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂ return ERR_PTR(ret);
>>>> +ÂÂÂÂ }
>>>> +
>>>> +ÂÂÂÂ /* Try to attach the device to the PM domain at the specified index. */
>>>> +ÂÂÂÂ ret = __genpd_dev_pm_attach(genpd_dev, dev->of_node, index);
>>>> +ÂÂÂÂ if (ret < 1) {
>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂ device_unregister(genpd_dev);
>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂ return ret ? ERR_PTR(ret) : NULL;
>>>> +ÂÂÂÂ }
>>>> +
>>>> +ÂÂÂÂ pm_runtime_set_active(genpd_dev);
>>>> +ÂÂÂÂ pm_runtime_enable(genpd_dev);
>>>> +
>>>> +ÂÂÂÂ return genpd_dev;
>>>> +}
>>>> +EXPORT_SYMBOL_GPL(genpd_dev_pm_attach_by_id);
>>>
>>> Thanks for sending this. Believe it or not this has still been on my to-do list
>>> and so we definitely need a solution for Tegra.
>>>
>>> Looking at the above it appears that additional power-domains exposed as devices
>>> to the client device. So I assume that this means that the drivers for devices
>>> with multiple power-domains will need to call RPM APIs for each of these
>>> additional power-domains. Is that correct?
>>
>> They can, but should not!
>>
>> Instead, the driver shall use device_link_add() and device_link_del(),
>> dynamically, depending on what PM domain that their original device
>> needs for the current running use case.
>>
>> In that way, they keep existing runtime PM deployment, operating on
>> its original device.
>
> OK, sounds good. Any reason why the linking cannot be handled by the above API? Is there a use-case where you would not want it linked?

I am guessing the linking is what would give the driver the ability to decide which subset of powerdomains it actually wants to control
at any point using runtime PM. If we have cases wherein the driver would want to turn on/off _all_ its associated powerdomains _always_
then a default linking of all would help.

--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation