Skip to contentSkip to conversation

clk: add fsl-flexspi driver

PATCH In review Michael Walle 2 participants 9 messages Nov 5, 2020 – Nov 6, 2020

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

v2 cover clk: add fsl-flexspi driver

On Layerscape SoCs which feature the FlexSPI controller there is a single register which can control the divider value. The base frequency is the platform PLL.

Right now the LS1028A and the LX2160A aren't able to switch the SCK frequency on the FlexSPI interface. Add a new clock driver which operate on said register.

Michael Walle (5):
clk: divider: add devm_clk_hw_register_divider_table()
dt-bindings: clock: document the fsl-flexspi-clk driver
clk: fsl-flexspi: new driver
arm64: dts: ls1028a: fix FlexSPI clock
arm64: dts: lx2160a: fix FlexSPI clock

 .../bindings/clock/fsl,flexspi-clock.yaml     |  55 +++++++++
 .../arm64/boot/dts/freescale/fsl-ls1028a.dtsi |  15 ++-
 .../arm64/boot/dts/freescale/fsl-lx2160a.dtsi |  15 ++-
 drivers/clk/Kconfig                           |   8 ++
 drivers/clk/Makefile                          |   1 +
 drivers/clk/clk-divider.c                     |  34 ++++++
 drivers/clk/clk-fsl-flexspi.c                 | 106 ++++++++++++++++++
 include/linux/clk-provider.h                  |  27 +++++
 8 files changed, 257 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/clock/fsl,flexspi-clock.yaml
 create mode 100644 drivers/clk/clk-fsl-flexspi.c
Signature · 1 line
2.20.1
#1 lore raw

PATCH v2 1/5 clk: divider: add devm_clk_hw_register_divider_table()

This will simplify drivers which would only unregister the clk in their remove() op.

---
Changes since v1:
- new patch

 drivers/clk/clk-divider.c    | 34 ++++++++++++++++++++++++++++++++++
 include/linux/clk-provider.h | 27 +++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)
drivers/clk/clk-divider.c +34 -0
index 8de12cb0c43d..c499799693cc 100644
@@ -8,6 +8,7 @@
  */
 
 #include <linux/clk-provider.h>
+#include <linux/device.h>
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/io.h>
@@ -578,3 +579,36 @@ void clk_hw_unregister_divider(struct clk_hw *hw)
 	kfree(div);
 }
 EXPORT_SYMBOL_GPL(clk_hw_unregister_divider);
+
+static void devm_clk_hw_release_divider(struct device *dev, void *res)
+{
+	clk_hw_unregister_divider(*(struct clk_hw **)res);
+}
+
+struct clk_hw *__devm_clk_hw_register_divider(struct device *dev,
+		struct device_node *np, const char *name,
+		const char *parent_name, const struct clk_hw *parent_hw,
+		const struct clk_parent_data *parent_data, unsigned long flags,
+		void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags,
+		const struct clk_div_table *table, spinlock_t *lock)
+{
+	struct clk_hw **ptr, *hw;
+
+	ptr = devres_alloc(devm_clk_hw_release_divider, sizeof(*ptr), GFP_KERNEL);
+	if (!ptr)
+		return ERR_PTR(-ENOMEM);
+
+	hw = __clk_hw_register_divider(dev, np, name, parent_name, parent_hw,
+				       parent_data, flags, reg, shift, width,
+				       clk_divider_flags, table, lock);
+
+	if (!IS_ERR(hw)) {
+		*ptr = hw;
+		devres_add(dev, ptr);
+	} else {
+		devres_free(ptr);
+	}
+
+	return hw;
+}
+EXPORT_SYMBOL_GPL(__devm_clk_hw_register_divider);
include/linux/clk-provider.h +27 -0
index 03a5de5f99f4..9ead4633c8c8 100644
@@ -639,6 +639,12 @@ struct clk_hw *__clk_hw_register_divider(struct device *dev,
 		const struct clk_parent_data *parent_data, unsigned long flags,
 		void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags,
 		const struct clk_div_table *table, spinlock_t *lock);
+struct clk_hw *__devm_clk_hw_register_divider(struct device *dev,
+		struct device_node *np, const char *name,
+		const char *parent_name, const struct clk_hw *parent_hw,
+		const struct clk_parent_data *parent_data, unsigned long flags,
+		void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags,
+		const struct clk_div_table *table, spinlock_t *lock);
 struct clk *clk_register_divider_table(struct device *dev, const char *name,
 		const char *parent_name, unsigned long flags,
 		void __iomem *reg, u8 shift, u8 width,
@@ -779,6 +785,27 @@ struct clk *clk_register_divider_table(struct device *dev, const char *name,
 				  (parent_data), (flags), (reg), (shift),     \
 				  (width), (clk_divider_flags), (table),      \
 				  (lock))
+/**
+ * devm_clk_hw_register_divider_table - register a table based divider clock
+ * with the clock framework (devres variant)
+ * @dev: device registering this clock
+ * @name: name of this clock
+ * @parent_name: name of clock's parent
+ * @flags: framework-specific flags
+ * @reg: register address to adjust divider
+ * @shift: number of bits to shift the bitfield
+ * @width: width of the bitfield
+ * @clk_divider_flags: divider-specific flags for this clock
+ * @table: array of divider/value pairs ending with a div set to 0
+ * @lock: shared register lock for this clock
+ */
+#define devm_clk_hw_register_divider_table(dev, name, parent_name, flags,     \
+					   reg, shift, width,		      \
+					   clk_divider_flags, table, lock)    \
+	__devm_clk_hw_register_divider((dev), NULL, (name), (parent_name),    \
+				       NULL, NULL, (flags), (reg), (shift),   \
+				       (width), (clk_divider_flags), (table), \
+				       (lock))
 
 void clk_unregister_divider(struct clk *clk);
 void clk_hw_unregister_divider(struct clk_hw *hw);
Signature · 1 line
2.20.1
#2 lore raw

PATCH v2 2/5 dt-bindings: clock: document the fsl-flexspi-clk driver

In reply to Michael Walle

---
Changes since v1:
- none

 .../bindings/clock/fsl,flexspi-clock.yaml     | 55 +++++++++++++++++++
 1 file changed, 55 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/fsl,flexspi-clock.yaml
Documentation/devicetree/bindings/clock/fsl,flexspi-clock.yaml new file +55 -0
new file mode 100644
index 000000000000..1fa390ee7b9b
@@ -0,0 +1,55 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/clock/fsl,flexspi-clock.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Freescale FlexSPI clock driver for Layerscape SoCs
+
+maintainers:
+  - Michael Walle <[email protected]>
+
+description:
+  The Freescale Layerscape SoCs have a special FlexSPI clock which is
+  derived from the platform PLL.
+
+properties:
+  compatible:
+    enum:
+      - fsl,ls1028a-flexspi-clk
+      - fsl,lx2160a-flexspi-clk
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  '#clock-cells':
+    const: 0
+
+  clock-output-names:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - '#clock-cells'
+
+additionalProperties: false
+
+examples:
+  - |
+    dcfg {
+        #address-cells = <1>;
+        #size-cells = <1>;
+
+        fspi_clk: clock-controller@900 {
+            compatible = "fsl,ls1028a-flexspi-clk";
+            reg = <0x900 0x4>;
+            #clock-cells = <0>;
+            clocks = <&parentclk>;
+            clock-output-names = "fspi_clk";
+        };
+    };
Signature · 1 line
2.20.1
#3 lore raw

PATCH v2 3/5 clk: fsl-flexspi: new driver

In reply to Michael Walle

Add support for the FlexSPI clock on Freescale Layerscape SoCs. The clock is a simple divider based one and is located inside the device configuration space (DCFG).

This will allow switching the SCK frequencies for the FlexSPI interface on the LS1028A and the LX2160A.

---
Changes since v1:
- use devm_clk_hw_register_divider_table() and drop remove()

 drivers/clk/Kconfig           |   8 +++
 drivers/clk/Makefile          |   1 +
 drivers/clk/clk-fsl-flexspi.c | 106 ++++++++++++++++++++++++++++++++++
 3 files changed, 115 insertions(+)
 create mode 100644 drivers/clk/clk-fsl-flexspi.c
drivers/clk/Kconfig +8 -0
index c715d4681a0b..0066f5af9e77 100644
@@ -188,6 +188,14 @@ config COMMON_CLK_CS2000_CP
 	help
 	  If you say yes here you get support for the CS2000 clock multiplier.
 
