Skip to contentSkip to conversation

clk: versatile: respect parent rate in ICST clock

PATCH New Linus Walleij 2 participants 4 messages Jan 20, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 5/5 clk: versatile: respect parent rate in ICST clock

If the ICST clock has a parent, respect the rate of the parent when calculating the clock frequency. Alter const arguments as this involves modifying the ICST parameter struct, and do not define the reference clock on the Integrator as we have the reference clock from the device tree. Keep it everywhere else.

---
Hi Mike, looking for an ACK for this one as well.

---
 drivers/clk/versatile/clk-icst.c       | 10 +++++++---
 drivers/clk/versatile/clk-icst.h       |  2 +-
 drivers/clk/versatile/clk-impd1.c      |  4 ++--
 drivers/clk/versatile/clk-integrator.c |  3 +--
 drivers/clk/versatile/clk-realview.c   |  2 +-
 5 files changed, 12 insertions(+), 9 deletions(-)
drivers/clk/versatile/clk-icst.c +7 -3
index c98adbe62733..4bbfbf49b009 100644
@@ -33,7 +33,7 @@ struct clk_icst {
 	struct clk_hw hw;
 	void __iomem *vcoreg;
 	void __iomem *lockreg;
-	const struct icst_params *params;
+	struct icst_params *params;
 	unsigned long rate;
 };
 
