Add the System Timer Module for the NXP S32 architecture
Subsystems (3)
v2 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:
- 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
s32g platform
.../bindings/timer/nxp,stm-timer.yaml | 50 ++ drivers/clocksource/Kconfig | 9 + drivers/clocksource/Makefile | 2 + drivers/clocksource/timer-nxp-stm.c | 563 ++++++++++++++++++ 4 files changed, 624 insertions(+) create mode 100644 Documentation/devicetree/bindings/timer/nxp,stm-timer.yaml create mode 100644 drivers/clocksource/timer-nxp-stm.c
Signature · 1 line
2.43.0
PATCH v2 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.
--- .../bindings/timer/nxp,stm-timer.yaml | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Documentation/devicetree/bindings/timer/nxp,stm-timer.yaml
Documentation/devicetree/bindings/timer/nxp,stm-timer.yaml new file +50 -0
@@ -0,0 +1,50 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/timer/nxp,stm-timer.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: + enum: + - nxp,s32g-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,s32g-stm"; + reg = <0x4011c000 0x3000>; + interrupts = <GIC_SPI 24 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clks 0x3b>; + };
Signature · 1 line
2.43.0
Re: [PATCH v2 1/2] dt-bindings: timer: Add NXP System Timer Module
Quoted 8 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]>Signed-off-by Daniel Lezcano <[email protected]>---
I got only this patch, no cover letter, no changelog. What happened here?
Documentation/devicetree/bindings/timer/nxp,stm-timer.yaml
Quoted 9 lines
.../bindings/timer/nxp,stm-timer.yaml | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Documentation/devicetree/bindings/timer/nxp,stm-timer.yamlDocumentation/devicetree/bindings/timer/nxp,stm-timer.yaml new file +0
-0
Filename following compatible.
Quoted 13 lines
Documentation/devicetree/bindings/timer/nxp,stm-timer.yaml new file +12
-0@@ -0,0 +1,50 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/timer/nxp,stm-timer.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: NXP System Timer Module (STM) + +maintainers: + - Daniel Lezcano <[email protected]> + +description:
Documentation/devicetree/bindings/timer/nxp,stm-timer.yaml line 22
Quoted 10 lines
Documentation/devicetree/bindings/timer/nxp,stm-timer.yaml new file +10
-0+ 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: + enum: + - nxp,s32g-stm
Previously it was told to me there is no such soc as s32g but they are named differently, e.g. s32g2. See other bindings.
Please consult internally and come with one unified approach to all NXP bindings. Otherwise, if this is a real soc, fix this for top level compatibles, because there is no s32g there either.
This applies to all NXP-related patches (which I am sure was previously discussed on the lists).
What is confusing: previous compatible was correct and I did not ask to change it.
Best regards,
Krzysztof
Re: [PATCH v2 1/2] dt-bindings: timer: Add NXP System Timer Module
Quoted 11 lines · Krzysztof Kozlowski
Quoted 8 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]>Signed-off-by Daniel Lezcano <[email protected]>---
I got only this patch, no cover letter, no changelog. What happened here?
My bad, my scripts needs some more work :)
Will Cc you in the next version
Quoted 43 lines
Documentation/devicetree/bindings/timer/nxp,stm-timer.yaml
Quoted 9 lines
.../bindings/timer/nxp,stm-timer.yaml | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+)create mode 100644
Documentation/devicetree/bindings/timer/nxp,stm-timer.yamlDocumentation/devicetree/bindings/timer/nxp,stm-timer.yaml new file +0
-0Filename following compatible.
Quoted 13 lines
Documentation/devicetree/bindings/timer/nxp,stm-timer.yaml new file +12
-0@@ -0,0 +1,50 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/timer/nxp,stm-timer.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: NXP System Timer Module (STM) + +maintainers: + - Daniel Lezcano <[email protected]> + +description:Documentation/devicetree/bindings/timer/nxp,stm-timer.yaml line 22
Quoted 10 lines
Documentation/devicetree/bindings/timer/nxp,stm-timer.yaml new file +10
-0+ 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: + enum: + - nxp,s32g-stmPreviously it was told to me there is no such soc as s32g but they are named differently, e.g. s32g2. See other bindings.
Please consult internally and come with one unified approach to all NXP bindings. Otherwise, if this is a real soc, fix this for top level compatibles, because there is no s32g there either.
Quoted 5 lines
This applies to all NXP-related patches (which I am sure was previously discussed on the lists).
What is confusing: previous compatible was correct and I did not ask to change it.
Yeah, I think the answer is straightforward. It is s32g2 and s32g3, the two platforms having the STM. I'll will fix the compatibles.
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
PATCH v2 2/2 clocksource/drivers/nxp-timer: Add the System Timer Module for the s32g platform
In reply to Daniel LezcanoSTM 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.
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 instanciate each STM instance 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.
In order to improve the driver quality for debug purpose, the debugfs entry is set to show the registers and the refcount of an STM instance.
--- drivers/clocksource/Kconfig | 9 + drivers/clocksource/Makefile | 2 + drivers/clocksource/timer-nxp-stm.c | 563 ++++++++++++++++++++++++++++ 3 files changed, 574 insertions(+) create mode 100644 drivers/clocksource/timer-nxp-stm.c
drivers/clocksource/Kconfig +9 -0
@@ -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
@@ -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 +563 -0
563 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v2 2/2] clocksource/drivers/nxp-timer: Add the System Timer Module for the s32g platform
Quoted 12 lines · 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
Quoted 7 lines
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.
Missing: ' ... for S32G3' ?
Quoted 6 lines
There is a special STM instance called
STM_TSwhich is dedicated to the timestamp. The 7th STM instanceSTM_07is directly tied to theSTM_TSwhich means it is not usable as a clockevent.The driver instanciate each STM instance described in the device tree
instanciate - > instantiate ?
[ ... ]
Quoted 9 lines
drivers/clocksource/timer-nxp-stm.c new file +9
-0+#include <linux/clk.h> +#include <linux/clockchips.h> +#include <linux/cpuhotplug.h> +#include <linux/debugfs.h> +#include <linux/interrupt.h> +#include <linux/module.h> +#include <linux/of_irq.h> +#include <linux/platform_device.h> +#include <linux/sched_clock.h>
drivers/clocksource/timer-nxp-stm.c line 33
Quoted 10 lines
drivers/clocksource/timer-nxp-stm.c new file +10
-0+#include <linux/units.h> + +#define STM_CR (__base) (__base) + +#define STM_CR_TEN BIT(0) +#define STM_CR_FRZ BIT(1) +#define STM_CR_CPS_OFFSET 8u +#define STM_CR_CPS_MASK GENMASK(15, STM_CR_CPS_OFFSET) + +#define STM_CNT (__base) (__base + 0x04)
Shouldn't the macro arguments be enclosed in parentheses to avoid potential evaluation order issues?
[ ... ]
Quoted 39 lines
drivers/clocksource/timer-nxp-stm.c new file +39
-0+static int __init nxp_stm_timer_probe (struct platform_device *pdev) +{ +struct stm_timer *stm_timer; +struct device *dev = &pdev->dev; +struct device_node *np = dev->of_node; +const char *name =of_node_full_name (np); +struct clk *clk; +void __iomem *base; +int irq, ret; + +/* +* The device tree can have multiple STM nodes described, so +* it makes this driver a good candidate for the async probe. +* It is still unclear if the time framework does correctly +* handle a parallel loading of the timers but at least this +* driver is ready to support the option. +*/ +guard (stm_instances)(&stm_instances_lock); + +/* +* The S32Gx are SoCs featuring a diverse set of cores. Linux +* is expected to run on Cortex-A53 cores, while other +* software stacks will operate on Cortex-M cores. The number +* of STM instances has been sized to include at most one +* instance per core. +* +* As we need a clocksource and a clockevent per cpu, we +* simply initialize a clocksource per cpu along with the +* clockevent which makes the resulting code simpler. +* +* However if the device tree is describing more STM instances +* than the number of cores, then we ignore them. +*/ +if (stm_instances >=num_possible_cpus ()) +return 0 ; + + base =devm_of_iomap (dev, np,0 ,NULL ); +if (IS_ERR (base)) +return dev_err_probe (dev,PTR_ERR (base),"Failed to iomap %pOFn\n" , np);
drivers/clocksource/timer-nxp-stm.c line 497
Quoted 10 lines
drivers/clocksource/timer-nxp-stm.c new file +10
-0+ + irq =irq_of_parse_and_map (np,0 ); +if (irq <=0 ) +return dev_err_probe (dev, irq,"Failed to parse and map IRQ\n" ); + + ret =devm_add_action_or_reset (dev, devm_irq_dispose_mapping, &irq); +if (ret) { +irq_dispose_mapping (irq); +return dev_err_probe (dev, ret,"Failed to add devm action\n" ); + }
Wouldn't platform_get_irq achieve the same result, but with less hassle?
Signature · 2 lines
Regards, Ghennadi