diff mbox

[3/3] cpufreq: kirkwood: use the powersave multiplexer

Message ID 1409597225-24368-4-git-send-email-mturquette@linaro.org
State New
Headers show

Commit Message

Mike Turquette Sept. 1, 2014, 6:47 p.m. UTC
The powersave clock acts like a multiplexer for the cpu, selecting
either the clock signal derived from the cpu pll or from the ddr clock.
This patch changes powersave from a gate clock to a mux clock to better
reflect this behavior.

This is a cleaner approach whereby the frequency of the cpu always
matches the rate of powersave_clk. The cpufreq driver for the kirkwood
platform no longer must parse this behavior out of various calls to
clk_enable and clk_disable, but can instead simply select the parent cpu
it wants when changing rate. Likewise when requesting the cpu rate we
need only query powersave_clk's rate through the usual call to
clk_get_rate.

The new clock data and corresponding changes to the cpufreq driver are
combined into this single commit to avoid a git bisect issue where this
cpufreq driver fails to work properly between the commit that updates
the kirkwood clock driver and the commit that changes how the cpufreq
driver uses that clock.

Cc: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Mike Turquette <mturquette@linaro.org>
---
 drivers/clk/mvebu/kirkwood.c       | 15 +++++++++++++--
 drivers/cpufreq/kirkwood-cpufreq.c | 14 +++++---------
 2 files changed, 18 insertions(+), 11 deletions(-)

Comments

Viresh Kumar Sept. 2, 2014, 4:49 a.m. UTC | #1
On 2 September 2014 00:17, Mike Turquette <mturquette@linaro.org> wrote:

> @@ -150,7 +146,7 @@ static int kirkwood_cpufreq_probe(struct platform_device *pdev)
>                 err = PTR_ERR(priv.powersave_clk);
>                 goto out_ddr;
>         }
> -       clk_prepare(priv.powersave_clk);
> +       clk_prepare_enable(priv.powersave_clk);

Shouldn't this be done in a separate patch? Or is this really related?

>
>         of_node_put(np);
>         np = NULL;

Other than that: Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

Yeah, you can take it through clock tree..
Mike Turquette Sept. 2, 2014, 10 p.m. UTC | #2
On Mon, Sep 1, 2014 at 9:49 PM, Viresh Kumar <viresh.kumar@linaro.org> wrote:
> On 2 September 2014 00:17, Mike Turquette <mturquette@linaro.org> wrote:
>
>> @@ -150,7 +146,7 @@ static int kirkwood_cpufreq_probe(struct platform_device *pdev)
>>                 err = PTR_ERR(priv.powersave_clk);
>>                 goto out_ddr;
>>         }
>> -       clk_prepare(priv.powersave_clk);
>> +       clk_prepare_enable(priv.powersave_clk);
>
> Shouldn't this be done in a separate patch? Or is this really related?

It is related. Before this change powersave_clk was modeled as a gate.
The separate clk_enable/clk_disable operations were used to toggle the
mux. This patch does two things:

1) remove the old gate-style powersave_clk in the clock driver and
replace with the mux-style powersave_clk data
2) update the cpufreq driver to handle the mux properly

So the change you pointed out above is part of #2.

These two changes are coupled in one patch to prevent git bisect breakage.

>
>>
>>         of_node_put(np);
>>         np = NULL;
>
> Other than that: Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
>
> Yeah, you can take it through clock tree..

Cool.

Thanks,
Mike
diff mbox

Patch

