Skip to contentSkip to conversation

clockevent: add low power STM32 timer

PATCH Superseded Benjamin Gaignard 3 participants 13 messages Apr 1, 2020 – Apr 16, 2020

Subsystems (7)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v6 cover clockevent: add low power STM32 timer

This series add low power timer as boadcast clockevent device. Low power timer could runs even when CPUs are in idle mode and could wakeup them.

version 6:
- simplify binding, DT and code to use only one interrupt

version 5:
- document interrupts and interrupt-names bindings
- use a different wake up interrupt
- add device-tree patch
- make STM32MP157 select low power timer configuration flag
- enable fast_io in regmap configuration

version 4:
- move defines in mfd/stm32-lptimer.h
- change compatible and subnode names
- document wakeup-source property
- reword commit message
- make driver Kconfig depends of MFD_STM32_LPTIMER
- remove useless include
- remove rate and clk fields from the private structure
- to add comments about the registers sequence in stm32_clkevent_lp_set_timer
- rework probe function and use devm_request_irq()
- do not allow module to be removed

version 3:
- fix timer set sequence
- don't forget to free irq on remove function
- use devm_kzalloc to simplify errors handling in probe function

version 2:
- stm32 clkevent driver is now a child of the stm32 lp timer node
- add a probe function and adpat the driver to use regmap provide by it parent
- stop using timer_of helpers

Benjamin Gaignard (6):
dt-bindings: mfd: Document STM32 low power timer bindings
ARM: dts: stm32: Add timer subnodes on stm32mp15 SoCs
mfd: stm32: Add defines to be used for clkevent purpose
mfd: stm32: enable regmap fast_io for stm32-lptimer
clocksource: Add Low Power STM32 timers driver
ARM: mach-stm32: select low power timer for STM32MP157

 .../devicetree/bindings/mfd/st,stm32-lptimer.yaml  |  21 ++
 arch/arm/boot/dts/stm32mp151.dtsi                  |  35 ++++
 arch/arm/mach-stm32/Kconfig                        |   1 +
 drivers/clocksource/Kconfig                        |   4 +
 drivers/clocksource/Makefile                       |   1 +
 drivers/clocksource/timer-stm32-lp.c               | 221 +++++++++++++++++++++
 drivers/mfd/stm32-lptimer.c                        |   1 +
 include/linux/mfd/stm32-lptimer.h                  |   5 +
 8 files changed, 289 insertions(+)
 create mode 100644 drivers/clocksource/timer-stm32-lp.c
Signature · 7 lines
2.15.0


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#1 lore raw

PATCH v6 1/6 dt-bindings: mfd: Document STM32 low power timer bindings

Add a subnode to STM low power timer bindings to support timer driver

---
version 6:
- only use one interrupt

version 5:
- the previous has been acked-by Rob but since I have docummented interrupts and interrupt-names properties I haven't applied it here.

version 4:
- change compatible and subnode names
- document wakeup-source property

 .../devicetree/bindings/mfd/st,stm32-lptimer.yaml   | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
Documentation/devicetree/bindings/mfd/st,stm32-lptimer.yaml +21 -0
index 1a4cc5f3fb33..2a99b2296d2b 100644
@@ -33,12 +33,17 @@ properties:
     items:
       - const: mux
 
+  interrupts:
+    maxItems: 1
+
   "#address-cells":
     const: 1
 
   "#size-cells":
     const: 0
 
+  wakeup-source: true
+
   pwm:
     type: object
 
@@ -81,6 +86,16 @@ patternProperties:
     required:
       - compatible
 
+  timer:
+    type: object
+
+    properties:
+      compatible:
+        const: st,stm32-lptimer-timer
+
+    required:
+      - compatible
+
 required:
   - "#address-cells"
   - "#size-cells"
@@ -94,11 +109,13 @@ additionalProperties: false
 examples:
   - |
     #include <dt-bindings/clock/stm32mp1-clks.h>
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
     timer@40002400 {
       compatible = "st,stm32-lptimer";
       reg = <0x40002400 0x400>;
       clocks = <&timer_clk>;
       clock-names = "mux";
+      interrupts-extended = <&exti 47 IRQ_TYPE_LEVEL_HIGH>;
       #address-cells = <1>;
       #size-cells = <0>;
 
@@ -115,6 +132,10 @@ examples:
       counter {
         compatible = "st,stm32-lptimer-counter";
       };
+
+      timer {
+        compatible = "st,stm32-lptimer-timer";
+      };
     };
 
 ...