+config COMMON_CLK_FSL_FLEXSPI
+	tristate "Clock driver for FlexSPI on Layerscape SoCs"
+	depends on ARCH_LAYERSCAPE || COMPILE_TEST
+    default ARCH_LAYERSCAPE && SPI_NXP_FLEXSPI
+	help
+	  On Layerscape SoCs there is a special clock for the FlexSPI
+	  interface.
+
 config COMMON_CLK_FSL_SAI
 	bool "Clock driver for BCLK of Freescale SAI cores"
 	depends on ARCH_LAYERSCAPE || COMPILE_TEST
drivers/clk/Makefile +1 -0
index da8fcf147eb1..dbdc590e7de3 100644
@@ -30,6 +30,7 @@ obj-$(CONFIG_COMMON_CLK_CS2000_CP)	+= clk-cs2000-cp.o
 obj-$(CONFIG_ARCH_EFM32)		+= clk-efm32gg.o
 obj-$(CONFIG_ARCH_SPARX5)		+= clk-sparx5.o
 obj-$(CONFIG_COMMON_CLK_FIXED_MMIO)	+= clk-fixed-mmio.o
+obj-$(CONFIG_COMMON_CLK_FSL_FLEXSPI)	+= clk-fsl-flexspi.o
 obj-$(CONFIG_COMMON_CLK_FSL_SAI)	+= clk-fsl-sai.o
 obj-$(CONFIG_COMMON_CLK_GEMINI)		+= clk-gemini.o
 obj-$(CONFIG_COMMON_CLK_ASPEED)		+= clk-aspeed.o
drivers/clk/clk-fsl-flexspi.c new file +106 -0

106 lines not on this page · raw message

Signature · 1 line
2.20.1
#4 lore raw

PATCH v2 4/5 arm64: dts: ls1028a: fix FlexSPI clock

In reply to Michael Walle

Now that we have a proper driver for the FlexSPI interface use it. This will fix SCK frequency switching on Layerscape SoCs.

This was tested on the Kontron sl28 board.

---
Changes since v1:
- none

 arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi +13 -2
index ef413bae44cb..4c8b20e6312b 100644
@@ -204,9 +204,20 @@
 		};
 
 		dcfg: syscon@1e00000 {
-			compatible = "fsl,ls1028a-dcfg", "syscon";
+			#address-cells = <1>;
+			#size-cells = <1>;
+			compatible = "fsl,ls1028a-dcfg", "syscon", "simple-mfd";
 			reg = <0x0 0x1e00000 0x0 0x10000>;
+			ranges = <0x0 0x0 0x1e00000 0x10000>;
 			little-endian;
+
+			fspi_clk: clock-controller@900 {
+				compatible = "fsl,ls1028a-flexspi-clk";
+				reg = <0x900 0x4>;
+				#clock-cells = <0>;
+				clocks = <&clockgen 4 0>;
+				clock-output-names = "fspi_clk";
+			};
 		};
 
 		rst: syscon@1e60000 {
@@ -316,7 +327,7 @@
 			      <0x0 0x20000000 0x0 0x10000000>;
 			reg-names = "fspi_base", "fspi_mmap";
 			interrupts = <GIC_SPI 25 IRQ_TYPE_LEVEL_HIGH>;
-			clocks = <&clockgen 4 3>, <&clockgen 4 3>;
+			clocks = <&clockgen 4 3>, <&fspi_clk>;
 			clock-names = "fspi_en", "fspi";
 			status = "disabled";
 		};
Signature · 1 line
2.20.1
#5 lore raw

PATCH v2 5/5 arm64: dts: lx2160a: fix FlexSPI clock

In reply to Michael Walle

Now that we have a proper driver for the FlexSPI interface use it. This will fix SCK frequency switching on Layerscape SoCs.

This was only compile time tested.

---
Changes since v1:
- none

 arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi +13 -2
