Skip to contentSkip to conversation

clk: at91: rework sckc bindings

PATCH Applied Alexandre Belloni 3 participants 12 messages Feb 19, 2019 – Apr 25, 2019

Subsystems (3)
lore
Share & tools
lore

Alexandre Belloni

author maintainer
#0 lore raw

cover clk: at91: rework sckc bindings

Hi,

This is a rework of the sckc DT bindings to avoid warnings with dtc. DT backward compatibility is kept.

This series also fix a possible issue with the sama5d3 slow RC oscillator.

The sckc driver changes and documetation can go through the clk tree and we will handle th DT changes.

Alexandre Belloni (7):
dt-bindings: clock: at91: new sckc bindings
clk: at91: modernize sckc binding
clk: at91: sckc: handle different RC startup time
ARM: dts: at91: at91sam9x5: switch to new sckc bindings
ARM: dts: at91: at91sam9g45: switch to new sckc bindings
ARM: dts: at91: at91sam9rl: switch to new sckc bindings
ARM: dts: at91: sama5d3: switch to new sckc bindings

 .../devicetree/bindings/clock/at91-clock.txt  |  30 ++--
 arch/arm/boot/dts/at91-wb50n.dtsi             |   2 +-
 arch/arm/boot/dts/at91sam9g45.dtsi            |  25 +---
 arch/arm/boot/dts/at91sam9rl.dtsi             |  25 +---
 arch/arm/boot/dts/at91sam9x5.dtsi             |  23 +--
 arch/arm/boot/dts/sama5d3.dtsi                |  27 +---
 drivers/clk/at91/sckc.c                       | 134 ++++++------------
 7 files changed, 73 insertions(+), 193 deletions(-)
Signature · 1 line
2.20.1
author maintainer
#1 lore raw

PATCH 1/7 dt-bindings: clock: at91: new sckc bindings

Remove the need for child nodes in the sckc binding to be able to remove dtc warnings and have a more modern binding.

Also document optional properties.

---
 .../devicetree/bindings/clock/at91-clock.txt  | 30 ++++++++-----------
 1 file changed, 12 insertions(+), 18 deletions(-)
Documentation/devicetree/bindings/clock/at91-clock.txt +12 -18
index e9f70fcdfe80..cb838c1c4bdd 100644
@@ -8,29 +8,23 @@ Slow Clock controller:
 
 Required properties:
 - compatible : shall be one of the following:
-	"atmel,at91sam9x5-sckc" or
+	"atmel,at91sam9x5-sckc",
+	"atmel,sama5d3-sckc" or
 	"atmel,sama5d4-sckc":
 		at91 SCKC (Slow Clock Controller)
-		This node contains the slow clock definitions.
-
-	"atmel,at91sam9x5-clk-slow-osc":
-		at91 slow oscillator
-
-	"atmel,at91sam9x5-clk-slow-rc-osc":
-		at91 internal slow RC oscillator
-- reg : defines the IO memory reserved for the SCKC.
-- #size-cells : shall be 0 (reg is used to encode clk id).
-- #address-cells : shall be 1 (reg is used to encode clk id).
+- #clock-cells : shall be 0.
+- clocks : shall be the input parent clock phandle for the clock.
 
+Optional properties:
+- atmel,osc-bypass : boolean property. Set this when a clock signal is directly
+  provided on XIN.
 
 For example:
