Skip to contentSkip to conversation

Nuvoton WPCM450 clock and reset driver

PATCH Superseded Jonathan Neuschäfer 2 participants 7 messages Mar 10, 2024 – Mar 11, 2024

Subsystems (4)

v10 of 12 Superseded Latest is v12 →

lore
Share & tools
lore

Jonathan Neuschäfer

author maintainer
#0 lore raw

v10 cover Nuvoton WPCM450 clock and reset driver

This series adds support for the clock and reset controller in the Nuvoton WPCM450 SoC. This means that the clock rates for peripherals will be calculated automatically based on the clock tree as it was preconfigured by the bootloader. The 24 MHz dummy clock, that is currently in the devicetree, is no longer needed. Somewhat unfortunately, this also means that there is a breaking change once the devicetree starts relying on the clock driver, but I find it acceptable in this case, because WPCM450 is still at a somewhat early stage.

v10:
- A small tweak (using selected instead of extending an already-long default line) in Kconfig, for better robustness

v9:
- Various improvements to the driver
- No longer use global clock names (and the clock-output-names property) to refer to the reference clock, but instead rely on a phandle reference

v8:
- https://lore.kernel.org/lkml/[email protected]/
- Use %pe throughout the driver

v7:
- Simplified the error handling, by largely removing resource deallocation, which:
- was already incomplete
- would only happen in a case when the system is in pretty bad state because the clock driver didn't initialize correctly (in other words, the clock driver isn't optional enough that complex error handling really pays off)

v6:
- Dropped all patches except the clock binding and the clock driver, because they have mostly been merged
- Minor correction to how RESET_SIMPLE is selected

v5:
- Dropped patch 2 (watchdog: npcm: Enable clock if provided), which was since merged upstream
- Added patch 2 (clocksource: timer-npcm7xx: Enable timer 1 clock before use) again, because I wasn't able to find it in linux-next
- Switched the driver to using struct clk_parent_data
- Rebased on 6.1-rc3

v4:
- Leave WDT clock running during after restart handler
- Fix reset controller initialization
- Dropped patch 2/7 (clocksource: timer-npcm7xx: Enable timer 1 clock before use), as it was applied by Daniel Lezcano

v3:
- https://lore.kernel.org/lkml/[email protected]/
- Changed "refclk" string to "ref"
- Fixed some dead code in the driver
- Added clk_prepare_enable call to the watchdog restart handler
- Added a few review tags

v2:
- https://lore.kernel.org/lkml/[email protected]/
- various small improvements

v1:
- https://lore.kernel.org/lkml/[email protected]/

Jonathan Neuschäfer (4):
dt-bindings: clock: Add Nuvoton WPCM450 clock/reset controller
ARM: dts: wpcm450: Remove clock-output-names from reference clock node
clk: wpcm450: Add Nuvoton WPCM450 clock/reset controller driver
ARM: dts: wpcm450: Switch clocks to clock controller

 .../bindings/clock/nuvoton,wpcm450-clk.yaml   |  65 +++
 .../arm/boot/dts/nuvoton/nuvoton-wpcm450.dtsi |  23 +-
 drivers/clk/Makefile                          |   2 +-
 drivers/clk/nuvoton/Kconfig                   |  10 +-
 drivers/clk/nuvoton/Makefile                  |   1 +
 drivers/clk/nuvoton/clk-wpcm450.c             | 372 ++++++++++++++++++
 .../dt-bindings/clock/nuvoton,wpcm450-clk.h   |  67 ++++
 7 files changed, 525 insertions(+), 15 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/clock/nuvoton,wpcm450-clk.yaml
 create mode 100644 drivers/clk/nuvoton/clk-wpcm450.c
 create mode 100644 include/dt-bindings/clock/nuvoton,wpcm450-clk.h

--
2.43.0

author maintainer
#1 lore raw

PATCH v10 1/4 dt-bindings: clock: Add Nuvoton WPCM450 clock/reset controller

The Nuvoton WPCM450 SoC has a combined clock and reset controller. Add a devicetree binding for it, as well as definitions for the bit numbers used by it.

---
v10:
- no changes

v9:
- Remove clock-output-names in example, because it's now unnecessary due to driver improvements

v5-v8:
- no changes

v4:
- https://lore.kernel.org/lkml/[email protected]/
- Add R-b tag

