Skip to contentSkip to conversation

ARM: topology: Allow to set the frequency through a clock

PATCH RESEND Superseded Maxime Ripard 2 participants 5 messages Jun 17, 2014 – Jun 18, 2014

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover ARM: topology: Allow to set the frequency through a clock

Hi,

This patch series add the possibility for the topology code to get the CPU frequency through a DT clock handle instead of needing a clock-frequency property.

Indeed, this information can be quite redundant if the clock tree defined in the DT is already describing the CPU parent clock.

Maxime

Maxime Ripard (2):
ARM: topology: Use a clock if possible to get the CPU frequency
ARM: sunxi: Add clocks node to the CPU nodes

 arch/arm/boot/dts/sun6i-a31.dtsi |  4 ++++
 arch/arm/boot/dts/sun7i-a20.dtsi |  2 ++
 arch/arm/kernel/topology.c       | 24 +++++++++++++++++-------
 3 files changed, 23 insertions(+), 7 deletions(-)
Signature · 1 line
2.0.0
#1 lore raw

PATCH RESEND 1/2 ARM: topology: Use a clock if possible to get the CPU frequency

The Cortex-A7 and Cortex-A15 based SoCs need a clock-frequency property in the topology code.

Allow to use a clock to provide the same information.

---
 arch/arm/kernel/topology.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)
arch/arm/kernel/topology.c +17 -7
index 9d853189028b..0bd044cbbcb2 100644
@@ -11,6 +11,7 @@
  * for more details.
  */
 
+#include <linux/clk.h>
 #include <linux/cpu.h>
 #include <linux/cpumask.h>
 #include <linux/export.h>
