Skip to contentSkip to conversation

Add Core Divider clock support for Armada 370/XP

PATCH Superseded Ezequiel Garcia 5 participants 19 messages Sep 25, 2013 – Sep 26, 2013

Subsystems (3)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover Add Core Divider clock support for Armada 370/XP

This patchset adds support for a set of clocks available in Armada 370/XP known as "Core Divider" clocks.

These are a set of gatable clocks, derived from a fixed PLL at a configurable ratio. Although this patchset adds support for the more general case, we only support one of the clocks, namely the NAND ECC clock.

With this infrastructure in place, the addition of the rest of the clocks would be fairly easy.

In addition, the NAND clock is added as a fixed-ratio from the NAND ECC clock, to model accurately the SoC clock tree.

A pictorical representation of the clock tree would be:

    PLL
    |
    |
    ---------------------
    |			|
    |			|
    NAND ECC clock	...
    |
    |
    NAND clock

This patchset is based on v3.12-rc2. Any opinions are highly appreciated.

Thanks!

Ezequiel Garcia (5):
clk: mvebu: Add core-divider clock
ARM: mvebu: Add Core Divider clock device-tree binding
ARM: mvebu: Add a 2 GHz fixed-clock Armada 370/XP
ARM: mvebu: Add the core-divider clock to Armada 370/XP
ARM: mvebu: Add NAND clock to Armada 370/XP

 .../bindings/clock/mvebu-corediv-clock.txt         |  19 ++
 arch/arm/boot/dts/armada-370-xp.dtsi               |  25 +++
 drivers/clk/mvebu/Kconfig                          |   5 +
 drivers/clk/mvebu/Makefile                         |   1 +
 drivers/clk/mvebu/clk-corediv.c                    | 209 +++++++++++++++++++++
 5 files changed, 259 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/mvebu-corediv-clock.txt
 create mode 100644 drivers/clk/mvebu/clk-corediv.c
Signature · 1 line
1.8.1.5
#1 lore raw

PATCH 1/5 clk: mvebu: Add core-divider clock

This commit introduces a new group of clocks present in Armada 370/XP SoCs (called "Core Divider" clocks) and add a provider for them. The only clock supported for now is the NAND ECC clock, but the infrastructure to add the rest is already set.

---
 drivers/clk/mvebu/Kconfig       |   5 +
 drivers/clk/mvebu/Makefile      |   1 +
 drivers/clk/mvebu/clk-corediv.c | 209 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 215 insertions(+)
 create mode 100644 drivers/clk/mvebu/clk-corediv.c
drivers/clk/mvebu/Kconfig +5 -0
index 0b0f3e7..c339b82 100644
@@ -4,15 +4,20 @@ config MVEBU_CLK_COMMON
 config MVEBU_CLK_CPU
 	bool
 
+config MVEBU_CLK_COREDIV
+	bool
+
 config ARMADA_370_CLK
 	bool
 	select MVEBU_CLK_COMMON
 	select MVEBU_CLK_CPU
+	select MVEBU_CLK_COREDIV
 
 config ARMADA_XP_CLK
 	bool
 	select MVEBU_CLK_COMMON
 	select MVEBU_CLK_CPU
+	select MVEBU_CLK_COREDIV
 
 config DOVE_CLK
 	bool
drivers/clk/mvebu/Makefile +1 -0
index 1c7e70c..21bbfb4 100644
@@ -1,5 +1,6 @@
 obj-$(CONFIG_MVEBU_CLK_COMMON)	+= common.o
 obj-$(CONFIG_MVEBU_CLK_CPU) 	+= clk-cpu.o
+obj-$(CONFIG_MVEBU_CLK_COREDIV)	+= clk-corediv.o
 
 obj-$(CONFIG_ARMADA_370_CLK)	+= armada-370.o
 obj-$(CONFIG_ARMADA_XP_CLK)	+= armada-xp.o
drivers/clk/mvebu/clk-corediv.c new file +209 -0

