Skip to contentSkip to conversation

clockevent: add low power STM32 timer

PATCH Superseded Benjamin Gaignard 4 participants 15 messages Feb 17, 2020 – Mar 19, 2020

Subsystems (5)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#1 lore raw

PATCH v4 1/3 dt-bindings: mfd: Document STM32 low power timer bindings

In reply to Benjamin Gaignard

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

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

 .../devicetree/bindings/mfd/st,stm32-lptimer.yaml        | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
Documentation/devicetree/bindings/mfd/st,stm32-lptimer.yaml +16 -0
index 1a4cc5f3fb33..ddf190cb800b 100644
@@ -39,6 +39,8 @@ properties:
   "#size-cells":
     const: 0
 
+  wakeup-source: true
+
   pwm:
     type: object
 
@@ -81,6 +83,16 @@ patternProperties:
     required:
       - compatible
 
+  timer:
+    type: object
+
+    properties:
+      compatible:
+        const: st,stm32-lptimer-timer
+
+    required:
+      - compatible
+
 required:
   - "#address-cells"
   - "#size-cells"
@@ -115,6 +127,10 @@ examples:
       counter {
         compatible = "st,stm32-lptimer-counter";
       };
+
+      timer {
+        compatible = "st,stm32-lptimer-timer";
+      };
     };
 
 ...
Signature · 1 line
2.15.0
#3 lore raw

PATCH v4 2/3 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.

---
version 4:
- move defines in mfd/stm32-lptimer.h

 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
#9 lore raw

PATCH v4 3/3 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.

---
version 4:
- move defines in mfd/stm32-lptimer.h
- change compatiblename
- 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
- make sure that wakeup interrupt is set

 drivers/clocksource/Kconfig          |   7 ++
 drivers/clocksource/Makefile         |   1 +
 drivers/clocksource/timer-stm32-lp.c | 213 +++++++++++++++++++++++++++++++++++
 3 files changed, 221 insertions(+)
 create mode 100644 drivers/clocksource/timer-stm32-lp.c
drivers/clocksource/Kconfig +7 -0
index cc909e465823..9fc2b513db6f 100644
@@ -292,6 +292,13 @@ 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
+	help
+	  This option enables support for STM32 low power clockevent available
+	  on STM32 SoCs
+
 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 +213 -0

213 lines not on this page · raw message

Signature · 1 line
2.15.0
#0 lore raw

v4 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 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 (3):
dt-bindings: mfd: Document STM32 low power timer bindings
mfd: stm32: Add defines to be used for clkevent purpose
clocksource: Add Low Power STM32 timers driver

 .../devicetree/bindings/mfd/st,stm32-lptimer.yaml  |  16 ++
 drivers/clocksource/Kconfig                        |   7 +
 drivers/clocksource/Makefile                       |   1 +
 drivers/clocksource/timer-stm32-lp.c               | 213 +++++++++++++++++++++
 include/linux/mfd/stm32-lptimer.h                  |   5 +
 5 files changed, 242 insertions(+)
 create mode 100644 drivers/clocksource/timer-stm32-lp.c
Signature · 1 line
2.15.0
maintainer Acked-by on v4 1/3
#2 lore raw

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

In reply to Benjamin Gaignard
Quoted 11 lines · Benjamin Gaignard

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

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

 .../devicetree/bindings/mfd/st,stm32-lptimer.yaml        | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
#4 lore raw

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

In reply to Benjamin Gaignard

Hi Lee,

Quoted 3 lines · Benjamin Gaignard

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

Are you fine if I pick this patch with the series?

Quoted 28 lines

---
version 4:
- move defines in mfd/stm32-lptimer.h

 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 · 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
#10 lore raw

Re: [PATCH v4 3/3] clocksource: Add Low Power STM32 timers driver

In reply to Benjamin Gaignard
Quoted 125 lines · 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.