@@ -84,6 +84,8 @@ static unsigned long icst_recalc_rate(struct clk_hw *hw,
 	struct clk_icst *icst = to_icst(hw);
 	struct icst_vco vco;
 
+	if (parent_rate)
+		icst->params->ref = parent_rate;
 	vco = vco_get(icst->vcoreg);
 	icst->rate = icst_hz(icst->params, vco);
 	return icst->rate;
@@ -105,6 +107,8 @@ static int icst_set_rate(struct clk_hw *hw, unsigned long rate,
 	struct clk_icst *icst = to_icst(hw);
 	struct icst_vco vco;
 
+	if (parent_rate)
+		icst->params->ref = parent_rate;
 	vco = icst_hz_to_vco(icst->params, rate);
 	icst->rate = icst_hz(icst->params, vco);
 	vco_set(icst->lockreg, icst->vcoreg, vco);
@@ -135,8 +139,8 @@ struct clk *icst_clk_register(struct device *dev,
 	init.name = name;
 	init.ops = &icst_ops;
 	init.flags = CLK_IS_ROOT;
-	init.parent_names = NULL;
-	init.num_parents = 0;
+	init.parent_names = (parent_name ? &parent_name : NULL);
+	init.num_parents = (parent_name ? 1 : 0);
 	icst->hw.init = &init;
 	icst->params = desc->params;
 	icst->vcoreg = base + desc->vco_offset;
drivers/clk/versatile/clk-icst.h +1 -1
index 04e6f0aef588..e72b1c15d084 100644
@@ -8,7 +8,7 @@
  *	memory base
  */
 struct clk_icst_desc {
-	const struct icst_params *params;
+	struct icst_params *params;
 	u32 vco_offset;
 	u32 lock_offset;
 };
drivers/clk/versatile/clk-impd1.c +2 -2
index 6d8b8e1a080a..a3edc0463517 100644
@@ -39,7 +39,7 @@ static struct impd1_clk impd1_clks[4];
  * There are two VCO's on the IM-PD1
  */
 
-static const struct icst_params impd1_vco1_params = {
+static struct icst_params impd1_vco1_params = {
 	.ref		= 24000000,	/* 24 MHz */
 	.vco_max	= ICST525_VCO_MAX_3V,
 	.vco_min	= ICST525_VCO_MIN,
@@ -57,7 +57,7 @@ static const struct clk_icst_desc impd1_icst1_desc = {
 	.lock_offset = IMPD1_LOCK,
 };
 
-static const struct icst_params impd1_vco2_params = {
+static struct icst_params impd1_vco2_params = {
 	.ref		= 24000000,	/* 24 MHz */
 	.vco_max	= ICST525_VCO_MAX_3V,
 	.vco_min	= ICST525_VCO_MIN,
drivers/clk/versatile/clk-integrator.c +1 -2
index 5d36a719fefb..b1f46d5154ea 100644
@@ -20,8 +20,7 @@
 /* Base offset for the core module */
 static void __iomem *cm_base;
 
-static const struct icst_params cp_auxosc_params = {
-	.ref		= 24000000,
+static struct icst_params cp_auxosc_params = {
 	.vco_max	= ICST525_VCO_MAX_5V,
 	.vco_min	= ICST525_VCO_MIN,
 	.vd_min 	= 8,
drivers/clk/versatile/clk-realview.c +1 -1
index c8b523117fb7..a1491590e028 100644
@@ -21,7 +21,7 @@
  * Implementation of the ARM RealView clock trees.
  */
 
-static const struct icst_params realview_oscvco_params = {
+static struct icst_params realview_oscvco_params = {
 	.ref		= 24000000,
 	.vco_max	= ICST307_VCO_MAX,
 	.vco_min	= ICST307_VCO_MIN,
Signature · 1 line
1.8.4.2
#1 lore raw

PATCH 5/5 clk: versatile: respect parent rate in ICST clock

Quoted 6 lines · Linus Walleij

If the ICST clock has a parent, respect the rate of the parent when calculating the clock frequency. Alter const arguments as this involves modifying the ICST parameter struct, and do not define the reference clock on the Integrator as we have the reference clock from the device tree. Keep it everywhere else.

This is not what I'd call a good idea.

Quoted 6 lines
drivers/clk/versatile/clk-icst.c +2 -0
@@ -84,6 +84,8 @@ static unsigned long icst_recalc_rate(struct clk_hw *hw,
 	struct clk_icst *icst = to_icst(hw);
 	struct icst_vco vco;
 
+	if (parent_rate)
+		icst->params->ref = parent_rate;

...

Quoted 14 lines
drivers/clk/versatile/clk-impd1.c +1 -1
index 6d8b8e1a080a..a3edc0463517 100644
@@ -39,7 +39,7 @@ static struct impd1_clk impd1_clks[4];
  * There are two VCO's on the IM-PD1
  */
 
-static const struct icst_params impd1_vco1_params = {
+static struct icst_params impd1_vco1_params = {
 	.ref		= 24000000,	/* 24 MHz */
 	.vco_max	= ICST525_VCO_MAX_3V,
 	.vco_min	= ICST525_VCO_MIN,

drivers/clk/versatile/clk-impd1.c static const struct clk_icst_desc impd1_icst1_desc = { · line 63

Quoted 8 lines
drivers/clk/versatile/clk-impd1.c +1 -1
@@ -57,7 +57,7 @@ static const struct clk_icst_desc impd1_icst1_desc = {
 	.lock_offset = IMPD1_LOCK,
 };
 
-static const struct icst_params impd1_vco2_params = {
+static struct icst_params impd1_vco2_params = {
 	.ref		= 24000000,	/* 24 MHz */
 	.vco_max	= ICST525_VCO_MAX_3V,
 	.vco_min	= ICST525_VCO_MIN,

Right, so we end up writing directly into these _shared_ _statically_ _allocated_ structures.

drivers/clk/versatile/clk-realview.c line 25

Quoted 11 lines
drivers/clk/versatile/clk-realview.c +1 -1
index c8b523117fb7..a1491590e028 100644
@@ -21,7 +21,7 @@
  * Implementation of the ARM RealView clock trees.
  */
 
-static const struct icst_params realview_oscvco_params = {
+static struct icst_params realview_oscvco_params = {
 	.ref		= 24000000,

And this one is shared by two different VCOs. Thankfully, the only reason this isn't a problem is because they're both sourced from a 24MHz clock.

Signature · 3 lines
FTTC broadband for 0.8mile line: 5.8Mbps down 500kbps up.  Estimation
in database were 13.1 to 19Mbit for a good line, about 7.5+ for a bad.
Estimate before purchase was "up to 13.2Mbit".
#2 lore raw

PATCH 5/5 clk: versatile: respect parent rate in ICST clock

Quoted 8 lines · Russell King - ARM Linux

drivers/clk/versatile/clk-impd1.c static const struct clk_icst_desc impd1_icst1_desc = { · line 63

Quoted 5 lines
drivers/clk/versatile/clk-impd1.c +1 -1
-static const struct icst_params impd1_vco2_params = {
+static struct icst_params impd1_vco2_params = {
      .ref            = 24000000,     /* 24 MHz */
      .vco_max        = ICST525_VCO_MAX_3V,
      .vco_min        = ICST525_VCO_MIN,

Right, so we end up writing directly into these _shared_ _statically_ _allocated_ structures.

Argh yeah that's right.

I'll think of something better, like allocating the params on-the-fly for DT instead.

Yours,
Linus Walleij

#3 lore raw

PATCH 5/5 clk: versatile: respect parent rate in ICST clock

Quoted 12 lines · Linus Walleij
Quoted 8 lines · Russell King - ARM Linux

drivers/clk/versatile/clk-impd1.c static const struct clk_icst_desc impd1_icst1_desc = { · line 63

Quoted 5 lines
drivers/clk/versatile/clk-impd1.c +1 -1
-static const struct icst_params impd1_vco2_params = {
+static struct icst_params impd1_vco2_params = {
      .ref            = 24000000,     /* 24 MHz */
      .vco_max        = ICST525_VCO_MAX_3V,
      .vco_min        = ICST525_VCO_MIN,

Right, so we end up writing directly into these _shared_ _statically_ _allocated_ structures.

Quoted 4 lines

Argh yeah that's right.

I'll think of something better, like allocating the params on-the-fly for DT instead.

That's actually why they're const - they're const because they are not supposed to be written to...

Signature · 3 lines
FTTC broadband for 0.8mile line: 5.8Mbps down 500kbps up.  Estimation
in database were 13.1 to 19Mbit for a good line, about 7.5+ for a bad.
Estimate before purchase was "up to 13.2Mbit".