From: Dmitry Osipenko <digetx@gmail.com>
To: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>,
Thierry Reding <thierry.reding@gmail.com>,
Jonathan Hunter <jonathanh@nvidia.com>,
Paul Fertser <fercerpav@gmail.com>,
Matt Merhar <mattmerhar@protonmail.com>,
Peter Geis <pgwipeout@gmail.com>,
Nicolas Chauvet <kwizart@gmail.com>,
Viresh Kumar <vireshk@kernel.org>,
Stephen Boyd <sboyd@kernel.org>
Cc: linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 1/1] soc/tegra: Add devm_tegra_core_dev_init_opp_table()
Date: Mon, 17 May 2021 17:47:09 +0300 [thread overview]
Message-ID: <a3b42449-4cd8-f692-c41a-205cbaa987eb@gmail.com> (raw)
In-Reply-To: <3ea6b48f-af3f-51db-8d7b-1292a68ae74e@canonical.com>
17.05.2021 14:43, Krzysztof Kozlowski пишет:
...
>> +static int tegra_core_dev_init_opp_state(struct device *dev)
>> +{
>> + struct dev_pm_opp *opp;
>> + unsigned long rate;
>> + struct clk *clk;
>> + int err;
>> +
>> + clk = devm_clk_get(dev, NULL);
>> + if (IS_ERR(clk)) {
>> + dev_err(dev, "failed to get clk: %pe\n", clk);
>> + return PTR_ERR(clk);
>> + }
>> +
>> + rate = clk_get_rate(clk);
>> + if (!rate) {
>> + dev_err(dev, "failed to get clk rate\n");
>> + return -EINVAL;
>> + }
>> +
>> + opp = dev_pm_opp_find_freq_ceil(dev, &rate);
>> +
>> + if (opp == ERR_PTR(-ERANGE))
>> + opp = dev_pm_opp_find_freq_floor(dev, &rate);
>> +
>> + err = PTR_ERR_OR_ZERO(opp);
>> + if (err) {
>> + dev_err(dev, "failed to get OPP for %ld Hz: %d\n",
>> + rate, err);
>> + return err;
>> + }
>> +
>> + dev_pm_opp_put(opp);
>> +
>> + /* first dummy rate-setting initializes voltage vote */
>> + err = dev_pm_opp_set_rate(dev, rate);
>> + if (err) {
>> + dev_err(dev, "failed to initialize OPP clock: %d\n", err);
>> + return err;
>> + }
>
>
> The devm_pm_opp_set_clkname will call clk_get(), so here you should drop
> the clk reference at the end. Why having it twice?
The devm_pm_opp_set_clkname assigns clock to the OPP table.
The devm_clk_get() is needed for the clk_get_rate(). OPP core doesn't
initialize voltage vote and we need this initialization for the Tegra
memory drivers.
The reference count of the clk will be dropped automatically once device
driver is released. The resource-managed helper avoids the need to care
about the error unwinding in the code, making it clean and easy to follow.
...
>> +EXPORT_SYMBOL_GPL(devm_tegra_core_dev_init_opp_table);
>> diff --git a/include/soc/tegra/common.h b/include/soc/tegra/common.h
>> index 98027a76ce3d..e8eab13aa199 100644
>> --- a/include/soc/tegra/common.h
>> +++ b/include/soc/tegra/common.h
>> @@ -6,6 +6,36 @@
>> #ifndef __SOC_TEGRA_COMMON_H__
>> #define __SOC_TEGRA_COMMON_H__
>>
>> +#include <linux/errno.h>
>> +#include <linux/types.h>
>> +
>> +struct device;
>> +
>> +/**
>> + * Tegra SoC core device OPP table configuration
>> + *
>> + * @init_state: pre-initialize OPP state of a device
>> + */
>> +struct tegra_core_opp_params {
>> + bool init_state;
>> +};
>> +
>> +#ifdef CONFIG_ARCH_TEGRA
>> bool soc_is_tegra(void);
>> +int devm_tegra_core_dev_init_opp_table(struct device *dev,
>> + struct tegra_core_opp_params *params);
>> +#else
>> +static inline bool soc_is_tegra(void)
>
> This looks unrelated. Please make it a separate patch.
The missing stub for soc_is_tegra() popped up multiple times before.
Hence it didn't look like a bad idea to me to add stub for it since this
patch touches code around it.
I'll factor it out into a separate patch in v2.
next prev parent reply other threads:[~2021-05-17 16:16 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-16 20:51 [PATCH v1 0/1] Add devm_tegra_core_dev_init_opp_table() helper Dmitry Osipenko
2021-05-16 20:51 ` [PATCH v1 1/1] soc/tegra: Add devm_tegra_core_dev_init_opp_table() Dmitry Osipenko
2021-05-17 3:37 ` Viresh Kumar
2021-05-17 14:09 ` Dmitry Osipenko
2021-05-18 3:26 ` Viresh Kumar
2021-05-17 11:43 ` Krzysztof Kozlowski
2021-05-17 14:47 ` Dmitry Osipenko [this message]
2021-05-17 14:52 ` Krzysztof Kozlowski
2021-05-17 15:23 ` Dmitry Osipenko
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=a3b42449-4cd8-f692-c41a-205cbaa987eb@gmail.com \
--to=digetx@gmail.com \
--cc=fercerpav@gmail.com \
--cc=jonathanh@nvidia.com \
--cc=krzysztof.kozlowski@canonical.com \
--cc=kwizart@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=mattmerhar@protonmail.com \
--cc=pgwipeout@gmail.com \
--cc=sboyd@kernel.org \
--cc=thierry.reding@gmail.com \
--cc=vireshk@kernel.org \
/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
all inboxes | Powered by JetHome®