Skip to content

Commit a13b110

Browse files
elkablogregkh
authored andcommitted
cpufreq: armada-37xx: Fix setting TBG parent for load levels
[ Upstream commit 22592df ] With CPU frequency determining software [1] we have discovered that after this driver does one CPU frequency change, the base frequency of the CPU is set to the frequency of TBG-A-P clock, instead of the TBG that is parent to the CPU. This can be reproduced on EspressoBIN and Turris MOX: cd /sys/devices/system/cpu/cpufreq/policy0 echo powersave >scaling_governor echo performance >scaling_governor Running the mhz tool before this driver is loaded reports 1000 MHz, and after loading the driver and executing commands above the tool reports 800 MHz. The change of TBG clock selector is supposed to happen in function armada37xx_cpufreq_dvfs_setup. Before the function returns, it does this: parent = clk_get_parent(clk); clk_set_parent(clk, parent); The armada-37xx-periph clock driver has the .set_parent method implemented correctly for this, so if the method was actually called, this would work. But since the introduction of the common clock framework in commit b247649 ("clk: introduce the common clock..."), the clk_set_parent function checks whether the parent is actually changing, and if the requested new parent is same as the old parent (which is obviously the case for the code above), the .set_parent method is not called at all. This patch fixes this issue by filling the correct TBG clock selector directly in the armada37xx_cpufreq_dvfs_setup during the filling of other registers at the same address. But the determination of CPU TBG index cannot be done via the common clock framework, therefore we need to access the North Bridge Peripheral Clock registers directly in this driver. [1] https://github.com/wtarreau/mhz Signed-off-by: Marek Behún <kabel@kernel.org> Acked-by: Gregory CLEMENT <gregory.clement@bootlin.com> Tested-by: Pali Rohár <pali@kernel.org> Tested-by: Tomasz Maciej Nowak <tmn505@gmail.com> Tested-by: Anders Trier Olesen <anders.trier.olesen@gmail.com> Tested-by: Philip Soares <philips@netisense.com> Fixes: 92ce45f ("cpufreq: Add DVFS support for Armada 37xx") Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 1faf7e6 commit a13b110

1 file changed

Lines changed: 23 additions & 12 deletions

File tree

‎drivers/cpufreq/armada-37xx-cpufreq.c‎

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525

2626
#include "cpufreq-dt.h"
2727

28+
/* Clk register set */
29+
#define ARMADA_37XX_CLK_TBG_SEL 0
30+
#define ARMADA_37XX_CLK_TBG_SEL_CPU_OFF 22
31+
2832
/* Power management in North Bridge register set */
2933
#define ARMADA_37XX_NB_L0L1 0x18
3034
#define ARMADA_37XX_NB_L2L3 0x1C
@@ -120,10 +124,15 @@ static struct armada_37xx_dvfs *armada_37xx_cpu_freq_info_get(u32 freq)
120124
* will be configured then the DVFS will be enabled.
121125
*/
122126
static void __init armada37xx_cpufreq_dvfs_setup(struct regmap *base,
123-
struct clk *clk, u8 *divider)
127+
struct regmap *clk_base, u8 *divider)
124128
{
129+
u32 cpu_tbg_sel;
125130
int load_lvl;
126-
struct clk *parent;
131+
132+
/* Determine to which TBG clock is CPU connected */
133+
regmap_read(clk_base, ARMADA_37XX_CLK_TBG_SEL, &cpu_tbg_sel);
134+
cpu_tbg_sel >>= ARMADA_37XX_CLK_TBG_SEL_CPU_OFF;
135+
cpu_tbg_sel &= ARMADA_37XX_NB_TBG_SEL_MASK;
127136

128137
for (load_lvl = 0; load_lvl < LOAD_LEVEL_NR; load_lvl++) {
129138
unsigned int reg, mask, val, offset = 0;
@@ -142,6 +151,11 @@ static void __init armada37xx_cpufreq_dvfs_setup(struct regmap *base,
142151
mask = (ARMADA_37XX_NB_CLK_SEL_MASK
143152
<< ARMADA_37XX_NB_CLK_SEL_OFF);
144153

154+
/* Set TBG index, for all levels we use the same TBG */
155+
val = cpu_tbg_sel << ARMADA_37XX_NB_TBG_SEL_OFF;
156+
mask = (ARMADA_37XX_NB_TBG_SEL_MASK
157+
<< ARMADA_37XX_NB_TBG_SEL_OFF);
158+
145159
/*
146160
* Set cpu divider based on the pre-computed array in
147161
* order to have balanced step.
@@ -160,14 +174,6 @@ static void __init armada37xx_cpufreq_dvfs_setup(struct regmap *base,
160174

161175
regmap_update_bits(base, reg, mask, val);
162176
}
163-
164-
/*
165-
* Set cpu clock source, for all the level we keep the same
166-
* clock source that the one already configured. For this one
167-
* we need to use the clock framework
168-
*/
169-
parent = clk_get_parent(clk);
170-
clk_set_parent(clk, parent);
171177
}
172178

173179
/*
@@ -358,11 +364,16 @@ static int __init armada37xx_cpufreq_driver_init(void)
358364
struct platform_device *pdev;
359365
unsigned long freq;
360366
unsigned int cur_frequency, base_frequency;
361-
struct regmap *nb_pm_base, *avs_base;
367+
struct regmap *nb_clk_base, *nb_pm_base, *avs_base;
362368
struct device *cpu_dev;
363369
int load_lvl, ret;
364370
struct clk *clk, *parent;
365371

372+
nb_clk_base =
373+
syscon_regmap_lookup_by_compatible("marvell,armada-3700-periph-clock-nb");
374+
if (IS_ERR(nb_clk_base))
375+
return -ENODEV;
376+
366377
nb_pm_base =
367378
syscon_regmap_lookup_by_compatible("marvell,armada-3700-nb-pm");
368379

@@ -439,7 +450,7 @@ static int __init armada37xx_cpufreq_driver_init(void)
439450
armada37xx_cpufreq_avs_configure(avs_base, dvfs);
440451
armada37xx_cpufreq_avs_setup(avs_base, dvfs);
441452

442-
armada37xx_cpufreq_dvfs_setup(nb_pm_base, clk, dvfs->divider);
453+
armada37xx_cpufreq_dvfs_setup(nb_pm_base, nb_clk_base, dvfs->divider);
443454
clk_put(clk);
444455

445456
for (load_lvl = ARMADA_37XX_DVFS_LOAD_0; load_lvl < LOAD_LEVEL_NR;

0 commit comments

Comments
 (0)