Signature · 1 line
2.15.0
Acked-by on v6 1/6
#2 lore raw

Re: [PATCH v6 1/6] dt-bindings: mfd: Document STM32 low power timer bindings

Quoted 12 lines · Benjamin Gaignard

Add a subnode to STM low power timer bindings to support timer driver

---
version 6:
- only use one interrupt

version 5:
- the previous has been acked-by Rob but since I have docummented interrupts and interrupt-names properties I haven't applied it here.

Quoted 7 lines

version 4:
- change compatible and subnode names
- document wakeup-source property

 .../devicetree/bindings/mfd/st,stm32-lptimer.yaml   | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Hi Benjamin,

Thanks,
Fabrice

Quoted 65 lines
Documentation/devicetree/bindings/mfd/st,stm32-lptimer.yaml +21 -0
index 1a4cc5f3fb33..2a99b2296d2b 100644
@@ -33,12 +33,17 @@ properties:
     items:
       - const: mux
 
+  interrupts:
+    maxItems: 1
+
   "#address-cells":
     const: 1
 
   "#size-cells":
     const: 0
 
+  wakeup-source: true
+
   pwm:
     type: object
 
@@ -81,6 +86,16 @@ patternProperties:
     required:
       - compatible
 
+  timer:
+    type: object
+
+    properties:
+      compatible:
+        const: st,stm32-lptimer-timer
+
+    required:
+      - compatible
+
 required:
   - "#address-cells"
   - "#size-cells"
@@ -94,11 +109,13 @@ additionalProperties: false
 examples:
   - |
     #include <dt-bindings/clock/stm32mp1-clks.h>
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
     timer@40002400 {
       compatible = "st,stm32-lptimer";
       reg = <0x40002400 0x400>;
       clocks = <&timer_clk>;
       clock-names = "mux";
+      interrupts-extended = <&exti 47 IRQ_TYPE_LEVEL_HIGH>;
       #address-cells = <1>;
       #size-cells = <0>;
 
@@ -115,6 +132,10 @@ examples:
       counter {
         compatible = "st,stm32-lptimer-counter";
       };
+
+      timer {
+        compatible = "st,stm32-lptimer-timer";
+      };
     };
 
...
#3 lore raw

Re: [PATCH v6 1/6] dt-bindings: mfd: Document STM32 low power timer bindings

In reply to Benjamin Gaignard
Quoted 12 lines · Benjamin Gaignard

Add a subnode to STM low power timer bindings to support timer driver

---
version 6:
- only use one interrupt

version 5:
- the previous has been acked-by Rob but since I have docummented interrupts and interrupt-names properties I haven't applied it here.

Quoted 6 lines

version 4:
- change compatible and subnode names
- document wakeup-source property

 .../devicetree/bindings/mfd/st,stm32-lptimer.yaml   | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

For my own reference:

Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#4 lore raw

PATCH v6 2/6 ARM: dts: stm32: Add timer subnodes on stm32mp15 SoCs

In reply to Benjamin Gaignard

Add timer subnode and interrupts to low power timer nodes for all stm32mp15x SoCs.

---
 arch/arm/boot/dts/stm32mp151.dtsi | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
arch/arm/boot/dts/stm32mp151.dtsi +35 -0
index fb41d0778b00..09e2dc209976 100644
@@ -358,6 +358,8 @@
 			reg = <0x40009000 0x400>;
 			clocks = <&rcc LPTIM1_K>;
 			clock-names = "mux";
+			interrupts-extended = <&exti 47 IRQ_TYPE_LEVEL_HIGH>;
+			wakeup-source;
 			status = "disabled";
 
 			pwm {
@@ -376,6 +378,11 @@
 				compatible = "st,stm32-lptimer-counter";
 				status = "disabled";
 			};
