Add the System Timer Module counter
Subsystems (4)
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.
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 | 387 ++++++++++++++++++ 4 files changed, 473 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 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 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
Re: [PATCH v1 2/3] dt-bindings: counter: Add NXP System Timer Module Counter
Quoted 9 lines · Daniel Lezcano
Add 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.
Signed-off-by Daniel Lezcano <[email protected]>--- .../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
PATCH 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 | 387 ++++++++++++++++++++++++++++++++++ 3 files changed, 398 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 +387 -0
387 lines not on this page · raw message
Signature · 1 line
2.43.0
kernel test robot
build botRe: [PATCH v1 3/3] counter: Add STM based counter
kernel test robot noticed the following build errors:
Hi Daniel,
kernel test robot noticed the following build errors:
[auto build test ERROR on robh/for-next]
[also build test ERROR on linus/master v6.18 next-20251208] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Daniel-Lezcano/counters-Reorder-the-Makefile/20251208-110937 base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next patch link: https://lore.kernel.org/r/20251208030413.3117660-4-daniel.lezcano%40linaro.org patch subject: [PATCH v1 3/3] counter: Add STM based counter config: loongarch-randconfig-001-20251209 (https://download.01.org/0day-ci/archive/20251209/[email protected]/config) compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 6ec8c4351cfc1d0627d1633b02ea787bd29c77d8) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251209/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> drivers/counter/nxp-stm-cnt.c:110:2: error: call to undeclared function 'FIELD_MODIFY'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
110 | FIELD_MODIFY(STM_CR_CPS_MASK, ®, prescaler);
| ^
>> drivers/counter/nxp-stm-cnt.c:119:9: error: call to undeclared function 'FIELD_GET'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
119 | return FIELD_GET(STM_CR_CPS_MASK, reg);
| ^
drivers/counter/nxp-stm-cnt.c:128:11: error: call to undeclared function 'FIELD_GET'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
128 | return !!FIELD_GET(STM_CR_TEN, reg);
| ^3 errors generated.
vim +/FIELD_MODIFY +110 drivers/counter/nxp-stm-cnt.c
103
104 static void nxp_stm_cnt_set_prescaler(struct nxp_stm_cnt *stm_cnt, u8 prescaler)
105 {
106 u32 reg;
107
108 reg = readl(STM_CR(stm_cnt->base));
109
> 110 FIELD_MODIFY(STM_CR_CPS_MASK, ®, prescaler);
111
112 writel(reg, STM_CR(stm_cnt->base));
113 }
114
115 static u8 nxp_stm_cnt_get_prescaler(struct nxp_stm_cnt *stm_cnt)
116 {
117 u32 reg = readl(STM_CR(stm_cnt->base));
118
> 119 return FIELD_GET(STM_CR_CPS_MASK, reg); 120 }
121
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH v1 3/3] counter: Add STM based counter
In reply to Daniel Lezcanokernel test robot noticed the following build warnings:
Hi Daniel,
kernel test robot noticed the following build warnings:
[auto build test WARNING on robh/for-next]
[also build test WARNING on linus/master v6.18 next-20251208] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Daniel-Lezcano/counters-Reorder-the-Makefile/20251208-110937 base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next patch link: https://lore.kernel.org/r/20251208030413.3117660-4-daniel.lezcano%40linaro.org patch subject: [PATCH v1 3/3] counter: Add STM based counter config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20251209/[email protected]/config) compiler: alpha-linux-gcc (GCC) 15.1.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251209/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
drivers/counter/nxp-stm-cnt.c: In function 'nxp_stm_cnt_set_prescaler':
drivers/counter/nxp-stm-cnt.c:110:9: error: implicit declaration of function 'FIELD_MODIFY' [-Wimplicit-function-declaration]
110 | FIELD_MODIFY(STM_CR_CPS_MASK, ®, prescaler);
| ^~~~~~~~~~~~
drivers/counter/nxp-stm-cnt.c: In function 'nxp_stm_cnt_get_prescaler':
drivers/counter/nxp-stm-cnt.c:119:16: error: implicit declaration of function 'FIELD_GET' [-Wimplicit-function-declaration]
119 | return FIELD_GET(STM_CR_CPS_MASK, reg);
| ^~~~~~~~~
drivers/counter/nxp-stm-cnt.c: At top level:
>> drivers/counter/nxp-stm-cnt.c:303:32: warning: 'nxp_stm_cnt_pm_ops' defined but not used [-Wunused-const-variable=]
303 | static const struct dev_pm_ops nxp_stm_cnt_pm_ops = {
| ^~~~~~~~~~~~~~~~~~vim +/nxp_stm_cnt_pm_ops +303 drivers/counter/nxp-stm-cnt.c
302
> 303 static const struct dev_pm_ops nxp_stm_cnt_pm_ops = { 304 .suspend = nxp_stm_cnt_suspend,
305 .resume = nxp_stm_cnt_resume,
306 };
307
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH v1 3/3] counter: Add STM based counter
In reply to Daniel Lezcanokernel test robot noticed the following build warnings:
Hi Daniel,
kernel test robot noticed the following build warnings:
[auto build test WARNING on robh/for-next]
[also build test WARNING on linus/master v6.18 next-20251208] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Daniel-Lezcano/counters-Reorder-the-Makefile/20251208-110937 base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next patch link: https://lore.kernel.org/r/20251208030413.3117660-4-daniel.lezcano%40linaro.org patch subject: [PATCH v1 3/3] counter: Add STM based counter config: riscv-allyesconfig (https://download.01.org/0day-ci/archive/20251209/[email protected]/config) compiler: clang version 16.0.6 (https://github.com/llvm/llvm-project 7cbf1a2591520c2491aa35339f227775f4d3adf6) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251209/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/counter/nxp-stm-cnt.c:303:32: warning: unused variable 'nxp_stm_cnt_pm_ops' [-Wunused-const-variable]
static const struct dev_pm_ops nxp_stm_cnt_pm_ops = {
^1 warning generated.
vim +/nxp_stm_cnt_pm_ops +303 drivers/counter/nxp-stm-cnt.c
302
> 303 static const struct dev_pm_ops nxp_stm_cnt_pm_ops = { 304 .suspend = nxp_stm_cnt_suspend,
305 .resume = nxp_stm_cnt_resume,
306 };
307
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki