Skip to contentSkip to conversation

Add timers for Mstar SoCs

PATCH Applied Romain Perier 2 participants 10 messages Dec 17, 2021 – Jan 10, 2022

Subsystems (5)
lore
Share & tools
lore

Romain Perier

author maintainer
#0 lore raw

v3 cover Add timers for Mstar SoCs

This patches series adds a new driver for the timers found in the Mstar MSC313e SoCs and newer. It adds a basic clocksource driver, the corresponding devicetree bindings and its documentation.

Changes since v2:
- Reworded commit 2/6
- Added Rob's 'Reviewed-by:' tag

Changes since v1:
- Make delay conditionnal for ARM, so it builds on all platforms
- Improved commit message for the timer driver
- MSC313E_TIMER is now silent and enabled by platform
- Updated msc313e_timer_setup() to make it safe
- Updated msc313e_timer_current_value() to make it safe
- Renamed the driver variant for ssd20xd to "sstar,ssd20xd-timer"
- Moved timer settings for the ssd202d from mstar-infinity2m-ssd20xd.dtsi to mstar-infinity2m.dtsi.
- Select MSC313E_TIMER on mstar platforms
- Fixed wrong dt-bindings doc that included an rtc property (whoops!)

Romain Perier (6):
clocksource: Add MStar MSC313e timer support
clocksource: msc313e: Add support for ssd20xd-based platforms
ARM: mstar: Select MSC313E_TIMER
dt-bindings: timer: Add Mstar MSC313e timer devicetree bindings
documentation
ARM: dts: mstar: Add timers device nodes
ARM: dts: mstar: Switch to compatible "sstar,ssd20xd-timer" on
infinity2m

 .../bindings/timer/mstar,msc313e-timer.yaml   |  46 ++++
 MAINTAINERS                                   |   1 +
 arch/arm/boot/dts/mstar-infinity2m.dtsi       |  18 ++
 arch/arm/boot/dts/mstar-v7.dtsi               |  20 ++
 arch/arm/mach-mstar/Kconfig                   |   1 +
 drivers/clocksource/Kconfig                   |   9 +
 drivers/clocksource/Makefile                  |   1 +
 drivers/clocksource/timer-msc313e.c           | 253 ++++++++++++++++++
 8 files changed, 349 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/timer/mstar,msc313e-timer.yaml
 create mode 100644 drivers/clocksource/timer-msc313e.c
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH v3 1/6 clocksource: Add MStar MSC313e timer support

The MSC313e-compatible SoCs have 3 timer hardware blocks. All of these are free running 32-bit increasing counters and can generate interrupts. Based onto a maximum value register, each timer can either count from 0 to max, one time then stop (which generates interrupts) or can count from 0 to max and then roll. This commit adds basic support for these timers, the first timer block being used as clocksource/sched_clock and delay, while the others will be used as clockevents.

---
 MAINTAINERS                         |   1 +
 drivers/clocksource/Kconfig         |   9 +
 drivers/clocksource/Makefile        |   1 +
 drivers/clocksource/timer-msc313e.c | 244 ++++++++++++++++++++++++++++
 4 files changed, 255 insertions(+)
 create mode 100644 drivers/clocksource/timer-msc313e.c
MAINTAINERS +1 -0
index 43007f2d29e0..4dbc122c7937 100644
@@ -2291,6 +2291,7 @@ F:	Documentation/devicetree/bindings/gpio/mstar,msc313-gpio.yaml
 F:	arch/arm/boot/dts/mstar-*
 F:	arch/arm/mach-mstar/
 F:	drivers/clk/mstar/
+F:	drivers/clocksource/timer-msc313e.c
 F:	drivers/gpio/gpio-msc313.c
 F:	drivers/rtc/rtc-msc313.c
 F:	drivers/watchdog/msc313e_wdt.c
drivers/clocksource/Kconfig +9 -0
index f65e31bab9ae..ba46d6860e2d 100644
@@ -671,6 +671,15 @@ config MILBEAUT_TIMER
 	help
 	  Enables the support for Milbeaut timer driver.
 