diff --git a/drivers/clk/mvebu/kirkwood.c b/drivers/clk/mvebu/kirkwood.c
index f73a2fa..99550f2 100644
--- a/drivers/clk/mvebu/kirkwood.c
+++ b/drivers/clk/mvebu/kirkwood.c
@@ -216,7 +216,6 @@  static const struct clk_gating_soc_desc kirkwood_gating_desc[] __initconst = {
 	{ "runit", NULL, 7, 0 },
 	{ "xor0", NULL, 8, 0 },
 	{ "audio", NULL, 9, 0 },
-	{ "powersave", "cpuclk", 11, 0 },
 	{ "sata0", NULL, 14, 0 },
 	{ "sata1", NULL, 15, 0 },
 	{ "xor1", NULL, 16, 0 },
@@ -247,6 +246,16 @@  struct clk_muxing_ctrl {
 	int num_muxes;
 };
 
+static const char *powersave_parents[] = {
+	"cpuclk",
+	"ddrclk",
+};
+
+static const struct clk_muxing_soc_desc kirkwood_mux_desc[] __initconst = {
+	{ "powersave", powersave_parents, ARRAY_SIZE(powersave_parents),
+		11, 1, 0 },
+};
+
 #define to_clk_mux(_hw) container_of(_hw, struct clk_mux, hw)
 
 static struct clk *clk_muxing_get_src(
@@ -323,8 +332,10 @@  static void __init kirkwood_clk_init(struct device_node *np)
 	else
 		mvebu_coreclk_setup(np, &kirkwood_coreclks);
 
-	if (cgnp)
+	if (cgnp) {
 		mvebu_clk_gating_setup(cgnp, kirkwood_gating_desc);
+		kirkwood_clk_muxing_setup(cgnp, kirkwood_mux_desc);
+	}
 }
 CLK_OF_DECLARE(kirkwood_clk, "marvell,kirkwood-core-clock",
 	       kirkwood_clk_init);
diff --git a/drivers/cpufreq/kirkwood-cpufreq.c b/drivers/cpufreq/kirkwood-cpufreq.c
index 37a4806..7906d4a 100644
--- a/drivers/cpufreq/kirkwood-cpufreq.c
+++ b/drivers/cpufreq/kirkwood-cpufreq.c
@@ -12,7 +12,6 @@ 
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/clk.h>
-#include <linux/clk-provider.h>
 #include <linux/cpufreq.h>
 #include <linux/of_device.h>
 #include <linux/platform_device.h>
@@ -39,8 +38,7 @@  static struct priv
  * - cpu clk
  * - ddr clk
  *
- * The frequencies are set at runtime before registering this *
- * table.
+ * The frequencies are set at runtime before registering this table.
  */
 static struct cpufreq_frequency_table kirkwood_freq_table[] = {
 	{0, STATE_CPU_FREQ,	0}, /* CPU uses cpuclk */
@@ -50,9 +48,7 @@  static struct cpufreq_frequency_table kirkwood_freq_table[] = {
 
 static unsigned int kirkwood_cpufreq_get_cpu_frequency(unsigned int cpu)
 {
-	if (__clk_is_enabled(priv.powersave_clk))
-		return kirkwood_freq_table[1].frequency;
-	return kirkwood_freq_table[0].frequency;
+	return clk_get_rate(priv.powersave_clk) / 1000;
 }
 
 static int kirkwood_cpufreq_target(struct cpufreq_policy *policy,
@@ -70,10 +66,10 @@  static int kirkwood_cpufreq_target(struct cpufreq_policy *policy,
 
 	switch (state) {
 	case STATE_CPU_FREQ:
-		clk_disable(priv.powersave_clk);
+		clk_set_parent(priv.powersave_clk, priv.cpu_clk);
 		break;
 	case STATE_DDR_FREQ:
-		clk_enable(priv.powersave_clk);
+		clk_set_parent(priv.powersave_clk, priv.ddr_clk);
 		break;
 	}
 
@@ -150,7 +146,7 @@  static int kirkwood_cpufreq_probe(struct platform_device *pdev)
 		err = PTR_ERR(priv.powersave_clk);
 		goto out_ddr;
 	}
-	clk_prepare(priv.powersave_clk);
+	clk_prepare_enable(priv.powersave_clk);
 
 	of_node_put(np);
 	np = NULL;