v3:
- Change clock-output-names and clock-names from "refclk" to "ref", suggested by Krzysztof Kozlowski

v2:
- https://lore.kernel.org/lkml/[email protected]/
- Various improvements, suggested by Krzysztof Kozlowski

v1:
- https://lore.kernel.org/lkml/[email protected]/

---
 .../bindings/clock/nuvoton,wpcm450-clk.yaml   | 65 ++++++++++++++++++
 .../dt-bindings/clock/nuvoton,wpcm450-clk.h   | 67 +++++++++++++++++++
 2 files changed, 132 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/nuvoton,wpcm450-clk.yaml
 create mode 100644 include/dt-bindings/clock/nuvoton,wpcm450-clk.h
Documentation/devicetree/bindings/clock/nuvoton,wpcm450-clk.yaml new file +65 -0
new file mode 100644
index 00000000000000..93521cf68a040f
@@ -0,0 +1,65 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/clock/nuvoton,wpcm450-clk.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Nuvoton WPCM450 clock controller
+
+maintainers:
+  - Jonathan Neuschäfer <[email protected]>
+
+description:
+  The clock controller of the Nuvoton WPCM450 SoC supplies clocks and resets to
+  the rest of the chip.
+
+properties:
+  compatible:
+    const: nuvoton,wpcm450-clk
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    items:
+      - description: Reference clock oscillator (should be 48 MHz)
+
+  clock-names:
+    items:
+      - const: ref
+
+  '#clock-cells':
+    const: 1
+
+  '#reset-cells':
+    const: 1
+
+additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+  - '#clock-cells'
+
+examples:
+  - |
+    #include <dt-bindings/clock/nuvoton,wpcm450-clk.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    refclk: clock-48mhz {
+      /* 48 MHz reference oscillator */
+      compatible = "fixed-clock";
+      clock-frequency = <48000000>;
+      #clock-cells = <0>;
+    };
+
+    clk: clock-controller@b0000200 {
+      reg = <0xb0000200 0x100>;
+      compatible = "nuvoton,wpcm450-clk";
+      clocks = <&refclk>;
+      clock-names = "ref";
+      #clock-cells = <1>;
+      #reset-cells = <1>;
+    };
include/dt-bindings/clock/nuvoton,wpcm450-clk.h new file +67 -0

67 lines not on this page · raw message

--
2.43.0

author maintainer
#2 lore raw

PATCH v10 2/4 ARM: dts: wpcm450: Remove clock-output-names from reference clock node

In reply to Jonathan Neuschäfer

This is not necessary anymore, because the clk-wpcm450 driver doesn't rely on global clock names anymore.

---

v10:
- no changes

v9:
- New patch

---
 arch/arm/boot/dts/nuvoton/nuvoton-wpcm450.dtsi | 1 -
 1 file changed, 1 deletion(-)
