Skip to contentSkip to conversation

clocksource: npcm: add NPCM7xx timer driver

PATCH Superseded Tomer Maimon 3 participants 7 messages Feb 26, 2018 – Mar 7, 2018

Subsystems (3)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Tomer Maimon

author maintainer
#0 lore raw

v4 cover clocksource: npcm: add NPCM7xx timer driver

Addressed comments from:.
- Brendan Higgins: https://www.spinics.net/lists/devicetree/msg202331.html

Changes since version 3:
- Modify prefix to npcm7xx_
- Modify licensing to SPDX license format

Changes since version 2:
- The shutdown function called oneshot function that can cause a crash in the system, Modify shutdown call to unique shutdown function.
- Adding support to resume function
- Using timer-of.c API
- Modify NPCM750 compatible name.

Changes since version 1:
- Rename driver name
- Removing unnecessary dependencies in configuration
- Adding prefix to the macros
- No changes to dt-binding documentation since v1

Modified driver have been tested on the NPCM750 evaluation board.

Tomer Maimon (2):
dt-binding: timer: document NPCM7xx timer DT bindings
clocksource: npcm: add NPCM7xx timer driver

 .../bindings/timer/nuvoton,npcm7xx-timer.txt       |  25 +++
 drivers/clocksource/Kconfig                        |   8 +
 drivers/clocksource/Makefile                       |   1 +
 drivers/clocksource/npcm7xx-timer.c                | 237 +++++++++++++++++++++
 4 files changed, 271 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt
 create mode 100644 drivers/clocksource/npcm7xx-timer.c
Signature · 1 line
2.14.1
author maintainer
#1 lore raw

PATCH v4 1/2 dt-binding: timer: document NPCM7xx timer DT bindings

Added device tree binding documentation for Nuvoton NPCM7xx timer.

---
 .../bindings/timer/nuvoton,npcm7xx-timer.txt       | 25 ++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt
Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt new file +25 -0
new file mode 100644
index 000000000000..c5150522e618
@@ -0,0 +1,25 @@
+Nuvoton NPCM7xx timer
+
+Nuvoton NPCM7xx have three timer modules, each timer module provides five 24-bit
+timer counters.
+
+Required properties:
+- compatible      : "nuvoton,npcm750-timer" for Poleg NPCM750.
+- reg             : Offset and length of the register set for the device.
+- interrupts      : Contain the timer interrupt with flags for
+                    falling edge.
+
+Required clocking property, have to be one of:
+- clocks          : phandle of timer reference clock.
+- clock-frequency : The frequency in Hz of the clock that drives the NPCM7xx
+                    timer (usually 25000000).
+
+Example:
+
+timer@f0008000 {
+    compatible = "nuvoton,npcm750-timer";
+    interrupts = <GIC_SPI 32 IRQ_TYPE_LEVEL_HIGH>;
+    reg = <0xf0008000 0x1000>;
+    clocks = <&clk NPCM7XX_CLK_TIMER>;
+};
+
Signature · 1 line
2.14.1
#2 lore raw

Re: [PATCH v4 1/2] dt-binding: timer: document NPCM7xx timer DT bindings

Hi Tomer,

Quoted 16 lines · Tomer Maimon

Added device tree binding documentation for Nuvoton NPCM7xx timer.

---
 .../bindings/timer/nuvoton,npcm7xx-timer.txt       | 25 ++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt
Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt new file +0 -0
new file mode 100644
index 000000000000..c5150522e618

Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt line 1

Quoted 1 line
Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt new file +1 -0
@@ -0,0 +1,25 @@
+Nuvoton NPCM7xx timer

Would it make more sense to all this Nuvoton NPCM Timer? This way the name stays generic for when you add other systems.

Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt line 4

Quoted 3 lines
Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt new file +3 -0
+
+Nuvoton NPCM7xx have three timer modules, each timer module provides five 24-bit
+timer counters.

I notice the timer has a register in the middle of it that is used for the watchdog. Should we describe this in the same binding? Even if we just add some text that adds

... and one watchdog register.

Quoted 8 lines
Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt new file +8 -0
+
+Required properties:
+- compatible      : "nuvoton,npcm750-timer" for Poleg NPCM750.
+- reg             : Offset and length of the register set for the device.
+- interrupts      : Contain the timer interrupt with flags for
+                    falling edge.
+
+Required clocking property, have to be one of:

Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt line 22

Quoted 10 lines
Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt new file +10 -0
+- clocks          : phandle of timer reference clock.
+- clock-frequency : The frequency in Hz of the clock that drives the NPCM7xx
+                    timer (usually 25000000).
+
+Example:
+
+timer@f0008000 {
+    compatible = "nuvoton,npcm750-timer";
+    interrupts = <GIC_SPI 32 IRQ_TYPE_LEVEL_HIGH>;
+    reg = <0xf0008000 0x1000>;

This can probably be <0xf0008000 0x50>, as tthe timer hardware only has registers up to base + 0x50.

Quoted 6 lines
Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt new file +3 -1
+    clocks = <&clk NPCM7XX_CLK_TIMER>;
+};
+
--

2.14.1

author maintainer
#3 lore raw

Re: [PATCH v4 1/2] dt-binding: timer: document NPCM7xx timer DT bindings

Sorry for the late response

Quoted 13 lines · Joel Stanley

Hi Tomer,

Quoted 10 lines · Tomer Maimon

Added device tree binding documentation for Nuvoton NPCM7xx timer.

---
 .../bindings/timer/nuvoton,npcm7xx-timer.txt       | 25 ++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt
Quoted 11 lines

Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt line 1

Quoted 7 lines
Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt new file +1 -0
new file mode 100644
index 000000000000..c5150522e618
@@ -0,0 +1,25 @@
+Nuvoton NPCM7xx timer

Would it make more sense to all this Nuvoton NPCM Timer? This way the name stays generic for when you add other systems.

we cant promise the timer will stay the same in the next generation, I will leave this for NPCM7xx

Quoted 11 lines

Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt line 4

Quoted 3 lines
Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt new file +3 -0
+
+Nuvoton NPCM7xx have three timer modules, each timer module provides five 24-bit
+timer counters.

I notice the timer has a register in the middle of it that is used for the watchdog. Should we describe this in the same binding? Even if we just add some text that adds

... and one watchdog register.

I'm not sure, because the binding is only for the timer I dont think I need to describe what is the
register contains

Quoted 13 lines
Quoted 13 lines
Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt new file +13 -0
+
+Required properties:
+- compatible      : "nuvoton,npcm750-timer" for Poleg NPCM750.
+- reg             : Offset and length of the register set for the device.
+- interrupts      : Contain the timer interrupt with flags for
+                    falling edge.
+
+Required clocking property, have to be one of:
+- clocks          : phandle of timer reference clock.
+- clock-frequency : The frequency in Hz of the clock that drives the NPCM7xx
+                    timer (usually 25000000).
+
+Example:
Quoted 8 lines

Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt line 22

Quoted 5 lines
Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt new file +5 -0
+
+timer@f0008000 {
+    compatible = "nuvoton,npcm750-timer";
+    interrupts = <GIC_SPI 32 IRQ_TYPE_LEVEL_HIGH>;
+    reg = <0xf0008000 0x1000>;

This can probably be <0xf0008000 0x50>, as tthe timer hardware only has registers up to base + 0x50.

Thanks,
I will modify it in the next version, waiting fro more comments.

Quoted 7 lines
Quoted 7 lines
Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt new file +3 -1
+    clocks = <&clk NPCM7XX_CLK_TIMER>;
+};
+
--

2.14.1

Cheers,

Tomer

#4 lore raw

Re: [PATCH v4 1/2] dt-binding: timer: document NPCM7xx timer DT bindings

In reply to Tomer Maimon
Quoted 21 lines · Tomer Maimon

Added device tree binding documentation for Nuvoton NPCM7xx timer.

---
 .../bindings/timer/nuvoton,npcm7xx-timer.txt       | 25 ++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt
Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt new file +5 -0
new file mode 100644
index 000000000000..c5150522e618
@@ -0,0 +1,25 @@
+Nuvoton NPCM7xx timer
+
+Nuvoton NPCM7xx have three timer modules, each timer module provides five 24-bit
+timer counters.
+

Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt line 15

Quoted 10 lines
Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt new file +10 -0
+Required properties:
+- compatible      : "nuvoton,npcm750-timer" for Poleg NPCM750.
+- reg             : Offset and length of the register set for the device.
+- interrupts      : Contain the timer interrupt with flags for
+                    falling edge.
+
+Required clocking property, have to be one of:
+- clocks          : phandle of timer reference clock.
+- clock-frequency : The frequency in Hz of the clock that drives the NPCM7xx
+                    timer (usually 25000000).

Why one of these and not the phandle only ? That will make the driver cleaner.

Quoted 11 lines
Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt new file +10 -0
+
+Example:
+
+timer@f0008000 {
+    compatible = "nuvoton,npcm750-timer";
+    interrupts = <GIC_SPI 32 IRQ_TYPE_LEVEL_HIGH>;
+    reg = <0xf0008000 0x1000>;
+    clocks = <&clk NPCM7XX_CLK_TIMER>;
+};
+
Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
author maintainer
#5 lore raw

PATCH v4 2/2 clocksource: npcm: add NPCM7xx timer driver

In reply to Tomer Maimon

Add Nuvoton BMC NPCM7xx timer driver.

the clocksource Enable 24-bit TIMER0 and TIMER1 counters, while TIMER0 serve as clockevent and TIMER1 serve as clocksource.

---
 drivers/clocksource/Kconfig         |   8 ++
 drivers/clocksource/Makefile        |   1 +
 drivers/clocksource/npcm7xx-timer.c | 237 ++++++++++++++++++++++++++++++++++++
 3 files changed, 246 insertions(+)
 create mode 100644 drivers/clocksource/npcm7xx-timer.c
drivers/clocksource/Kconfig +8 -0
index b3b4ed9b6874..bfc80653d89f 100644
@@ -130,6 +130,14 @@ config VT8500_TIMER
 	help
 	  Enables support for the VT8500 driver.
 