209 lines not on this page · raw message

Signature · 1 line
1.8.1.5
#2 lore raw

PATCH 2/5 ARM: mvebu: Add Core Divider clock device-tree binding

In reply to Ezequiel Garcia

The Armada 370/XP SoCs have a Core Divider clock providing several clocks. For now, only the NAND clock is supported.

Cc devicetree at vger.kernel.org
---
 .../devicetree/bindings/clock/mvebu-corediv-clock.txt | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/mvebu-corediv-clock.txt
Documentation/devicetree/bindings/clock/mvebu-corediv-clock.txt new file +19 -0
new file mode 100644
index 0000000..ea60f4d
@@ -0,0 +1,19 @@
+* Core Divider Clock bindings for Marvell MVEBU SoCs
+
+The following is a list of provided IDs and clock names on Armada 370/XP:
+ 0 = nand_ecc   (NAND ECC clock)
+
+Required properties:
+- compatible : must be "marvell,armada-370-corediv-clock"
+- reg : must be the register address of Core Divider control register
+- #clock-cells : from common clock binding; shall be set to 1
+- #clocks : must be set to the parent's phandle
+
+Example:
+
+corediv_clk: corediv-clocks at 18740 {
+	compatible = "marvell,armada-370-corediv-clock";
+	reg = <0x18740 0x8>;
+	#clock-cells = <1>;
+	clocks = <&pll>;
+};
Signature · 1 line
1.8.1.5
#3 lore raw

PATCH 3/5 ARM: mvebu: Add a 2 GHz fixed-clock Armada 370/XP

In reply to Ezequiel Garcia

Armada 370/XP SoCs have a 2 GHz fixed PLL that is used to feed other clocks. This commit adds a DT representation of this clock through a fixed-clock compatible node.

---
 arch/arm/boot/dts/armada-370-xp.dtsi | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/arm/boot/dts/armada-370-xp.dtsi +9 -0
index 1de2dae..924c721 100644
@@ -252,4 +252,13 @@
 
 		};
 	};
+
+	clocks {
+		/* 2 GHz fixed main PLL */
+		mainpll: mainpll {
+			compatible = "fixed-clock";
+			#clock-cells = <0>;
+			clock-frequency = <2000000000>;
+		};
+	};
  };
Signature · 1 line
1.8.1.5
#4 lore raw

PATCH 4/5 ARM: mvebu: Add the core-divider clock to Armada 370/XP

In reply to Ezequiel Garcia

The Armada 370/XP SoC has a clock provider called "Core Divider", that is derived from a fixed 2 GHz PLL clock.

---
 arch/arm/boot/dts/armada-370-xp.dtsi | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/arm/boot/dts/armada-370-xp.dtsi +8 -0
index 924c721..d0f81cc 100644
@@ -137,6 +137,14 @@
 				status = "disabled";
 			};
 
+			coredivclk: corediv-clock at 18740 {
+				compatible = "marvell,armada-370-corediv-clock";
+				reg = <0x18740 0x8>;
+				#clock-cells = <1>;
+				clocks = <&mainpll>;
+				clock-output-names = "nandecc";
+			};
+
 			timer at 20300 {
 				reg = <0x20300 0x30>, <0x21040 0x30>;
 				interrupts = <37>, <38>, <39>, <40>, <5>, <6>;
Signature · 1 line
1.8.1.5
#5 lore raw

PATCH 5/5 ARM: mvebu: Add NAND clock to Armada 370/XP

In reply to Ezequiel Garcia

Add the NAND clock available at Armada 370/XP SoC, which is a fixed-factor derived from the NAND ECC clock. This is the clock feeding the NAND controller.

---
 arch/arm/boot/dts/armada-370-xp.dtsi | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/arm/boot/dts/armada-370-xp.dtsi +8 -0
index d0f81cc..8f14092 100644
@@ -268,5 +268,13 @@
 			#clock-cells = <0>;
 			clock-frequency = <2000000000>;
 		};