-	sckc: sckc@fffffe50 {
-		compatible = "atmel,sama5d3-pmc";
-		reg = <0xfffffe50 0x4>
-		#size-cells = <0>;
-		#address-cells = <1>;
-
-		/* put at91 slow clocks here */
+	sckc@fffffe50 {
+		compatible = "atmel,at91sam9x5-sckc";
+		reg = <0xfffffe50 0x4>;
+		clocks = <&slow_xtal>;
+		#clock-cells = <0>;
 	};
 
 Power Management Controller (PMC):
Signature · 1 line
2.20.1
maintainer Reviewed-by on v1 1/7
#2 lore raw

Re: [PATCH 1/7] dt-bindings: clock: at91: new sckc bindings

Quoted 11 lines · Alexandre Belloni

Remove the need for child nodes in the sckc binding to be able to remove dtc warnings and have a more modern binding.

Also document optional properties.

---
 .../devicetree/bindings/clock/at91-clock.txt  | 30 ++++++++-----------
 1 file changed, 12 insertions(+), 18 deletions(-)
author maintainer
#4 lore raw

PATCH 2/7 clk: at91: modernize sckc binding

In reply to Alexandre Belloni

Remove the need for child nodes in the sckc binding and register the whole sckc tree (3 clocks in total) from the sckc node.

DT backward compatibility is kept by looking for properties in child nodes when they are not present in the sckc node.

---
 drivers/clk/at91/sckc.c | 125 ++++++++++++----------------------------
 1 file changed, 36 insertions(+), 89 deletions(-)
drivers/clk/at91/sckc.c +36 -89
index ab6ecefc49ad..470aef586f57 100644
@@ -152,28 +152,6 @@ at91_clk_register_slow_osc(void __iomem *sckcr,
 	return hw;
 }
 
-static void __init
-of_at91sam9x5_clk_slow_osc_setup(struct device_node *np, void __iomem *sckcr)
-{
-	struct clk_hw *hw;
-	const char *parent_name;
-	const char *name = np->name;
-	u32 startup;
-	bool bypass;
-
-	parent_name = of_clk_get_parent_name(np, 0);
-	of_property_read_string(np, "clock-output-names", &name);
-	of_property_read_u32(np, "atmel,startup-time-usec", &startup);
-	bypass = of_property_read_bool(np, "atmel,osc-bypass");
-
-	hw = at91_clk_register_slow_osc(sckcr, name, parent_name, startup,
-					 bypass);
-	if (IS_ERR(hw))
-		return;
-
-	of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
-}
-
 static unsigned long clk_slow_rc_osc_recalc_rate(struct clk_hw *hw,
 						 unsigned long parent_rate)
 {
@@ -266,28 +244,6 @@ at91_clk_register_slow_rc_osc(void __iomem *sckcr,
 	return hw;
 }
 
-static void __init
-of_at91sam9x5_clk_slow_rc_osc_setup(struct device_node *np, void __iomem *sckcr)
-{
-	struct clk_hw *hw;
-	u32 frequency = 0;
-	u32 accuracy = 0;
-	u32 startup = 0;
-	const char *name = np->name;
-
-	of_property_read_string(np, "clock-output-names", &name);
-	of_property_read_u32(np, "clock-frequency", &frequency);
-	of_property_read_u32(np, "clock-accuracy", &accuracy);
-	of_property_read_u32(np, "atmel,startup-time-usec", &startup);
-
-	hw = at91_clk_register_slow_rc_osc(sckcr, name, frequency, accuracy,
-					    startup);
-	if (IS_ERR(hw))
-		return;
-
-	of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
-}
-
 static int clk_sam9x5_slow_set_parent(struct clk_hw *hw, u8 index)
 {
 	struct clk_sam9x5_slow *slowck = to_clk_sam9x5_slow(hw);
@@ -365,64 +321,55 @@ at91_clk_register_sam9x5_slow(void __iomem *sckcr,
 	return hw;
 }
 
-static void __init
-of_at91sam9x5_clk_slow_setup(struct device_node *np, void __iomem *sckcr)
+static void __init of_at91sam9x5_sckc_setup(struct device_node *np)
 {
+	const char *parent_names[2] = { "slow_rc_osc", "slow_osc" };
+	void __iomem *regbase = of_iomap(np, 0);
+	struct device_node *child = NULL;
+	const char *xtal_name;
 	struct clk_hw *hw;
-	const char *parent_names[2];
-	unsigned int num_parents;
-	const char *name = np->name;
+	bool bypass;
 
-	num_parents = of_clk_get_parent_count(np);
-	if (num_parents == 0 || num_parents > 2)
+	if (!regbase)
 		return;
 
-	of_clk_parent_fill(np, parent_names, num_parents);
-
-	of_property_read_string(np, "clock-output-names", &name);
-
-	hw = at91_clk_register_sam9x5_slow(sckcr, name, parent_names,
-					    num_parents);
+	hw = at91_clk_register_slow_rc_osc(regbase, parent_names[0], 32768,
+					   50000000, 75);
 	if (IS_ERR(hw))
 		return;
 
-	of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
-}
+	xtal_name = of_clk_get_parent_name(np, 0);
+	if (!xtal_name) {
+		/* DT backward compatibility */
+		child = of_get_compatible_child(np, "atmel,at91sam9x5-clk-slow-osc");
+		if (!child)
+			return;
+
+		xtal_name = of_clk_get_parent_name(child, 0);
+		bypass = of_property_read_bool(child, "atmel,osc-bypass");
+
+		child =  of_get_compatible_child(np, "atmel,at91sam9x5-clk-slow");
+	} else {
+		bypass = of_property_read_bool(np, "atmel,osc-bypass");
+	}
 
-static const struct of_device_id sckc_clk_ids[] __initconst = {
-	/* Slow clock */
-	{
-		.compatible = "atmel,at91sam9x5-clk-slow-osc",
-		.data = of_at91sam9x5_clk_slow_osc_setup,
-	},
-	{
-		.compatible = "atmel,at91sam9x5-clk-slow-rc-osc",
-		.data = of_at91sam9x5_clk_slow_rc_osc_setup,
-	},
-	{
-		.compatible = "atmel,at91sam9x5-clk-slow",
-		.data = of_at91sam9x5_clk_slow_setup,
-	},
-	{ /*sentinel*/ }
-};
+	if (!xtal_name)
+		return;
 
-static void __init of_at91sam9x5_sckc_setup(struct device_node *np)
-{
-	struct device_node *childnp;
-	void (*clk_setup)(struct device_node *, void __iomem *);
-	const struct of_device_id *clk_id;
-	void __iomem *regbase = of_iomap(np, 0);
+	hw = at91_clk_register_slow_osc(regbase, parent_names[1], xtal_name,
+					1200000, bypass);
+	if (IS_ERR(hw))
+		return;
 
-	if (!regbase)
+	hw = at91_clk_register_sam9x5_slow(regbase, "slowck", parent_names, 2);
+	if (IS_ERR(hw))
 		return;
 
-	for_each_child_of_node(np, childnp) {
-		clk_id = of_match_node(sckc_clk_ids, childnp);
-		if (!clk_id)
-			continue;
-		clk_setup = clk_id->data;
-		clk_setup(childnp, regbase);
-	}
+	of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
+
+	/* DT backward compatibility */
+	if (child)
+		of_clk_add_hw_provider(child, of_clk_hw_simple_get, hw);
 }
 CLK_OF_DECLARE(at91sam9x5_clk_sckc, "atmel,at91sam9x5-sckc",
 	       of_at91sam9x5_sckc_setup);
Signature · 1 line
2.20.1
maintainer Applied
#5 lore raw

Re: [PATCH 2/7] clk: at91: modernize sckc binding

Quoting Alexandre Belloni (2019-02-19 09:01:55)

Quoted 8 lines

Remove the need for child nodes in the sckc binding and register the whole sckc tree (3 clocks in total) from the sckc node.

DT backward compatibility is kept by looking for properties in child nodes when they are not present in the sckc node.

---

Applied to clk-next

author maintainer
#6 lore raw

PATCH 3/7 clk: at91: sckc: handle different RC startup time

In reply to Alexandre Belloni

The sama5d3 slow RC oscillator as a different startup time than all the previous SoCs. Handle that using its own compatible.

---
 drivers/clk/at91/sckc.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/clk/at91/sckc.c +15 -2
index 470aef586f57..e76b1d64e905 100644
@@ -321,7 +321,8 @@ at91_clk_register_sam9x5_slow(void __iomem *sckcr,
 	return hw;
 }
 
-static void __init of_at91sam9x5_sckc_setup(struct device_node *np)
+static void __init at91sam9x5_sckc_register(struct device_node *np,
+					    unsigned int rc_osc_startup_us)
 {
 	const char *parent_names[2] = { "slow_rc_osc", "slow_osc" };
 	void __iomem *regbase = of_iomap(np, 0);
@@ -334,7 +335,7 @@ static void __init of_at91sam9x5_sckc_setup(struct device_node *np)
 		return;
 
 	hw = at91_clk_register_slow_rc_osc(regbase, parent_names[0], 32768,
-					   50000000, 75);
+					   50000000, rc_osc_startup_us);
 	if (IS_ERR(hw))
 		return;
 
@@ -371,9 +372,21 @@ static void __init of_at91sam9x5_sckc_setup(struct device_node *np)
 	if (child)
 		of_clk_add_hw_provider(child, of_clk_hw_simple_get, hw);
 }
+
+static void __init of_at91sam9x5_sckc_setup(struct device_node *np)
+{
+	at91sam9x5_sckc_register(np, 75);
+}
 CLK_OF_DECLARE(at91sam9x5_clk_sckc, "atmel,at91sam9x5-sckc",
 	       of_at91sam9x5_sckc_setup);
 
+static void __init of_sama5d3_sckc_setup(struct device_node *np)
+{
+	at91sam9x5_sckc_register(np, 500);
+}
+CLK_OF_DECLARE(sama5d3_clk_sckc, "atmel,sama5d3-sckc",
+	       of_sama5d3_sckc_setup);
+
 static int clk_sama5d4_slow_osc_prepare(struct clk_hw *hw)
 {
 	struct clk_sama5d4_slow_osc *osc = to_clk_sama5d4_slow_osc(hw);
Signature · 1 line
2.20.1
maintainer Applied
#7 lore raw

Re: [PATCH 3/7] clk: at91: sckc: handle different RC startup time

Quoting Alexandre Belloni (2019-02-19 09:01:56)

Quoted 5 lines

The sama5d3 slow RC oscillator as a different startup time than all the previous SoCs. Handle that using its own compatible.

---

Applied to clk-next

author maintainer
#8 lore raw

PATCH 4/7 ARM: dts: at91: at91sam9x5: switch to new sckc bindings

In reply to Alexandre Belloni

Remove the child nodes of the sckc as they are not necessary anymore.

---
 arch/arm/boot/dts/at91sam9x5.dtsi | 23 +++--------------------
 1 file changed, 3 insertions(+), 20 deletions(-)
arch/arm/boot/dts/at91sam9x5.dtsi +3 -20
index 07443a387a8f..ff50f49842f4 100644
@@ -148,28 +148,11 @@
 				clocks = <&pmc PMC_TYPE_CORE PMC_MCK>;
 			};
 
-			sckc@fffffe50 {
+			clk32k: sckc@fffffe50 {
 				compatible = "atmel,at91sam9x5-sckc";
 				reg = <0xfffffe50 0x4>;
-
-				slow_osc: slow_osc {
-					compatible = "atmel,at91sam9x5-clk-slow-osc";
-					#clock-cells = <0>;
-					clocks = <&slow_xtal>;
-				};
-
-				slow_rc_osc: slow_rc_osc {
-					compatible = "atmel,at91sam9x5-clk-slow-rc-osc";
-					#clock-cells = <0>;
-					clock-frequency = <32768>;
-					clock-accuracy = <50000000>;
-				};
-
-				clk32k: slck {
-					compatible = "atmel,at91sam9x5-clk-slow";
-					#clock-cells = <0>;
-					clocks = <&slow_rc_osc>, <&slow_osc>;
-				};
+				clocks = <&slow_xtal>;
+				#clock-cells = <0>;
 			};
 
 			tcb0: timer@f8008000 {
Signature · 1 line
2.20.1
author maintainer
#9 lore raw

PATCH 5/7 ARM: dts: at91: at91sam9g45: switch to new sckc bindings

In reply to Alexandre Belloni

Remove the child nodes of the sckc as they are not necessary anymore.

---
 arch/arm/boot/dts/at91sam9g45.dtsi | 25 +++----------------------
 1 file changed, 3 insertions(+), 22 deletions(-)
arch/arm/boot/dts/at91sam9g45.dtsi +3 -22
index d16db1fa7e15..74a011077d54 100644
@@ -1257,30 +1257,11 @@
 				};
 			};
 
-			sckc@fffffd50 {
+			clk32k: sckc@fffffd50 {
 				compatible = "atmel,at91sam9x5-sckc";
 				reg = <0xfffffd50 0x4>;
-
-				slow_osc: slow_osc {
-					compatible = "atmel,at91sam9x5-clk-slow-osc";
-					#clock-cells = <0>;
-					atmel,startup-time-usec = <1200000>;
-					clocks = <&slow_xtal>;
-				};
-
-				slow_rc_osc: slow_rc_osc {
-					compatible = "atmel,at91sam9x5-clk-slow-rc-osc";
-					#clock-cells = <0>;
-					atmel,startup-time-usec = <75>;
-					clock-frequency = <32768>;
-					clock-accuracy = <50000000>;
-				};
-
-				clk32k: slck {
-					compatible = "atmel,at91sam9x5-clk-slow";
-					#clock-cells = <0>;
-					clocks = <&slow_rc_osc &slow_osc>;
-				};
+				clocks = <&slow_xtal>;
+				#clock-cells = <0>;
 			};
 
 			rtc@fffffd20 {
Signature · 1 line
2.20.1
author maintainer
#10 lore raw

PATCH 6/7 ARM: dts: at91: at91sam9rl: switch to new sckc bindings

In reply to Alexandre Belloni

Remove the child nodes of the sckc as they are not necessary anymore.

---
 arch/arm/boot/dts/at91sam9rl.dtsi | 25 +++----------------------
 1 file changed, 3 insertions(+), 22 deletions(-)
arch/arm/boot/dts/at91sam9rl.dtsi +3 -22
index 3862ff2f26e0..f5f09a30dd3f 100644
@@ -867,30 +867,11 @@
 				status = "disabled";
 			};
 
-			sckc@fffffd50 {
+			clk32k: sckc@fffffd50 {
 				compatible = "atmel,at91sam9x5-sckc";
 				reg = <0xfffffd50 0x4>;
-
-				slow_osc: slow_osc {
-					compatible = "atmel,at91sam9x5-clk-slow-osc";
-					#clock-cells = <0>;
-					atmel,startup-time-usec = <1200000>;
-					clocks = <&slow_xtal>;
-				};
-
-				slow_rc_osc: slow_rc_osc {
-					compatible = "atmel,at91sam9x5-clk-slow-rc-osc";
-					#clock-cells = <0>;
-					atmel,startup-time-usec = <75>;
-					clock-frequency = <32768>;
-					clock-accuracy = <50000000>;
-				};
-
-				clk32k: slck {
-					compatible = "atmel,at91sam9x5-clk-slow";
-					#clock-cells = <0>;
-					clocks = <&slow_rc_osc &slow_osc>;
-				};
+				clocks = <&slow_xtal>;
+				#clock-cells = <0>;
 			};
 
 			rtc@fffffd20 {
Signature · 1 line
2.20.1
author maintainer
#11 lore raw

PATCH 7/7 ARM: dts: at91: sama5d3: switch to new sckc bindings

In reply to Alexandre Belloni

Remove the child nodes of the sckc as they are not necessary anymore.

Also, switch to the new atmel,sama5d3-sckc compatible string to use the proper startup time for the RC oscillator (500 µs instead of 75).

---
 arch/arm/boot/dts/at91-wb50n.dtsi |  2 +-
 arch/arm/boot/dts/sama5d3.dtsi    | 27 ++++-----------------------
 2 files changed, 5 insertions(+), 24 deletions(-)
arch/arm/boot/dts/at91-wb50n.dtsi +1 -1
index 85692c8ef2b1..4ed8500a5cb8 100644
@@ -42,7 +42,7 @@
 	clock-frequency = <12000000>;
 };
 
-&slow_osc {
+&clk32k {
 	atmel,osc-bypass;
 };
 
arch/arm/boot/dts/sama5d3.dtsi +4 -23
index 1408fa4a62e4..05f6554d4177 100644
@@ -1370,30 +1370,11 @@
 				status = "disabled";
 			};
 
-			sckc@fffffe50 {
-				compatible = "atmel,at91sam9x5-sckc";
+			clk32k: sckc@fffffe50 {
+				compatible = "atmel,sama5d3-sckc";
 				reg = <0xfffffe50 0x4>;
-
-				slow_rc_osc: slow_rc_osc {
-					compatible = "atmel,at91sam9x5-clk-slow-rc-osc";
-					#clock-cells = <0>;
-					clock-frequency = <32768>;
-					clock-accuracy = <50000000>;
-					atmel,startup-time-usec = <75>;
-				};
-
-				slow_osc: slow_osc {
-					compatible = "atmel,at91sam9x5-clk-slow-osc";
-					#clock-cells = <0>;
-					clocks = <&slow_xtal>;
-					atmel,startup-time-usec = <1200000>;
-				};
-
-				clk32k: slowck {
-					compatible = "atmel,at91sam9x5-clk-slow";
-					#clock-cells = <0>;
-					clocks = <&slow_rc_osc &slow_osc>;
-				};
+				clocks = <&slow_xtal>;
+				#clock-cells = <0>;
 			};
 
 			rtc@fffffeb0 {
Signature · 1 line
2.20.1