arch/arm/boot/dts/nuvoton/nuvoton-wpcm450.dtsi +0 -1
index 6e1f0f164cb4f5..9dfdd8f67319d3 100644
@@ -40,7 +40,6 @@ clk24m: clock-24mhz {
 	refclk: clock-48mhz {
 		/* 48 MHz reference oscillator */
 		compatible = "fixed-clock";
-		clock-output-names = "ref";
 		clock-frequency = <48000000>;
 		#clock-cells = <0>;
 	};

--
2.43.0

#3 lore raw

Re: [PATCH v10 2/4] ARM: dts: wpcm450: Remove clock-output-names from reference clock node

Quoted 3 lines · Jonathan Neuschäfer

This is not necessary anymore, because the clk-wpcm450 driver doesn't rely on global clock names anymore.

Your commit msg should say: since which commit.

Best regards,
Krzysztof

author maintainer
#4 lore raw

Re: [PATCH v10 2/4] ARM: dts: wpcm450: Remove clock-output-names from reference clock node

Quoted 6 lines · Krzysztof Kozlowski
Quoted 3 lines · Jonathan Neuschäfer

This is not necessary anymore, because the clk-wpcm450 driver doesn't rely on global clock names anymore.

Your commit msg should say: since which commit.

Good point, I'll do that in the next iteration

author maintainer
#5 lore raw

PATCH v10 3/4 clk: wpcm450: Add Nuvoton WPCM450 clock/reset controller driver

In reply to Jonathan Neuschäfer

This driver implements the following features w.r.t. the clock and reset controller in the WPCM450 SoC:

- It calculates the rates for all clocks managed by the clock controller
- It leaves the clock tree mostly unchanged, except that it enables/ disables clock gates based on usage.
- It exposes the reset lines managed by the controller using the Generic Reset Controller subsystem

NOTE: If the driver and the corresponding devicetree node are present,
the driver will disable "unused" clocks. This is problem until the clock relations are properly declared in the devicetree (in a later patch). Until then, the clk_ignore_unused kernel parameter can be used as a workaround.

---

I have considered converting this driver to a platform driver instead of using CLK_OF_DECLARE, because platform drivers are generally the way forward. However, the timer-npcm7xx driver used on the same platform requires is initialized with TIMER_OF_DECLARE and thus requires the clocks to be available earlier than a platform driver can provide them.

v10:
- select RESET_{CONTROLLER,SIMPLE} from CLK_WPCM450 instead of messing with the 'default' statement

v9:
- Apply comments made by Stephen Boyd
- Move to drivers/clk/nuvoton/ directory
- Update SPDX license identifier from GPL-2.0 to GPL-2.0-only
- Rename clk_np variable to np
- Use of_clk_hw_register
- Refer to clock parents by .fw_name

v8:
- https://lore.kernel.org/lkml/[email protected]/
- Use %pe format specifier throughout the driver, as suggested by Philipp Zabel
- Add Joel's R-b

v7:
- https://lore.kernel.org/lkml/[email protected]/
- Simplify error handling by not deallocating resources

v6:
- Enable RESET_SIMPLE based on ARCH_WPCM450, not ARCH_NPCM, as suggested by Tomer Maimon

v5:
- https://lore.kernel.org/lkml/[email protected]/
- Switch to using clk_parent_data

v4:
- Fix reset controller initialization

v3:
- Change reference clock name from "refclk" to "ref"
- Remove unused variable in return path of wpcm450_clk_register_pll
- Remove unused divisor tables

v2:
- no changes

---
 drivers/clk/Makefile              |   2 +-
 drivers/clk/nuvoton/Kconfig       |  10 +-
 drivers/clk/nuvoton/Makefile      |   1 +
 drivers/clk/nuvoton/clk-wpcm450.c | 372 ++++++++++++++++++++++++++++++
 4 files changed, 383 insertions(+), 2 deletions(-)
 create mode 100644 drivers/clk/nuvoton/clk-wpcm450.c
drivers/clk/Makefile +1 -1
index 14fa8d4ecc1fbe..cdeb2ecf3a8e99 100644
@@ -107,7 +107,7 @@ endif
 obj-y					+= mstar/
 obj-y					+= mvebu/
 obj-$(CONFIG_ARCH_MXS)			+= mxs/
-obj-$(CONFIG_ARCH_MA35)			+= nuvoton/
+obj-y					+= nuvoton/
 obj-$(CONFIG_COMMON_CLK_NXP)		+= nxp/
 obj-$(CONFIG_COMMON_CLK_PISTACHIO)	+= pistachio/
 obj-$(CONFIG_COMMON_CLK_PXA)		+= pxa/
drivers/clk/nuvoton/Kconfig +9 -1
index fe4b7f62f46704..908881654b2e91 100644
@@ -3,7 +3,7 @@
 
 config COMMON_CLK_NUVOTON
 	bool "Nuvoton clock controller common support"
-	depends on ARCH_MA35 || COMPILE_TEST
+	depends on ARCH_MA35 || ARCH_NPCM || COMPILE_TEST
 	default y
 	help
 	  Say y here to enable common clock controller for Nuvoton platforms.
@@ -16,4 +16,12 @@ config CLK_MA35D1
 	help
 	  Build the clock controller driver for MA35D1 SoC.
 
+config CLK_WPCM450
+	bool "Nuvoton WPCM450 clock/reset controller support"
+	default y
+	select RESET_CONTROLLER
+	select RESET_SIMPLE
+	help
+	  Build the clock and reset controller driver for the WPCM450 SoC.
+
 endif
drivers/clk/nuvoton/Makefile +1 -0
index c3c59dd9f2aaab..b130f0d3889ca0 100644
@@ -2,3 +2,4 @@
 obj-$(CONFIG_CLK_MA35D1) += clk-ma35d1.o
 obj-$(CONFIG_CLK_MA35D1) += clk-ma35d1-divider.o
 obj-$(CONFIG_CLK_MA35D1) += clk-ma35d1-pll.o
+obj-$(CONFIG_CLK_WPCM450) += clk-wpcm450.o
drivers/clk/nuvoton/clk-wpcm450.c new file +372 -0

372 lines not on this page · raw message

--
2.43.0

author maintainer
#6 lore raw

PATCH v10 4/4 ARM: dts: wpcm450: Switch clocks to clock controller

In reply to Jonathan Neuschäfer

This change is incompatible with older kernels because it requires the clock controller driver, but I think that's acceptable because WPCM450 support is generally still in an early phase.

---

It's probably best to delay merging of this patch until after the driver is merged; I'm including it here for review, and in case someone want's to set up a shared branch between the clock and devicetree parts.

v10:
- Reintroducing this patch as part of the clock/reset controller series

---
 .../arm/boot/dts/nuvoton/nuvoton-wpcm450.dtsi | 22 +++++++++----------
 1 file changed, 10 insertions(+), 12 deletions(-)
arch/arm/boot/dts/nuvoton/nuvoton-wpcm450.dtsi +10 -12
index 9dfdd8f67319d3..7e3ea8b31151b3 100644
@@ -2,6 +2,7 @@
 // Copyright 2021 Jonathan Neuschäfer
 
 #include <dt-bindings/interrupt-controller/irq.h>
+#include <dt-bindings/clock/nuvoton,wpcm450-clk.h>
 
 / {
 	compatible = "nuvoton,wpcm450";
@@ -30,13 +31,6 @@ cpu@0 {
 		};
 	};
 
-	clk24m: clock-24mhz {
-		/* 24 MHz dummy clock */
-		compatible = "fixed-clock";
-		clock-frequency = <24000000>;
-		#clock-cells = <0>;
-	};
-
 	refclk: clock-48mhz {
 		/* 48 MHz reference oscillator */
 		compatible = "fixed-clock";
@@ -70,7 +64,7 @@ serial0: serial@b8000000 {
 			reg = <0xb8000000 0x20>;
 			reg-shift = <2>;
 			interrupts = <7 IRQ_TYPE_LEVEL_HIGH>;
-			clocks = <&clk24m>;
+			clocks = <&clk WPCM450_CLK_UART0>;
 			pinctrl-names = "default";
 			pinctrl-0 = <&bsp_pins>;
 			status = "disabled";
@@ -81,7 +75,7 @@ serial1: serial@b8000100 {
 			reg = <0xb8000100 0x20>;
 			reg-shift = <2>;
 			interrupts = <8 IRQ_TYPE_LEVEL_HIGH>;
-			clocks = <&clk24m>;
+			clocks = <&clk WPCM450_CLK_UART1>;
 			status = "disabled";
 		};
 
@@ -89,14 +83,18 @@ timer0: timer@b8001000 {
 			compatible = "nuvoton,wpcm450-timer";
 			interrupts = <12 IRQ_TYPE_LEVEL_HIGH>;
 			reg = <0xb8001000 0x1c>;
-			clocks = <&clk24m>;
+			clocks = <&clk WPCM450_CLK_TIMER0>,
+				 <&clk WPCM450_CLK_TIMER1>,
+				 <&clk WPCM450_CLK_TIMER2>,
+				 <&clk WPCM450_CLK_TIMER3>,
+				 <&clk WPCM450_CLK_TIMER4>;
 		};
 
 		watchdog0: watchdog@b800101c {
 			compatible = "nuvoton,wpcm450-wdt";
 			interrupts = <1 IRQ_TYPE_LEVEL_HIGH>;
 			reg = <0xb800101c 0x4>;
-			clocks = <&clk24m>;
+			clocks = <&clk WPCM450_CLK_WDT>;
 		};
 
 		aic: interrupt-controller@b8002000 {
@@ -480,7 +478,7 @@ fiu: spi-controller@c8000000 {
 			#size-cells = <0>;
 			reg = <0xc8000000 0x1000>, <0xc0000000 0x4000000>;
 			reg-names = "control", "memory";
-			clocks = <&clk 0>;
+			clocks = <&clk WPCM450_CLK_FIU>;
 			nuvoton,shm = <&shm>;
 			status = "disabled";
 		};

--
2.43.0