* [PATCH] cpufreq: qoriq: enhance bus frequency calculation
@ 2017-03-09 8:15 YuanTian Tang
2017-03-09 9:39 ` Viresh Kumar
0 siblings, 1 reply; 5+ messages in thread
From: YuanTian Tang @ 2017-03-09 8:15 UTC (permalink / raw)
To: rjw, viresh.kumar
Cc: linux-pm, linux-kernel, linux-arm-kernel, Tang Yuantian, Tang Yuantian
From: Tang Yuantian <Yuantian.Tang@nxp.com>
On some platforms, property device-type may be missed in soc node
in dts which caused the bus-frequency can not be obtained correctly.
This patch enhanced the bus-frequency calculation. When property
device-type is missed in dts, bus-frequency will be obtained by
looking up clock table to get platform clock and hence get its
frequency.
Signed-off-by: Tang Yuantian <yuantian.tang@nxp.com>
---
drivers/cpufreq/qoriq-cpufreq.c | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/drivers/cpufreq/qoriq-cpufreq.c b/drivers/cpufreq/qoriq-cpufreq.c
index bfec1bc..0f22e40 100644
--- a/drivers/cpufreq/qoriq-cpufreq.c
+++ b/drivers/cpufreq/qoriq-cpufreq.c
@@ -52,17 +52,27 @@ static u32 get_bus_freq(void)
{
struct device_node *soc;
u32 sysfreq;
+ struct clk *pltclk;
+ int ret;
+ /* get platform freq by searching bus-frequency property */
soc = of_find_node_by_type(NULL, "soc");
- if (!soc)
- return 0;
-
- if (of_property_read_u32(soc, "bus-frequency", &sysfreq))
- sysfreq = 0;
+ if (soc) {
+ ret = of_property_read_u32(soc, "bus-frequency", &sysfreq);
+ of_node_put(soc);
+ if (!ret)
+ return sysfreq;
+ }
- of_node_put(soc);
+ /* get platform freq by its clock name */
+ pltclk = clk_get(NULL, "cg-pll0-div1");
+ if (IS_ERR(pltclk)) {
+ pr_err("%s: can't get bus frequency %ld\n",
+ __func__, PTR_ERR(pltclk));
+ return PTR_ERR(pltclk);
+ }
- return sysfreq;
+ return clk_get_rate(pltclk);
}
static struct clk *cpu_to_clk(int cpu)
--
2.1.0.27.g96db324
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] cpufreq: qoriq: enhance bus frequency calculation
2017-03-09 8:15 [PATCH] cpufreq: qoriq: enhance bus frequency calculation YuanTian Tang
@ 2017-03-09 9:39 ` Viresh Kumar
2017-03-10 1:44 ` Andy Tang
0 siblings, 1 reply; 5+ messages in thread
From: Viresh Kumar @ 2017-03-09 9:39 UTC (permalink / raw)
To: YuanTian Tang
Cc: rjw, linux-pm, linux-kernel, linux-arm-kernel, Tang Yuantian
On 09-03-17, 16:15, YuanTian Tang wrote:
> From: Tang Yuantian <Yuantian.Tang@nxp.com>
>
> On some platforms, property device-type may be missed in soc node
> in dts which caused the bus-frequency can not be obtained correctly.
>
> This patch enhanced the bus-frequency calculation. When property
> device-type is missed in dts, bus-frequency will be obtained by
> looking up clock table to get platform clock and hence get its
> frequency.
>
> Signed-off-by: Tang Yuantian <yuantian.tang@nxp.com>
> ---
> drivers/cpufreq/qoriq-cpufreq.c | 24 +++++++++++++++++-------
> 1 file changed, 17 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/cpufreq/qoriq-cpufreq.c b/drivers/cpufreq/qoriq-cpufreq.c
> index bfec1bc..0f22e40 100644
> --- a/drivers/cpufreq/qoriq-cpufreq.c
> +++ b/drivers/cpufreq/qoriq-cpufreq.c
> @@ -52,17 +52,27 @@ static u32 get_bus_freq(void)
> {
> struct device_node *soc;
> u32 sysfreq;
> + struct clk *pltclk;
> + int ret;
>
> + /* get platform freq by searching bus-frequency property */
> soc = of_find_node_by_type(NULL, "soc");
> - if (!soc)
> - return 0;
> -
> - if (of_property_read_u32(soc, "bus-frequency", &sysfreq))
> - sysfreq = 0;
> + if (soc) {
> + ret = of_property_read_u32(soc, "bus-frequency", &sysfreq);
> + of_node_put(soc);
> + if (!ret)
> + return sysfreq;
> + }
>
> - of_node_put(soc);
> + /* get platform freq by its clock name */
> + pltclk = clk_get(NULL, "cg-pll0-div1");
Will this always work? If yes, then what about dropping the code parsing DT
completely ? That is, just rely on clk_get_rate() in all cases.
> + if (IS_ERR(pltclk)) {
> + pr_err("%s: can't get bus frequency %ld\n",
> + __func__, PTR_ERR(pltclk));
You need to properly align this. Try running checkpatch over this patch or:
checkpatch --strict
> + return PTR_ERR(pltclk);
> + }
>
> - return sysfreq;
> + return clk_get_rate(pltclk);
> }
>
> static struct clk *cpu_to_clk(int cpu)
> --
> 2.1.0.27.g96db324
--
viresh
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH] cpufreq: qoriq: enhance bus frequency calculation
2017-03-09 9:39 ` Viresh Kumar
@ 2017-03-10 1:44 ` Andy Tang
2017-03-10 10:05 ` Viresh Kumar
0 siblings, 1 reply; 5+ messages in thread
From: Andy Tang @ 2017-03-10 1:44 UTC (permalink / raw)
To: Viresh Kumar; +Cc: rjw, linux-pm, linux-kernel, linux-arm-kernel
Hi Viresh,
> -----Original Message-----
> From: Viresh Kumar [mailto:viresh.kumar@linaro.org]
> Sent: Thursday, March 09, 2017 5:39 PM
> To: Y.T. Tang
> Cc: rjw@rjwysocki.net; linux-pm@vger.kernel.org; linux-
> kernel@vger.kernel.org; linux-arm-kernel@lists.infradead.org; Y.T. Tang
> Subject: Re: [PATCH] cpufreq: qoriq: enhance bus frequency calculation
>
> On 09-03-17, 16:15, YuanTian Tang wrote:
> > From: Tang Yuantian <Yuantian.Tang@nxp.com>
> >
> > On some platforms, property device-type may be missed in soc node in
> > dts which caused the bus-frequency can not be obtained correctly.
> >
> > This patch enhanced the bus-frequency calculation. When property
> > device-type is missed in dts, bus-frequency will be obtained by
> > looking up clock table to get platform clock and hence get its
> > frequency.
> >
> > Signed-off-by: Tang Yuantian <yuantian.tang@nxp.com>
> > ---
> > drivers/cpufreq/qoriq-cpufreq.c | 24 +++++++++++++++++-------
> > 1 file changed, 17 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/cpufreq/qoriq-cpufreq.c
> > b/drivers/cpufreq/qoriq-cpufreq.c index bfec1bc..0f22e40 100644
> > --- a/drivers/cpufreq/qoriq-cpufreq.c
> > +++ b/drivers/cpufreq/qoriq-cpufreq.c
> > @@ -52,17 +52,27 @@ static u32 get_bus_freq(void) {
> > struct device_node *soc;
> > u32 sysfreq;
> > + struct clk *pltclk;
> > + int ret;
> >
> > + /* get platform freq by searching bus-frequency property */
> > soc = of_find_node_by_type(NULL, "soc");
> > - if (!soc)
> > - return 0;
> > -
> > - if (of_property_read_u32(soc, "bus-frequency", &sysfreq))
> > - sysfreq = 0;
> > + if (soc) {
> > + ret = of_property_read_u32(soc, "bus-frequency", &sysfreq);
> > + of_node_put(soc);
> > + if (!ret)
> > + return sysfreq;
> > + }
> >
> > - of_node_put(soc);
> > + /* get platform freq by its clock name */
> > + pltclk = clk_get(NULL, "cg-pll0-div1");
>
> Will this always work? If yes, then what about dropping the code parsing DT
> completely ? That is, just rely on clk_get_rate() in all cases.
>
We put all the clock tree configuration in driver, not in dts. cg-pll0-div1 is hardcoded in driver since we don't depend on dts. We kind of don't have other choices but use the hardcode clock name here too.
> > + if (IS_ERR(pltclk)) {
> > + pr_err("%s: can't get bus frequency %ld\n",
> > + __func__, PTR_ERR(pltclk));
>
> You need to properly align this. Try running checkpatch over this patch or:
>
> checkpatch --strict
>
I did check it with checkpatch script, but without --strict parameter.
After applying --strict, script tell the alignment issue. :)
Regards,
Andy
> > + return PTR_ERR(pltclk);
> > + }
> >
> > - return sysfreq;
> > + return clk_get_rate(pltclk);
> > }
> >
> > static struct clk *cpu_to_clk(int cpu)
> > --
> > 2.1.0.27.g96db324
>
> --
> viresh
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] cpufreq: qoriq: enhance bus frequency calculation
2017-03-10 1:44 ` Andy Tang
@ 2017-03-10 10:05 ` Viresh Kumar
2017-03-10 10:12 ` Andy Tang
0 siblings, 1 reply; 5+ messages in thread
From: Viresh Kumar @ 2017-03-10 10:05 UTC (permalink / raw)
To: Andy Tang; +Cc: rjw, linux-pm, linux-kernel, linux-arm-kernel
On 10-03-17, 01:44, Andy Tang wrote:
> > Will this always work? If yes, then what about dropping the code parsing DT
> > completely ? That is, just rely on clk_get_rate() in all cases.
> >
> We put all the clock tree configuration in driver, not in dts.
> cg-pll0-div1 is hardcoded in driver since we don't depend on dts.
> We kind of don't have other choices but use the hardcode clock name
> here too.
Looks like you misread my comment. Let me try again. Will it be fine
to write get_bus_freq() this way?
static u32 get_bus_freq(void)
{
struct clk *pltclk;
/* get platform freq by its clock name */
pltclk = clk_get(NULL, "cg-pll0-div1");
if (IS_ERR(pltclk)) {
pr_err("%s: can't get bus frequency %ld\n",
__func__, PTR_ERR(pltclk));
return PTR_ERR(pltclk);
}
return clk_get_rate(pltclk);
}
--
viresh
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH] cpufreq: qoriq: enhance bus frequency calculation
2017-03-10 10:05 ` Viresh Kumar
@ 2017-03-10 10:12 ` Andy Tang
0 siblings, 0 replies; 5+ messages in thread
From: Andy Tang @ 2017-03-10 10:12 UTC (permalink / raw)
To: Viresh Kumar; +Cc: rjw, linux-pm, linux-kernel, linux-arm-kernel
Hi Viresh,
> -----Original Message-----
> From: Viresh Kumar [mailto:viresh.kumar@linaro.org]
> Sent: Friday, March 10, 2017 6:05 PM
> To: Andy Tang
> Cc: rjw@rjwysocki.net; linux-pm@vger.kernel.org; linux-
> kernel@vger.kernel.org; linux-arm-kernel@lists.infradead.org
> Subject: Re: [PATCH] cpufreq: qoriq: enhance bus frequency calculation
>
> On 10-03-17, 01:44, Andy Tang wrote:
> > > Will this always work? If yes, then what about dropping the code
> > > parsing DT completely ? That is, just rely on clk_get_rate() in all cases.
> > >
> > We put all the clock tree configuration in driver, not in dts.
> > cg-pll0-div1 is hardcoded in driver since we don't depend on dts.
> > We kind of don't have other choices but use the hardcode clock name
> > here too.
>
> Looks like you misread my comment. Let me try again. Will it be fine to write
> get_bus_freq() this way?
>
> static u32 get_bus_freq(void)
> {
> struct clk *pltclk;
>
> /* get platform freq by its clock name */
> pltclk = clk_get(NULL, "cg-pll0-div1");
> if (IS_ERR(pltclk)) {
> pr_err("%s: can't get bus frequency %ld\n",
> __func__, PTR_ERR(pltclk));
> return PTR_ERR(pltclk);
> }
>
> return clk_get_rate(pltclk);
> }
>
Yes, we can. But for some legacy powerpc-based socs, this may not work.
powerpc-base socs are still using legacy clock driver. For compatibility sake, we better be compatible with old ones. It would break any compatibility this way.
Regards,
Yuantian
> --
> viresh
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-03-10 10:12 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-09 8:15 [PATCH] cpufreq: qoriq: enhance bus frequency calculation YuanTian Tang
2017-03-09 9:39 ` Viresh Kumar
2017-03-10 1:44 ` Andy Tang
2017-03-10 10:05 ` Viresh Kumar
2017-03-10 10:12 ` Andy Tang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).