+
+			timer {
+				compatible = "st,stm32-lptimer-timer";
+				status = "disabled";
+			};
 		};
 
 		spi2: spi@4000b000 {
@@ -1135,6 +1142,8 @@
 			reg = <0x50021000 0x400>;
 			clocks = <&rcc LPTIM2_K>;
 			clock-names = "mux";
+			interrupts-extended = <&exti 48 IRQ_TYPE_LEVEL_HIGH>;
+			wakeup-source;
 			status = "disabled";
 
 			pwm {
@@ -1153,6 +1162,11 @@
 				compatible = "st,stm32-lptimer-counter";
 				status = "disabled";
 			};
+
+			timer {
+				compatible = "st,stm32-lptimer-timer";
+				status = "disabled";
+			};
 		};
 
 		lptimer3: timer@50022000 {
@@ -1162,6 +1176,8 @@
 			reg = <0x50022000 0x400>;
 			clocks = <&rcc LPTIM3_K>;
 			clock-names = "mux";
+			interrupts-extended = <&exti 50 IRQ_TYPE_LEVEL_HIGH>;
+			wakeup-source;
 			status = "disabled";
 
 			pwm {
@@ -1175,6 +1191,11 @@
 				reg = <2>;
 				status = "disabled";
 			};
+
+			timer {
+				compatible = "st,stm32-lptimer-timer";
+				status = "disabled";
+			};
 		};
 
 		lptimer4: timer@50023000 {
@@ -1182,6 +1203,8 @@
 			reg = <0x50023000 0x400>;
 			clocks = <&rcc LPTIM4_K>;
 			clock-names = "mux";
+			interrupts-extended = <&exti 52 IRQ_TYPE_LEVEL_HIGH>;
+			wakeup-source;
 			status = "disabled";
 
 			pwm {
@@ -1189,6 +1212,11 @@
 				#pwm-cells = <3>;
 				status = "disabled";
 			};
+
+			timer {
+				compatible = "st,stm32-lptimer-timer";
+				status = "disabled";
+			};
 		};
 
 		lptimer5: timer@50024000 {
@@ -1196,6 +1224,8 @@
 			reg = <0x50024000 0x400>;
 			clocks = <&rcc LPTIM5_K>;
 			clock-names = "mux";
+			interrupts-extended = <&exti 53 IRQ_TYPE_LEVEL_HIGH>;
+			wakeup-source;
 			status = "disabled";
 
 			pwm {
@@ -1203,6 +1233,11 @@
 				#pwm-cells = <3>;
 				status = "disabled";
 			};
+
+			timer {
+				compatible = "st,stm32-lptimer-timer";
+				status = "disabled";
+			};
 		};
 
 		vrefbuf: vrefbuf@50025000 {
Signature · 1 line
2.15.0
#5 lore raw

PATCH v6 3/6 mfd: stm32: Add defines to be used for clkevent purpose

In reply to Benjamin Gaignard

Add defines to be able to enable/clear irq and configure one shot mode.

---
 include/linux/mfd/stm32-lptimer.h | 5 +++++
 1 file changed, 5 insertions(+)
include/linux/mfd/stm32-lptimer.h +5 -0
index 605f62264825..90b20550c1c8 100644
@@ -27,10 +27,15 @@
 #define STM32_LPTIM_CMPOK		BIT(3)
 
 /* STM32_LPTIM_ICR - bit fields */
+#define STM32_LPTIM_ARRMCF		BIT(1)
 #define STM32_LPTIM_CMPOKCF_ARROKCF	GENMASK(4, 3)
 
+/* STM32_LPTIM_IER - bit flieds */
+#define STM32_LPTIM_ARRMIE	BIT(1)
+
 /* STM32_LPTIM_CR - bit fields */
 #define STM32_LPTIM_CNTSTRT	BIT(2)
+#define STM32_LPTIM_SNGSTRT	BIT(1)
 #define STM32_LPTIM_ENABLE	BIT(0)
 
 /* STM32_LPTIM_CFGR - bit fields */
Signature · 1 line
2.15.0
Acked-by on v6 3/6
#6 lore raw

Re: [PATCH v6 3/6] mfd: stm32: Add defines to be used for clkevent purpose

Quoted 7 lines · Benjamin Gaignard

Add defines to be able to enable/clear irq and configure one shot mode.

---
 include/linux/mfd/stm32-lptimer.h | 5 +++++
 1 file changed, 5 insertions(+)

Hi Benjamin,

Thanks,
Fabrice

Quoted 22 lines
include/linux/mfd/stm32-lptimer.h +5 -0
index 605f62264825..90b20550c1c8 100644
@@ -27,10 +27,15 @@
 #define STM32_LPTIM_CMPOK		BIT(3)
 
 /* STM32_LPTIM_ICR - bit fields */
+#define STM32_LPTIM_ARRMCF		BIT(1)
 #define STM32_LPTIM_CMPOKCF_ARROKCF	GENMASK(4, 3)
 
+/* STM32_LPTIM_IER - bit flieds */
+#define STM32_LPTIM_ARRMIE	BIT(1)
+
 /* STM32_LPTIM_CR - bit fields */
 #define STM32_LPTIM_CNTSTRT	BIT(2)
+#define STM32_LPTIM_SNGSTRT	BIT(1)
 #define STM32_LPTIM_ENABLE	BIT(0)
 
 /* STM32_LPTIM_CFGR - bit fields */
#7 lore raw

PATCH v6 4/6 mfd: stm32: enable regmap fast_io for stm32-lptimer

In reply to Benjamin Gaignard

Because stm32-lptimer need to write in registers in interrupt context enable regmap fast_io to use a spin_lock to protect registers access rather than a mutex.

---
 drivers/mfd/stm32-lptimer.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mfd/stm32-lptimer.c +1 -0
index a00f99f36559..746e51a17cc8 100644
@@ -17,6 +17,7 @@ static const struct regmap_config stm32_lptimer_regmap_cfg = {
 	.val_bits = 32,
 	.reg_stride = sizeof(u32),
 	.max_register = STM32_LPTIM_MAX_REGISTER,
+	.fast_io = true,
 };
 
 static int stm32_lptimer_detect_encoder(struct stm32_lptimer *ddata)
Signature · 1 line
2.15.0
Acked-by on v6 4/6
#8 lore raw

Re: [PATCH v6 4/6] mfd: stm32: enable regmap fast_io for stm32-lptimer

Quoted 8 lines · Benjamin Gaignard

Because stm32-lptimer need to write in registers in interrupt context enable regmap fast_io to use a spin_lock to protect registers access rather than a mutex.

---
 drivers/mfd/stm32-lptimer.c | 1 +
 1 file changed, 1 insertion(+)

Hi Benjamin,

Thanks,
Fabrice

Quoted 7 lines
drivers/mfd/stm32-lptimer.c +0 -0
index a00f99f36559..746e51a17cc8 100644

drivers/mfd/stm32-lptimer.c static const struct regmap_config stm32_lptimer_regmap_cfg = { · line 23

Quoted 7 lines
drivers/mfd/stm32-lptimer.c +1 -0
@@ -17,6 +17,7 @@ static const struct regmap_config stm32_lptimer_regmap_cfg = {
 	.val_bits = 32,
 	.reg_stride = sizeof(u32),
 	.max_register = STM32_LPTIM_MAX_REGISTER,
+	.fast_io = true,
 };
 
 static int stm32_lptimer_detect_encoder(struct stm32_lptimer *ddata)

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#9 lore raw

Re: [PATCH v6 4/6] mfd: stm32: enable regmap fast_io for stm32-lptimer

In reply to Benjamin Gaignard
Quoted 8 lines · Benjamin Gaignard

Because stm32-lptimer need to write in registers in interrupt context enable regmap fast_io to use a spin_lock to protect registers access rather than a mutex.

---
 drivers/mfd/stm32-lptimer.c | 1 +
 1 file changed, 1 insertion(+)

For my own reference:

Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#10 lore raw

PATCH v6 5/6 clocksource: Add Low Power STM32 timers driver

In reply to Benjamin Gaignard

From: Benjamin Gaignard <[email protected]>

Implement clock event driver using low power STM32 timers.
Low power timer counters running even when CPUs are stopped.
It could be used as clock event broadcaster to wake up CPUs but not like a clocksource because each it rise an interrupt the counter restart from 0.

Low power timers have a 16 bits counter and a prescaler which allow to divide the clock per power of 2 to up 128 to target a 32KHz rate.

---
 drivers/clocksource/Kconfig          |   4 +
 drivers/clocksource/Makefile         |   1 +
 drivers/clocksource/timer-stm32-lp.c | 221 +++++++++++++++++++++++++++++++++++
 3 files changed, 226 insertions(+)
 create mode 100644 drivers/clocksource/timer-stm32-lp.c
drivers/clocksource/Kconfig +4 -0
index cc909e465823..f340a64286ef 100644
@@ -292,6 +292,10 @@ config CLKSRC_STM32
 	select CLKSRC_MMIO
 	select TIMER_OF
 
+config CLKSRC_STM32_LP
+	bool "Low power clocksource for STM32 SoCs"
+	depends on MFD_STM32_LPTIMER || COMPILE_TEST
+
 config CLKSRC_MPS2
 	bool "Clocksource for MPS2 SoCs" if COMPILE_TEST
 	depends on GENERIC_SCHED_CLOCK
drivers/clocksource/Makefile +1 -0
index 713686faa549..c00fffbd4769 100644
@@ -44,6 +44,7 @@ obj-$(CONFIG_BCM_KONA_TIMER)	+= bcm_kona_timer.o
 obj-$(CONFIG_CADENCE_TTC_TIMER)	+= timer-cadence-ttc.o
 obj-$(CONFIG_CLKSRC_EFM32)	+= timer-efm32.o
 obj-$(CONFIG_CLKSRC_STM32)	+= timer-stm32.o
+obj-$(CONFIG_CLKSRC_STM32_LP)	+= timer-stm32-lp.o
 obj-$(CONFIG_CLKSRC_EXYNOS_MCT)	+= exynos_mct.o
 obj-$(CONFIG_CLKSRC_LPC32XX)	+= timer-lpc32xx.o
 obj-$(CONFIG_CLKSRC_MPS2)	+= mps2-timer.o
drivers/clocksource/timer-stm32-lp.c new file +221 -0

221 lines not on this page · raw message

Signature · 1 line
2.15.0
#11 lore raw

PATCH v6 6/6 ARM: mach-stm32: select low power timer for STM32MP157

In reply to Benjamin Gaignard

Make MACH_STM32MP157 select CLKSRC_STM32_LP to get a broadcast timer.

---
 arch/arm/mach-stm32/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm/mach-stm32/Kconfig +1 -0
index 57699bd8f107..d78f55b7b1d0 100644
@@ -46,6 +46,7 @@ if ARCH_MULTI_V7
 config MACH_STM32MP157
 	bool "STMicroelectronics STM32MP157"
 	select ARM_ERRATA_814220
+	select CLKSRC_STM32_LP
 	default y
 
 endif # ARMv7-A
Signature · 1 line
2.15.0
#12 lore raw
In reply to Benjamin Gaignard
Quoted 46 lines · Benjamin Gaignard

This series add low power timer as boadcast clockevent device. Low power timer could runs even when CPUs are in idle mode and could wakeup them.

version 6:
- simplify binding, DT and code to use only one interrupt

version 5:
- document interrupts and interrupt-names bindings
- use a different wake up interrupt
- add device-tree patch
- make STM32MP157 select low power timer configuration flag
- enable fast_io in regmap configuration

version 4:
- move defines in mfd/stm32-lptimer.h
- change compatible and subnode names
- document wakeup-source property
- reword commit message
- make driver Kconfig depends of MFD_STM32_LPTIMER
- remove useless include
- remove rate and clk fields from the private structure
- to add comments about the registers sequence in stm32_clkevent_lp_set_timer
- rework probe function and use devm_request_irq()
- do not allow module to be removed

version 3:
- fix timer set sequence
- don't forget to free irq on remove function
- use devm_kzalloc to simplify errors handling in probe function

version 2:
- stm32 clkevent driver is now a child of the stm32 lp timer node
- add a probe function and adpat the driver to use regmap provide by it parent
- stop using timer_of helpers

Benjamin Gaignard (6):
dt-bindings: mfd: Document STM32 low power timer bindings
ARM: dts: stm32: Add timer subnodes on stm32mp15 SoCs
mfd: stm32: Add defines to be used for clkevent purpose
mfd: stm32: enable regmap fast_io for stm32-lptimer
clocksource: Add Low Power STM32 timers driver
ARM: mach-stm32: select low power timer for STM32MP157

Quoted 8 lines
 .../devicetree/bindings/mfd/st,stm32-lptimer.yaml  |  21 ++
 arch/arm/boot/dts/stm32mp151.dtsi                  |  35 ++++
 arch/arm/mach-stm32/Kconfig                        |   1 +
 drivers/clocksource/Kconfig                        |   4 +
 drivers/clocksource/Makefile                       |   1 +
 drivers/clocksource/timer-stm32-lp.c               | 221 +++++++++++++++++++++
 drivers/mfd/stm32-lptimer.c                        |   1 +
 include/linux/mfd/stm32-lptimer.h                  |   5 +

I'd be happy to take this set, but you need Acks from the other subsystem Maintainers before I can do so.

Quoted 3 lines
 8 files changed, 289 insertions(+)
 create mode 100644 drivers/clocksource/timer-stm32-lp.c
Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog