From: Christoph Niedermaier <cniedermaier@dh-electronics.com>
To: Marek Vasut <marex@denx.de>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>
Cc: Viresh Kumar <viresh.kumar@linaro.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Shawn Guo <shawnguo@kernel.org>, Fabio Estevam <festevam@denx.de>,
NXP Linux Team <linux-imx@nxp.com>,
"open list:CPU FREQUENCY SCALING FRAMEWORK"
<linux-pm@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH] cpufreq: imx6q: Disable only available frequencies
Date: Thu, 11 May 2023 20:51:33 +0000 [thread overview]
Message-ID: <a377e725107341a8bf57b5aaf63f058b@dh-electronics.com> (raw)
In-Reply-To: <898fe00e-43f4-a8aa-b2b4-5b293fc77640@denx.de>
From: Marek Vasut [mailto:marex@denx.de]
Sent: Thursday, May 11, 2023 9:26 PM
> On 5/11/23 11:23, Christoph Niedermaier wrote:
>> In the example in Documentation/power/opp.rst, an availability check
>> is present before disabling a specific frequency. If a frequency isn't
>> available, the warning of a failed disabling of a non-existent
>> frequency is misleading. Therefore, check the availability of the
>> frequency in a separate inline function before disabling it.
>
> [...]
>
>> diff --git a/drivers/cpufreq/imx6q-cpufreq.c b/drivers/cpufreq/imx6q-cpufreq.c
>> index 48e1772e98fd..4e2d2bc47aba 100644
>> --- a/drivers/cpufreq/imx6q-cpufreq.c
>> +++ b/drivers/cpufreq/imx6q-cpufreq.c
>> @@ -209,6 +209,21 @@ static struct cpufreq_driver imx6q_cpufreq_driver = {
>> .suspend = cpufreq_generic_suspend,
>> };
>>
>> +static inline int disable_freq_if_available(struct device *dev,
>
> The inline isn't needed, esp. on static function, let the compiler
> figure it out.
>
> Also, "disable if available" should rather be "disable if unavailable" I
> think ?
Here I mean the OPP and I can only disable an available frequency.
>
>> + unsigned long freq)
>> +{
>> + struct dev_pm_opp *opp;
>> + int ret = 0;
>> +
>> + opp = dev_pm_opp_find_freq_exact(dev, freq, true);
>> + if (!IS_ERR(opp)) {
>> + dev_pm_opp_put(opp);
>> + ret = dev_pm_opp_disable(dev, freq);
>> + }
>> +
>> + return ret;
>> +}
>> +
>> #define OCOTP_CFG3 0x440
>> #define OCOTP_CFG3_SPEED_SHIFT 16
>> #define OCOTP_CFG3_SPEED_1P2GHZ 0x3
>> @@ -254,16 +269,16 @@ static int imx6q_opp_check_speed_grading(struct device *dev)
>> val &= 0x3;
>>
>> if (val < OCOTP_CFG3_SPEED_996MHZ)
>> - if (dev_pm_opp_disable(dev, 996000000))
>> + if (disable_freq_if_available(dev, 996000000))
>> dev_warn(dev, "failed to disable 996MHz OPP\n");
>>
>> if (of_machine_is_compatible("fsl,imx6q") ||
>> of_machine_is_compatible("fsl,imx6qp")) {
>
> Can we introduce a function like:
>
> void imx_disable_freq_if_unavailable(struct device *dev, u32 freq_mhz,
> u32 val, u32 mask)
> {
> if (val == mask)
> return;
> if (!disable_freq_if_available(dev, freq_mhz * 1000000))
> return;
> dev_warn(dev, "failed to disable %dMHz OPP\n", mhz);
> }
>
> And then just call it multiple times in here, to reduce duplication ?
>
>> if (val != OCOTP_CFG3_SPEED_852MHZ)
>> - if (dev_pm_opp_disable(dev, 852000000))
>> + if (disable_freq_if_available(dev, 852000000))
>> dev_warn(dev, "failed to disable 852MHz OPP\n");
>
Yes, using a function to reduce duplications would be good.
Regards
Christoph
prev parent reply other threads:[~2023-05-13 7:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-11 9:23 [PATCH] cpufreq: imx6q: Disable only available frequencies Christoph Niedermaier
2023-05-11 9:51 ` Viresh Kumar
2023-05-11 9:53 ` Viresh Kumar
2023-05-11 14:38 ` Christoph Niedermaier
2023-05-12 4:41 ` Viresh Kumar
2023-05-11 19:25 ` Marek Vasut
2023-05-11 20:51 ` Christoph Niedermaier [this message]
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=a377e725107341a8bf57b5aaf63f058b@dh-electronics.com \
--to=cniedermaier@dh-electronics.com \
--cc=festevam@denx.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-imx@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=marex@denx.de \
--cc=rafael@kernel.org \
--cc=shawnguo@kernel.org \
--cc=viresh.kumar@linaro.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