+
+		ndclk: nand_clock {
+			compatible = "fixed-factor-clock";
+			#clock-cells = <0>;
+			clocks = <&coredivclk 0>;
+	                clock-div = <2>;
+	                clock-mult = <1>;
+		};
 	};
  };
Signature · 1 line
1.8.1.5
#6 lore raw

cover Add Core Divider clock support for Armada 370/XP

In reply to Ezequiel Garcia

(Ccing forgotten mvebu maintainers)

Quoted 49 lines · Ezequiel Garcia

This patchset adds support for a set of clocks available in Armada 370/XP known as "Core Divider" clocks.

These are a set of gatable clocks, derived from a fixed PLL at a configurable ratio. Although this patchset adds support for the more general case, we only support one of the clocks, namely the NAND ECC clock.

With this infrastructure in place, the addition of the rest of the clocks would be fairly easy.

In addition, the NAND clock is added as a fixed-ratio from the NAND ECC clock, to model accurately the SoC clock tree.

A pictorical representation of the clock tree would be:

    PLL
    |
    |
    ---------------------
    |			|
    |			|
    NAND ECC clock	...
    |
    |
    NAND clock

This patchset is based on v3.12-rc2. Any opinions are highly appreciated.

Thanks!

Ezequiel Garcia (5):
clk: mvebu: Add core-divider clock
ARM: mvebu: Add Core Divider clock device-tree binding
ARM: mvebu: Add a 2 GHz fixed-clock Armada 370/XP
ARM: mvebu: Add the core-divider clock to Armada 370/XP
ARM: mvebu: Add NAND clock to Armada 370/XP

 .../bindings/clock/mvebu-corediv-clock.txt         |  19 ++
 arch/arm/boot/dts/armada-370-xp.dtsi               |  25 +++
 drivers/clk/mvebu/Kconfig                          |   5 +
 drivers/clk/mvebu/Makefile                         |   1 +
 drivers/clk/mvebu/clk-corediv.c                    | 209 +++++++++++++++++++++
 5 files changed, 259 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/mvebu-corediv-clock.txt
 create mode 100644 drivers/clk/mvebu/clk-corediv.c
Signature · 1 line
1.8.1.5
Signature · 3 lines
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com
#7 lore raw

cover Add Core Divider clock support for Armada 370/XP

Hi Ezequiel,

Quoted 31 lines · Ezequiel Garcia

(Ccing forgotten mvebu maintainers)

Quoted 28 lines · Ezequiel Garcia

This patchset adds support for a set of clocks available in Armada 370/XP known as "Core Divider" clocks.

These are a set of gatable clocks, derived from a fixed PLL at a configurable ratio. Although this patchset adds support for the more general case, we only support one of the clocks, namely the NAND ECC clock.

With this infrastructure in place, the addition of the rest of the clocks would be fairly easy.

In addition, the NAND clock is added as a fixed-ratio from the NAND ECC clock, to model accurately the SoC clock tree.

A pictorical representation of the clock tree would be:

    PLL
    |
    |
    ---------------------
    |			|
    |			|
    NAND ECC clock	...
    |
    |
    NAND clock

This patchset is based on v3.12-rc2. Any opinions are highly appreciated.

For the whole series you can add my

I just wonder if you were enable to test the enable and disable for the clock, because the datasheet is a little fuzzy about it.

Thanks,

Gregory

Quoted 22 lines
Quoted 21 lines

Thanks!

Ezequiel Garcia (5):
clk: mvebu: Add core-divider clock
ARM: mvebu: Add Core Divider clock device-tree binding
ARM: mvebu: Add a 2 GHz fixed-clock Armada 370/XP
ARM: mvebu: Add the core-divider clock to Armada 370/XP
ARM: mvebu: Add NAND clock to Armada 370/XP

 .../bindings/clock/mvebu-corediv-clock.txt         |  19 ++
 arch/arm/boot/dts/armada-370-xp.dtsi               |  25 +++
 drivers/clk/mvebu/Kconfig                          |   5 +
 drivers/clk/mvebu/Makefile                         |   1 +
 drivers/clk/mvebu/clk-corediv.c                    | 209 +++++++++++++++++++++
 5 files changed, 259 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/mvebu-corediv-clock.txt
 create mode 100644 drivers/clk/mvebu/clk-corediv.c
Signature · 1 line
1.8.1.5
Signature · 4 lines
Gregory Clement, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com
#8 lore raw

cover Add Core Divider clock support for Armada 370/XP

Quoted 32 lines · Gregory CLEMENT

Hi Ezequiel,

Quoted 29 lines · Ezequiel Garcia

(Ccing forgotten mvebu maintainers)

Quoted 26 lines · Ezequiel Garcia

This patchset adds support for a set of clocks available in Armada 370/XP known as "Core Divider" clocks.

These are a set of gatable clocks, derived from a fixed PLL at a configurable ratio. Although this patchset adds support for the more general case, we only support one of the clocks, namely the NAND ECC clock.

With this infrastructure in place, the addition of the rest of the clocks would be fairly easy.

In addition, the NAND clock is added as a fixed-ratio from the NAND ECC clock, to model accurately the SoC clock tree.

A pictorical representation of the clock tree would be:

    PLL
    |
    |
    ---------------------
    |			|
    |			|
    NAND ECC clock	...
    |
    |
    NAND clock
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

This patchset is based on v3.12-rc2. Any opinions are highly appreciated.

For the whole series you can add my

Great! However, I found some issues on this patchset :-(, see below.

Quoted 3 lines

I just wonder if you were enable to test the enable and disable for the clock, because the datasheet is a little fuzzy about it.

Enabling and disabling the clock seems to work OK. I must admit I did just a simple test:

* If NAND DT node does not consume the correct clock, the controller stops working just as soon as the core clock framework disables the unused clocks.
* If you make the NAND DT node consumer of the "ndclk", the controller works fine.

On the other side, I found this approach is incorrect! (silly me!).

Declaring the NAND clock as a fixed-ratio from the NAND ECC clock, and making the NAND DT consume the NAND clock removes the possibility of setting the clock rate from the NAND driver.

This happens because the controller's clock is declared as fixed, whereas the clock that can be adjusted is the NAND ECC (the parent of NAND clock).

I've been thinking on how to work this out in a clean way, but I'm not sure which way is cleaner/better. These are my options so far, feel free to propose any other:

1. The NAND DT node consumes the two clocks: NAND ECC and NAND clock. It uses the former to set the rate, and the latter to read the rate to calculate the timings.

This means we have to modify the NAND driver (but not too much).

2. We register the NAND clock in the clk-corediv driver, as a child of NAND ECC, and implement some set_rate operation to act on NAND ECC. The NAND DT node can then consume this clock.

This has the advantage that it's transparent to the NAND driver (which currently consumes one clock).

3. We hack the NAND driver to consume the NAND ECC, but use the rate as the half of it, and forget about the halved-rate NAND clock. This seems certainly hacky.

Thoughts?

Signature · 3 lines
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com
#9 lore raw

cover Add Core Divider clock support for Armada 370/XP

Dear Ezequiel Garcia,

Quoted 3 lines · Ezequiel Garcia

3. We hack the NAND driver to consume the NAND ECC, but use the rate as the half of it, and forget about the halved-rate NAND clock. This seems certainly hacky.

Is this really hacky? Since we can't change the rate of one without changing the other, or gating the one without the other, we can also see those two clocks as being an internal business of the NAND hardware block. So instead of seeing things as:

                        -------------
 NAND ECC clk    ---->  |           | 
     ||                 |  NAND HW  |
     ||                 |   block   |
     \/                 |           |
 NAND clk        ---->  |           |
                        -------------

You can see things as follows:

-------------
| |
| NAND HW |

 NAND clk        ---->  |   block   |
                        |           |
                        |           |
                        -------------

and the ECC clock is actually some internal business of the NAND hw block, and therefore handled internally by the NAND driver, as your option (3) suggests.

Since the amount of details that we have about the exact hardware architecture are pretty scarce, I believe this is probably the easiest solution.

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#10 lore raw

cover Add Core Divider clock support for Armada 370/XP

Quoted 31 lines · Thomas Petazzoni

Dear Ezequiel Garcia,

Quoted 3 lines · Ezequiel Garcia

3. We hack the NAND driver to consume the NAND ECC, but use the rate as the half of it, and forget about the halved-rate NAND clock. This seems certainly hacky.

Is this really hacky? Since we can't change the rate of one without changing the other, or gating the one without the other, we can also see those two clocks as being an internal business of the NAND hardware block. So instead of seeing things as:

                        -------------
 NAND ECC clk    ---->  |           | 
     ||                 |  NAND HW  |
     ||                 |   block   |
     \/                 |           |
 NAND clk        ---->  |           |
                        -------------

You can see things as follows:

-------------
| |
| NAND HW |

 NAND clk        ---->  |   block   |
                        |           |
                        |           |
                        -------------
Quoted 8 lines

and the ECC clock is actually some internal business of the NAND hw block, and therefore handled internally by the NAND driver, as your option (3) suggests.

Since the amount of details that we have about the exact hardware architecture are pretty scarce, I believe this is probably the easiest solution.

Hm... could be. Considering the lack of hardware details (as you point out) maybe this is indeed the best option.

And it has the cool advantage of simplfying the clock tree, which is unnecessarily complex with the NAND ECC clock -> NAND clock layout.

On the other side, Emilio has just pointed out (in private) that there's a flag "CLK_SET_RATE_PARENT" that is meant for these cases.

Anyway, I feel inclined to your suggestion and just forget about the NAND ECC clock for good, which is only confusing.

Thanks,

Signature · 3 lines
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com
#11 lore raw

cover Add Core Divider clock support for Armada 370/XP

Dear Ezequiel Garcia,

Quoted 11 lines · Ezequiel Garcia

Hm... could be. Considering the lack of hardware details (as you point out) maybe this is indeed the best option.

And it has the cool advantage of simplfying the clock tree, which is unnecessarily complex with the NAND ECC clock -> NAND clock layout.

On the other side, Emilio has just pointed out (in private) that there's a flag "CLK_SET_RATE_PARENT" that is meant for these cases.

Anyway, I feel inclined to your suggestion and just forget about the NAND ECC clock for good, which is only confusing.

Yes, I also believe it's the easiest solution.

Thomas

Signature · 3 lines
Thomas Petazzoni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
maintainer
#12 lore raw

PATCH 1/5 clk: mvebu: Add core-divider clock

In reply to Ezequiel Garcia

Hi Ezequiel

Review

Quoted 11 lines
(quoted diff) +11 -0
+static int clk_corediv_enable(struct clk_hw *hwclk)
+{
+	struct clk_corediv *corediv = to_corediv_clk(hwclk);
+	struct clk_corediv_desc *desc = &corediv->desc;
+	u32 reg;
+
+	reg = readl(corediv->reg);
+	reg |= (BIT(desc->fieldbit) << CORE_CLOCK_DIVIDER_ENABLE_OFFSET);
+	writel(reg, corediv->reg);
+	return 0;
+}

Shouldn't there be spinlocks around these register accesses? At least the core gate clk driver has a spinlock.

Quoted 8 lines
(quoted diff) +8 -0
+static long clk_corediv_round_rate(struct clk_hw *hwclk, unsigned long rate,
+	     				          unsigned long *parent_rate)
+{
+	/* Valid ratio are 1:4, 1:5, 1:6 and 1:8 */
+	u32 div;
+
+	div = *parent_rate / rate;
+	if (div <= 4)

Review

Quoted 10 lines
(quoted diff) +10 -0
+	   div = 4;
+	   else if (div <= 5)
+	   	div = 5;
+		else if (div <= 6)
+		     div = 6;
+		     else
+			div = 8;
+
+	return *parent_rate / div;
+}

This looks odd. Is not the following clearer?

	div = *parent_rate / rate;
	if (div < 5)
	   div = 4;
	   else if (div > 6)
		div = 8;

The CodingStyle might require some {} here?

+ /*
+ * Wait for clocks to settle down, and then clear all the
+ * ratios request and the reload request.

+      */
+      udelay(1000);
+      reg &= ~(CORE_CLOCK_DIVIDER_RATIO_MASK | CORE_CLOCK_DIVIDER_RATIO_RELOAD);
+      writel(reg, corediv->reg);
+      udelay(1000);

Documentation/timers/timers-howto.txt says:

SLEEPING FOR ~USECS OR SMALL MSECS ( 10us - 20ms):
* Use usleep_range

Andrew

#13 lore raw

PATCH 1/5 clk: mvebu: Add core-divider clock

Quoted 17 lines · Andrew Lunn

Hi Ezequiel

Review

Quoted 11 lines
(quoted diff) +11 -0
+static int clk_corediv_enable(struct clk_hw *hwclk)
+{
+	struct clk_corediv *corediv = to_corediv_clk(hwclk);
+	struct clk_corediv_desc *desc = &corediv->desc;
+	u32 reg;
+
+	reg = readl(corediv->reg);
+	reg |= (BIT(desc->fieldbit) << CORE_CLOCK_DIVIDER_ENABLE_OFFSET);
+	writel(reg, corediv->reg);
+	return 0;
+}

Shouldn't there be spinlocks around these register accesses? At least the core gate clk driver has a spinlock.

Indeed.

Quoted 21 lines
Quoted 8 lines
(quoted diff) +8 -0
+static long clk_corediv_round_rate(struct clk_hw *hwclk, unsigned long rate,
+	     				          unsigned long *parent_rate)
+{
+	/* Valid ratio are 1:4, 1:5, 1:6 and 1:8 */
+	u32 div;
+
+	div = *parent_rate / rate;
+	if (div <= 4)

Review

Quoted 10 lines
(quoted diff) +10 -0
+	   div = 4;
+	   else if (div <= 5)
+	   	div = 5;
+		else if (div <= 6)
+		     div = 6;
+		     else
+			div = 8;
+
+	return *parent_rate / div;
+}

This looks odd. Is not the following clearer?

Quoted 8 lines
	div = *parent_rate / rate;
	if (div < 5)
	   div = 4;
	   else if (div > 6)
		div = 8;

The CodingStyle might require some {} here?

Mmmm... no, it's not at all clearer to me.
IMHO, the original construction explicitly show the possible ratios:

	/* If it's smaller than or equal to 4, set to 4 */
	if (div <= 4)
		div = 4;

	/* Otherwise, if it's between 4 and 5, set to 5 */
	else if (div <= 5)
	 	div = 5;

	/* Otherwise, if it's between 5 and 6, set to 6 */
	else if (div <= 6)
		div = 6;

	/* Otherwise, if it's bigger than 6, set to 8 */
	else
		div = 8;

(And I don't think we need any braces).

Is this not clear?

Quoted 10 lines
(quoted diff) +8 -0
+   /*
+    * Wait for clocks to settle down, and then clear all the
+     * ratios request and the reload request.
+      */
+      udelay(1000);
+      reg &= ~(CORE_CLOCK_DIVIDER_RATIO_MASK | CORE_CLOCK_DIVIDER_RATIO_RELOAD);
+      writel(reg, corediv->reg);
+      udelay(1000);
Quoted 5 lines

Documentation/timers/timers-howto.txt says:

SLEEPING FOR ~USECS OR SMALL MSECS ( 10us - 20ms):
* Use usleep_range

Right, forgot about that as well...

Thanks for the feedback!

Signature · 3 lines
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com
maintainer
#14 lore raw

PATCH 1/5 clk: mvebu: Add core-divider clock

Quoted 28 lines
Quoted 18 lines
Quoted 5 lines
(quoted diff) +5 -0
+	/* Valid ratio are 1:4, 1:5, 1:6 and 1:8 */
+	u32 div;
+
+	div = *parent_rate / rate;
+	if (div <= 4)

Review

Quoted 10 lines
(quoted diff) +10 -0
+	   div = 4;
+	   else if (div <= 5)
+	   	div = 5;
+		else if (div <= 6)
+		     div = 6;
+		     else
+			div = 8;
+
+	return *parent_rate / div;
+}

This looks odd. Is not the following clearer?

Quoted 6 lines
	div = *parent_rate / rate;
	if (div < 5)
	   div = 4;
	   else if (div > 6)
		div = 8;

Mmmm... no, it's not at all clearer to me.
IMHO, the original construction explicitly show the possible ratios:

Quoted 7 lines
	/* If it's smaller than or equal to 4, set to 4 */
	if (div <= 4)
		div = 4;

	/* Otherwise, if it's between 4 and 5, set to 5 */
	else if (div <= 5)
	 	div = 5;

If div was a float or double, i would probably agree. But its a u32. It cannot be between 4 and 5. It must be 5. So it becomes

if (div <= 4)

 		div = 4;
        else if (div == 5)
	        div = 5;
        else if (div == 6)
                div = 6
        else 
	    div = 8

Those two middle statements look odd to me...

Andrew

#15 lore raw

PATCH 1/5 clk: mvebu: Add core-divider clock

In reply to Ezequiel Garcia
Quoted 54 lines · Ezequiel Garcia
Quoted 17 lines · Andrew Lunn

Hi Ezequiel

Review

Quoted 11 lines
(quoted diff) +11 -0
+static int clk_corediv_enable(struct clk_hw *hwclk)
+{
+	struct clk_corediv *corediv = to_corediv_clk(hwclk);
+	struct clk_corediv_desc *desc =&corediv->desc;
+	u32 reg;
+
+	reg = readl(corediv->reg);
+	reg |= (BIT(desc->fieldbit)<<  CORE_CLOCK_DIVIDER_ENABLE_OFFSET);
+	writel(reg, corediv->reg);
+	return 0;
+}

Shouldn't there be spinlocks around these register accesses? At least the core gate clk driver has a spinlock.

Indeed.

Quoted 21 lines
Quoted 8 lines
(quoted diff) +8 -0
+static long clk_corediv_round_rate(struct clk_hw *hwclk, unsigned long rate,
+	     				          unsigned long *parent_rate)
+{
+	/* Valid ratio are 1:4, 1:5, 1:6 and 1:8 */
+	u32 div;
+
+	div = *parent_rate / rate;
+	if (div<= 4)

Review

Quoted 10 lines
(quoted diff) +10 -0
+	   div = 4;
+	   else if (div<= 5)
+	   	div = 5;
+		else if (div<= 6)
+		     div = 6;
+		     else
+			div = 8;
+
+	return *parent_rate / div;
+}

This looks odd. Is not the following clearer?

Quoted 8 lines
	div = *parent_rate / rate;
	if (div<  5)
	   div = 4;
	   else if (div>  6)
		div = 8;

The CodingStyle might require some {} here?

Mmmm... no, it's not at all clearer to me.
IMHO, the original construction explicitly show the possible ratios:

Quoted 7 lines
	/* If it's smaller than or equal to 4, set to 4 */
	if (div<= 4)
		div = 4;

	/* Otherwise, if it's between 4 and 5, set to 5 */
	else if (div<= 5)
	 	div = 5;

how can an integer be between 4 and 5? surely it is 4 or 5.

Quoted 3 lines
	/* Otherwise, if it's between 5 and 6, set to 6 */
	else if (div<= 6)
		div = 6;

see above.

Quoted 27 lines
	/* Otherwise, if it's bigger than 6, set to 8 */
	else
		div = 8;

(And I don't think we need any braces).

Is this not clear?

Quoted 10 lines
(quoted diff) +8 -0
+   /*
+    * Wait for clocks to settle down, and then clear all the
+     * ratios request and the reload request.
+      */
+      udelay(1000);
+      reg&= ~(CORE_CLOCK_DIVIDER_RATIO_MASK | CORE_CLOCK_DIVIDER_RATIO_RELOAD);
+      writel(reg, corediv->reg);
+      udelay(1000);
Quoted 5 lines

Documentation/timers/timers-howto.txt says:

SLEEPING FOR ~USECS OR SMALL MSECS ( 10us - 20ms):
* Use usleep_range

Right, forgot about that as well...

Thanks for the feedback!

Signature · 2 lines
Ben Dooks				http://www.codethink.co.uk/
Senior Engineer				Codethink - Providing Genius
#16 lore raw

PATCH 1/5 clk: mvebu: Add core-divider clock

In reply to Andrew Lunn

Hey Andrew,

Quoted 11 lines · Andrew Lunn
(quoted diff) +8 -0
+   /*
+    * Wait for clocks to settle down, and then clear all the
+     * ratios request and the reload request.
+      */
+      udelay(1000);
+      reg &= ~(CORE_CLOCK_DIVIDER_RATIO_MASK | CORE_CLOCK_DIVIDER_RATIO_RELOAD);
+      writel(reg, corediv->reg);
+      udelay(1000);
Quoted 5 lines

Documentation/timers/timers-howto.txt says:

SLEEPING FOR ~USECS OR SMALL MSECS ( 10us - 20ms):
* Use usleep_range

Given the set_rate should be protected by spinlocks (as you pointed out), I guess we can't afford using usleep_range (the context is now non-atomic).

Now, according to arch/arm/include/asm/delay.h this is the suggestion for udelay and friends:

* Use only for very small delays ( < 2 msec). Should probably use a
* lookup table, really, as the multiplications take much too long with
* short delays. This is a "reasonable" implementation, though (and
* the first constant multiplications gets optimized away if the delay is
* a constant)

Which means we could just use udelay(1000) without much trouble.

On the other side, since we know the rate the clock is running, we could use __delay() just as drivers/clk/sunxi/clk-factors.c is doing. __delay() has a much simpler implementation, which feels correct in this case of "wait until the clock settles".

Therefore, I'm currently going to try that option.

Signature · 3 lines
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com
maintainer
#17 lore raw

PATCH 2/5 ARM: mvebu: Add Core Divider clock device-tree binding

In reply to Ezequiel Garcia

Hi Ezequiel

+#define CORE_CLOCK_DIVIDER_RATIO_OFFSET 0x8
...

reg = readl(corediv->reg + CORE_CLOCK_DIVIDER_RATIO_OFFSET);

...

+Example:
+
+corediv_clk: corediv-clocks at 18740 {

+	      compatible = "marvell,armada-370-corediv-clock";
+	      reg = <0x18740 0x8>;
+	      #clock-cells = <1>;
+	      clocks = <&pll>;

+};

The reg property seems to be wrong.

Andrew

#18 lore raw

PATCH 2/5 ARM: mvebu: Add Core Divider clock device-tree binding

Quoted 18 lines · Andrew Lunn

Hi Ezequiel

+#define CORE_CLOCK_DIVIDER_RATIO_OFFSET 0x8
...

reg = readl(corediv->reg + CORE_CLOCK_DIVIDER_RATIO_OFFSET);

...

(quoted diff) +8 -0
+Example:
+
+corediv_clk: corediv-clocks at 18740 {
+	      compatible = "marvell,armada-370-corediv-clock";
+	      reg = <0x18740 0x8>;
+	      #clock-cells = <1>;
+	      clocks = <&pll>;
+};
Quoted 2 lines

The reg property seems to be wrong.

Mm.. good catch!

Thanks for the review,

Signature · 3 lines
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com