Add the System Timer Module counter
Subsystems (4)
v2 cover Add the System Timer Module counter
The NXP S32 family provides a System Timer Module (STM), a 32-bit free-running counter clocked from a peripheral clock. The STM includes a prescaler and one or more compare channels generating optional interrupts. When used as a generic hardware counter, only the main free-running counter is required, while the compare channels are typically unused.
On S32G2 devices, the STM is exposed as a simple counter block that can operate continuously and be shared across subsystems such as the Linux kernel, firmware components running on Cortex-M7 cores, or other co-processors. The counter can be read atomically and provides a stable timestamp source to correlate events occurring in different execution contexts.
The Linux kernel controls the STM through a memory-mapped interface, configuring the prescaler, enabling or disabling the counter, and accounting for wrap-arounds. Other subsystems access the counter in read-only mode, making it a shared timestamp reference across the platform.
This driver adds support for the STM when used as a counter on S32G2 platforms. The device is described in the device tree using the following compatible:
compatible = "nxp,s32g2-stm-cnt";
The driver exposes basic counter functionality: start, stop, reset, prescaler configuration, and overflow handling.
Changelog:
* v2
- Added Rob's tag
** kbuild
- Reordered alphabetically the headers
- Added bitfield.h header
- Use DEFINE_SIMPLE_DEV_PM_OPS() and pm_sleep_ptr()
Daniel Lezcano (3):
counters: Reorder the Makefile
dt-bindings: counter: Add NXP System Timer Module Counter
counter: Add STM based counter
.../bindings/counter/nxp,s32g2-stm-cnt.yaml | 64 +++ drivers/counter/Kconfig | 10 + drivers/counter/Makefile | 21 +- drivers/counter/nxp-stm-cnt.c | 386 ++++++++++++++++++ 4 files changed, 472 insertions(+), 9 deletions(-) create mode 100644 Documentation/devicetree/bindings/counter/nxp,s32g2-stm-cnt.yaml create mode 100644 drivers/counter/nxp-stm-cnt.c
Signature · 1 line
2.43.0
PATCH v2 1/3 counters: Reorder the Makefile
The next changes provide a new driver. For the sake of clarity, reorder the Makefile alphabetically.
No functional changes intended.
--- drivers/counter/Makefile | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/counter/Makefile +11 -9
@@ -6,14 +6,16 @@ obj-$(CONFIG_COUNTER) += counter.o counter-y := counter-core.o counter-sysfs.o counter-chrdev.o -obj-$(CONFIG_I8254) += i8254.o -obj-$(CONFIG_104_QUAD_8) += 104-quad-8.o +obj-$(CONFIG_104_QUAD_8) += 104-quad-8.o +obj-$(CONFIG_FTM_QUADDEC) += ftm-quaddec.o +obj-$(CONFIG_I8254) += i8254.o +obj-$(CONFIG_INTEL_QEP) += intel-qep.o obj-$(CONFIG_INTERRUPT_CNT) += interrupt-cnt.o -obj-$(CONFIG_RZ_MTU3_CNT) += rz-mtu3-cnt.o -obj-$(CONFIG_STM32_TIMER_CNT) += stm32-timer-cnt.o -obj-$(CONFIG_STM32_LPTIMER_CNT) += stm32-lptimer-cnt.o -obj-$(CONFIG_TI_EQEP) += ti-eqep.o -obj-$(CONFIG_FTM_QUADDEC) += ftm-quaddec.o obj-$(CONFIG_MICROCHIP_TCB_CAPTURE) += microchip-tcb-capture.o -obj-$(CONFIG_INTEL_QEP) += intel-qep.o -obj-$(CONFIG_TI_ECAP_CAPTURE) += ti-ecap-capture.o +obj-$(CONFIG_RZ_MTU3_CNT) += rz-mtu3-cnt.o +obj-$(CONFIG_STM32_TIMER_CNT) += stm32-timer-cnt.o +obj-$(CONFIG_STM32_LPTIMER_CNT) += stm32-lptimer-cnt.o +obj-$(CONFIG_TI_ECAP_CAPTURE) += ti-ecap-capture.o +obj-$(CONFIG_TI_EQEP) += ti-eqep.o + +
Signature · 1 line
2.43.0
PATCH v2 2/3 dt-bindings: counter: Add NXP System Timer Module Counter
In reply to Daniel LezcanoAdd the System Timer Module description found on the NXP s32 platform when it is used as a counter and the compatible for the s32g2 variant.
--- .../bindings/counter/nxp,s32g2-stm-cnt.yaml | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Documentation/devicetree/bindings/counter/nxp,s32g2-stm-cnt.yaml
Documentation/devicetree/bindings/counter/nxp,s32g2-stm-cnt.yaml new file +64 -0
@@ -0,0 +1,64 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/counter/nxp,s32g2-stm-cnt.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 counter is driven by the STM module clock divided by an 8-bit prescale + value. + +properties: + compatible: + oneOf: + - const: nxp,s32g2-stm-cnt + - items: + - const: nxp,s32g3-stm-cnt + - const: nxp,s32g2-stm-cnt + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + items: + - description: Counter clock + - description: Module clock + - description: Register clock + + clock-names: + items: + - const: counter + - const: module + - const: register + +required: + - compatible + - reg + - interrupts + - clocks + - clock-names + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + + timer@4011c000 { + compatible = "nxp,s32g2-stm-cnt"; + reg = <0x4011c000 0x3000>; + interrupts = <GIC_SPI 24 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clks 0x3b>, <&clks 0x3c>, <&clks 0x3c>; + clock-names = "counter", "module", "register"; + };
Signature · 1 line
2.43.0
PATCH v2 3/3 counter: Add STM based counter
In reply to Daniel LezcanoThe NXP S32G2 automotive platform integrates four Cortex-A53 cores and three Cortex-M7 cores, along with a large number of timers and counters. These hardware blocks can be used as clocksources or clockevents, or as timestamp counters shared across the various subsystems running alongside the Linux kernel, such as firmware components. Their actual usage depends on the overall platform software design.
In a Linux-based system, the kernel controls the counter, which is a read-only shared resource for the other subsystems. One of its primary purposes is to act as a common timestamp source for messages or traces, allowing correlation of events occurring in different operating system contexts.
These changes introduce a basic counter driver that can start, stop, and reset the counter. It also handles overflow accounting and configures the prescaler value.
--- drivers/counter/Kconfig | 10 + drivers/counter/Makefile | 1 + drivers/counter/nxp-stm-cnt.c | 386 ++++++++++++++++++++++++++++++++++ 3 files changed, 397 insertions(+) create mode 100644 drivers/counter/nxp-stm-cnt.c
drivers/counter/Kconfig +10 -0
@@ -90,6 +90,16 @@ config MICROCHIP_TCB_CAPTURE To compile this driver as a module, choose M here: the module will be called microchip-tcb-capture. +config NXP_STM_CNT + tristate "NXP System Timer Module Counter driver" + depends on ARCH_S32 || COMPILE_TEST + help + Select this option to enable the NXP System Timer Module + Counter driver. + + To compile this driver as a module, choose M here: the + module will be called nxp_stm_cnt. + config RZ_MTU3_CNT tristate "Renesas RZ/G2L MTU3a counter driver" depends on RZ_MTU3
drivers/counter/Makefile +1 -0
@@ -12,6 +12,7 @@ obj-$(CONFIG_I8254) += i8254.o obj-$(CONFIG_INTEL_QEP) += intel-qep.o obj-$(CONFIG_INTERRUPT_CNT) += interrupt-cnt.o obj-$(CONFIG_MICROCHIP_TCB_CAPTURE) += microchip-tcb-capture.o +obj-$(CONFIG_NXP_STM_CNT) += nxp-stm-cnt.o obj-$(CONFIG_RZ_MTU3_CNT) += rz-mtu3-cnt.o obj-$(CONFIG_STM32_TIMER_CNT) += stm32-timer-cnt.o obj-$(CONFIG_STM32_LPTIMER_CNT) += stm32-lptimer-cnt.o
drivers/counter/nxp-stm-cnt.c new file +386 -0
386 lines not on this page · raw message
Signature · 1 line
2.43.0