Skip to contentSkip to conversation

Add the System Timer Module for the NXP S32 architecture

PATCH Superseded Daniel Lezcano 2 participants 5 messages Apr 1, 2025 – Apr 2, 2025

Subsystems (3)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover Add the System Timer Module for the NXP S32 architecture

These couple of changes bring the System Timer Module - STM which is part of the NXP S32 architecture.

The timer module has one counter and four comparators, an interrupt line when one of the comparator matches the counter. That means the interrupt is shared across the comparator.

The number of STM is equal to the number of core available on the system. For the s32g2 variant, there are three Cortex-M3 and four Cortex-A53, consequently there are seven STM modules dedicated to those.

In addition, there is a STM variant which is read-only, so the counter can not be set because it is tied to another STM module dedicated to timestamp. These special STM modules are apart and will be handled differently as they can not be used as a clockevent. They are not part of these changes.

The choice is to have one STM instance, aka one STM description in the device tree, which initialize a clocksource and a clockevent per CPU. The latter is assigned to a CPU given the order of their description. First is CPU0, second is CPU1, etc ...

Changelog:

- v3
- Fixed bindings, compatible description and name (Krzysztof Kozlowski)
- Fixed bindings filename to fit the compatible (Krzysztof Kozlowski)
- Fixed a couple of typos in the driver changelog (Ghennadi Procopciuc)
- Enclosed macro into parenthesis (Ghennadi Procopciuc)
- Replaced irq_of_parse_and_map() by platform_get_irq() (Ghennadi Procopciuc)
- Fixed checkpatch --script reports
- Removed debugfs as the driver is not considered complex enough (Arnd Bergmann)

- v2:
- Fixed errors reported by 'make dt_binding_check' (Rob Herring)
- Removed unneeded '|' symbol (Rob Herring)
- Removed 'clocks' description (Rob Herring)
- Removed 'clock-names' because there is only one description (Rob Herring)
- Renamed 'stm@' to 'timer@' in the DT binding example (Rob Herring)
- Fixed dt bindings patch subject (Krzysztof Kozlowski)
- Dropped 'OneOf' in the DT bindings (Krzysztof Kozlowski)
- Dropped the STM instances structure
- Use the dev_err_probe() helper (Krzysztof Kozlowski)
- Use the dev_err_probe() helper (Krzysztof Kozlowski)
- Use devm_clk_get_enabled() (Krzysztof Kozlowski)
- Removed unneeded headers (Ghennadi Procopciuc)
- Removed unused macro (Ghennadi Procopciuc)
- Replaced 'int' by 'unsigned int' (Ghennadi Procopciuc)
- Removed dev_set_drvdata() (Ghennadi Procopciuc)
- Prevent disabling the entire module and set min delta (Ghennadi Procopciuc)
- Factored out the clocksource / clockevent init routine (Ghennadi Procopciuc)
- Use devm_request_irq() (Ghennadi Procopciuc.)
- Use irq_dispose_mapping() for error rollbacking (Ghennadi Procopciuc)

- v1: initial post

Daniel Lezcano (2):
dt-bindings: timer: Add NXP System Timer Module clocksource/drivers/nxp-timer: Add the System Timer Module for the
s32gx platforms

 .../bindings/timer/nxp,s32g2-stm.yaml         |  53 ++
 drivers/clocksource/Kconfig                   |   9 +
 drivers/clocksource/Makefile                  |   2 +
 drivers/clocksource/timer-nxp-stm.c           | 496 ++++++++++++++++++
 4 files changed, 560 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/timer/nxp,s32g2-stm.yaml
 create mode 100644 drivers/clocksource/timer-nxp-stm.c
Signature · 1 line
2.43.0
#1 lore raw

PATCH v3 1/2 dt-bindings: timer: Add NXP System Timer Module

Add the System Timer Module description found on the NXP s32 platform and the compatible for the s32g2 variant.

Cc Ghennadi Procopciuc <[email protected]>
Cc Krzysztof Kozlowski <[email protected]>
Cc Thomas Fossati <[email protected]>
---
 .../bindings/timer/nxp,s32g2-stm.yaml         | 53 +++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/timer/nxp,s32g2-stm.yaml
Documentation/devicetree/bindings/timer/nxp,s32g2-stm.yaml new file +53 -0
new file mode 100644
index 000000000000..2016f346b2ee
@@ -0,0 +1,53 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/timer/nxp,s32g2-stm.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: NXP System Timer Module (STM)
+
+maintainers:
+  - Daniel Lezcano <[email protected]>
+
+description:
+  The System Timer Module supports commonly required system and application
+  software timing functions. STM includes a 32-bit count-up timer and four
+  32-bit compare channels with a separate interrupt source for each channel.
+  The timer is driven by the STM module clock divided by an 8-bit prescale
+  value.
+
+properties:
+  compatible:
+    oneOf:
+      - const: nxp,s32g2-stm
+      - items:
+          - const: nxp,s32g3-stm
+          - const: nxp,s32g2-stm
+
+  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@4011c000 {
+        compatible = "nxp,s32g2-stm";
+        reg = <0x4011c000 0x3000>;
+        interrupts = <GIC_SPI 24 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&clks 0x3b>;
+    };
Signature · 1 line
2.43.0
Reviewed-by on v3 1/2
#2 lore raw

Re: [PATCH v3 1/2] dt-bindings: timer: Add NXP System Timer Module

Quoted 11 lines · Daniel Lezcano

Add the System Timer Module description found on the NXP s32 platform and the compatible for the s32g2 variant.

Cc Ghennadi Procopciuc <[email protected]>
Cc Krzysztof Kozlowski <[email protected]>
Cc Thomas Fossati <[email protected]>
---
 .../bindings/timer/nxp,s32g2-stm.yaml         | 53 +++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/timer/nxp,s32g2-stm.yaml

Best regards,
Krzysztof

#3 lore raw

PATCH v3 2/2 clocksource/drivers/nxp-timer: Add the System Timer Module for the s32gx platforms

In reply to Daniel Lezcano

STM supports commonly required system and application software timing functions. STM includes a 32-bit count-up timer and four 32-bit compare channels with a separate interrupt source for each channel. The timer is driven by the STM module clock divided by an 8-bit prescale value (1 to 256).

STM has the following features:
• One 32-bit count-up timer with an 8-bit prescaler
• Four 32-bit compare channels
• An independent interrupt source for each channel
• Ability to stop the timer in Debug mode

The s32g platform is declined into two versions, the s32g2 and the s32g3. The former has a STM block with 8 timers and the latter has 12 timers.

The platform is designed to have one usable STM instance per core on the system which is composed of 3 x Cortex-M3 + 4 Cortex-A53 for the s32g2 and 3 x Cortex-M3 + 8 Cortex-A53 for the s32g3.

There is a special STM instance called STM_TS which is dedicated to the timestamp. The 7th STM instance STM_07 is directly tied to the STM_TS which means it is not usable as a clockevent.

The driver instantiate each STM described in the device tree as a clocksource and a clockevent conforming to the reference manual even if the Linux system does not use all of the clocksource. Each clockevent will have a cpumask set for a specific CPU.

Given the counter is shared between the clocksource and the clockevent, the STM module can not be disabled by one or another so the refcounting mechanism is used to stop the counter when it reaches zero and to start it when it is one. The suspend and resume relies on the refcount to stop the module.

As the device tree will have multiple STM entries, the driver can be probed in parallel with the async option but it is not enabled yet. However, the driver code takes care of preventing a race by putting a lock to protect the number of STM instances global variable which means it is ready to support the option when enough testing will be done with the underlying time framework.

Cc Ghennadi Procopciuc <[email protected]>
Cc Krzysztof Kozlowski <[email protected]>
Cc Thomas Fossati <[email protected]>
---
 drivers/clocksource/Kconfig         |   9 +
 drivers/clocksource/Makefile        |   2 +
 drivers/clocksource/timer-nxp-stm.c | 496 ++++++++++++++++++++++++++++
 3 files changed, 507 insertions(+)
 create mode 100644 drivers/clocksource/timer-nxp-stm.c
drivers/clocksource/Kconfig +9 -0
index 487c85259967..e86e327392af 100644
@@ -763,4 +763,13 @@ config RALINK_TIMER
 	  Enables support for system tick counter present on
 	  Ralink SoCs RT3352 and MT7620.
 
+config NXP_STM_TIMER
+	bool "NXP System Timer Module driver"
+	depends on ARCH_S32 || COMPILE_TEST
+	select CLKSRC_MMIO
+	help
+	  Support for NXP System Timer Module. It will create, in this
+	  order, a clocksource, a broadcast clockevent and a per cpu
+	  clockevent.
+
 endmenu
drivers/clocksource/Makefile +2 -0
index 43ef16a4efa6..c3a92e6b9f94 100644
@@ -92,3 +92,5 @@ obj-$(CONFIG_GXP_TIMER)			+= timer-gxp.o
 obj-$(CONFIG_CLKSRC_LOONGSON1_PWM)	+= timer-loongson1-pwm.o
 obj-$(CONFIG_EP93XX_TIMER)		+= timer-ep93xx.o
 obj-$(CONFIG_RALINK_TIMER)		+= timer-ralink.o
+obj-$(CONFIG_NXP_STM_TIMER)		+= timer-nxp-stm.o
+
drivers/clocksource/timer-nxp-stm.c new file +496 -0

496 lines not on this page · raw message

Signature · 1 line
2.43.0
#4 lore raw

Re: [PATCH v3 2/2] clocksource/drivers/nxp-timer: Add the System Timer Module for the s32gx platforms

drivers/clocksource/timer-nxp-stm.c line 481

Quoted 4 lines · Daniel Lezcano
drivers/clocksource/timer-nxp-stm.c new file +4 -0
+
+static const struct of_device_id nxp_stm_of_match[] = {
+	{ .compatible = "nxp,s32g2-stm" },
+	{ .compatible = "nxp,s32g3-stm" },

Drop, the entire point of me asking for compatibility is not to have useless entries for the same devices.

drivers/clocksource/timer-nxp-stm.c line 490

Quoted 9 lines
drivers/clocksource/timer-nxp-stm.c new file +9 -0
+	{ }
+};
+MODULE_DEVICE_TABLE(of, nxp_stm_of_match);
+
+static struct platform_driver nxp_stm_probe = {
+	.probe	= nxp_stm_timer_probe,
+	.driver	= {
+		.name		= "nxp-stm",
+		.of_match_table	= of_match_ptr(nxp_stm_of_match),

Drop of_match_ptr, you have here a warning.

Quoted 9 lines
drivers/clocksource/timer-nxp-stm.c new file +6 -0
+	},
+};
+module_platform_driver(nxp_stm_probe);
+
+MODULE_DESCRIPTION("NXP System Timer Module driver");
+MODULE_LICENSE("GPL");
Signature · 1 line
2.43.0