+config NPCM7XX_TIMER
+	bool "NPCM7xx timer driver" if COMPILE_TEST
+	depends on HAS_IOMEM
+	select CLKSRC_MMIO
+	help
+	  Enable 24-bit TIMER0 and TIMER1 counters in the NPCM7xx arcithcture,
+	  While TIMER0 serves as clockevent and TIMER1 serves as clocksource.
+
 config CADENCE_TTC_TIMER
 	bool "Cadence TTC timer driver" if COMPILE_TEST
 	depends on COMMON_CLK
drivers/clocksource/Makefile +1 -0
index d6dec4489d66..b16c1a2b9e0d 100644
@@ -55,6 +55,7 @@ obj-$(CONFIG_CLKSRC_NPS)	+= timer-nps.o
 obj-$(CONFIG_OXNAS_RPS_TIMER)	+= timer-oxnas-rps.o
 obj-$(CONFIG_OWL_TIMER)		+= owl-timer.o
 obj-$(CONFIG_SPRD_TIMER)	+= timer-sprd.o
+obj-$(CONFIG_NPCM7XX_TIMER)	+= npcm7xx-timer.o
 
 obj-$(CONFIG_ARC_TIMERS)		+= arc_timer.o
 obj-$(CONFIG_ARM_ARCH_TIMER)		+= arm_arch_timer.o
drivers/clocksource/npcm7xx-timer.c new file +237 -0

237 lines not on this page · raw message

Signature · 1 line
2.14.1
#6 lore raw

Hi Tomer,

change the subject to: clocksource/drivers/npcm: Add NPCM7xx timer driver

Quoted 7 lines · Tomer Maimon

Add Nuvoton BMC NPCM7xx timer driver.

the clocksource Enable 24-bit TIMER0 and TIMER1 counters, while TIMER0 serve as clockevent and TIMER1 serve as clocksource.

[ ... ]

drivers/clocksource/Kconfig config VT8500_TIMER · line 138

Quoted 6 lines
drivers/clocksource/Kconfig +6 -0
+config NPCM7XX_TIMER
+	bool "NPCM7xx timer driver" if COMPILE_TEST
+	depends on HAS_IOMEM
+	select CLKSRC_MMIO
+	help
+	  Enable 24-bit TIMER0 and TIMER1 counters in the NPCM7xx arcithcture,

architecture

Quoted 10 lines
drivers/clocksource/Kconfig +2 -0
+	  While TIMER0 serves as clockevent and TIMER1 serves as clocksource.
+
 config CADENCE_TTC_TIMER
 	bool "Cadence TTC timer driver" if COMPILE_TEST
 	depends on COMMON_CLK
drivers/clocksource/Makefile +0 -0
index d6dec4489d66..b16c1a2b9e0d 100644

drivers/clocksource/Makefile obj-$(CONFIG_CLKSRC_NPS) += timer-nps.o · line 58

Quoted 4 lines
drivers/clocksource/Makefile +1 -0
@@ -55,6 +55,7 @@ obj-$(CONFIG_CLKSRC_NPS)	+= timer-nps.o
 obj-$(CONFIG_OXNAS_RPS_TIMER)	+= timer-oxnas-rps.o
 obj-$(CONFIG_OWL_TIMER)		+= owl-timer.o
 obj-$(CONFIG_SPRD_TIMER)	+= timer-sprd.o
+obj-$(CONFIG_NPCM7XX_TIMER)	+= npcm7xx-timer.o

Not mandatory but if you can change to timer-npcm7xx that would be nice.

Quoted 1 line
drivers/clocksource/Makefile +0 -0
 obj-$(CONFIG_ARC_TIMERS)		+= arc_timer.o

[ ... ]

drivers/clocksource/Makefile

Quoted 2 lines
drivers/clocksource/Makefile +2 -0
+static int npcm7xx_clockevent_setnextevent(unsigned long evt,
+		struct clock_event_device *clk)

npcm7xx_timer_set_next_event()

[ ... ]

Quoted 7 lines
drivers/clocksource/Makefile +7 -0
+static int __init npcm7xx_timer_init(struct device_node *np)
+{
+	struct clk *clk;
+	int ret;
+	u32 rate;
+
+	clk = of_clk_get(np, 0);

drivers/clocksource/Makefile

Quoted 10 lines
drivers/clocksource/Makefile +10 -0
+
+	if (IS_ERR(clk)) {
+		ret = of_property_read_u32(np, "clock-frequency", &rate);
+		if (ret)
+			return ret;
+	} else {
+		clk_prepare_enable(clk);
+		rate = clk_get_rate(clk);
+		npcm7xx_to.of_clk.clk = clk;
+	}

[ ... ]

See comment on DT binding patch 1/2

Quoted 12 lines
drivers/clocksource/Makefile +11 -0
+err_timer_of_init:
+	if (!IS_ERR(clk)) {
+		clk_disable_unprepare(clk);
+		clk_put(clk);
+	}
+
+	return ret;
+}
+
+TIMER_OF_DECLARE(npcm7xx, "nuvoton,npcm750-timer", npcm7xx_timer_init);
+
Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog