Skip to contentSkip to conversation

Add timer driver for StarFive JH7110 RISC-V SoC

PATCH In review Xingyu Wu 3 participants 8 messages Dec 19, 2023 – Feb 27, 2024

Subsystems (5)
lore
Share & tools
lore

Xingyu Wu

author
#0 lore raw

v8 cover Add timer driver for StarFive JH7110 RISC-V SoC

This patch serises are to add timer driver for the StarFive JH7110 RISC-V SoC. The first patch adds documentation to describe device tree bindings. The subsequent patch adds timer driver and support JH7110 SoC. The last patch adds device node about timer in JH7110 dts.

This timer has four free-running 32 bit counters and runs in 24MHz clock on StarFive JH7110 SoC. And each channel(counter) triggers an interrupt when timeout. They support one-shot mode and continuous-run mode.

This timer is used as global timer and register clockevent for each CPU core after riscv-timer registration on the StarFive JH7110 SoC.

Changes since v7:
- Rebased on 6.7-rc6.
- Modified the Kconfig file and added selection in SOC_STARFIVE.
- Used the timer as a global timer and registered as clockevent for each CPU core.
- Dropped the timeout function in the interrupt handler callback.
- Changed the way in the functions of jh7110_timer_tick_resume() and jh7110_timer_resume().
- Dropped the registration of clocksource in the probe.

v7: https://lore.kernel.org/all/[email protected]/

Changes since v6:
- Rebased on 6.6-rc6.
- Used sizeof() instead of the numbers of characters about names.
- Added devm_add_action_or_reset() to release the resets and clocksources in the case of remove or error in the probe.
- Added flags to check each clocksource is suceessfully registered and used in the release function.
- Dropped the variable of irq in the jh7110_clkevt struct.
- Dropped the wrappers and used enum definitions and writel() calls directly.

v6: https://lore.kernel.org/all/[email protected]/

Changes since v5:
- Rebased on 6.6-rc5.
- Changed the number about characters of name.
- Made the clkevt->periodic to a local variable.
- Dropped the variables of device and base.
- Used clkevt->evt.irq directly and dropped the extra copy of irq.

V5: https://lore.kernel.org/all/[email protected]/

Changes since v4:
- Rebased on 6.5.
- Dropped the useless enum and used value directly when writing registers.
- Modified the description in Kconfig.
- Add the reviewed tag in patch 3.

v4: https://lore.kernel.org/all/[email protected]/

Changes since v3:
- Rebased on 6.5-rc6
- Dropped the useless enum names like 'JH7110_TIMER_CH_0'.
- Dropped the platform data about JH7110 and used the register offsets directly.
- Drroped the useless functions of clk_disable_unprepare().

v3: https://lore.kernel.org/all/[email protected]/

Changes since v2:
- Rebased on 6.4-rc7.
- Merged the header file into the c file.
- Renamed the functions from 'starfive_' to 'jh7110_'
- Used function 'clocksource_register_hz' instead of 'clocksource_mmio_init'.

v2: https://lore.kernel.org/all/[email protected]/

Changes since v1:
- Added description about timer and modified properties' description in dt-bindings.
- Dropped the 'interrupt-names' and 'clock-frequency' in dt-bindings.
- Renamed the functions and added 'starfive_'
- Modified that the driver probe by platform bus.

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

Xingyu Wu (3):
dt-bindings: timer: Add timer for StarFive JH7110 SoC
clocksource: Add JH7110 timer driver
riscv: dts: jh7110: starfive: Add timer node

 .../bindings/timer/starfive,jh7110-timer.yaml |  96 +++++
 MAINTAINERS                                   |   7 +
 arch/riscv/Kconfig.socs                       |   1 +
 arch/riscv/boot/dts/starfive/jh7110.dtsi      |  20 +
 drivers/clocksource/Kconfig                   |   9 +
 drivers/clocksource/Makefile                  |   1 +
 drivers/clocksource/timer-jh7110.c            | 360 ++++++++++++++++++
 include/linux/cpuhotplug.h                    |   1 +
 8 files changed, 495 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/timer/starfive,jh7110-timer.yaml
 create mode 100644 drivers/clocksource/timer-jh7110.c
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v8 1/3 dt-bindings: timer: Add timer for StarFive JH7110 SoC

Add bindings for the timer on the JH7110 RISC-V SoC by StarFive Technology Ltd.

---
 .../bindings/timer/starfive,jh7110-timer.yaml | 96 +++++++++++++++++++
 1 file changed, 96 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/timer/starfive,jh7110-timer.yaml
Documentation/devicetree/bindings/timer/starfive,jh7110-timer.yaml new file +96 -0
new file mode 100644
index 000000000000..9a2dac11eb06
@@ -0,0 +1,96 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/timer/starfive,jh7110-timer.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: StarFive JH7110 Timer
+
+maintainers:
+  - Xingyu Wu <[email protected]>
+  - Samin Guo <[email protected]>
+
+description:
+  This timer has four free-running 32 bit counters in StarFive JH7110 SoC.
+  And each channel(counter) triggers an interrupt when timeout. They support
+  one-shot mode and continuous-run mode.
+
+properties:
+  compatible:
+    const: starfive,jh7110-timer
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    items:
+      - description: channel 0
+      - description: channel 1
+      - description: channel 2
+      - description: channel 3
+
+  clocks:
+    items:
+      - description: timer APB
+      - description: channel 0
+      - description: channel 1
+      - description: channel 2
+      - description: channel 3
+
+  clock-names:
+    items:
+      - const: apb
+      - const: ch0
+      - const: ch1
+      - const: ch2
+      - const: ch3
+
+  resets:
+    items:
+      - description: timer APB
+      - description: channel 0
+      - description: channel 1
+      - description: channel 2
+      - description: channel 3
+
+  reset-names:
+    items:
+      - const: apb
+      - const: ch0
+      - const: ch1
+      - const: ch2
+      - const: ch3
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - resets
+  - reset-names
+
+additionalProperties: false
+
+examples:
+  - |
+    timer@13050000 {
+        compatible = "starfive,jh7110-timer";
+        reg = <0x13050000 0x10000>;
+        interrupts = <69>, <70>, <71> ,<72>;
+        clocks = <&clk 124>,
+                 <&clk 125>,
+                 <&clk 126>,
+                 <&clk 127>,
+                 <&clk 128>;
+        clock-names = "apb", "ch0", "ch1",
+                      "ch2", "ch3";
+        resets = <&rst 117>,
+                 <&rst 118>,
+                 <&rst 119>,
+                 <&rst 120>,
+                 <&rst 121>;
+        reset-names = "apb", "ch0", "ch1",
+                      "ch2", "ch3";
+    };
+
Signature · 1 line
2.25.1
author
#2 lore raw

PATCH v8 2/3 clocksource: Add JH7110 timer driver

In reply to Xingyu Wu

Add timer driver for the StarFive JH7110 SoC and select it by CONFIG_SOC_STARFIVE.

This timer has four free-running and independent 32-bit counters. Each channel(counter) can trigger an interrupt when timeout even CPU is sleeping. So this timer is used as global timer and register clockevent for each CPU core after riscv-timer registration on the StarFive JH7110 SoC.

---
 MAINTAINERS                        |   7 +
 arch/riscv/Kconfig.socs            |   1 +
 drivers/clocksource/Kconfig        |   9 +
 drivers/clocksource/Makefile       |   1 +
 drivers/clocksource/timer-jh7110.c | 360 +++++++++++++++++++++++++++++
 include/linux/cpuhotplug.h         |   1 +
 6 files changed, 379 insertions(+)
 create mode 100644 drivers/clocksource/timer-jh7110.c
MAINTAINERS +7 -0
index 9104430e148e..fe0e803606a5 100644
@@ -20617,6 +20617,13 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/sound/starfive,jh7110-tdm.yaml
 F:	sound/soc/starfive/jh7110_tdm.c
 
+STARFIVE JH7110 TIMER DRIVER
+M:	Samin Guo <[email protected]>
+M:	Xingyu Wu <[email protected]>
+S:	Supported
+F:	Documentation/devicetree/bindings/timer/starfive,jh7110-timer.yaml
+F:	drivers/clocksource/timer-jh7110.c
+
 STARFIVE JH71X0 CLOCK DRIVERS
 M:	Emil Renner Berthing <[email protected]>
 M:	Hal Feng <[email protected]>