---
version 4:
- move defines in mfd/stm32-lptimer.h
- change compatiblename
- 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
- make sure that wakeup interrupt is set

 drivers/clocksource/Kconfig          |   7 ++
 drivers/clocksource/Makefile         |   1 +
 drivers/clocksource/timer-stm32-lp.c | 213 +++++++++++++++++++++++++++++++++++
 3 files changed, 221 insertions(+)
 create mode 100644 drivers/clocksource/timer-stm32-lp.c
drivers/clocksource/Kconfig +7 -0
index cc909e465823..9fc2b513db6f 100644
@@ -292,6 +292,13 @@ 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
+	help
+	  This option enables support for STM32 low power clockevent available
+	  on STM32 SoCs
+
 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 +58 -0
new file mode 100644
index 000000000000..50eecdb88216
@@ -0,0 +1,213 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) STMicroelectronics 2019 - All Rights Reserved
+ * Authors: Benjamin Gaignard <[email protected]> for STMicroelectronics.
+ *	    Pascal Paillet <[email protected]> for STMicroelectronics.
+ */
+
+#include <linux/clk.h>
+#include <linux/clockchips.h>
+#include <linux/interrupt.h>
+#include <linux/mfd/stm32-lptimer.h>
+#include <linux/module.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+#include <linux/platform_device.h>
+#include <linux/pm_wakeirq.h>
+
+#define CFGR_PSC_OFFSET		9
+#define STM32_LP_RATING		400
+#define STM32_TARGET_CLKRATE	(32000 * HZ)
+#define STM32_LP_MAX_PSC	7
+
+struct stm32_lp_private {
+	struct regmap *reg;
+	struct clock_event_device clkevt;
+	unsigned long period;
+};
+
+static struct stm32_lp_private*
+to_priv(struct clock_event_device *clkevt)
+{
+	return container_of(clkevt, struct stm32_lp_private, clkevt);
+}
+
+static int stm32_clkevent_lp_shutdown(struct clock_event_device *clkevt)
+{
+	struct stm32_lp_private *priv = to_priv(clkevt);
+
+	regmap_write(priv->reg, STM32_LPTIM_CR, 0);
+	regmap_write(priv->reg, STM32_LPTIM_IER, 0);
+	/* clear pending flags */
+	regmap_write(priv->reg, STM32_LPTIM_ICR, STM32_LPTIM_ARRMCF);
+
+	return 0;
+}
+
+static int stm32_clkevent_lp_set_timer(unsigned long evt,
+				       struct clock_event_device *clkevt,
+				       int is_periodic)
+{
+	struct stm32_lp_private *priv = to_priv(clkevt);
+
+	/* disable LPTIMER to be able to write into IER register*/
+	regmap_write(priv->reg, STM32_LPTIM_CR, 0);
+	/* enable ARR interrupt */
+	regmap_write(priv->reg, STM32_LPTIM_IER, STM32_LPTIM_ARRMIE);
+	/* enable LPTIMER to be able to write into ARR register */
+	regmap_write(priv->reg, STM32_LPTIM_CR, STM32_LPTIM_ENABLE);

drivers/clocksource/timer-stm32-lp.c line 68

Quoted 10 lines
drivers/clocksource/timer-stm32-lp.c new file +10 -0
+	/* set next event counter */
+	regmap_write(priv->reg, STM32_LPTIM_ARR, evt);
+
+	/* start counter */
+	if (is_periodic)
+		regmap_write(priv->reg, STM32_LPTIM_CR,
+			     STM32_LPTIM_CNTSTRT | STM32_LPTIM_ENABLE);
+	else
+		regmap_write(priv->reg, STM32_LPTIM_CR,
+			     STM32_LPTIM_SNGSTRT | STM32_LPTIM_ENABLE);

The regmap config in stm32-lptimer is not defined with the fast_io flag (on purpose or not?) that means we can potentially deadlock here as the lock is a mutex.

Isn't it detected with the lock validation scheme?

drivers/clocksource/timer-stm32-lp.c line 193

Quoted 6 lines
drivers/clocksource/timer-stm32-lp.c new file +6 -0
+	return 0;
+}
+static int stm32_clkevent_lp_remove(struct platform_device *pdev)
+{
+	return -EBUSY; /* cannot unregister clockevent */
+}