+config MSC313E_TIMER
+	bool "MSC313E timer driver" if COMPILE_TEST
+	select TIMER_OF
+	select CLKSRC_MMIO
+	help
+	  Enables support for the MStar MSC313E timer driver.
+	  This provides access to multiple interrupt generating
+	  programmable 32-bit free running incrementing counters.
+
 config INGENIC_TIMER
 	bool "Clocksource/timer using the TCU in Ingenic JZ SoCs"
 	default MACH_INGENIC
drivers/clocksource/Makefile +1 -0
index c17ee32a7151..fa5f624eadb6 100644
@@ -88,3 +88,4 @@ obj-$(CONFIG_CSKY_MP_TIMER)		+= timer-mp-csky.o
 obj-$(CONFIG_GX6605S_TIMER)		+= timer-gx6605s.o
 obj-$(CONFIG_HYPERV_TIMER)		+= hyperv_timer.o
 obj-$(CONFIG_MICROCHIP_PIT64B)		+= timer-microchip-pit64b.o
+obj-$(CONFIG_MSC313E_TIMER)		+= timer-msc313e.o
drivers/clocksource/timer-msc313e.c new file +244 -0

244 lines not on this page · raw message

Signature · 1 line
2.34.1
merge bot Applied
#2 lore raw

[tip: timers/core] clocksource/drivers: Add MStar MSC313e timer support

The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     5fc1f93f69989e72be7a84ded6ee867d6415f690
Gitweb:        https://git.kernel.org/tip/5fc1f93f69989e72be7a84ded6ee867d6415f690
Author:        Romain Perier <[email protected]>
AuthorDate:    Fri, 17 Dec 2021 20:57:22 +01:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Mon, 20 Dec 2021 13:28:28 +01:00

clocksource/drivers: Add MStar MSC313e timer support

The MSC313e-compatible SoCs have 3 timer hardware blocks. All of these are free running 32-bit increasing counters and can generate interrupts. Based onto a maximum value register, each timer can either count from 0 to max, one time then stop (which generates interrupts) or can count from 0 to max and then roll. This commit adds basic support for these timers, the first timer block being used as clocksource/sched_clock and delay, while the others will be used as clockevents.

---
 MAINTAINERS                         |   1 +-
 drivers/clocksource/Kconfig         |   9 +-
 drivers/clocksource/Makefile        |   1 +-
 drivers/clocksource/timer-msc313e.c | 244 +++++++++++++++++++++++++++-
 4 files changed, 255 insertions(+)
 create mode 100644 drivers/clocksource/timer-msc313e.c
MAINTAINERS +1 -0
index 7a2345c..f39a161 100644
@@ -2282,6 +2282,7 @@ F:	Documentation/devicetree/bindings/gpio/mstar,msc313-gpio.yaml
 F:	arch/arm/boot/dts/mstar-*
 F:	arch/arm/mach-mstar/
 F:	drivers/clk/mstar/
+F:	drivers/clocksource/timer-msc313e.c
 F:	drivers/gpio/gpio-msc313.c
 F:	drivers/rtc/rtc-msc313.c
 F:	drivers/watchdog/msc313e_wdt.c
drivers/clocksource/Kconfig +9 -0
index 821ea4a..cfb8ea0 100644
@@ -672,6 +672,15 @@ config MILBEAUT_TIMER
 	help
 	  Enables the support for Milbeaut timer driver.
 
+config MSC313E_TIMER
+	bool "MSC313E timer driver" if COMPILE_TEST
+	select TIMER_OF
+	select CLKSRC_MMIO
+	help
+	  Enables support for the MStar MSC313E timer driver.
+	  This provides access to multiple interrupt generating
+	  programmable 32-bit free running incrementing counters.
+
 config INGENIC_TIMER
 	bool "Clocksource/timer using the TCU in Ingenic JZ SoCs"
 	default MACH_INGENIC
drivers/clocksource/Makefile +1 -0
index c17ee32..fa5f624 100644
@@ -88,3 +88,4 @@ obj-$(CONFIG_CSKY_MP_TIMER)		+= timer-mp-csky.o
 obj-$(CONFIG_GX6605S_TIMER)		+= timer-gx6605s.o
 obj-$(CONFIG_HYPERV_TIMER)		+= hyperv_timer.o
 obj-$(CONFIG_MICROCHIP_PIT64B)		+= timer-microchip-pit64b.o
