Nuvoton WPCM450 clock and reset driver
Subsystems (7)
Jonathan Neuschäfer
maintainerv2 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.
Upstreaming plan (although other suggestions are welcome):
Once reviewed,
- The ARM/dts changes should go through Joel Stanley's bmc tree
- The clocksource/timer changes should probably go via Daniel Lezcano and TIP
- The watchdog patch should go via the watchdog tree
- The clock controller bindings and driver should go through the clk tree
- It might make sense to delay the final ARM/dts patch ("ARM: dts: wpcm450:
Switch clocks to clock controller") until next cycle to make sure it is merged after the clock driver.
New in version 2:
- various small improvements
v1:
- https://lore.kernel.org/lkml/[email protected]/
Jonathan Neuschäfer (7):
dt-bindings: timer: nuvoton,npcm7xx-timer: Allow specifying all clocks
clocksource: timer-npcm7xx: Enable timer 1 clock before use
watchdog: npcm: Enable clock if provided
dt-bindings: clock: Add Nuvoton WPCM450 clock/reset controller
ARM: dts: wpcm450: Add clock controller node
clk: wpcm450: Add Nuvoton WPCM450 clock/reset controller driver
ARM: dts: wpcm450: Switch clocks to clock controller
.../bindings/clock/nuvoton,wpcm450-clk.yaml | 66 +++ .../bindings/timer/nuvoton,npcm7xx-timer.yaml | 8 +- arch/arm/boot/dts/nuvoton-wpcm450.dtsi | 29 +- drivers/clk/Makefile | 1 + drivers/clk/clk-wpcm450.c | 378 ++++++++++++++++++ drivers/clocksource/timer-npcm7xx.c | 10 + drivers/reset/Kconfig | 2 +- drivers/watchdog/npcm_wdt.c | 12 + .../dt-bindings/clock/nuvoton,wpcm450-clk.h | 67 ++++ 9 files changed, 564 insertions(+), 9 deletions(-) create mode 100644 Documentation/devicetree/bindings/clock/nuvoton,wpcm450-clk.yaml create mode 100644 drivers/clk/clk-wpcm450.c create mode 100644 include/dt-bindings/clock/nuvoton,wpcm450-clk.h
--
2.35.1
Jonathan Neuschäfer
maintainerPATCH v2 1/7 dt-bindings: timer: nuvoton,npcm7xx-timer: Allow specifying all clocks
The timer module contains multiple timers. In the WPCM450 SoC, each timer runs off a clock can be gated individually. To model this correctly, the timer node in the devicetree needs to take multiple clock inputs.
---
v2:
- no changes
--- .../devicetree/bindings/timer/nuvoton,npcm7xx-timer.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.yaml +7 -1
@@ -23,7 +23,13 @@ properties: - description: The timer interrupt of timer 0 clocks: - maxItems: 1 + items: + - description: The reference clock for timer 0 + - description: The reference clock for timer 1 + - description: The reference clock for timer 2 + - description: The reference clock for timer 3 + - description: The reference clock for timer 4 + minItems: 1 required: - compatible
--
2.35.1
Re: [PATCH v2 1/7] dt-bindings: timer: nuvoton,npcm7xx-timer: Allow specifying all clocks
Quoted 4 lines · Jonathan Neuschäfer
The timer module contains multiple timers. In the WPCM450 SoC, each timer runs off a clock can be gated individually. To model this correctly, the timer node in the devicetree needs to take multiple clock inputs.
Quoted 9 lines
Signed-off-by Jonathan Neuschäfer <[email protected]>---
v2:
- no changes--- .../devicetree/bindings/timer/nuvoton,npcm7xx-timer.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
Jonathan Neuschäfer
maintainerPATCH v2 2/7 clocksource: timer-npcm7xx: Enable timer 1 clock before use
In reply to Jonathan NeuschäferIn the WPCM450 SoC, the clocks for each timer can be gated individually. To prevent the timer 1 clock from being gated, enable it explicitly.
---
v2:
- Provide context in pr_warn message
v1:
- https://lore.kernel.org/lkml/[email protected]/
--- drivers/clocksource/timer-npcm7xx.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/clocksource/timer-npcm7xx.c +10 -0
@@ -188,6 +188,7 @@ static void __init npcm7xx_clocksource_init(void)static int __init npcm7xx_timer_init (struct device_node *np) { +struct clk *clk;int ret; ret =timer_of_init (np, &npcm7xx_to);
@@ -199,6 +200,15 @@ static int __init npcm7xx_timer_init(struct device_node *np) npcm7xx_to.of_clk.rate = npcm7xx_to.of_clk.rate / (NPCM7XX_Tx_MIN_PRESCALE +1 ); +/* Enable the clock for timer1, if it exists */ + clk =of_clk_get (np,1 ); +if (clk) { +if (!IS_ERR (clk)) +clk_prepare_enable (clk); +else +pr_warn ("%pOF: Failed to get clock for timer1: %pe" , np, clk); + } +npcm7xx_clocksource_init ();npcm7xx_clockevents_init ();
--
2.35.1
Jonathan Neuschäfer
maintainerPATCH v2 3/7 watchdog: npcm: Enable clock if provided
In reply to Jonathan NeuschäferOn the Nuvoton WPCM450 SoC, with its upcoming clock driver, peripheral clocks are individually gated and ungated. Therefore, the watchdog driver must be able to ungate the watchdog clock.
---
v2:
- Add clk_disable_unprepare call, suggested by Guenter Roeck
v1:
- https://lore.kernel.org/lkml/[email protected]/
--- drivers/watchdog/npcm_wdt.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/watchdog/npcm_wdt.c +12 -0
@@ -3,6 +3,7 @@// Copyright (c) 2018 IBM Corp. #include <linux/bitops.h> +#include <linux/clk.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/kernel.h>
@@ -43,6 +44,7 @@struct npcm_wdt {struct watchdog_device wdd;void __iomem *reg; +struct clk *clk; };static inline struct npcm_wdt *to_npcm_wdt (struct watchdog_device *wdd)
@@ -66,6 +68,9 @@ static int npcm_wdt_start(struct watchdog_device *wdd)struct npcm_wdt *wdt =to_npcm_wdt (wdd);u32 val; +if (wdt->clk) +clk_prepare_enable (wdt->clk); +if (wdd->timeout <2 ) val =0x800 ;else if (wdd->timeout <3 )
@@ -100,6 +105,9 @@ static int npcm_wdt_stop(struct watchdog_device *wdd)writel (0 , wdt->reg); +if (wdt->clk) +clk_disable_unprepare (wdt->clk); +return 0 ; }
@@ -191,6 +199,10 @@ static int npcm_wdt_probe(struct platform_device *pdev)if (IS_ERR (wdt->reg))return PTR_ERR (wdt->reg); + wdt->clk =devm_clk_get_optional (&pdev->dev,NULL ); +if (IS_ERR (wdt->clk)) +return PTR_ERR (wdt->clk); + irq =platform_get_irq (pdev,0 );if (irq <0 )return irq;
--
2.35.1
Re: [PATCH v2 3/7] watchdog: npcm: Enable clock if provided
Quoted 5 lines · Jonathan Neuschäfer
On the Nuvoton WPCM450 SoC, with its upcoming clock driver, peripheral clocks are individually gated and ungated. Therefore, the watchdog driver must be able to ungate the watchdog clock.
Signed-off-by Jonathan Neuschäfer <[email protected]>
Quoted 65 lines
---
v2:
- Addclk_disable_unpreparecall, suggested by Guenter Roeckv1:
- https://lore.kernel.org/lkml/[email protected]/--- drivers/watchdog/npcm_wdt.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)drivers/watchdog/npcm_wdt.c +12
-1@@ -3,6 +3,7 @@// Copyright (c) 2018 IBM Corp. #include <linux/bitops.h> +#include <linux/clk.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/kernel.h> @@ -43,6 +44,7 @@struct npcm_wdt {struct watchdog_device wdd;void __iomem *reg; +struct clk *clk; };static inline struct npcm_wdt *to_npcm_wdt (struct watchdog_device *wdd)@@ -66,6 +68,9 @@ static int npcm_wdt_start(struct watchdog_device *wdd)struct npcm_wdt *wdt =to_npcm_wdt (wdd);u32 val; +if (wdt->clk) +clk_prepare_enable (wdt->clk); +if (wdd->timeout <2 ) val =0x800 ;else if (wdd->timeout <3 )@@ -100,6 +105,9 @@ static int npcm_wdt_stop(struct watchdog_device *wdd)writel (0 , wdt->reg); +if (wdt->clk) +clk_disable_unprepare (wdt->clk); +return 0 ; }@@ -191,6 +199,10 @@ static int npcm_wdt_probe(struct platform_device *pdev)if (IS_ERR (wdt->reg))return PTR_ERR (wdt->reg); + wdt->clk =devm_clk_get_optional (&pdev->dev,NULL ); +if (IS_ERR (wdt->clk)) +return PTR_ERR (wdt->clk); + irq =platform_get_irq (pdev,0 );if (irq <0 )return irq; --2.35.1
Jonathan Neuschäfer
maintainerPATCH v2 4/7 dt-bindings: clock: Add Nuvoton WPCM450 clock/reset controller
In reply to Jonathan NeuschäferThe 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.
---
v2:
- Various improvements, suggested by Krzysztof Kozlowski
v1:
- https://lore.kernel.org/lkml/[email protected]/
--- .../bindings/clock/nuvoton,wpcm450-clk.yaml | 66 ++++++++++++++++++ .../dt-bindings/clock/nuvoton,wpcm450-clk.h | 67 +++++++++++++++++++ 2 files changed, 133 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 +66 -0
@@ -0,0 +1,66 @@ +# 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: refclk + + '#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-output-names = "refclk"; + clock-frequency = <48000000>; + #clock-cells = <0>; + }; + + clk: clock-controller@b0000200 { + reg = <0xb0000200 0x100>; + compatible = "nuvoton,wpcm450-clk"; + clocks = <&refclk>; + clock-names = "refclk"; + #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.35.1
Re: [PATCH v2 4/7] dt-bindings: clock: Add Nuvoton WPCM450 clock/reset controller
Quoted 44 lines · Jonathan Neuschäfer
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.
Signed-off-by Jonathan Neuschäfer <[email protected]>---
v2:
- Various improvements, suggested by Krzysztof Kozlowskiv1:
- https://lore.kernel.org/lkml/[email protected]/--- .../bindings/clock/nuvoton,wpcm450-clk.yaml | 66 ++++++++++++++++++ .../dt-bindings/clock/nuvoton,wpcm450-clk.h | 67 +++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/nuvoton,wpcm450-clk.yaml create mode 100644 include/dt-bindings/clock/nuvoton,wpcm450-clk.hDocumentation/devicetree/bindings/clock/nuvoton,wpcm450-clk.yaml new file +19
-0@@ -0,0 +1,66 @@ +# 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 +
Documentation/devicetree/bindings/clock/nuvoton,wpcm450-clk.yaml line 29
Quoted 10 lines
Documentation/devicetree/bindings/clock/nuvoton,wpcm450-clk.yaml new file +10
-0+ reg: + maxItems: 1 + + clocks: + items: + - description: Reference clock oscillator (should be 48 MHz) + + clock-names: + items: + - const: refclk
Sorry for not bringing it up earlier - this should be just "ref". Names in values should not have suffixes (so no "tx-dma", "wake-gpio", "ref-clk" etc).
Best regards,
Krzysztof
Jonathan Neuschäfer
maintainerRe: [PATCH v2 4/7] dt-bindings: clock: Add Nuvoton WPCM450 clock/reset controller
Quoted 7 lines · Krzysztof Kozlowski
Quoted 6 lines · Jonathan Neuschäfer
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.
Signed-off-by Jonathan Neuschäfer <[email protected]>---
[...]
Quoted 7 lines
Documentation/devicetree/bindings/clock/nuvoton,wpcm450-clk.yaml line 29
Quoted 3 lines
Documentation/devicetree/bindings/clock/nuvoton,wpcm450-clk.yaml new file +3
-0+ clock-names: + items: + - const: refclkSorry for not bringing it up earlier - this should be just "ref". Names in values should not have suffixes (so no "tx-dma", "wake-gpio", "ref-clk" etc).
Ok, I'll fix it throughout the patchset.
Jonathan
Jonathan Neuschäfer
maintainerPATCH v2 5/7 ARM: dts: wpcm450: Add clock controller node
In reply to Jonathan NeuschäferThis declares the clock controller and the necessary 48 Mhz reference clock in the WPCM450 device. Switching devices over to the clock controller is intentionally done in a separate patch to give time for the clock controller driver to land.
---
v2:
- no changes
--- arch/arm/boot/dts/nuvoton-wpcm450.dtsi | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
arch/arm/boot/dts/nuvoton-wpcm450.dtsi +17 -0
@@ -39,6 +39,14 @@ clk24m: clock-24mhz { #clock-cells = <0>; }; + refclk: clock-48mhz { + /* 48 MHz reference oscillator */ + compatible = "fixed-clock"; + clock-output-names = "refclk"; + clock-frequency = <48000000>; + #clock-cells = <0>; + }; + soc { compatible = "simple-bus"; #address-cells = <1>;
@@ -51,6 +59,15 @@ gcr: syscon@b0000000 { reg = <0xb0000000 0x200>; }; + clk: clock-controller@b0000200 { + compatible = "nuvoton,wpcm450-clk"; + reg = <0xb0000200 0x100>; + clocks = <&refclk>; + clock-names = "refclk"; + #clock-cells = <1>; + #reset-cells = <1>; + }; + serial0: serial@b8000000 { compatible = "nuvoton,wpcm450-uart"; reg = <0xb8000000 0x20>;
--
2.35.1
Jonathan Neuschäfer
maintainerPATCH v2 6/7 clk: wpcm450: Add Nuvoton WPCM450 clock/reset controller driver
In reply to Jonathan NeuschäferThis 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.
---
v2:
- no changes
--- drivers/clk/Makefile | 1 + drivers/clk/clk-wpcm450.c | 378 ++++++++++++++++++++++++++++++++++++++ drivers/reset/Kconfig | 2 +- 3 files changed, 380 insertions(+), 1 deletion(-) create mode 100644 drivers/clk/clk-wpcm450.c
drivers/clk/Makefile +1 -0
@@ -73,6 +73,7 @@ obj-$(CONFIG_ARCH_VT8500) += clk-vt8500.o obj-$(CONFIG_COMMON_CLK_RS9_PCIE) += clk-renesas-pcie.o obj-$(CONFIG_COMMON_CLK_VC5) += clk-versaclock5.o obj-$(CONFIG_COMMON_CLK_WM831X) += clk-wm831x.o +obj-$(CONFIG_ARCH_WPCM450) += clk-wpcm450.o obj-$(CONFIG_COMMON_CLK_XGENE) += clk-xgene.o # please keep this section sorted lexicographically by directory path name
drivers/clk/clk-wpcm450.c new file +378 -0
378 lines not on this page · raw message
drivers/reset/Kconfig +1 -1
@@ -201,7 +201,7 @@ config RESET_SCMI config RESET_SIMPLE bool "Simple Reset Controller Driver" if COMPILE_TEST - default ARCH_ASPEED || ARCH_BCM4908 || ARCH_BITMAIN || ARCH_REALTEK || ARCH_STM32 || (ARCH_INTEL_SOCFPGA && ARM64) || ARCH_SUNXI || ARC + default ARCH_ASPEED || ARCH_BCM4908 || ARCH_BITMAIN || ARCH_REALTEK || ARCH_STM32 || (ARCH_INTEL_SOCFPGA && ARM64) || ARCH_SUNXI || ARC || ARCH_NPCM help This enables a simple reset controller driver for reset lines that that can be asserted and deasserted by toggling bits in a contiguous,
--
2.35.1
Jonathan Neuschäfer
maintainerPATCH v2 7/7 ARM: dts: wpcm450: Switch clocks to clock controller
In reply to Jonathan NeuschäferThis 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.
---
v2:
- no changes
--- arch/arm/boot/dts/nuvoton-wpcm450.dtsi | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)
arch/arm/boot/dts/nuvoton-wpcm450.dtsi +9 -11
@@ -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";
@@ -32,13 +33,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";
@@ -73,7 +67,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";
@@ -84,7 +78,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"; };
@@ -92,14 +86,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 {
--
2.35.1