Won't be the mfd into an inconsistent state here? The other subsystems will be removed but this one will prevent to unload the module leading to a situation where the mfd is partially removed but still there without a possible recovery, no?

Quoted 14 lines
drivers/clocksource/timer-stm32-lp.c new file +14 -0
+static const struct of_device_id stm32_clkevent_lp_of_match[] = {
+	{ .compatible = "st,stm32-lptimer-timer", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, stm32_clkevent_lp_of_match);
+
+static struct platform_driver stm32_clkevent_lp_driver = {
+	.probe	= stm32_clkevent_lp_probe,
+	.remove = stm32_clkevent_lp_remove,
+	.driver	= {
+		.name = "stm32-lptimer-timer",
+		.of_match_table = of_match_ptr(stm32_clkevent_lp_of_match),
+	},
+};
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
#11 lore raw

Re: [PATCH v4 3/3] clocksource: Add Low Power STM32 timers driver

Quoted 140 lines · Daniel Lezcano
Quoted 125 lines · 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.

---
version 4:
- move defines in mfd/stm32-lptimer.h
- change compatiblename
- 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
- make sure that wakeup interrupt is set

  drivers/clocksource/Kconfig          |   7 ++
  drivers/clocksource/Makefile         |   1 +
  drivers/clocksource/timer-stm32-lp.c | 213 +++++++++++++++++++++++++++++++++++
  3 files changed, 221 insertions(+)

create mode 100644 drivers/clocksource/timer-stm32-lp.c

drivers/clocksource/Kconfig +7 -0
index cc909e465823..9fc2b513db6f 100644
@@ -292,6 +292,13 @@ 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
+	help
+	  This option enables support for STM32 low power clockevent available
+	  on STM32 SoCs
+
  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 +58 -0
new file mode 100644
index 000000000000..50eecdb88216
@@ -0,0 +1,213 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) STMicroelectronics 2019 - All Rights Reserved
+ * Authors: Benjamin Gaignard <[email protected]> for STMicroelectronics.
+ *	    Pascal Paillet <[email protected]> for STMicroelectronics.
+ */
+
+#include <linux/clk.h>
+#include <linux/clockchips.h>
+#include <linux/interrupt.h>
+#include <linux/mfd/stm32-lptimer.h>
+#include <linux/module.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+#include <linux/platform_device.h>
+#include <linux/pm_wakeirq.h>
+
+#define CFGR_PSC_OFFSET		9
+#define STM32_LP_RATING		400
+#define STM32_TARGET_CLKRATE	(32000 * HZ)
+#define STM32_LP_MAX_PSC	7
+
+struct stm32_lp_private {
+	struct regmap *reg;
+	struct clock_event_device clkevt;
+	unsigned long period;
+};
+
+static struct stm32_lp_private*
+to_priv(struct clock_event_device *clkevt)
+{
+	return container_of(clkevt, struct stm32_lp_private, clkevt);
+}
+
+static int stm32_clkevent_lp_shutdown(struct clock_event_device *clkevt)
+{
+	struct stm32_lp_private *priv = to_priv(clkevt);
+
+	regmap_write(priv->reg, STM32_LPTIM_CR, 0);
+	regmap_write(priv->reg, STM32_LPTIM_IER, 0);
+	/* clear pending flags */
+	regmap_write(priv->reg, STM32_LPTIM_ICR, STM32_LPTIM_ARRMCF);
+
+	return 0;
+}
+
+static int stm32_clkevent_lp_set_timer(unsigned long evt,
+				       struct clock_event_device *clkevt,
+				       int is_periodic)
+{
+	struct stm32_lp_private *priv = to_priv(clkevt);
+
+	/* disable LPTIMER to be able to write into IER register*/
+	regmap_write(priv->reg, STM32_LPTIM_CR, 0);
+	/* enable ARR interrupt */
+	regmap_write(priv->reg, STM32_LPTIM_IER, STM32_LPTIM_ARRMIE);
+	/* enable LPTIMER to be able to write into ARR register */
+	regmap_write(priv->reg, STM32_LPTIM_CR, STM32_LPTIM_ENABLE);

drivers/clocksource/timer-stm32-lp.c line 68

Quoted 10 lines
drivers/clocksource/timer-stm32-lp.c new file +10 -0
+	/* set next event counter */
+	regmap_write(priv->reg, STM32_LPTIM_ARR, evt);
+
+	/* start counter */
+	if (is_periodic)
+		regmap_write(priv->reg, STM32_LPTIM_CR,
+			     STM32_LPTIM_CNTSTRT | STM32_LPTIM_ENABLE);
+	else
+		regmap_write(priv->reg, STM32_LPTIM_CR,
+			     STM32_LPTIM_SNGSTRT | STM32_LPTIM_ENABLE);

The regmap config in stm32-lptimer is not defined with the fast_io flag (on purpose or not?) that means we can potentially deadlock here as the lock is a mutex.

Quoted 1 line

Isn't it detected with the lock validation scheme?

It wasn't a problem with other parts of the mfd and I don't notice issues so I guess it is ok.

Quoted 11 lines

drivers/clocksource/timer-stm32-lp.c line 193

Quoted 7 lines
drivers/clocksource/timer-stm32-lp.c new file +6 -0
+	return 0;
+}
+static int stm32_clkevent_lp_remove(struct platform_device *pdev)
+{
+	return -EBUSY; /* cannot unregister clockevent */
+}