arch/riscv/Kconfig.socs +1 -0
index e08e91c49abe..e986590f40b0 100644
@@ -35,6 +35,7 @@ config SOC_STARFIVE
 	select PINCTRL
 	select RESET_CONTROLLER
 	select ARM_AMBA
+	select STARFIVE_JH7110_TIMER
 	help
 	  This enables support for StarFive SoC platform hardware.
 
drivers/clocksource/Kconfig +9 -0
index 34faa0320ece..3f273f07a258 100644
@@ -641,6 +641,15 @@ config RISCV_TIMER
 	  is accessed via both the SBI and the rdcycle instruction.  This is
 	  required for all RISC-V systems.
 
+config STARFIVE_JH7110_TIMER
+	bool "Timer for the STARFIVE JH7110 SoC" if COMPILE_TEST
+	select TIMER_OF
+	select CLKSRC_MMIO
+	help
+	  This enables the timer for StarFive JH7110 SoC. On RISC-V platform,
+	  the system has started RISCV_TIMER, but you can also use this timer
+	  which can provide four channels of higher rating on the JH7110 SoC.
+
 config CLINT_TIMER
 	bool "CLINT Timer for the RISC-V platform" if COMPILE_TEST
 	depends on GENERIC_SCHED_CLOCK && RISCV
drivers/clocksource/Makefile +1 -0
index 4bb856e4df55..8dc2f0ea2d0f 100644
@@ -80,6 +80,7 @@ obj-$(CONFIG_INGENIC_TIMER)		+= ingenic-timer.o
 obj-$(CONFIG_CLKSRC_ST_LPC)		+= clksrc_st_lpc.o
 obj-$(CONFIG_X86_NUMACHIP)		+= numachip.o
 obj-$(CONFIG_RISCV_TIMER)		+= timer-riscv.o
+obj-$(CONFIG_STARFIVE_JH7110_TIMER)	+= timer-jh7110.o
 obj-$(CONFIG_CLINT_TIMER)		+= timer-clint.o
 obj-$(CONFIG_CSKY_MP_TIMER)		+= timer-mp-csky.o
 obj-$(CONFIG_GX6605S_TIMER)		+= timer-gx6605s.o
drivers/clocksource/timer-jh7110.c new file +360 -0

360 lines not on this page · raw message

include/linux/cpuhotplug.h +1 -0
index efc0c0b07efb..f28a3aaf93f9 100644
@@ -187,6 +187,7 @@ enum cpuhp_state {
 	CPUHP_AP_CSKY_TIMER_STARTING,
 	CPUHP_AP_TI_GP_TIMER_STARTING,
 	CPUHP_AP_HYPERV_TIMER_STARTING,
+	CPUHP_AP_JH7110_TIMER_STARTING,
 	/* Must be the last timer callback */
 	CPUHP_AP_DUMMY_TIMER_STARTING,
 	CPUHP_AP_ARM_XEN_STARTING,
Signature · 1 line
2.25.1
#3 lore raw

Re: [PATCH v8 2/3] clocksource: Add JH7110 timer driver

Quoted 25 lines · Xingyu Wu

Add timer driver for the StarFive JH7110 SoC and select it by CONFIG_SOC_STARFIVE.

This timer has four free-running and independent 32-bit counters. Each channel(counter) can trigger an interrupt when timeout even CPU is sleeping. So this timer is used as global timer and register clockevent for each CPU core after riscv-timer registration on the StarFive JH7110 SoC.

---
 MAINTAINERS                        |   7 +
 arch/riscv/Kconfig.socs            |   1 +
 drivers/clocksource/Kconfig        |   9 +
 drivers/clocksource/Makefile       |   1 +
 drivers/clocksource/timer-jh7110.c | 360 +++++++++++++++++++++++++++++
 include/linux/cpuhotplug.h         |   1 +
 6 files changed, 379 insertions(+)
 create mode 100644 drivers/clocksource/timer-jh7110.c
MAINTAINERS +0 -0
index 9104430e148e..fe0e803606a5 100644

MAINTAINERS S: Maintained · line 20621

Quoted 5 lines
MAINTAINERS +2 -0
@@ -20617,6 +20617,13 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/sound/starfive,jh7110-tdm.yaml
 F:	sound/soc/starfive/jh7110_tdm.c
 
+STARFIVE JH7110 TIMER DRIVER
+M:	Samin Guo <[email protected]>

Last time I sent a mail to [email protected] it bounced. Was that just a temporary error?

/Emil

Quoted 8 lines
MAINTAINERS +5 -0
+M:	Xingyu Wu <[email protected]>
+S:	Supported
+F:	Documentation/devicetree/bindings/timer/starfive,jh7110-timer.yaml
+F:	drivers/clocksource/timer-jh7110.c
+
 STARFIVE JH71X0 CLOCK DRIVERS
 M:	Emil Renner Berthing <[email protected]>
 M:	Hal Feng <[email protected]>
author
#4 lore raw

Re: [PATCH v8 2/3] clocksource: Add JH7110 timer driver

Quoted 29 lines · Emil Renner Berthing
Quoted 28 lines · Xingyu Wu

Add timer driver for the StarFive JH7110 SoC and select it by CONFIG_SOC_STARFIVE.

This timer has four free-running and independent 32-bit counters. Each channel(counter) can trigger an interrupt when timeout even CPU is sleeping. So this timer is used as global timer and register clockevent for each CPU core after riscv-timer registration on the StarFive JH7110 SoC.

---
 MAINTAINERS                        |   7 +
 arch/riscv/Kconfig.socs            |   1 +
 drivers/clocksource/Kconfig        |   9 +
 drivers/clocksource/Makefile       |   1 +
 drivers/clocksource/timer-jh7110.c | 360 +++++++++++++++++++++++++++++
 include/linux/cpuhotplug.h         |   1 +
 6 files changed, 379 insertions(+)
 create mode 100644 drivers/clocksource/timer-jh7110.c
MAINTAINERS +0 -0
index 9104430e148e..fe0e803606a5 100644
@@ -20617,6 +20617,13 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/sound/starfive,jh7110-tdm.yaml
 F:	sound/soc/starfive/jh7110_tdm.c
 
Quoted 7 lines

MAINTAINERS S: Maintained · line 20621

Quoted 2 lines
MAINTAINERS +2 -0
+STARFIVE JH7110 TIMER DRIVER
+M:	Samin Guo <[email protected]>

Last time I sent a mail to [email protected] it bounced. Was that just a temporary error?

/Emil

Oh, This email has been deactivated and I don't have his other personal email. I had dropped it in the driver but forget it here.
Will fix.

Thanks,
Xingyu Wu

Quoted 9 lines
Quoted 9 lines
MAINTAINERS +5 -0
+M:	Xingyu Wu <[email protected]>
+S:	Supported
+F:	Documentation/devicetree/bindings/timer/starfive,jh7110-timer.yaml
+F:	drivers/clocksource/timer-jh7110.c
+
 STARFIVE JH71X0 CLOCK DRIVERS
 M:	Emil Renner Berthing <[email protected]>
 M:	Hal Feng <[email protected]>
#5 lore raw

Re: [PATCH v8 2/3] clocksource: Add JH7110 timer driver

In reply to Xingyu Wu
Quoted 5 lines · Xingyu Wu
drivers/clocksource/timer-jh7110.c new file +5 -0
+
+struct jh7110_clkevt {
+	struct clk *clk;
+	struct reset_control *rst;
+	void __iomem *base;

drivers/clocksource/timer-jh7110.c line 68

Quoted 10 lines
drivers/clocksource/timer-jh7110.c new file +10 -0
+	u32 reload_val;
+	int irq;
+	char name[sizeof("jh7110-timer.chX")];
+};
+
+struct jh7110_timer_priv {
+	struct reset_control *prst;
+	struct device *dev;
+	struct jh7110_clkevt clkevt[JH7110_TIMER_CH_MAX];
+};

Please format your data structures according to documentation:

https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#struct-declarations-and-initializers

drivers/clocksource/timer-jh7110.c line 162

Quoted 7 lines
drivers/clocksource/timer-jh7110.c new file +7 -0
+/* IRQ handler for the timer */
+static irqreturn_t jh7110_timer_interrupt(int irq, void *data)
+{
+	struct clock_event_device *evt = data;
+	struct jh7110_clkevt *clkevt = &jh7110_timer_info.clkevt[0];
+	u8 cpu_id = smp_processor_id();
+	u32 reg = readl(clkevt->base + JH7110_TIMER_INT_STATUS);

https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#variable-declarations

Quoted 42 lines
drivers/clocksource/timer-jh7110.c new file +42 -0
+	/* Check interrupt status and channel(cpu) ID */
+	if (!(reg & BIT(cpu_id)))
+		return IRQ_NONE;
+
+	clkevt = &jh7110_timer_info.clkevt[cpu_id];
+	writel(JH7110_TIMER_INT_CLR_ENA, (clkevt->base + JH7110_TIMER_INT_CLR));
+
+	if (evt->event_handler)
+		evt->event_handler(evt);
+
+	return IRQ_HANDLED;
+}
+
+static int jh7110_timer_set_periodic(struct clock_event_device *evt)
+{
+	struct jh7110_clkevt *clkevt = JH7110_PERCPU_GET_CLKEVT;
+
+	writel(JH7110_TIMER_MODE_CONTIN, clkevt->base + JH7110_TIMER_CTL);
+	return 0;
+}
+
+static int jh7110_timer_set_oneshot(struct clock_event_device *evt)
+{
+	struct jh7110_clkevt *clkevt = JH7110_PERCPU_GET_CLKEVT;
+
+	writel(JH7110_TIMER_MODE_SINGLE, clkevt->base + JH7110_TIMER_CTL);
+	return 0;
+}
+
+static int jh7110_timer_set_next_event(unsigned long next,
+				       struct clock_event_device *evt)
+{
+	struct jh7110_clkevt *clkevt = JH7110_PERCPU_GET_CLKEVT;
+
+	writel(JH7110_TIMER_MODE_SINGLE, clkevt->base + JH7110_TIMER_CTL);
+	writel(next, clkevt->base + JH7110_TIMER_LOAD);
+
+	return jh7110_timer_start(clkevt);
+}
+
+static DEFINE_PER_CPU(struct clock_event_device, jh7110_clock_event) = {
+	.features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,

drivers/clocksource/timer-jh7110.c line 215

Quoted 10 lines
drivers/clocksource/timer-jh7110.c new file +10 -0
+	.rating = JH7110_CLOCKEVENT_RATING,
+	.set_state_shutdown = jh7110_timer_shutdown,
+	.set_state_periodic = jh7110_timer_set_periodic,
+	.set_state_oneshot = jh7110_timer_set_oneshot,
+	.set_state_oneshot_stopped = jh7110_timer_shutdown,
+	.tick_resume = jh7110_timer_tick_resume,
+	.set_next_event = jh7110_timer_set_next_event,
+	.suspend = jh7110_timer_suspend,
+	.resume = jh7110_timer_resume,
+};

See formatting rules.

Quoted 18 lines
drivers/clocksource/timer-jh7110.c new file +18 -0
+static int jh7110_timer_starting_cpu(unsigned int cpu)
+{
+	struct clock_event_device *evt = per_cpu_ptr(&jh7110_clock_event, cpu);
+	struct jh7110_timer_priv *priv = &jh7110_timer_info;
+	int ret;
+	u32 rate;
+
+	if (cpu >= JH7110_TIMER_CH_MAX)
+		return -ENOMEM;
+
+	ret = clk_prepare_enable(priv->clkevt[cpu].clk);
+	if (ret)
+		return ret;
+
+	ret = reset_control_deassert(priv->clkevt[cpu].rst);
+	if (ret)
+		return ret;
+

drivers/clocksource/timer-jh7110.c line 244

Quoted 10 lines
drivers/clocksource/timer-jh7110.c new file +10 -0
+	rate = clk_get_rate(priv->clkevt[cpu].clk);
+	evt->cpumask = cpumask_of(cpu);
+	evt->irq = priv->clkevt[cpu].irq;
+	evt->name = priv->clkevt[cpu].name;
+	clockevents_config_and_register(evt, rate, JH7110_TIMER_MIN_TICKS,
+					JH7110_TIMER_MAX_TICKS);
+
+	ret = devm_request_irq(priv->dev, evt->irq, jh7110_timer_interrupt,
+			       IRQF_TIMER | IRQF_IRQPOLL,
+			       evt->name, evt);

How is this all supposed to work from a CPU hotplug state callback which runs in the early bringup phase with interrupts disabled? clk_prepare() which is invoked from clk_prepare_enable() can sleep and devm_request_irq() can sleep too.

Did you ever test this with the required debug config options enabled?

https://www.kernel.org/doc/html/latest/process/submit-checklist.html

Obviously not.

Quoted 18 lines
drivers/clocksource/timer-jh7110.c new file +18 -0
+	if (ret)
+		return ret;
+
+	ret = irq_set_affinity(evt->irq, cpumask_of(cpu));
+	if (ret)
+		return ret;
+	/* Use one-shot mode */
+	writel(JH7110_TIMER_MODE_SINGLE, (priv->clkevt[cpu].base + JH7110_TIMER_CTL));
+
+	return jh7110_timer_start(&priv->clkevt[cpu]);
+}
+
+static void jh7110_timer_release(void *data)
+{
+	struct jh7110_timer_priv *priv = data;
+	int i;
+
+	for (i = 0; i < JH7110_TIMER_CH_MAX; i++) {

drivers/clocksource/timer-jh7110.c line 273

Quoted 10 lines
drivers/clocksource/timer-jh7110.c new file +10 -0
+		/* Disable each channel of timer */
+		if (priv->clkevt[i].base)
+			writel(JH7110_TIMER_DIS, priv->clkevt[i].base + JH7110_TIMER_ENABLE);
+
+		/* Avoid no initialization in the loop of the probe */
+		if (!IS_ERR_OR_NULL(priv->clkevt[i].rst))
+			reset_control_assert(priv->clkevt[i].rst);
+
+		if (!IS_ERR_OR_NULL(priv->clkevt[i].clk))
+			clk_disable_unprepare(priv->clkevt[i].clk);

Same problem. And of course this does not undo the other steps of jh7110_timer_starting_cpu() so if you offline a CPU and then online it again the callback will fail because the clockevent is already registered and the interrupt requested. Clearly untested too.

Thanks,

tglx

author
#6 lore raw

PATCH v8 3/3 riscv: dts: jh7110: starfive: Add timer node

In reply to Xingyu Wu

Add the timer node for the Starfive JH7110 SoC.

---
 arch/riscv/boot/dts/starfive/jh7110.dtsi | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
arch/riscv/boot/dts/starfive/jh7110.dtsi +20 -0
index 45213cdf50dc..46836da9940f 100644
@@ -904,6 +904,26 @@ sysgpio: pinctrl@13040000 {
 			#gpio-cells = <2>;
 		};
 
+		timer@13050000 {
+			compatible = "starfive,jh7110-timer";
+			reg = <0x0 0x13050000 0x0 0x10000>;
+			interrupts = <69>, <70>, <71>, <72>;
+			clocks = <&syscrg JH7110_SYSCLK_TIMER_APB>,
+				 <&syscrg JH7110_SYSCLK_TIMER0>,
+				 <&syscrg JH7110_SYSCLK_TIMER1>,
+				 <&syscrg JH7110_SYSCLK_TIMER2>,
+				 <&syscrg JH7110_SYSCLK_TIMER3>;
+			clock-names = "apb", "ch0", "ch1",
+				      "ch2", "ch3";
+			resets = <&syscrg JH7110_SYSRST_TIMER_APB>,
+				 <&syscrg JH7110_SYSRST_TIMER0>,
+				 <&syscrg JH7110_SYSRST_TIMER1>,
+				 <&syscrg JH7110_SYSRST_TIMER2>,
+				 <&syscrg JH7110_SYSRST_TIMER3>;
+			reset-names = "apb", "ch0", "ch1",
+				      "ch2", "ch3";
+		};
+
 		watchdog@13070000 {
 			compatible = "starfive,jh7110-wdt";
 			reg = <0x0 0x13070000 0x0 0x10000>;
Signature · 1 line
2.25.1
author
#7 lore raw
In reply to Xingyu Wu

Hi Daniel,

Could you please help to review this patch and give your comments if you have time? Thanks.

Best regards,
Xingyu Wu

-----邮件原件-----
发件人: Xingyu Wu <[email protected]>
发送时间: 2023年12月19日 22:54
收件人: Daniel Lezcano <[email protected]>; Thomas Gleixner <[email protected]>; Emil Renner Berthing <[email protected]>; Christophe JAILLET <[email protected]>
抄送: [email protected]; [email protected]; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Paul Walmsley <[email protected]>; Palmer Dabbelt <[email protected]>; Albert Ou <[email protected]>; Philipp Zabel <[email protected]>; Walker Chen <[email protected]>; Xingyu Wu <[email protected]>; [email protected]; Conor Dooley <[email protected]> 主题: [PATCH v8 0/3] Add timer driver for StarFive JH7110 RISC-V SoC

This patch serises are to add timer driver for the StarFive JH7110 RISC-V SoC. The first patch adds documentation to describe device tree bindings. The subsequent patch adds timer driver and support JH7110 SoC. The last patch adds device node about timer in JH7110 dts.

This timer has four free-running 32 bit counters and runs in 24MHz clock on StarFive JH7110 SoC. And each channel(counter) triggers an interrupt when timeout. They support one-shot mode and continuous-run mode.

This timer is used as global timer and register clockevent for each CPU core after riscv-timer registration on the StarFive JH7110 SoC.

Changes since v7:
- Rebased on 6.7-rc6.
- Modified the Kconfig file and added selection in SOC_STARFIVE.
- Used the timer as a global timer and registered as clockevent for each CPU core.
- Dropped the timeout function in the interrupt handler callback.
- Changed the way in the functions of jh7110_timer_tick_resume() and jh7110_timer_resume().
- Dropped the registration of clocksource in the probe.

v7: https://lore.kernel.org/all/[email protected]/

Changes since v6:
- Rebased on 6.6-rc6.
- Used sizeof() instead of the numbers of characters about names.
- Added devm_add_action_or_reset() to release the resets and clocksources in the case of remove or error in the probe.
- Added flags to check each clocksource is suceessfully registered and used in the release function.
- Dropped the variable of irq in the jh7110_clkevt struct.
- Dropped the wrappers and used enum definitions and writel() calls directly.

v6: https://lore.kernel.org/all/[email protected]/

Changes since v5:
- Rebased on 6.6-rc5.
- Changed the number about characters of name.
- Made the clkevt->periodic to a local variable.
- Dropped the variables of device and base.
- Used clkevt->evt.irq directly and dropped the extra copy of irq.

V5: https://lore.kernel.org/all/[email protected]/

Changes since v4:
- Rebased on 6.5.
- Dropped the useless enum and used value directly when writing registers.
- Modified the description in Kconfig.
- Add the reviewed tag in patch 3.

v4: https://lore.kernel.org/all/[email protected]/

Changes since v3:
- Rebased on 6.5-rc6
- Dropped the useless enum names like 'JH7110_TIMER_CH_0'.
- Dropped the platform data about JH7110 and used the register offsets directly.
- Drroped the useless functions of clk_disable_unprepare().

v3: https://lore.kernel.org/all/[email protected]/

Changes since v2:
- Rebased on 6.4-rc7.
- Merged the header file into the c file.
- Renamed the functions from 'starfive_' to 'jh7110_'
- Used function 'clocksource_register_hz' instead of 'clocksource_mmio_init'.

v2: https://lore.kernel.org/all/[email protected]/

Changes since v1:
- Added description about timer and modified properties' description in dt-bindings.
- Dropped the 'interrupt-names' and 'clock-frequency' in dt-bindings.
- Renamed the functions and added 'starfive_'
- Modified that the driver probe by platform bus.

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

Xingyu Wu (3):
dt-bindings: timer: Add timer for StarFive JH7110 SoC
clocksource: Add JH7110 timer driver
riscv: dts: jh7110: starfive: Add timer node

 .../bindings/timer/starfive,jh7110-timer.yaml |  96 +++++
 MAINTAINERS                                   |   7 +
 arch/riscv/Kconfig.socs                       |   1 +
 arch/riscv/boot/dts/starfive/jh7110.dtsi      |  20 +
 drivers/clocksource/Kconfig                   |   9 +
 drivers/clocksource/Makefile                  |   1 +
 drivers/clocksource/timer-jh7110.c            | 360 ++++++++++++++++++
 include/linux/cpuhotplug.h                    |   1 +
 8 files changed, 495 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/timer/starfive,jh7110-timer.yaml
 create mode 100644 drivers/clocksource/timer-jh7110.c

--
2.25.1