+obj-$(CONFIG_MSC313E_TIMER)		+= timer-msc313e.o
drivers/clocksource/timer-msc313e.c new file +244 -0

244 lines not on this page · raw message

author maintainer
#3 lore raw

PATCH v3 2/6 clocksource: msc313e: Add support for ssd20xd-based platforms

In reply to Romain Perier

On SSD20X family SoCs the timers are connected to a 432MHz clock instead of 12MHz that all the previous chips used. There is no way to reduce or divide these clocks in the clktree yet as we do not know exactly where the 432MHz clock comes from but it is enabled at boot.

The SSD20X timers have an input clock divider within the timer itself to configure the frequency. timer0 is preconfigured at power up to run at 12MHz so it is backwards compatible and doesn't need special handling right now. timer1 and timer2 run at 432Mhz at power up so are not backward compatible.

This commit adds support for the input clock divider register and sets timer1 and timer2 to run at 48Mhz for clockevents.

---
 drivers/clocksource/timer-msc313e.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/clocksource/timer-msc313e.c +9 -0
index 154e73444a0c..54c54ca7c786 100644
@@ -33,7 +33,9 @@
 #define MSC313E_REG_TIMER_MAX_HIGH	0x0c
 #define MSC313E_REG_COUNTER_LOW		0x10
 #define MSC313E_REG_COUNTER_HIGH	0x14
+#define MSC313E_REG_TIMER_DIVIDE	0x18
 
+#define MSC313E_CLK_DIVIDER		9
 #define TIMER_SYNC_TICKS		3
 
 #ifdef CONFIG_ARM
@@ -179,6 +181,12 @@ static int __init msc313e_clkevt_init(struct device_node *np)
 	if (ret)
 		return ret;
 
+	if (of_device_is_compatible(np, "sstar,ssd20xd-timer")) {
+		to->of_clk.rate = clk_get_rate(to->of_clk.clk) / MSC313E_CLK_DIVIDER;
+		to->of_clk.period = DIV_ROUND_UP(to->of_clk.rate, HZ);
+		writew(MSC313E_CLK_DIVIDER - 1, timer_of_base(to) + MSC313E_REG_TIMER_DIVIDE);
+	}
+
 	msc313e_clkevt.cpumask = cpu_possible_mask;
 	msc313e_clkevt.irq = to->of_irq.irq;
 	to->clkevt = msc313e_clkevt;
@@ -242,3 +250,4 @@ static int __init msc313e_timer_init(struct device_node *np)
 }
 
 TIMER_OF_DECLARE(msc313, "mstar,msc313e-timer", msc313e_timer_init);
+TIMER_OF_DECLARE(ssd20xd, "sstar,ssd20xd-timer", msc313e_timer_init);
Signature · 1 line
2.34.1
merge bot Applied
#4 lore raw

[tip: timers/core] clocksource/drivers/msc313e: Add support for ssd20xd-based platforms

The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     e64da64f410cf4f9697e25ab76cdfc679f4fb6db
Gitweb:        https://git.kernel.org/tip/e64da64f410cf4f9697e25ab76cdfc679f4fb6db
Author:        Romain Perier <[email protected]>
AuthorDate:    Fri, 17 Dec 2021 20:57:23 +01:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Mon, 20 Dec 2021 13:28:39 +01:00

clocksource/drivers/msc313e: Add support for ssd20xd-based platforms

On SSD20X family SoCs the timers are connected to a 432MHz clock instead of 12MHz that all the previous chips used. There is no way to reduce or divide these clocks in the clktree yet as we do not know exactly where the 432MHz clock comes from but it is enabled at boot.

The SSD20X timers have an input clock divider within the timer itself to configure the frequency. timer0 is preconfigured at power up to run at 12MHz so it is backwards compatible and doesn't need special handling right now. timer1 and timer2 run at 432Mhz at power up so are not backward compatible.

This commit adds support for the input clock divider register and sets timer1 and timer2 to run at 48Mhz for clockevents.

---
 drivers/clocksource/timer-msc313e.c |  9 +++++++++
 1 file changed, 9 insertions(+)
drivers/clocksource/timer-msc313e.c +9 -0
index 154e734..54c54ca 100644
@@ -33,7 +33,9 @@
 #define MSC313E_REG_TIMER_MAX_HIGH	0x0c
 #define MSC313E_REG_COUNTER_LOW		0x10
 #define MSC313E_REG_COUNTER_HIGH	0x14
+#define MSC313E_REG_TIMER_DIVIDE	0x18
 
+#define MSC313E_CLK_DIVIDER		9
 #define TIMER_SYNC_TICKS		3
 
 #ifdef CONFIG_ARM
@@ -179,6 +181,12 @@ static int __init msc313e_clkevt_init(struct device_node *np)
 	if (ret)
 		return ret;
 
+	if (of_device_is_compatible(np, "sstar,ssd20xd-timer")) {
+		to->of_clk.rate = clk_get_rate(to->of_clk.clk) / MSC313E_CLK_DIVIDER;
+		to->of_clk.period = DIV_ROUND_UP(to->of_clk.rate, HZ);
+		writew(MSC313E_CLK_DIVIDER - 1, timer_of_base(to) + MSC313E_REG_TIMER_DIVIDE);
+	}
+
 	msc313e_clkevt.cpumask = cpu_possible_mask;
 	msc313e_clkevt.irq = to->of_irq.irq;
 	to->clkevt = msc313e_clkevt;
@@ -242,3 +250,4 @@ static int __init msc313e_timer_init(struct device_node *np)
 }
 
 TIMER_OF_DECLARE(msc313, "mstar,msc313e-timer", msc313e_timer_init);
+TIMER_OF_DECLARE(ssd20xd, "sstar,ssd20xd-timer", msc313e_timer_init);
author maintainer
#5 lore raw

PATCH v3 3/6 ARM: mstar: Select MSC313E_TIMER

In reply to Romain Perier

All of the ARCH_MSTARV7 have timers that can act as clocksource or clockevents so select the corresponding driver.

---
 arch/arm/mach-mstar/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm/mach-mstar/Kconfig +1 -0
index cd300eeedc20..d079d567bb72 100644
@@ -3,6 +3,7 @@ menuconfig ARCH_MSTARV7
 	depends on ARCH_MULTI_V7
 	select ARM_GIC
 	select ARM_HEAVY_MB
+	select MSC313E_TIMER
 	select MST_IRQ
 	select MSTAR_MSC313_MPLL
 	help
Signature · 1 line
2.34.1
author maintainer
#6 lore raw

PATCH v3 4/6 dt-bindings: timer: Add Mstar MSC313e timer devicetree bindings documentation

In reply to Romain Perier

This adds the documentation for the devicetree bindings of the Mstar MSC313e timer driver, found from MSC313e SoCs and newer.

---
 .../bindings/timer/mstar,msc313e-timer.yaml   | 46 +++++++++++++++++++
 1 file changed, 46 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/timer/mstar,msc313e-timer.yaml
Documentation/devicetree/bindings/timer/mstar,msc313e-timer.yaml new file +46 -0
new file mode 100644
index 000000000000..03d5dba5d5b3
@@ -0,0 +1,46 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/timer/mstar,msc313e-timer.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Mstar MSC313e Timer Device Tree Bindings
+
+maintainers:
+  - Daniel Palmer <[email protected]>
+  - Romain Perier <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - mstar,msc313e-timer
+      - sstar,ssd20xd-timer
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    timer@6040 {
+        compatible = "mstar,msc313e-timer";
+        reg = <0x6040 0x40>;
+        clocks = <&xtal_div2>;
+        interrupts-extended = <&intc_fiq GIC_SPI 0 IRQ_TYPE_LEVEL_HIGH>;
+    };
+...
Signature · 1 line
2.34.1
merge bot Applied
#7 lore raw

[tip: timers/core] dt-bindings: timer: Add Mstar MSC313e timer devicetree bindings documentation

The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     7647204c2e81b28b4a7c4eec7d539f998d48eaf0
Gitweb:        https://git.kernel.org/tip/7647204c2e81b28b4a7c4eec7d539f998d48eaf0
Author:        Romain Perier <[email protected]>
AuthorDate:    Fri, 17 Dec 2021 20:57:25 +01:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Mon, 20 Dec 2021 13:28:47 +01:00

dt-bindings: timer: Add Mstar MSC313e timer devicetree bindings documentation

This adds the documentation for the devicetree bindings of the Mstar MSC313e timer driver, found from MSC313e SoCs and newer.

---
 Documentation/devicetree/bindings/timer/mstar,msc313e-timer.yaml | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/timer/mstar,msc313e-timer.yaml
Documentation/devicetree/bindings/timer/mstar,msc313e-timer.yaml new file +46 -0
new file mode 100644
index 0000000..03d5dba
@@ -0,0 +1,46 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/timer/mstar,msc313e-timer.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Mstar MSC313e Timer Device Tree Bindings
+
+maintainers:
+  - Daniel Palmer <[email protected]>
+  - Romain Perier <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - mstar,msc313e-timer
+      - sstar,ssd20xd-timer
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    timer@6040 {
+        compatible = "mstar,msc313e-timer";
+        reg = <0x6040 0x40>;
+        clocks = <&xtal_div2>;
+        interrupts-extended = <&intc_fiq GIC_SPI 0 IRQ_TYPE_LEVEL_HIGH>;
+    };
+...
author maintainer
#8 lore raw

PATCH v3 5/6 ARM: dts: mstar: Add timers device nodes

In reply to Romain Perier

This adds the definition of the timers device node.

---
 arch/arm/boot/dts/mstar-v7.dtsi | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
arch/arm/boot/dts/mstar-v7.dtsi +20 -0
index 89ebfe4f29da..7ede4cec0af9 100644
@@ -123,6 +123,26 @@ watchdog@6000 {
 				clocks = <&xtal_div2>;
 			};
 
+			timer@6040 {
+				compatible = "mstar,msc313e-timer";
+				reg = <0x6040 0x40>;
+				clocks = <&xtal_div2>;
+				interrupts-extended = <&intc_fiq GIC_SPI 0 IRQ_TYPE_LEVEL_HIGH>;
+			};
+
+			timer1: timer@6080 {
+				compatible = "mstar,msc313e-timer";
+				reg = <0x6080 0x40>;
+				clocks = <&xtal_div2>;
+				interrupts-extended = <&intc_fiq GIC_SPI 1 IRQ_TYPE_LEVEL_HIGH>;
+			};
+
+			timer2: timer@60c0 {
+				compatible = "mstar,msc313e-timer";
+				reg = <0x60c0 0x40>;
+				clocks = <&xtal_div2>;
+				interrupts-extended = <&intc_fiq GIC_SPI 12 IRQ_TYPE_LEVEL_HIGH>;
+			};
 
 			intc_fiq: interrupt-controller@201310 {
 				compatible = "mstar,mst-intc";
Signature · 1 line
2.34.1
author maintainer
#9 lore raw

PATCH v3 6/6 ARM: dts: mstar: Switch to compatible "sstar,ssd20xd-timer" on infinity2m

In reply to Romain Perier

This defines the real oscillators as input of timer1 and timer2 and switch to "sstar,ssd20xd-timer".

---
 arch/arm/boot/dts/mstar-infinity2m.dtsi | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
arch/arm/boot/dts/mstar-infinity2m.dtsi +18 -0
index 6d4d1d224e96..080a18b9effb 100644
@@ -6,6 +6,14 @@
 
 #include "mstar-infinity.dtsi"
 
+/ {
+	clk_timer: timer_clk {
+		#clock-cells = <0>;
+		compatible = "fixed-clock";
+		clock-frequency = <432000000>;
+	};
+};
+
 &cpus {
 	cpu1: cpu@1 {
 		device_type = "cpu";
@@ -20,3 +28,13 @@ smpctrl: smpctrl@204000 {
 		status = "disabled";
 	};
 };
+
+&timer1 {
+	compatible = "sstar,ssd20xd-timer";
+	clocks = <&clk_timer>;
+};
+
+&timer2 {
+	compatible = "sstar,ssd20xd-timer";
+	clocks = <&clk_timer>;
+};
Signature · 1 line
2.34.1