From: Jon Hunter <jonathanh@nvidia.com>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
Linux PM list <linux-pm@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
linux-tegra@vger.kernel.org
Subject: Re: [PATCH V3] PM / clk: Add support for obtaining clocks from device-tree
Date: Thu, 10 Mar 2016 12:27:40 +0000 [thread overview]
Message-ID: <56E1683C.4020206@nvidia.com> (raw)
In-Reply-To: <CAMuHMdUToumZwuisg7HeOVuB7Amke7W=qpZ5f0dzavSqnjXygg@mail.gmail.com>
On 10/03/16 09:41, Geert Uytterhoeven wrote:
> Hi Jon,
>
> On Thu, Mar 10, 2016 at 10:00 AM, Jon Hunter <jonathanh@nvidia.com> wrote:
>> The PM clocks framework requires clients to pass either a con-id or a
>> valid clk pointer in order to add a clock to a device. Add a new
>> function of_pm_clk_add_clks() to allows device clocks to be retrieved
>> from device-tree and populated for a given device. Note that
>> of_clk_get_from_provider() is not defined if CONFIG_OF and
>> CONFIG_COMMON_CLK are not selected. Therefore, make of_pm_clk_add_clks()
>> dependent on these options.
>>
>> An optional function pointer may be passed to of_pm_clk_add_clks() that
>> can be used to filter the clocks that are added for a device when
>> calling of_pm_clk_add_clks().
>>
>> In order to handle errors encountered when adding clocks from
>> device-tree, add a function pm_clk_remove_clk() to remove any clocks
>> (using a pointer to the clk structure) that have been added
>> successfully before the error occurred.
>>
>> Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
>
> Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>
>
> But more comments below...
>
>> --- a/drivers/base/power/clock_ops.c
>> +++ b/drivers/base/power/clock_ops.c
>> @@ -137,6 +137,81 @@ int pm_clk_add_clk(struct device *dev, struct clk *clk)
>> return __pm_clk_add(dev, NULL, clk);
>> }
>>
>> +
>> +#if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK)
>> +/**
>> + * of_pm_clk_add_clks - Start using device clock(s) for power management.
>> + * @dev: Device whose clock(s) is going to be used for power management.
>> + * @of_pm_clk_filter: Optional function for filtering clocks
>> + *
>> + * Add a series of clocks described in the 'clocks' device-tree node for
>> + * a device to the list of clocks used for the power management of @dev.
>> + * If 'of_pm_clk_filter' is specified, then this filter function will be
>> + * called for each clock found and the clock will be added to the list
>> + * of clocks if this function returns true. Return success if clocks are
>> + * added successfully and return a negative error code if adding a clock
>> + * fails or there are no clocks that match with the filter function.
>> + */
>> +int of_pm_clk_add_clks(struct device *dev, of_pm_clk_filter fn, void *data)
>> +{
>
> [...]
>
>> + count = of_count_phandle_with_args(dev->of_node, "clocks",
>> + "#clock-cells");
>> + if (count == 0)
>> + return -ENODEV;
>
> [...]
>
> + return added ? 0 : -ENODEV;
>
> Is it an error condition if no clocks were present in DT, or if no clocks have
> been accepted by the filter function? If not, the caller has to check for
> -ENODEV. Now the caller has to call pm_clk_create() first, before it knows if
> any clocks will be added, it may want to call pm_clk_destroy() later if no
> clocks have been added.
It seems odd to me that someone would call this function and either
there are no clocks in the DT or they are all filtered out. For example,
most drivers are calling of_clk_get() because there are clocks they need
to add.
> Alternatively, you could return 0 vs. the actual number of clocks added.
However, a nice comprise here could be to return the number of clocks
added and let the user decide what to do. I like that idea. Not sure I
understand what you mean by "0 vs. the actual number of clocks added".
Do you just mean the return the number added?
> I hooked up your code in renesas-cpg-mssr.c, and it worked.
> However, I noticed it added 27 clocks for one device node (rcar_sound), and
> only then I realized that I only want to add the first clock accepted by the
> filter, not all of them, as the others are under driver control.
> I'm not sure this can be handled in the filter function.
> So I can't use your code (for now)...
I see, that is unfortunate. Are you using the void *data variable in
your filter? If not may be you could use this to indicate a clock has
been 'found' and don't match any further clocks.
If you cannot use it, then I am tempted to drop the filter function for
now as this simplifies the code. It can always be added later if someone
has a need for it.
Cheers
Jon
next prev parent reply other threads:[~2016-03-10 12:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-10 9:00 [PATCH V3] PM / clk: Add support for obtaining clocks from device-tree Jon Hunter
[not found] ` <1457600456-4283-1-git-send-email-jonathanh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2016-03-10 9:41 ` Geert Uytterhoeven
2016-03-10 12:27 ` Jon Hunter [this message]
2016-03-10 12:40 ` Geert Uytterhoeven
[not found] ` <CAMuHMdXNRade9m5Qm+EDiSw+VOqgosD-2vR1YZTeasqhHD4xCg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-03-10 13:23 ` Jon Hunter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56E1683C.4020206@nvidia.com \
--to=jonathanh@nvidia.com \
--cc=geert@linux-m68k.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=rjw@rjwysocki.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox