linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] arm: kirkwood: model cpu clock mux and update cpufreq driver
@ 2014-09-01 18:47 Mike Turquette
  2014-09-01 18:47 ` [PATCH 1/3] clk: mvebu: share locks between gate clocks Mike Turquette
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Mike Turquette @ 2014-09-01 18:47 UTC (permalink / raw)
  To: linux-kernel, Rafael J. Wysocki, Viresh Kumar
  Cc: patches, Mike Turquette, Andrew Lunn, Tomeu Vizoso

While reviewing Tomeu's "Per-user clock constraints" series I saw that
the Kirkwood cpufreq driver needed to use a new, public clk_is_enabled()
which I hoped not to merge [0].

This led to some investigation as to why this was needed and with
Andrew's help I came to realize that the powersave_clk on the kirkwood
platform acts more like a clock signal multiplexer than a gate. This mux
is unique to Kirkwood; none of the other mvebu platforms have it.

This series updates the kirkwood clock driver to model the powersave_clk
as a mux instead of a gate, and it updates and slightly simplifies the
cpufreq driver to use this clock as a mux.

Rafael & Viresh: I'd prefer to merge the cpufreq driver patch through
the clock tree since Tomeu's changes to the clock core depend on it.

[0] http://lkml.kernel.org/r/CAPtuhThyUPrY2AqVEsyRQqR-8hsj_GAe1W0u_XXonP-C2o_Xew@mail.gmail.com

Mike Turquette (3):
  clk: mvebu: share locks between gate clocks
  clk: mvebu: powersave clock is a multiplexer
  cpufreq: kirkwood: use the powersave multiplexer

 drivers/clk/mvebu/common.c         |   9 ++--
 drivers/clk/mvebu/common.h         |   2 +
 drivers/clk/mvebu/kirkwood.c       | 102 ++++++++++++++++++++++++++++++++++++-
 drivers/cpufreq/kirkwood-cpufreq.c |  14 ++---
 4 files changed, 113 insertions(+), 14 deletions(-)

-- 
1.8.3.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] clk: mvebu: share locks between gate clocks
  2014-09-01 18:47 [PATCH 0/3] arm: kirkwood: model cpu clock mux and update cpufreq driver Mike Turquette
@ 2014-09-01 18:47 ` Mike Turquette
  2014-09-01 18:47 ` [PATCH 2/3] clk: mvebu: powersave clock is a multiplexer Mike Turquette
  2014-09-01 18:47 ` [PATCH 3/3] cpufreq: kirkwood: use the powersave multiplexer Mike Turquette
  2 siblings, 0 replies; 6+ messages in thread
From: Mike Turquette @ 2014-09-01 18:47 UTC (permalink / raw)
  To: linux-kernel; +Cc: patches, Mike Turquette, Andrew Lunn

Refactor mvebu_clk_gating_setup() to use a common spinlock instead of a
unique lock for every instance of a struct clk_gating_ctrl object. This
will be used later for a separate mux clock type that shares a register
with gate clock types and needs to use the same lock to protect access
to the register.

Cc: Andrew Lunn <andrew@lunn.ch>
Tested-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Mike Turquette <mturquette@linaro.org>
---
 drivers/clk/mvebu/common.c | 9 ++++++---
 drivers/clk/mvebu/common.h | 2 ++
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/mvebu/common.c b/drivers/clk/mvebu/common.c
index 25ceccf..8145c4e 100644
--- a/drivers/clk/mvebu/common.c
+++ b/drivers/clk/mvebu/common.c
@@ -89,8 +89,10 @@ void __init mvebu_coreclk_setup(struct device_node *np,
  * Clock Gating Control
  */
 
+DEFINE_SPINLOCK(ctrl_gating_lock);
+
 struct clk_gating_ctrl {
-	spinlock_t lock;
+	spinlock_t *lock;
 	struct clk **gates;
 	int num_gates;
 };
@@ -138,7 +140,8 @@ void __init mvebu_clk_gating_setup(struct device_node *np,
 	if (WARN_ON(!ctrl))
 		goto ctrl_out;
 
-	spin_lock_init(&ctrl->lock);
+	/* lock must already be initialized */
+	ctrl->lock = &ctrl_gating_lock;
 
 	/* Count, allocate, and register clock gates */
 	for (n = 0; desc[n].name;)
@@ -155,7 +158,7 @@ void __init mvebu_clk_gating_setup(struct device_node *np,
 			(desc[n].parent) ? desc[n].parent : default_parent;
 		ctrl->gates[n] = clk_register_gate(NULL, desc[n].name, parent,
 					desc[n].flags, base, desc[n].bit_idx,
-					0, &ctrl->lock);
+					0, ctrl->lock);
 		WARN_ON(IS_ERR(ctrl->gates[n]));
 	}
 
diff --git a/drivers/clk/mvebu/common.h b/drivers/clk/mvebu/common.h
index f968b4d..8cd28e4 100644
--- a/drivers/clk/mvebu/common.h
+++ b/drivers/clk/mvebu/common.h
@@ -17,6 +17,8 @@
 
 #include <linux/kernel.h>
 
+extern spinlock_t ctrl_gating_lock;
+
 struct device_node;
 
 struct coreclk_ratio {
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] clk: mvebu: powersave clock is a multiplexer
  2014-09-01 18:47 [PATCH 0/3] arm: kirkwood: model cpu clock mux and update cpufreq driver Mike Turquette
  2014-09-01 18:47 ` [PATCH 1/3] clk: mvebu: share locks between gate clocks Mike Turquette
@ 2014-09-01 18:47 ` Mike Turquette
  2014-09-01 18:47 ` [PATCH 3/3] cpufreq: kirkwood: use the powersave multiplexer Mike Turquette
  2 siblings, 0 replies; 6+ messages in thread
From: Mike Turquette @ 2014-09-01 18:47 UTC (permalink / raw)
  To: linux-kernel; +Cc: patches, Mike Turquette, Tomeu Vizoso

Kirkwood is unique among the mvebu SoCs for having a clock multiplexer
that feeds into the cpu. This multiplexer can select either the cpu pll
or the ddr clock as its input signal, allowing for a choice between
performance and power savings.

This patch introduces the code needed to register the clock multiplexer
on Kirkwood SoCs but does not include the clock data to actually
register the clock. That will be done in a follow-up patch which is
necessary to prevent breaking git bisect.

Cc: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Tested-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Mike Turquette <mturquette@linaro.org>
---
 drivers/clk/mvebu/kirkwood.c | 87 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)

diff --git a/drivers/clk/mvebu/kirkwood.c b/drivers/clk/mvebu/kirkwood.c
index ddb666a..f73a2fa 100644
--- a/drivers/clk/mvebu/kirkwood.c
+++ b/drivers/clk/mvebu/kirkwood.c
@@ -13,9 +13,11 @@
  */
 
 #include <linux/kernel.h>
+#include <linux/slab.h>
 #include <linux/clk-provider.h>
 #include <linux/io.h>
 #include <linux/of.h>
+#include <linux/of_address.h>
 #include "common.h"
 
 /*
@@ -225,6 +227,91 @@ static const struct clk_gating_soc_desc kirkwood_gating_desc[] __initconst = {
 	{ }
 };
 
+
+/*
+ * Clock Muxing Control
+ */
+
+struct clk_muxing_soc_desc {
+	const char *name;
+	const char **parents;
+	int num_parents;
+	int shift;
+	int width;
+	unsigned long flags;
+};
+
+struct clk_muxing_ctrl {
+	spinlock_t *lock;
+	struct clk **muxes;
+	int num_muxes;
+};
+
+#define to_clk_mux(_hw) container_of(_hw, struct clk_mux, hw)
+
+static struct clk *clk_muxing_get_src(
+	struct of_phandle_args *clkspec, void *data)
+{
+	struct clk_muxing_ctrl *ctrl = (struct clk_muxing_ctrl *)data;
+	int n;
+
+	if (clkspec->args_count < 1)
+		return ERR_PTR(-EINVAL);
+
+	for (n = 0; n < ctrl->num_muxes; n++) {
+		struct clk_mux *mux =
+			to_clk_mux(__clk_get_hw(ctrl->muxes[n]));
+		if (clkspec->args[0] == mux->shift)
+			return ctrl->muxes[n];
+	}
+	return ERR_PTR(-ENODEV);
+}
+
+static void __init kirkwood_clk_muxing_setup(struct device_node *np,
+				   const struct clk_muxing_soc_desc *desc)
+{
+	struct clk_muxing_ctrl *ctrl;
+	void __iomem *base;
+	int n;
+
+	base = of_iomap(np, 0);
+	if (WARN_ON(!base))
+		return;
+
+	ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL);
+	if (WARN_ON(!ctrl))
+		goto ctrl_out;
+
+	/* lock must already be initialized */
+	ctrl->lock = &ctrl_gating_lock;
+
+	/* Count, allocate, and register clock muxes */
+	for (n = 0; desc[n].name;)
+		n++;
+
+	ctrl->num_muxes = n;
+	ctrl->muxes = kcalloc(ctrl->num_muxes, sizeof(struct clk *),
+			GFP_KERNEL);
+	if (WARN_ON(!ctrl->muxes))
+		goto muxes_out;
+
+	for (n = 0; n < ctrl->num_muxes; n++) {
+		ctrl->muxes[n] = clk_register_mux(NULL, desc[n].name,
+				desc[n].parents, desc[n].num_parents,
+				desc[n].flags, base, desc[n].shift,
+				desc[n].width, desc[n].flags, ctrl->lock);
+		WARN_ON(IS_ERR(ctrl->muxes[n]));
+	}
+
+	of_clk_add_provider(np, clk_muxing_get_src, ctrl);
+
+	return;
+muxes_out:
+	kfree(ctrl);
+ctrl_out:
+	iounmap(base);
+}
+
 static void __init kirkwood_clk_init(struct device_node *np)
 {
 	struct device_node *cgnp =
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] cpufreq: kirkwood: use the powersave multiplexer
  2014-09-01 18:47 [PATCH 0/3] arm: kirkwood: model cpu clock mux and update cpufreq driver Mike Turquette
  2014-09-01 18:47 ` [PATCH 1/3] clk: mvebu: share locks between gate clocks Mike Turquette
  2014-09-01 18:47 ` [PATCH 2/3] clk: mvebu: powersave clock is a multiplexer Mike Turquette
@ 2014-09-01 18:47 ` Mike Turquette
  2014-09-02  4:49   ` Viresh Kumar
  2 siblings, 1 reply; 6+ messages in thread
From: Mike Turquette @ 2014-09-01 18:47 UTC (permalink / raw)
  To: linux-kernel
  Cc: patches, Mike Turquette, Tomeu Vizoso, Rafael J. Wysocki, Viresh Kumar

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(-)

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;
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 3/3] cpufreq: kirkwood: use the powersave multiplexer
  2014-09-01 18:47 ` [PATCH 3/3] cpufreq: kirkwood: use the powersave multiplexer Mike Turquette
@ 2014-09-02  4:49   ` Viresh Kumar
  2014-09-02 22:00     ` Mike Turquette
  0 siblings, 1 reply; 6+ messages in thread
From: Viresh Kumar @ 2014-09-02  4:49 UTC (permalink / raw)
  To: Mike Turquette
  Cc: Linux Kernel Mailing List, Patch Tracking, Tomeu Vizoso,
	Rafael J. Wysocki

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..

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 3/3] cpufreq: kirkwood: use the powersave multiplexer
  2014-09-02  4:49   ` Viresh Kumar
@ 2014-09-02 22:00     ` Mike Turquette
  0 siblings, 0 replies; 6+ messages in thread
From: Mike Turquette @ 2014-09-02 22:00 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Linux Kernel Mailing List, Patch Tracking, Tomeu Vizoso,
	Rafael J. Wysocki

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-09-02 22:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-01 18:47 [PATCH 0/3] arm: kirkwood: model cpu clock mux and update cpufreq driver Mike Turquette
2014-09-01 18:47 ` [PATCH 1/3] clk: mvebu: share locks between gate clocks Mike Turquette
2014-09-01 18:47 ` [PATCH 2/3] clk: mvebu: powersave clock is a multiplexer Mike Turquette
2014-09-01 18:47 ` [PATCH 3/3] cpufreq: kirkwood: use the powersave multiplexer Mike Turquette
2014-09-02  4:49   ` Viresh Kumar
2014-09-02 22:00     ` Mike Turquette

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).