Won't be the mfd into an inconsistent state here? The other subsystems will be removed but this one will prevent to unload the module leading to a situation where the mfd is partially removed but still there without a possible recovery, no?

We can't enable the timer part of the mfd at the same time than the other features.
It has be exclusive and that exclude the problem you describe above.

Quoted 16 lines
Quoted 15 lines
drivers/clocksource/timer-stm32-lp.c new file +14 -0
+static const struct of_device_id stm32_clkevent_lp_of_match[] = {
+	{ .compatible = "st,stm32-lptimer-timer", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, stm32_clkevent_lp_of_match);
+
+static struct platform_driver stm32_clkevent_lp_driver = {
+	.probe	= stm32_clkevent_lp_probe,
+	.remove = stm32_clkevent_lp_remove,
+	.driver	= {
+		.name = "stm32-lptimer-timer",
+		.of_match_table = of_match_ptr(stm32_clkevent_lp_of_match),
+	},
+};
#12 lore raw

Re: [PATCH v4 3/3] clocksource: Add Low Power STM32 timers driver

On 20/02/2020 11:45, Benjamin GAIGNARD wrote:

[ ... ]

Quoted 23 lines
Quoted 23 lines
Quoted 9 lines
drivers/clocksource/timer-stm32-lp.c new file +9 -0
+{
+	struct stm32_lp_private *priv = to_priv(clkevt);
+
+	/* disable LPTIMER to be able to write into IER register*/
+	regmap_write(priv->reg, STM32_LPTIM_CR, 0);
+	/* enable ARR interrupt */
+	regmap_write(priv->reg, STM32_LPTIM_IER, STM32_LPTIM_ARRMIE);
+	/* enable LPTIMER to be able to write into ARR register */
+	regmap_write(priv->reg, STM32_LPTIM_CR, STM32_LPTIM_ENABLE);

drivers/clocksource/timer-stm32-lp.c line 68

Quoted 10 lines
drivers/clocksource/timer-stm32-lp.c new file +10 -0
+	/* set next event counter */
+	regmap_write(priv->reg, STM32_LPTIM_ARR, evt);
+
+	/* start counter */
+	if (is_periodic)
+		regmap_write(priv->reg, STM32_LPTIM_CR,
+			     STM32_LPTIM_CNTSTRT | STM32_LPTIM_ENABLE);
+	else
+		regmap_write(priv->reg, STM32_LPTIM_CR,
+			     STM32_LPTIM_SNGSTRT | STM32_LPTIM_ENABLE);

The regmap config in stm32-lptimer is not defined with the fast_io flag (on purpose or not?) that means we can potentially deadlock here as the lock is a mutex.

Quoted 3 lines
Quoted 1 line

Isn't it detected with the lock validation scheme?

It wasn't a problem with other parts of the mfd and I don't notice issues so I guess it is ok.

Given your comment below, the case can't happen I agree but there is still a heavy operation with the locking.

Quoted 10 lines
Quoted 10 lines

drivers/clocksource/timer-stm32-lp.c line 193

Quoted 6 lines
drivers/clocksource/timer-stm32-lp.c new file +6 -0
+	return 0;
+}
+static int stm32_clkevent_lp_remove(struct platform_device *pdev)
+{
+	return -EBUSY; /* cannot unregister clockevent */
+}

Won't be the mfd into an inconsistent state here? The other subsystems will be removed but this one will prevent to unload the module leading to a situation where the mfd is partially removed but still there without a possible recovery, no?

Quoted 2 lines

We can't enable the timer part of the mfd at the same time than the other features.

Hmm, interesting case. The DT binding does not give this information, especially in the example. You should fix the DT by giving two examples IMO.

Rob, how do you describe this situation (exclusive properties)?

Quoted 1 line

It has be exclusive and that exclude the problem you describe above.

Ok, the regmap_write is not a free operation and in this case you can get rid of all the regmap-ish in this driver.

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
Acked-by
#5 lore raw

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

In reply to Daniel Lezcano
Quoted 9 lines · Daniel Lezcano

Hi Lee,

Quoted 3 lines · Benjamin Gaignard

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

Are you fine if I pick this patch with the series?

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

Re: [PATCH v4 3/3] clocksource: Add Low Power STM32 timers driver

In reply to Daniel Lezcano

Hi Benjamin,

On 20/02/2020 12:05, Daniel Lezcano wrote:

[ ... ]

Quoted 4 lines
Quoted 1 line

It has be exclusive and that exclude the problem you describe above.

Ok, the regmap_write is not a free operation and in this case you can get rid of all the regmap-ish in this driver.

Are you planning to send the non-regmap version?

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
#14 lore raw

Re: [PATCH v4 3/3] clocksource: Add Low Power STM32 timers driver

Quoted 10 lines · Daniel Lezcano

Hi Benjamin,

On 20/02/2020 12:05, Daniel Lezcano wrote:

[ ... ]

Quoted 3 lines
Quoted 1 line

It has be exclusive and that exclude the problem you describe above.

Ok, the regmap_write is not a free operation and in this case you can get rid of all the regmap-ish in this driver.

Are you planning to send the non-regmap version?

No because the regmap is inherited from the mfd parent. I could use fast-io to improve that.

Benjamin

Quoted 3 lines

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

#6 lore raw

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

In reply to Daniel Lezcano
Quoted 6 lines · Daniel Lezcano
Quoted 3 lines · Benjamin Gaignard

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

Are you fine if I pick this patch with the series?

Nothing heard from you since I Acked this.

Are you still planning on taking this patch?

If so, can you also take patch 1 please?

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

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

Quoted 11 lines · Lee Jones
Quoted 5 lines · Daniel Lezcano
Quoted 3 lines · Benjamin Gaignard

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

Are you fine if I pick this patch with the series?

Nothing heard from you since I Acked this.

Are you still planning on taking this patch?

If so, can you also take patch 1 please?

I will send a v5.
Daniel could you wait until that to merge all the patches (even if this one won't change) ?

Benjamin

Quoted 1 line

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

#8 lore raw

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

Quoted 9 lines · Benjamin GAIGNARD
Quoted 6 lines · Lee Jones
Quoted 5 lines · Daniel Lezcano
Quoted 3 lines · Benjamin Gaignard

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

Are you fine if I pick this patch with the series?

Quoted 8 lines
Quoted 5 lines

Nothing heard from you since I Acked this.

Are you still planning on taking this patch?

If so, can you also take patch 1 please?

I will send a v5.
Daniel could you wait until that to merge all the patches (even if this one won't change) ?

Sure, no problem.

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