index 83072da6f6c6..6e375e80bd35 100644
@@ -659,9 +659,20 @@
 		};
 
 		dcfg: syscon@1e00000 {
-			compatible = "fsl,lx2160a-dcfg", "syscon";
+			#address-cells = <1>;
+			#size-cells = <1>;
+			compatible = "fsl,lx2160a-dcfg", "syscon", "simple-mfd";
 			reg = <0x0 0x1e00000 0x0 0x10000>;
+			ranges = <0x0 0x0 0x1e00000 0x10000>;
 			little-endian;
+
+			fspi_clk: clock-controller@900 {
+				compatible = "fsl,lx2160a-flexspi-clk";
+				reg = <0x900 0x4>;
+				#clock-cells = <0>;
+				clocks = <&clockgen 4 0>;
+				clock-output-names = "fspi_clk";
+			};
 		};
 
 		tmu: tmu@1f80000 {
@@ -776,7 +787,7 @@
 			      <0x0 0x20000000 0x0 0x10000000>;
 			reg-names = "fspi_base", "fspi_mmap";
 			interrupts = <GIC_SPI 25 IRQ_TYPE_LEVEL_HIGH>;
-			clocks = <&clockgen 4 3>, <&clockgen 4 3>;
+			clocks = <&clockgen 4 3>, <&fspi_clk>;
 			clock-names = "fspi_en", "fspi";
 			status = "disabled";
 		};
Signature · 1 line
2.20.1
#6 lore raw

RE: [PATCH v2 5/5] arm64: dts: lx2160a: fix FlexSPI clock

Quoted 39 lines

-----Original Message-----
From: Michael Walle <[email protected]>
Sent: Thursday, November 5, 2020 1:35 PM
To: [email protected]; [email protected]; linux- [email protected]; [email protected]
Cc: Michael Turquette <[email protected]>; Stephen Boyd <[email protected]>; Rob Herring <[email protected]>; Shawn Guo <[email protected]>; Leo Li <[email protected]>; Michael Walle <[email protected]>
Subject: [PATCH v2 5/5] arm64: dts: lx2160a: fix FlexSPI clock

Now that we have a proper driver for the FlexSPI interface use it. This will fix SCK frequency switching on Layerscape SoCs.

This was only compile time tested.

---
Changes since v1:
- none

 arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi +3 -1
index 83072da6f6c6..6e375e80bd35 100644
@@ -659,9 +659,20 @@
 		};
 
 		dcfg: syscon@1e00000 {
-			compatible = "fsl,lx2160a-dcfg", "syscon";
+			#address-cells = <1>;
+			#size-cells = <1>;
+			compatible = "fsl,lx2160a-dcfg", "syscon", "simple-

arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi line 674

Quoted 10 lines
arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi +7 -0
 mfd";
 			reg = <0x0 0x1e00000 0x0 0x10000>;
+			ranges = <0x0 0x0 0x1e00000 0x10000>;
 			little-endian;
+
+			fspi_clk: clock-controller@900 {
+				compatible = "fsl,lx2160a-flexspi-clk";
+				reg = <0x900 0x4>;
+				#clock-cells = <0>;
+				clocks = <&clockgen 4 0>;

This is different from the current <&clockgen 4 3>, is it an intended change?

Quoted 16 lines
arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi +2 -0
+				clock-output-names = "fspi_clk";
+			};
 		};
 
arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi +1 -2
 		tmu: tmu@1f80000 {
@@ -776,7 +787,7 @@
 			      <0x0 0x20000000 0x0 0x10000000>;
 			reg-names = "fspi_base", "fspi_mmap";
 			interrupts = <GIC_SPI 25 IRQ_TYPE_LEVEL_HIGH>;
-			clocks = <&clockgen 4 3>, <&clockgen 4 3>;
+			clocks = <&clockgen 4 3>, <&fspi_clk>;
 			clock-names = "fspi_en", "fspi";
 			status = "disabled";
 		};
--

2.20.1

#7 lore raw

Re: [PATCH v2 5/5] arm64: dts: lx2160a: fix FlexSPI clock

Am 2020-11-06 03:00, schrieb Leo Li:

Quoted 41 lines
Quoted 41 lines

-----Original Message-----
From: Michael Walle <[email protected]>
Sent: Thursday, November 5, 2020 1:35 PM
To: [email protected]; [email protected]; linux- [email protected]; [email protected]
Cc: Michael Turquette <[email protected]>; Stephen Boyd <[email protected]>; Rob Herring <[email protected]>; Shawn Guo <[email protected]>; Leo Li <[email protected]>; Michael Walle <[email protected]>
Subject: [PATCH v2 5/5] arm64: dts: lx2160a: fix FlexSPI clock

Now that we have a proper driver for the FlexSPI interface use it. This will fix SCK frequency switching on Layerscape SoCs.

This was only compile time tested.

---
Changes since v1:
- none

 arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi +4 -1
index 83072da6f6c6..6e375e80bd35 100644
@@ -659,9 +659,20 @@
 		};
 
 		dcfg: syscon@1e00000 {
-			compatible = "fsl,lx2160a-dcfg", "syscon";
+			#address-cells = <1>;
+			#size-cells = <1>;
+			compatible = "fsl,lx2160a-dcfg", "syscon", "simple-
 mfd";
 			reg = <0x0 0x1e00000 0x0 0x10000>;
+			ranges = <0x0 0x0 0x1e00000 0x10000>;
 			little-endian;
Quoted 8 lines

arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi line 673

Quoted 6 lines
arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi +6 -0
+
+			fspi_clk: clock-controller@900 {
+				compatible = "fsl,lx2160a-flexspi-clk";
+				reg = <0x900 0x4>;
+				#clock-cells = <0>;
+				clocks = <&clockgen 4 0>;

This is different from the current <&clockgen 4 3>, is it an intended change?

Yes, this change was intended. At least on the LS1028A this clock divider is connected to the platform base clock. I don't know why there was "<&clockgen 4 3>" in the first place. But because the clkgen clock cannot be changed it didn't matter before this commit. The flexspi driver only calls clk_set_rate(), never clk_get_rate(). On the LS1028A I actually meassured the resulting SCK frequency.
Looking at Figure 7. (Clock subsystem block diagram) in the LX2160A RM, this seems to be the case here, too.

-michael

#8 lore raw

Re: [PATCH v2 5/5] arm64: dts: lx2160a: fix FlexSPI clock

Am 2020-11-06 09:11, schrieb Michael Walle:

Quoted 51 lines

Am 2020-11-06 03:00, schrieb Leo Li:

Quoted 41 lines
Quoted 41 lines

-----Original Message-----
From: Michael Walle <[email protected]>
Sent: Thursday, November 5, 2020 1:35 PM
To: [email protected]; [email protected]; linux- [email protected]; [email protected]
Cc: Michael Turquette <[email protected]>; Stephen Boyd <[email protected]>; Rob Herring <[email protected]>; Shawn Guo <[email protected]>; Leo Li <[email protected]>; Michael Walle <[email protected]>
Subject: [PATCH v2 5/5] arm64: dts: lx2160a: fix FlexSPI clock

Now that we have a proper driver for the FlexSPI interface use it. This will fix SCK frequency switching on Layerscape SoCs.

This was only compile time tested.

---
Changes since v1:
- none

 arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi +4 -1
index 83072da6f6c6..6e375e80bd35 100644
@@ -659,9 +659,20 @@
 		};
 
 		dcfg: syscon@1e00000 {
-			compatible = "fsl,lx2160a-dcfg", "syscon";
+			#address-cells = <1>;
+			#size-cells = <1>;
+			compatible = "fsl,lx2160a-dcfg", "syscon", "simple-
 mfd";
 			reg = <0x0 0x1e00000 0x0 0x10000>;
+			ranges = <0x0 0x0 0x1e00000 0x10000>;
 			little-endian;
Quoted 8 lines

arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi line 673

Quoted 6 lines
arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi +6 -0
+
+			fspi_clk: clock-controller@900 {
+				compatible = "fsl,lx2160a-flexspi-clk";
+				reg = <0x900 0x4>;
+				#clock-cells = <0>;
+				clocks = <&clockgen 4 0>;

This is different from the current <&clockgen 4 3>, is it an intended change?

Quoted 8 lines

Yes, this change was intended. At least on the LS1028A this clock divider is connected to the platform base clock. I don't know why there was "<&clockgen 4 3>" in the first place. But because the clkgen clock cannot be changed it didn't matter before this commit. The flexspi driver only calls clk_set_rate(), never clk_get_rate(). On the LS1028A I actually meassured the resulting SCK frequency.
Looking at Figure 7. (Clock subsystem block diagram) in the LX2160A RM, this seems to be the case here, too.

Btw on the LS1028A this should be "<&clockgen 2 0>;" Will be fixed in the new version.
And because there so much difference between LS1028A and LX2160A, I'll mark the last patch (this one, for the LX2160A) as RFC until someone will test it.

-michael