@@ -100,8 +101,8 @@ static void __init parse_dt_topology(void)
 				 GFP_NOWAIT);
 
 	for_each_possible_cpu(cpu) {
-		const u32 *rate;
-		int len;
+		struct clk *clk;
+		u32 rate = 0;
 
 		/* too early to use cpu->of_node */
 		cn = of_get_cpu_node(cpu, NULL);
@@ -117,14 +118,23 @@ static void __init parse_dt_topology(void)
 		if (cpu_eff->compatible == NULL)
 			continue;
 
-		rate = of_get_property(cn, "clock-frequency", &len);
-		if (!rate || len != 4) {
-			pr_err("%s missing clock-frequency property\n",
-				cn->full_name);
+		clk = of_clk_get(cn, 0);
+		if (!IS_ERR(clk)) {
+			rate = clk_get_rate(clk);
+		} else {
+			if (of_property_read_u32(cn, "clock-frequency", &rate)) {
+				pr_err("%s missing clocks or clock-frequency properties\n",
+				       cn->full_name);
+				continue;
+			}
+		}
+
+		if (!rate) {
+			pr_err("%s invalid CPU frequency", cn->full_name);
 			continue;
 		}
 
-		capacity = ((be32_to_cpup(rate)) >> 20) * cpu_eff->efficiency;
+		capacity = ((rate) >> 20) * cpu_eff->efficiency;
 
 		/* Save min capacity of the system */
 		if (capacity < min_capacity)
Signature · 1 line
2.0.0
#2 lore raw

PATCH RESEND 1/2 ARM: topology: Use a clock if possible to get the CPU frequency

Quoted 38 lines · Maxime Ripard

The Cortex-A7 and Cortex-A15 based SoCs need a clock-frequency property in the topology code.

Allow to use a clock to provide the same information.

---
 arch/arm/kernel/topology.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)
arch/arm/kernel/topology.c +3 -3
index 9d853189028b..0bd044cbbcb2 100644
@@ -11,6 +11,7 @@
  * for more details.
  */
 
+#include <linux/clk.h>
 #include <linux/cpu.h>
 #include <linux/cpumask.h>
 #include <linux/export.h>
@@ -100,8 +101,8 @@ static void __init parse_dt_topology(void)
                                 GFP_NOWAIT);
 
        for_each_possible_cpu(cpu) {
-               const u32 *rate;
-               int len;
+               struct clk *clk;
+               u32 rate = 0;
 
                /* too early to use cpu->of_node */
                cn = of_get_cpu_node(cpu, NULL);
@@ -117,14 +118,23 @@ static void __init parse_dt_topology(void)
                if (cpu_eff->compatible == NULL)
                        continue;
 
-               rate = of_get_property(cn, "clock-frequency", &len);

arch/arm/kernel/topology.c static void __init parse_dt_topology(void) · line 127

Quoted 10 lines
arch/arm/kernel/topology.c +7 -3
-               if (!rate || len != 4) {
-                       pr_err("%s missing clock-frequency property\n",
-                               cn->full_name);
+               clk = of_clk_get(cn, 0);
+               if (!IS_ERR(clk)) {
+                       rate = clk_get_rate(clk);
+               } else {
+                       if (of_property_read_u32(cn, "clock-frequency", &rate)) {
+                               pr_err("%s missing clocks or clock-frequency properties\n",
+                                      cn->full_name);

This error check and message is redundant with the next error message. You can remove this one and just call of_property_read_u32. rate will remain untouched on error.

#3 lore raw

PATCH RESEND 1/2 ARM: topology: Use a clock if possible to get the CPU frequency

Hi Rob,

Quoted 39 lines · Rob Herring
Quoted 37 lines · Maxime Ripard

The Cortex-A7 and Cortex-A15 based SoCs need a clock-frequency property in the topology code.

Allow to use a clock to provide the same information.

---
 arch/arm/kernel/topology.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)
arch/arm/kernel/topology.c +3 -2
index 9d853189028b..0bd044cbbcb2 100644
@@ -11,6 +11,7 @@
  * for more details.
  */
 
+#include <linux/clk.h>
 #include <linux/cpu.h>
 #include <linux/cpumask.h>
 #include <linux/export.h>
@@ -100,8 +101,8 @@ static void __init parse_dt_topology(void)
                                 GFP_NOWAIT);
 
        for_each_possible_cpu(cpu) {
-               const u32 *rate;
-               int len;
+               struct clk *clk;
+               u32 rate = 0;
 
                /* too early to use cpu->of_node */
                cn = of_get_cpu_node(cpu, NULL);
@@ -117,14 +118,23 @@ static void __init parse_dt_topology(void)
                if (cpu_eff->compatible == NULL)
                        continue;
 
Quoted 15 lines

arch/arm/kernel/topology.c static void __init parse_dt_topology(void) · line 127

Quoted 11 lines
arch/arm/kernel/topology.c +7 -4
-               rate = of_get_property(cn, "clock-frequency", &len);
-               if (!rate || len != 4) {
-                       pr_err("%s missing clock-frequency property\n",
-                               cn->full_name);
+               clk = of_clk_get(cn, 0);
+               if (!IS_ERR(clk)) {
+                       rate = clk_get_rate(clk);
+               } else {
+                       if (of_property_read_u32(cn, "clock-frequency", &rate)) {
+                               pr_err("%s missing clocks or clock-frequency properties\n",
+                                      cn->full_name);

This error check and message is redundant with the next error message. You can remove this one and just call of_property_read_u32. rate will remain untouched on error.

I'm not sure what you mean here. There's no next error message in the code as far as I'm aware.

If you mean that I'd rather have something like

clk = of_clk_get(cn, 0);
if (!IS_ERR(clk))

	rate = clk_get_rate(clk);
else
	of_property_read_u32(cn, "clock-frequency", &rate));

if (!rate)

	pr_err()

Then, yes, it makes sense. I'll resend a version

Maxime

Signature · 10 lines
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140618/fdefee69/attachment.sig>
#4 lore raw

PATCH RESEND 2/2 ARM: sunxi: Add clocks node to the CPU nodes

In reply to Maxime Ripard

Setting the clock will make the topology code work, and will remove the following error at boot

[    0.097194] /cpus/cpu at 0 missing clock-frequency property
[    0.103657] /cpus/cpu at 1 missing clock-frequency property
[    0.110698] /cpus/cpu at 2 missing clock-frequency property
[    0.117132] /cpus/cpu at 3 missing clock-frequency property
---
 arch/arm/boot/dts/sun6i-a31.dtsi | 4 ++++
 arch/arm/boot/dts/sun7i-a20.dtsi | 2 ++
 2 files changed, 6 insertions(+)
arch/arm/boot/dts/sun6i-a31.dtsi +4 -0
index a9dfa12eb735..905b84add002 100644
@@ -34,24 +34,28 @@
 		cpu at 0 {
 			compatible = "arm,cortex-a7";
 			device_type = "cpu";
+			clocks = <&cpu>;
 			reg = <0>;
 		};
 
 		cpu at 1 {
 			compatible = "arm,cortex-a7";
 			device_type = "cpu";
+			clocks = <&cpu>;
 			reg = <1>;
 		};
 
 		cpu at 2 {
 			compatible = "arm,cortex-a7";
 			device_type = "cpu";
+			clocks = <&cpu>;
 			reg = <2>;
 		};
 
 		cpu at 3 {
 			compatible = "arm,cortex-a7";
 			device_type = "cpu";
+			clocks = <&cpu>;
 			reg = <3>;
 		};
 	};
arch/arm/boot/dts/sun7i-a20.dtsi +2 -0
index 01e94664232a..12a4940be551 100644
@@ -35,12 +35,14 @@
 		cpu at 0 {
 			compatible = "arm,cortex-a7";
 			device_type = "cpu";
+			clocks = <&cpu>;
 			reg = <0>;
 		};
 
 		cpu at 1 {
 			compatible = "arm,cortex-a7";
 			device_type = "cpu";
+			clocks = <&cpu>;
 			reg = <1>;
 		};
 	};
Signature · 1 line
2.0.0