Nuvoton WPCM450 clock and reset driver
Subsystems (7)
Jonathan Neuschäfer
maintainerv4 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.
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 (6):
dt-bindings: timer: nuvoton,npcm7xx-timer: Allow specifying all clocks
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 | 364 ++++++++++++++++++ drivers/reset/Kconfig | 2 +- drivers/watchdog/npcm_wdt.c | 16 + .../dt-bindings/clock/nuvoton,wpcm450-clk.h | 67 ++++ 8 files changed, 544 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 v4 1/6 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.
---
v4:
- no changes
v3:
- Add R-b tag
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
Jonathan Neuschäfer
maintainerPATCH v4 2/6 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.
---
v4:
- Don't disable clock in npcm_wdt_restart function
v3:
- https://lore.kernel.org/lkml/[email protected]/
- Add enable/disable calls to npcm_wdt_restart handler
- Not applied due to the above change: Acked-by: Guenter Roeck <[email protected]>
v2:
- https://lore.kernel.org/lkml/[email protected]/
- Add clk_disable_unprepare call, suggested by Guenter Roeck
v1:
- https://lore.kernel.org/lkml/[email protected]/
--- drivers/watchdog/npcm_wdt.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/watchdog/npcm_wdt.c +16 -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 ; }
@@ -147,6 +155,10 @@ static int npcm_wdt_restart(struct watchdog_device *wdd, {struct npcm_wdt *wdt =to_npcm_wdt (wdd); +/* For reset, we start the WDT clock and leave it running. */ +if (wdt->clk) +clk_prepare_enable (wdt->clk); +writel (NPCM_WTR |NPCM_WTRE |NPCM_WTE , wdt->reg);udelay (1000 );
@@ -191,6 +203,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 v4 2/6] 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 85 lines
---
v4:
- Don't disable clock innpcm_wdt_restartfunctionv3:
- https://lore.kernel.org/lkml/[email protected]/
- Add enable/disable calls tonpcm_wdt_restarthandler
- Not applied due to the above change: Acked-by: Guenter Roeck <[email protected]>v2:
- https://lore.kernel.org/lkml/[email protected]/
- Addclk_disable_unpreparecall, suggested by Guenter Roeckv1:
- https://lore.kernel.org/lkml/[email protected]/--- drivers/watchdog/npcm_wdt.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)--
2.35.1drivers/watchdog/npcm_wdt.c +16
-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 ; }@@ -147,6 +155,10 @@ static int npcm_wdt_restart(struct watchdog_device *wdd, {struct npcm_wdt *wdt =to_npcm_wdt (wdd); +/* For reset, we start the WDT clock and leave it running. */ +if (wdt->clk) +clk_prepare_enable (wdt->clk); +writel (NPCM_WTR |NPCM_WTRE |NPCM_WTE , wdt->reg);udelay (1000 );@@ -191,6 +203,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;
Jonathan Neuschäfer
maintainerPATCH v4 3/6 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.
---
v4:
- 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 | 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: 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-output-names = "ref"; + 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.35.1
Jonathan Neuschäfer
maintainerPATCH v4 4/6 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.
---
v4:
- no changes
v3:
- Change clock-output-names and clock-names from "refclk" to "ref"
v2:
- https://lore.kernel.org/lkml/[email protected]/
- no changes
--- arch/arm/boot/dts/nuvoton-wpcm450.dtsi | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
arch/arm/boot/dts/nuvoton-wpcm450.dtsi +17 -0
@@ -37,6 +37,14 @@ clk24m: clock-24mhz { #clock-cells = <0>; }; + refclk: clock-48mhz { + /* 48 MHz reference oscillator */ + compatible = "fixed-clock"; + clock-output-names = "ref"; + clock-frequency = <48000000>; + #clock-cells = <0>; + }; + soc { compatible = "simple-bus"; #address-cells = <1>;
@@ -49,6 +57,15 @@ gcr: syscon@b0000000 { reg = <0xb0000000 0x200>; }; + clk: clock-controller@b0000200 { + compatible = "nuvoton,wpcm450-clk"; + reg = <0xb0000200 0x100>; + clocks = <&refclk>; + clock-names = "ref"; + #clock-cells = <1>; + #reset-cells = <1>; + }; + serial0: serial@b8000000 { compatible = "nuvoton,wpcm450-uart"; reg = <0xb8000000 0x20>;
--
2.35.1
Jonathan Neuschäfer
maintainerPATCH v4 5/6 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.
---
v4:
- Fix reset controller initialization
v3:
- https://lore.kernel.org/lkml/[email protected]/
- Change reference clock name from "refclk" to "ref"
- Remove unused variable in return path of wpcm450_clk_register_pll
- Remove unused divisor tables
v2:
- https://lore.kernel.org/lkml/[email protected]/
- no changes
--- drivers/clk/Makefile | 1 + drivers/clk/clk-wpcm450.c | 364 ++++++++++++++++++++++++++++++++++++++ drivers/reset/Kconfig | 2 +- 3 files changed, 366 insertions(+), 1 deletion(-) create mode 100644 drivers/clk/clk-wpcm450.c
drivers/clk/Makefile +1 -0
@@ -74,6 +74,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 +364 -0
364 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 v4 6/6 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-v4:
- 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";
@@ -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";
@@ -71,7 +65,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";
@@ -82,7 +76,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"; };
@@ -90,14 +84,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