linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6] rtc: stm32: add alarm out and LSCO features.
@ 2022-05-04 13:02 Valentin Caron
  2022-05-04 13:02 ` [PATCH 1/6] dt-bindings: rtc: stm32: add st,lsco optional property to select output Valentin Caron
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: Valentin Caron @ 2022-05-04 13:02 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni, Rob Herring,
	Krzysztof Kozlowski, Alexandre Torgue
  Cc: Gabriel Fernandez, Amelie Delaunay, Valentin Caron, linux-rtc,
	devicetree, linux-stm32, linux-arm-kernel, linux-kernel

On STM32MP1x SOCs, RTC is able to output some signals on its own pins.

This series add the possibility to select two of these signals on
RTC pins :
 - LSCO (Low Speed Clock Output) that allow to output LSE clock on a pin.
   On STM32MP1x Discovery boards this feature is used to generate a clock
   to Wifi/Bluetooth module.
 - Alarm out that allow to send a pulse on a pin when alarm A of the RTC
   expires.

Amelie Delaunay (2):
  dt-bindings: rtc: stm32: add st,lsco optional property to select
    output
  rtc: stm32: add Low Speed Clock Output (LSCO) support

Gabriel Fernandez (2):
  ARM: dts: stm32: add RTC LSCO support on stm32mp157c-dk2
  ARM: dts: stm32: add RTC LSCO support on stm32mp135f-dk

Valentin Caron (2):
  dt-bindings: rtc: stm32: add alarm A out property to select output
  rtc: stm32: add alarm A out feature

 .../devicetree/bindings/rtc/st,stm32-rtc.yaml |  37 +++
 arch/arm/boot/dts/stm32mp13-pinctrl.dtsi      |   6 +
 arch/arm/boot/dts/stm32mp135f-dk.dts          |   4 +
 arch/arm/boot/dts/stm32mp15-pinctrl.dtsi      |   6 +
 arch/arm/boot/dts/stm32mp157c-dk2.dts         |   7 +
 drivers/rtc/Kconfig                           |   1 +
 drivers/rtc/rtc-stm32.c                       | 210 ++++++++++++++++++
 include/dt-bindings/rtc/rtc-stm32.h           |  14 ++
 8 files changed, 285 insertions(+)
 create mode 100644 include/dt-bindings/rtc/rtc-stm32.h

-- 
2.25.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/6] dt-bindings: rtc: stm32: add st,lsco optional property to select output
  2022-05-04 13:02 [PATCH 0/6] rtc: stm32: add alarm out and LSCO features Valentin Caron
@ 2022-05-04 13:02 ` Valentin Caron
  2022-05-16 23:52   ` Rob Herring
  2022-05-04 13:06 ` [PATCH 2/6] dt-bindings: rtc: stm32: add alarm A out " Valentin Caron
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Valentin Caron @ 2022-05-04 13:02 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni, Rob Herring,
	Krzysztof Kozlowski, Alexandre Torgue
  Cc: Gabriel Fernandez, Amelie Delaunay, Valentin Caron, linux-rtc,
	devicetree, linux-stm32, linux-arm-kernel, linux-kernel

From: Amelie Delaunay <amelie.delaunay@foss.st.com>

STM32 RTC has three output pins: RTC_OUT1, RTC_OUT2 or RTC_OUT2_RMP.

RTC Low-Speed Clock Output (LSCO) can be output on RTC_OUT1 or
RTC_OUT2_RMP.

This patch adds constants for RTC output bindings and adds st,lsco
optional property for stm32 rtc driver, to select and enable LSCO.
A pinctrl state is also optional to reserve pin for RTC output.

Signed-off-by: Amelie Delaunay <amelie.delaunay@foss.st.com>
Signed-off-by: Valentin Caron <valentin.caron@foss.st.com>
---
 .../devicetree/bindings/rtc/st,stm32-rtc.yaml | 20 +++++++++++++++++++
 include/dt-bindings/rtc/rtc-stm32.h           | 14 +++++++++++++
 2 files changed, 34 insertions(+)
 create mode 100644 include/dt-bindings/rtc/rtc-stm32.h

diff --git a/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml b/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml
index 764717ce1873..56d46ea35c5d 100644
--- a/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml
+++ b/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml
@@ -52,6 +52,13 @@ properties:
       override default rtc_ck parent clock phandle of the new parent clock of rtc_ck
     maxItems: 1
 
+  st,lsco:
+    $ref: "/schemas/types.yaml#/definitions/uint32"
+    description: |
+      To select and enable RTC Low Speed Clock Output.
+      Refer to <include/dt-bindings/rtc/rtc-stm32.h> for the supported values.
+      Pinctrl state named "default" may be defined to reserve pin for RTC output.
+
 allOf:
   - if:
       properties:
@@ -65,6 +72,9 @@ allOf:
           minItems: 1
           maxItems: 1
 
+        st,lsco:
+          maxItems: 0
+
         clock-names: false
 
       required:
@@ -82,6 +92,9 @@ allOf:
           minItems: 2
           maxItems: 2
 
+        st,lsco:
+          maxItems: 0
+
       required:
         - clock-names
         - st,syscfg
@@ -101,6 +114,9 @@ allOf:
         assigned-clocks: false
         assigned-clock-parents: false
 
+        st,lsco:
+          maxItems: 1
+
       required:
         - clock-names
 
@@ -130,12 +146,16 @@ examples:
   - |
     #include <dt-bindings/interrupt-controller/arm-gic.h>
     #include <dt-bindings/clock/stm32mp1-clks.h>
+    #include <dt-bindings/rtc/rtc-stm32.h>
     rtc@5c004000 {
       compatible = "st,stm32mp1-rtc";
       reg = <0x5c004000 0x400>;
       clocks = <&rcc RTCAPB>, <&rcc RTC>;
       clock-names = "pclk", "rtc_ck";
       interrupts = <GIC_SPI 3 IRQ_TYPE_LEVEL_HIGH>;
+      st,lsco = <RTC_OUT2_RMP>;
+      pinctrl-0 = <&rtc_out2_rmp_pins_a>;
+      pinctrl-names = "default";
     };
 
 ...
diff --git a/include/dt-bindings/rtc/rtc-stm32.h b/include/dt-bindings/rtc/rtc-stm32.h
new file mode 100644
index 000000000000..2fd78c2e62d4
--- /dev/null
+++ b/include/dt-bindings/rtc/rtc-stm32.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * This header provides constants for STM32_RTC bindings.
+ */
+
+#ifndef _DT_BINDINGS_RTC_RTC_STM32_H
+#define _DT_BINDINGS_RTC_RTC_STM32_H
+
+#define RTC_NO_OUT	0
+#define RTC_OUT1	1
+#define RTC_OUT2	2
+#define RTC_OUT2_RMP	3
+
+#endif
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 2/6] dt-bindings: rtc: stm32: add alarm A out property to select output
  2022-05-04 13:02 [PATCH 0/6] rtc: stm32: add alarm out and LSCO features Valentin Caron
  2022-05-04 13:02 ` [PATCH 1/6] dt-bindings: rtc: stm32: add st,lsco optional property to select output Valentin Caron
@ 2022-05-04 13:06 ` Valentin Caron
  2022-05-04 15:42   ` Rob Herring
  2022-05-04 20:27   ` Alexandre Belloni
  2022-05-04 13:06 ` [PATCH 3/6] rtc: stm32: add Low Speed Clock Output (LSCO) support Valentin Caron
                   ` (3 subsequent siblings)
  5 siblings, 2 replies; 13+ messages in thread
From: Valentin Caron @ 2022-05-04 13:06 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni, Rob Herring,
	Krzysztof Kozlowski, Alexandre Torgue
  Cc: Gabriel Fernandez, Amelie Delaunay, Valentin Caron, linux-rtc,
	devicetree, linux-stm32, linux-arm-kernel, linux-kernel

STM32 RTC can pulse some SOC pins when an alarm of RTC expires.

This patch adds property to activate alarm A output. The pulse can
output on three pins RTC_OUT1, RTC_OUT2, RTC_OUT2_RMP
(PC13, PB2, PI8 on stm32mp15) (PC13, PB2, PI1 on stm32mp13).

Signed-off-by: Valentin Caron <valentin.caron@foss.st.com>
---
 .../devicetree/bindings/rtc/st,stm32-rtc.yaml | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml b/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml
index 56d46ea35c5d..71e02604e8de 100644
--- a/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml
+++ b/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml
@@ -59,6 +59,13 @@ properties:
       Refer to <include/dt-bindings/rtc/rtc-stm32.h> for the supported values.
       Pinctrl state named "default" may be defined to reserve pin for RTC output.
 
+  st,alarm:
+    $ref: "/schemas/types.yaml#/definitions/uint32"
+    description: |
+      To select and enable RTC Alarm A output.
+      Refer to <include/dt-bindings/rtc/rtc-stm32.h> for the supported values.
+      Pinctrl state named "default" may be defined to reserve pin for RTC output.
+
 allOf:
   - if:
       properties:
@@ -75,6 +82,9 @@ allOf:
         st,lsco:
           maxItems: 0
 
+        st,alarm:
+          maxItems: 0
+
         clock-names: false
 
       required:
@@ -95,6 +105,9 @@ allOf:
         st,lsco:
           maxItems: 0
 
+        st,alarm:
+          maxItems: 0
+
       required:
         - clock-names
         - st,syscfg
@@ -117,6 +130,9 @@ allOf:
         st,lsco:
           maxItems: 1
 
+        st,alarm:
+          maxItems: 1
+
       required:
         - clock-names
 
@@ -153,8 +169,9 @@ examples:
       clocks = <&rcc RTCAPB>, <&rcc RTC>;
       clock-names = "pclk", "rtc_ck";
       interrupts = <GIC_SPI 3 IRQ_TYPE_LEVEL_HIGH>;
+      st,alarm = <RTC_OUT1>;
       st,lsco = <RTC_OUT2_RMP>;
-      pinctrl-0 = <&rtc_out2_rmp_pins_a>;
+      pinctrl-0 = <&rtc_out1_pins_a &rtc_out2_rmp_pins_a>;
       pinctrl-names = "default";
     };
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 3/6] rtc: stm32: add Low Speed Clock Output (LSCO) support
  2022-05-04 13:02 [PATCH 0/6] rtc: stm32: add alarm out and LSCO features Valentin Caron
  2022-05-04 13:02 ` [PATCH 1/6] dt-bindings: rtc: stm32: add st,lsco optional property to select output Valentin Caron
  2022-05-04 13:06 ` [PATCH 2/6] dt-bindings: rtc: stm32: add alarm A out " Valentin Caron
@ 2022-05-04 13:06 ` Valentin Caron
  2022-05-04 13:06 ` [PATCH 4/6] rtc: stm32: add alarm A out feature Valentin Caron
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 13+ messages in thread
From: Valentin Caron @ 2022-05-04 13:06 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni, Rob Herring,
	Krzysztof Kozlowski, Alexandre Torgue
  Cc: Gabriel Fernandez, Amelie Delaunay, Valentin Caron, linux-rtc,
	devicetree, linux-stm32, linux-arm-kernel, linux-kernel

From: Amelie Delaunay <amelie.delaunay@foss.st.com>

STM32 RTC is now registered as a clock provider.
It provides rtc_lsco clock, that means RTC_LSCO is output on either
RTC_OUT1 or RTC_OUT2_RMP, depending on st,lsco DT property
(PC13 or PI8 on stm32mp15), (PC13 or PI1 on stm32mp13).

Signed-off-by: Amelie Delaunay <amelie.delaunay@foss.st.com>
Signed-off-by: Valentin Caron <valentin.caron@foss.st.com>
---
 drivers/rtc/Kconfig     |   1 +
 drivers/rtc/rtc-stm32.c | 133 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 134 insertions(+)

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 41c65b4d2baf..2e8021d7c98a 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1888,6 +1888,7 @@ config RTC_DRV_R7301
 config RTC_DRV_STM32
 	tristate "STM32 RTC"
 	select REGMAP_MMIO
+	depends on COMMON_CLK
 	depends on ARCH_STM32 || COMPILE_TEST
 	help
 	   If you say yes here you get support for the STM32 On-Chip
diff --git a/drivers/rtc/rtc-stm32.c b/drivers/rtc/rtc-stm32.c
index ac9e228b56d0..ace041eb44b8 100644
--- a/drivers/rtc/rtc-stm32.c
+++ b/drivers/rtc/rtc-stm32.c
@@ -6,6 +6,7 @@
 
 #include <linux/bcd.h>
 #include <linux/clk.h>
+#include <linux/clk-provider.h>
 #include <linux/iopoll.h>
 #include <linux/ioport.h>
 #include <linux/mfd/syscon.h>
@@ -15,6 +16,8 @@
 #include <linux/regmap.h>
 #include <linux/rtc.h>
 
+#include <dt-bindings/rtc/rtc-stm32.h>
+
 #define DRIVER_NAME "stm32_rtc"
 
 /* STM32_RTC_TR bit fields  */
@@ -39,6 +42,11 @@
 #define STM32_RTC_CR_FMT		BIT(6)
 #define STM32_RTC_CR_ALRAE		BIT(8)
 #define STM32_RTC_CR_ALRAIE		BIT(12)
+#define STM32_RTC_CR_COSEL		BIT(19)
+#define STM32_RTC_CR_OSEL		GENMASK(22, 21)
+#define STM32_RTC_CR_COE		BIT(23)
+#define STM32_RTC_CR_TAMPOE		BIT(26)
+#define STM32_RTC_CR_OUT2EN		BIT(31)
 
 /* STM32_RTC_ISR/STM32_RTC_ICSR bit fields */
 #define STM32_RTC_ISR_ALRAWF		BIT(0)
@@ -75,6 +83,12 @@
 /* STM32_RTC_SR/_SCR bit fields */
 #define STM32_RTC_SR_ALRA		BIT(0)
 
+/* STM32_RTC_CFGR bit fields */
+#define STM32_RTC_CFGR_OUT2_RMP		BIT(0)
+#define STM32_RTC_CFGR_LSCOEN		GENMASK(2, 1)
+#define STM32_RTC_CFGR_LSCOEN_OUT1	1
+#define STM32_RTC_CFGR_LSCOEN_OUT2_RMP	2
+
 /* STM32_RTC_VERR bit fields */
 #define STM32_RTC_VERR_MINREV_SHIFT	0
 #define STM32_RTC_VERR_MINREV		GENMASK(3, 0)
@@ -89,6 +103,9 @@
 /* Max STM32 RTC register offset is 0x3FC */
 #define UNDEF_REG			0xFFFF
 
+/* Frequency of HSE clock (Hz) */
+#define STM32_RTC_HSE_FREQ 32768
+
 struct stm32_rtc;
 
 struct stm32_rtc_registers {
@@ -101,6 +118,7 @@ struct stm32_rtc_registers {
 	u16 wpr;
 	u16 sr;
 	u16 scr;
+	u16 cfgr;
 	u16 verr;
 };
 
@@ -115,6 +133,7 @@ struct stm32_rtc_data {
 	bool has_pclk;
 	bool need_dbp;
 	bool has_wakeirq;
+	bool has_lsco;
 };
 
 struct stm32_rtc {
@@ -128,8 +147,88 @@ struct stm32_rtc {
 	const struct stm32_rtc_data *data;
 	int irq_alarm;
 	int wakeirq_alarm;
+	int lsco;
+	struct clk *clk_lsco;
 };
 
+/*
+ *  -------------------------------------------------------------------------
+ * | TAMPOE | OSEL[1:0] | COE | OUT2EN |     RTC_OUT1     |     RTC_OUT2     |
+ * |	    |           |     |        |                  | or RTC_OUT2_RMP  |
+ * |-------------------------------------------------------------------------|
+ * |    0   |     00    |  0  | 0 or 1 |         -        |         -        |
+ * |--------|-----------|-----|--------|------------------|------------------|
+ * |    0   |     00    |  1  |    0   |      CALIB       |         -        |
+ * |--------|-----------|-----|--------|------------------|------------------|
+ * | 0 or 1 |    !=00   |  0  |    0   |     TAMPALRM     |         -        |
+ * |--------|-----------|-----|--------|------------------|------------------|
+ * |    0   |     00    |  1  |    1   |         -        |      CALIB       |
+ * |--------|-----------|-----|--------|------------------|------------------|
+ * | 0 or 1 |    !=00   |  0  |    1   |         -        |     TAMPALRM     |
+ * |--------|-----------|-----|--------|------------------|------------------|
+ * | 0 or 1 |    !=00   |  1  |    1   |     TAMPALRM     |      CALIB       |
+ *  -------------------------------------------------------------------------
+ */
+static int stm32_rtc_clk_lsco_check_availability(struct stm32_rtc *rtc)
+{
+	struct stm32_rtc_registers regs = rtc->data->regs;
+	unsigned int cr = readl_relaxed(rtc->base + regs.cr);
+	unsigned int cfgr = readl_relaxed(rtc->base + regs.cfgr);
+	unsigned int calib = STM32_RTC_CR_COE;
+	unsigned int tampalrm = STM32_RTC_CR_TAMPOE | STM32_RTC_CR_OSEL;
+
+	switch (rtc->lsco) {
+	case RTC_OUT1:
+		if ((!(cr & STM32_RTC_CR_OUT2EN) &&
+		     ((cr & calib) || cr & tampalrm)) ||
+		     ((cr & calib) && (cr & tampalrm)))
+			return -EBUSY;
+		break;
+	case RTC_OUT2_RMP:
+		if ((cr & STM32_RTC_CR_OUT2EN) &&
+		    (cfgr & STM32_RTC_CFGR_OUT2_RMP) &&
+		    ((cr & calib) || (cr & tampalrm)))
+			return -EBUSY;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	/* LSCO can only work if RTC clock source is HSE */
+	if (clk_get_rate(rtc->rtc_ck) != STM32_RTC_HSE_FREQ)
+		return -ERANGE;
+
+	return 0;
+}
+
+static int stm32_rtc_clk_lsco_register(struct platform_device *pdev)
+{
+	struct stm32_rtc *rtc = platform_get_drvdata(pdev);
+	struct stm32_rtc_registers regs = rtc->data->regs;
+	u8 lscoen;
+	int ret;
+
+	ret = stm32_rtc_clk_lsco_check_availability(rtc);
+	if (ret)
+		return ret;
+
+	lscoen = (rtc->lsco == RTC_OUT1) ? STM32_RTC_CFGR_LSCOEN_OUT1 :
+					   STM32_RTC_CFGR_LSCOEN_OUT2_RMP;
+
+	rtc->clk_lsco = clk_register_gate(&pdev->dev, "rtc_lsco",
+					  __clk_get_name(rtc->rtc_ck),
+					  CLK_IS_CRITICAL,
+					  rtc->base + regs.cfgr, lscoen,
+					  0, NULL);
+	if (IS_ERR(rtc->clk_lsco))
+		return PTR_ERR(rtc->clk_lsco);
+
+	of_clk_add_provider(pdev->dev.of_node,
+			    of_clk_src_simple_get, rtc->clk_lsco);
+
+	return 0;
+}
+
 static void stm32_rtc_wpr_unlock(struct stm32_rtc *rtc)
 {
 	const struct stm32_rtc_registers *regs = &rtc->data->regs;
@@ -145,6 +244,15 @@ static void stm32_rtc_wpr_lock(struct stm32_rtc *rtc)
 	writel_relaxed(RTC_WPR_WRONG_KEY, rtc->base + regs->wpr);
 }
 
+static void stm32_rtc_clk_lsco_disable(struct platform_device *pdev)
+{
+	struct stm32_rtc *rtc = platform_get_drvdata(pdev);
+	struct stm32_rtc_registers regs = rtc->data->regs;
+	unsigned int cfgr = readl_relaxed(rtc->base + regs.cfgr);
+
+	writel_relaxed(cfgr &= ~STM32_RTC_CFGR_LSCOEN, rtc->base + regs.cfgr);
+}
+
 static int stm32_rtc_enter_init_mode(struct stm32_rtc *rtc)
 {
 	const struct stm32_rtc_registers *regs = &rtc->data->regs;
@@ -548,6 +656,7 @@ static const struct stm32_rtc_data stm32_rtc_data = {
 	.has_pclk = false,
 	.need_dbp = true,
 	.has_wakeirq = false,
+	.has_lsco = false,
 	.regs = {
 		.tr = 0x00,
 		.dr = 0x04,
@@ -558,6 +667,7 @@ static const struct stm32_rtc_data stm32_rtc_data = {
 		.wpr = 0x24,
 		.sr = 0x0C, /* set to ISR offset to ease alarm management */
 		.scr = UNDEF_REG,
+		.cfgr = UNDEF_REG,
 		.verr = UNDEF_REG,
 	},
 	.events = {
@@ -570,6 +680,7 @@ static const struct stm32_rtc_data stm32h7_rtc_data = {
 	.has_pclk = true,
 	.need_dbp = true,
 	.has_wakeirq = false,
+	.has_lsco = false,
 	.regs = {
 		.tr = 0x00,
 		.dr = 0x04,
@@ -580,6 +691,7 @@ static const struct stm32_rtc_data stm32h7_rtc_data = {
 		.wpr = 0x24,
 		.sr = 0x0C, /* set to ISR offset to ease alarm management */
 		.scr = UNDEF_REG,
+		.cfgr = UNDEF_REG,
 		.verr = UNDEF_REG,
 	},
 	.events = {
@@ -601,6 +713,7 @@ static const struct stm32_rtc_data stm32mp1_data = {
 	.has_pclk = true,
 	.need_dbp = false,
 	.has_wakeirq = true,
+	.has_lsco = true,
 	.regs = {
 		.tr = 0x00,
 		.dr = 0x04,
@@ -611,6 +724,7 @@ static const struct stm32_rtc_data stm32mp1_data = {
 		.wpr = 0x24,
 		.sr = 0x50,
 		.scr = 0x5C,
+		.cfgr = 0x60,
 		.verr = 0x3F4,
 	},
 	.events = {
@@ -814,6 +928,22 @@ static int stm32_rtc_probe(struct platform_device *pdev)
 		goto err;
 	}
 
+	if (rtc->data->has_lsco) {
+		ret = of_property_read_s32(pdev->dev.of_node,
+					   "st,lsco", &rtc->lsco);
+		if (!ret) {
+			ret = stm32_rtc_clk_lsco_register(pdev);
+			if (ret)
+				dev_warn(&pdev->dev,
+					 "LSCO clock registration failed: %d\n",
+					 ret);
+		} else {
+			stm32_rtc_clk_lsco_disable(pdev);
+			rtc->lsco = ret;
+			dev_dbg(&pdev->dev, "No LSCO clock: %d\n", ret);
+		}
+	}
+
 	/*
 	 * If INITS flag is reset (calendar year field set to 0x00), calendar
 	 * must be initialized
@@ -852,6 +982,9 @@ static int stm32_rtc_remove(struct platform_device *pdev)
 	const struct stm32_rtc_registers *regs = &rtc->data->regs;
 	unsigned int cr;
 
+	if (!IS_ERR_OR_NULL(rtc->clk_lsco))
+		clk_unregister_gate(rtc->clk_lsco);
+
 	/* Disable interrupts */
 	stm32_rtc_wpr_unlock(rtc);
 	cr = readl_relaxed(rtc->base + regs->cr);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 4/6] rtc: stm32: add alarm A out feature
  2022-05-04 13:02 [PATCH 0/6] rtc: stm32: add alarm out and LSCO features Valentin Caron
                   ` (2 preceding siblings ...)
  2022-05-04 13:06 ` [PATCH 3/6] rtc: stm32: add Low Speed Clock Output (LSCO) support Valentin Caron
@ 2022-05-04 13:06 ` Valentin Caron
  2022-05-04 13:06 ` [PATCH 5/6] ARM: dts: stm32: add RTC LSCO support on stm32mp157c-dk2 Valentin Caron
  2022-05-04 13:06 ` [PATCH 6/6] ARM: dts: stm32: add RTC LSCO support on stm32mp135f-dk Valentin Caron
  5 siblings, 0 replies; 13+ messages in thread
From: Valentin Caron @ 2022-05-04 13:06 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni, Rob Herring,
	Krzysztof Kozlowski, Alexandre Torgue
  Cc: Gabriel Fernandez, Amelie Delaunay, Valentin Caron, linux-rtc,
	devicetree, linux-stm32, linux-arm-kernel, linux-kernel

STM32 RTC can pulse some SOC pins when an RTC alarm expires.
This patch adds this functionality for alarm A. The pulse can out on three
pins RTC_OUT1, RTC_OUT2, RTC_OUT2_RMP (PC13, PB2, PI8 on stm32mp15)
(PC13, PB2, PI1 on stm32mp13).

This patch only adds the functionality for devices which are using
st,stm32mp1-rtc compatible.

Signed-off-by: Valentin Caron <valentin.caron@foss.st.com>
---
 drivers/rtc/rtc-stm32.c | 77 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 77 insertions(+)

diff --git a/drivers/rtc/rtc-stm32.c b/drivers/rtc/rtc-stm32.c
index ace041eb44b8..f27927be20b2 100644
--- a/drivers/rtc/rtc-stm32.c
+++ b/drivers/rtc/rtc-stm32.c
@@ -5,6 +5,7 @@
  */
 
 #include <linux/bcd.h>
+#include <linux/bitfield.h>
 #include <linux/clk.h>
 #include <linux/clk-provider.h>
 #include <linux/iopoll.h>
@@ -44,8 +45,10 @@
 #define STM32_RTC_CR_ALRAIE		BIT(12)
 #define STM32_RTC_CR_COSEL		BIT(19)
 #define STM32_RTC_CR_OSEL		GENMASK(22, 21)
+#define STM32_RTC_CR_OSEL_ALARM_A	FIELD_PREP(STM32_RTC_CR_OSEL, 0x01)
 #define STM32_RTC_CR_COE		BIT(23)
 #define STM32_RTC_CR_TAMPOE		BIT(26)
+#define STM32_RTC_CR_TAMPALRM_TYPE	BIT(30)
 #define STM32_RTC_CR_OUT2EN		BIT(31)
 
 /* STM32_RTC_ISR/STM32_RTC_ICSR bit fields */
@@ -134,6 +137,7 @@ struct stm32_rtc_data {
 	bool need_dbp;
 	bool has_wakeirq;
 	bool has_lsco;
+	bool has_alarm_out;
 };
 
 struct stm32_rtc {
@@ -149,6 +153,7 @@ struct stm32_rtc {
 	int wakeirq_alarm;
 	int lsco;
 	struct clk *clk_lsco;
+	int out_alarm;
 };
 
 /*
@@ -253,6 +258,64 @@ static void stm32_rtc_clk_lsco_disable(struct platform_device *pdev)
 	writel_relaxed(cfgr &= ~STM32_RTC_CFGR_LSCOEN, rtc->base + regs.cfgr);
 }
 
+static int stm32_rtc_out_alarm_config(struct platform_device *pdev)
+{
+	struct stm32_rtc *rtc = platform_get_drvdata(pdev);
+	struct stm32_rtc_registers regs = rtc->data->regs;
+	unsigned int cr = readl_relaxed(rtc->base + regs.cr);
+	unsigned int cfgr = readl_relaxed(rtc->base + regs.cfgr);
+
+	cr &= ~STM32_RTC_CR_OSEL;
+	cr |= STM32_RTC_CR_OSEL_ALARM_A;
+	cr &= ~STM32_RTC_CR_TAMPOE;
+	cr &= ~STM32_RTC_CR_COE;
+	cr &= ~STM32_RTC_CR_TAMPALRM_TYPE;
+
+	switch (rtc->out_alarm) {
+	case RTC_OUT1:
+		cr &= ~STM32_RTC_CR_OUT2EN;
+		cfgr &= ~STM32_RTC_CFGR_OUT2_RMP;
+		break;
+	case RTC_OUT2:
+		cr |= STM32_RTC_CR_OUT2EN;
+		cfgr &= ~STM32_RTC_CFGR_OUT2_RMP;
+		break;
+	case RTC_OUT2_RMP:
+		cr |= STM32_RTC_CR_OUT2EN;
+		cfgr |= STM32_RTC_CFGR_OUT2_RMP;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	stm32_rtc_wpr_unlock(rtc);
+	writel_relaxed(cr, rtc->base + regs.cr);
+	writel_relaxed(cfgr, rtc->base + regs.cfgr);
+	stm32_rtc_wpr_lock(rtc);
+
+	return 0;
+}
+
+static void stm32_rtc_out_alarm_disable(struct platform_device *pdev)
+{
+	struct stm32_rtc *rtc = platform_get_drvdata(pdev);
+	struct stm32_rtc_registers regs = rtc->data->regs;
+	unsigned int cr = readl_relaxed(rtc->base + regs.cr);
+	unsigned int cfgr = readl_relaxed(rtc->base + regs.cfgr);
+
+	cr &= ~STM32_RTC_CR_OSEL;
+	cr &= ~STM32_RTC_CR_TAMPOE;
+	cr &= ~STM32_RTC_CR_COE;
+	cr &= ~STM32_RTC_CR_TAMPALRM_TYPE;
+	cr &= ~STM32_RTC_CR_OUT2EN;
+	cfgr &= ~STM32_RTC_CFGR_OUT2_RMP;
+
+	stm32_rtc_wpr_unlock(rtc);
+	writel_relaxed(cr, rtc->base + regs.cr);
+	writel_relaxed(cfgr, rtc->base + regs.cfgr);
+	stm32_rtc_wpr_lock(rtc);
+}
+
 static int stm32_rtc_enter_init_mode(struct stm32_rtc *rtc)
 {
 	const struct stm32_rtc_registers *regs = &rtc->data->regs;
@@ -657,6 +720,7 @@ static const struct stm32_rtc_data stm32_rtc_data = {
 	.need_dbp = true,
 	.has_wakeirq = false,
 	.has_lsco = false,
+	.has_alarm_out = false,
 	.regs = {
 		.tr = 0x00,
 		.dr = 0x04,
@@ -681,6 +745,7 @@ static const struct stm32_rtc_data stm32h7_rtc_data = {
 	.need_dbp = true,
 	.has_wakeirq = false,
 	.has_lsco = false,
+	.has_alarm_out = false,
 	.regs = {
 		.tr = 0x00,
 		.dr = 0x04,
@@ -714,6 +779,7 @@ static const struct stm32_rtc_data stm32mp1_data = {
 	.need_dbp = false,
 	.has_wakeirq = true,
 	.has_lsco = true,
+	.has_alarm_out = true,
 	.regs = {
 		.tr = 0x00,
 		.dr = 0x04,
@@ -928,6 +994,17 @@ static int stm32_rtc_probe(struct platform_device *pdev)
 		goto err;
 	}
 
+	if (rtc->data->has_alarm_out) {
+		ret = of_property_read_s32(pdev->dev.of_node, "st,alarm", &rtc->out_alarm);
+		if (!ret) {
+			ret = stm32_rtc_out_alarm_config(pdev);
+		} else {
+			stm32_rtc_out_alarm_disable(pdev);
+			rtc->out_alarm = ret;
+			dev_dbg(&pdev->dev, "No alarm out: %d\n", ret);
+		}
+	}
+
 	if (rtc->data->has_lsco) {
 		ret = of_property_read_s32(pdev->dev.of_node,
 					   "st,lsco", &rtc->lsco);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 5/6] ARM: dts: stm32: add RTC LSCO support on stm32mp157c-dk2
  2022-05-04 13:02 [PATCH 0/6] rtc: stm32: add alarm out and LSCO features Valentin Caron
                   ` (3 preceding siblings ...)
  2022-05-04 13:06 ` [PATCH 4/6] rtc: stm32: add alarm A out feature Valentin Caron
@ 2022-05-04 13:06 ` Valentin Caron
  2022-05-04 13:06 ` [PATCH 6/6] ARM: dts: stm32: add RTC LSCO support on stm32mp135f-dk Valentin Caron
  5 siblings, 0 replies; 13+ messages in thread
From: Valentin Caron @ 2022-05-04 13:06 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni, Rob Herring,
	Krzysztof Kozlowski, Alexandre Torgue
  Cc: Gabriel Fernandez, Amelie Delaunay, Valentin Caron, linux-rtc,
	devicetree, linux-stm32, linux-arm-kernel, linux-kernel

From: Gabriel Fernandez <gabriel.fernandez@foss.st.com>

Add LSCO support on stm32mp157c-dk2 board. LSCO output is mapped on
RTC_OUT2_RMP (PI8), directly routed on LPO_IN pin of Wifi/Bluetooth
module.

Signed-off-by: Gabriel Fernandez <gabriel.fernandez@foss.st.com>
Signed-off-by: Valentin Caron <valentin.caron@foss.st.com>
---
 arch/arm/boot/dts/stm32mp15-pinctrl.dtsi | 6 ++++++
 arch/arm/boot/dts/stm32mp157c-dk2.dts    | 7 +++++++
 2 files changed, 13 insertions(+)

diff --git a/arch/arm/boot/dts/stm32mp15-pinctrl.dtsi b/arch/arm/boot/dts/stm32mp15-pinctrl.dtsi
index 6052243ad81c..c65d1ea8b614 100644
--- a/arch/arm/boot/dts/stm32mp15-pinctrl.dtsi
+++ b/arch/arm/boot/dts/stm32mp15-pinctrl.dtsi
@@ -1244,6 +1244,12 @@ pins {
 		};
 	};
 
+	rtc_out2_rmp_pins_a: rtc-out2-rmp-pins-0 {
+		pins {
+			pinmux = <STM32_PINMUX('I', 8, ANALOG)>; /* RTC_OUT2_RMP */
+		};
+	};
+
 	sai2a_pins_a: sai2a-0 {
 		pins {
 			pinmux = <STM32_PINMUX('I', 5, AF10)>, /* SAI2_SCK_A */
diff --git a/arch/arm/boot/dts/stm32mp157c-dk2.dts b/arch/arm/boot/dts/stm32mp157c-dk2.dts
index 2bc92ef3aeb9..a1eda91bc2e3 100644
--- a/arch/arm/boot/dts/stm32mp157c-dk2.dts
+++ b/arch/arm/boot/dts/stm32mp157c-dk2.dts
@@ -11,6 +11,7 @@
 #include "stm32mp15-pinctrl.dtsi"
 #include "stm32mp15xxac-pinctrl.dtsi"
 #include "stm32mp15xx-dkx.dtsi"
+#include <dt-bindings/rtc/rtc-stm32.h>
 
 / {
 	model = "STMicroelectronics STM32MP157C-DK2 Discovery Board";
@@ -92,6 +93,12 @@ ltdc_ep1_out: endpoint@1 {
 	};
 };
 
+&rtc {
+	st,lsco = <RTC_OUT2_RMP>;
+	pinctrl-0 = <&rtc_out2_rmp_pins_a>;
+	pinctrl-names = "default";
+};
+
 &usart2 {
 	pinctrl-names = "default", "sleep", "idle";
 	pinctrl-0 = <&usart2_pins_c>;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 6/6] ARM: dts: stm32: add RTC LSCO support on stm32mp135f-dk
  2022-05-04 13:02 [PATCH 0/6] rtc: stm32: add alarm out and LSCO features Valentin Caron
                   ` (4 preceding siblings ...)
  2022-05-04 13:06 ` [PATCH 5/6] ARM: dts: stm32: add RTC LSCO support on stm32mp157c-dk2 Valentin Caron
@ 2022-05-04 13:06 ` Valentin Caron
  5 siblings, 0 replies; 13+ messages in thread
From: Valentin Caron @ 2022-05-04 13:06 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni, Rob Herring,
	Krzysztof Kozlowski, Alexandre Torgue
  Cc: Gabriel Fernandez, Amelie Delaunay, Valentin Caron, linux-rtc,
	devicetree, linux-stm32, linux-arm-kernel, linux-kernel

From: Gabriel Fernandez <gabriel.fernandez@foss.st.com>

Add LSCO support on stm32mp135f-dk board. LSCO output is mapped on
RTC_OUT2_RMP (PI1), directly routed on LPO_IN pin of Wifi/Bluetooth
module.

Signed-off-by: Gabriel Fernandez <gabriel.fernandez@foss.st.com>
Signed-off-by: Valentin Caron <valentin.caron@foss.st.com>
---
 arch/arm/boot/dts/stm32mp13-pinctrl.dtsi | 6 ++++++
 arch/arm/boot/dts/stm32mp135f-dk.dts     | 4 ++++
 2 files changed, 10 insertions(+)

diff --git a/arch/arm/boot/dts/stm32mp13-pinctrl.dtsi b/arch/arm/boot/dts/stm32mp13-pinctrl.dtsi
index d2472cd8f1d0..0aaafd529404 100644
--- a/arch/arm/boot/dts/stm32mp13-pinctrl.dtsi
+++ b/arch/arm/boot/dts/stm32mp13-pinctrl.dtsi
@@ -6,6 +6,12 @@
 #include <dt-bindings/pinctrl/stm32-pinfunc.h>
 
 &pinctrl {
+	rtc_out2_rmp_pins_a: rtc-out2-rmp-pins-0 {
+		pins {
+			pinmux = <STM32_PINMUX('I', 1, ANALOG)>; /* RTC_OUT2_RMP */
+		};
+	};
+
 	sdmmc1_b4_pins_a: sdmmc1-b4-0 {
 		pins {
 			pinmux = <STM32_PINMUX('C', 8, AF12)>, /* SDMMC1_D0 */
diff --git a/arch/arm/boot/dts/stm32mp135f-dk.dts b/arch/arm/boot/dts/stm32mp135f-dk.dts
index 09d6226d598f..de9fd89fce5c 100644
--- a/arch/arm/boot/dts/stm32mp135f-dk.dts
+++ b/arch/arm/boot/dts/stm32mp135f-dk.dts
@@ -12,6 +12,7 @@
 #include "stm32mp135.dtsi"
 #include "stm32mp13xf.dtsi"
 #include "stm32mp13-pinctrl.dtsi"
+#include <dt-bindings/rtc/rtc-stm32.h>
 
 / {
 	model = "STMicroelectronics STM32MP135F-DK Discovery Board";
@@ -63,6 +64,9 @@ &iwdg2 {
 };
 
 &rtc {
+	st,lsco = <RTC_OUT2_RMP>;
+	pinctrl-0 = <&rtc_out2_rmp_pins_a>;
+	pinctrl-names = "default";
 	status = "okay";
 };
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/6] dt-bindings: rtc: stm32: add alarm A out property to select output
  2022-05-04 13:06 ` [PATCH 2/6] dt-bindings: rtc: stm32: add alarm A out " Valentin Caron
@ 2022-05-04 15:42   ` Rob Herring
  2022-05-04 20:27   ` Alexandre Belloni
  1 sibling, 0 replies; 13+ messages in thread
From: Rob Herring @ 2022-05-04 15:42 UTC (permalink / raw)
  To: Valentin Caron
  Cc: Alessandro Zummo, Alexandre Belloni, Krzysztof Kozlowski,
	Alexandre Torgue, Gabriel Fernandez, Amelie Delaunay, linux-rtc,
	devicetree, linux-stm32, linux-arm-kernel, linux-kernel

On Wed, May 04, 2022 at 03:06:13PM +0200, Valentin Caron wrote:
> STM32 RTC can pulse some SOC pins when an alarm of RTC expires.
> 
> This patch adds property to activate alarm A output. The pulse can
> output on three pins RTC_OUT1, RTC_OUT2, RTC_OUT2_RMP
> (PC13, PB2, PI8 on stm32mp15) (PC13, PB2, PI1 on stm32mp13).
> 
> Signed-off-by: Valentin Caron <valentin.caron@foss.st.com>
> ---
>  .../devicetree/bindings/rtc/st,stm32-rtc.yaml | 19 ++++++++++++++++++-
>  1 file changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml b/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml
> index 56d46ea35c5d..71e02604e8de 100644
> --- a/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml
> +++ b/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml
> @@ -59,6 +59,13 @@ properties:
>        Refer to <include/dt-bindings/rtc/rtc-stm32.h> for the supported values.
>        Pinctrl state named "default" may be defined to reserve pin for RTC output.
>  
> +  st,alarm:
> +    $ref: "/schemas/types.yaml#/definitions/uint32"
> +    description: |
> +      To select and enable RTC Alarm A output.
> +      Refer to <include/dt-bindings/rtc/rtc-stm32.h> for the supported values.

No, sorry, you need to define the allowed values as a schema here.

> +      Pinctrl state named "default" may be defined to reserve pin for RTC output.
> +
>  allOf:
>    - if:
>        properties:
> @@ -75,6 +82,9 @@ allOf:
>          st,lsco:
>            maxItems: 0
>  
> +        st,alarm:
> +          maxItems: 0

st,alarm: false

or:

not:
  required: [ st,alarm ]

is how you disallow a property.

This should cause a warning, but this patch didn't apply for me.

> +
>          clock-names: false
>  
>        required:
> @@ -95,6 +105,9 @@ allOf:
>          st,lsco:
>            maxItems: 0
>  
> +        st,alarm:
> +          maxItems: 0
> +
>        required:
>          - clock-names
>          - st,syscfg
> @@ -117,6 +130,9 @@ allOf:
>          st,lsco:
>            maxItems: 1
>  
> +        st,alarm:
> +          maxItems: 1

maxItems applies to arrays, but this is a scalar value. I don't think 
you need this hunk.

> +
>        required:
>          - clock-names
>  
> @@ -153,8 +169,9 @@ examples:
>        clocks = <&rcc RTCAPB>, <&rcc RTC>;
>        clock-names = "pclk", "rtc_ck";
>        interrupts = <GIC_SPI 3 IRQ_TYPE_LEVEL_HIGH>;
> +      st,alarm = <RTC_OUT1>;
>        st,lsco = <RTC_OUT2_RMP>;
> -      pinctrl-0 = <&rtc_out2_rmp_pins_a>;
> +      pinctrl-0 = <&rtc_out1_pins_a &rtc_out2_rmp_pins_a>;
>        pinctrl-names = "default";
>      };
>  
> -- 
> 2.25.1
> 
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/6] dt-bindings: rtc: stm32: add alarm A out property to select output
  2022-05-04 13:06 ` [PATCH 2/6] dt-bindings: rtc: stm32: add alarm A out " Valentin Caron
  2022-05-04 15:42   ` Rob Herring
@ 2022-05-04 20:27   ` Alexandre Belloni
  2022-05-23 12:34     ` Valentin CARON
  1 sibling, 1 reply; 13+ messages in thread
From: Alexandre Belloni @ 2022-05-04 20:27 UTC (permalink / raw)
  To: Valentin Caron
  Cc: Alessandro Zummo, Rob Herring, Krzysztof Kozlowski,
	Alexandre Torgue, Gabriel Fernandez, Amelie Delaunay, linux-rtc,
	devicetree, linux-stm32, linux-arm-kernel, linux-kernel

Hello,

On 04/05/2022 15:06:13+0200, Valentin Caron wrote:
> STM32 RTC can pulse some SOC pins when an alarm of RTC expires.
> 
> This patch adds property to activate alarm A output. The pulse can
> output on three pins RTC_OUT1, RTC_OUT2, RTC_OUT2_RMP
> (PC13, PB2, PI8 on stm32mp15) (PC13, PB2, PI1 on stm32mp13).
> 
> Signed-off-by: Valentin Caron <valentin.caron@foss.st.com>
> ---
>  .../devicetree/bindings/rtc/st,stm32-rtc.yaml | 19 ++++++++++++++++++-
>  1 file changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml b/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml
> index 56d46ea35c5d..71e02604e8de 100644
> --- a/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml
> +++ b/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml
> @@ -59,6 +59,13 @@ properties:
>        Refer to <include/dt-bindings/rtc/rtc-stm32.h> for the supported values.
>        Pinctrl state named "default" may be defined to reserve pin for RTC output.
>  
> +  st,alarm:
> +    $ref: "/schemas/types.yaml#/definitions/uint32"
> +    description: |
> +      To select and enable RTC Alarm A output.
> +      Refer to <include/dt-bindings/rtc/rtc-stm32.h> for the supported values.
> +      Pinctrl state named "default" may be defined to reserve pin for RTC output.
> +
>  allOf:
>    - if:
>        properties:
> @@ -75,6 +82,9 @@ allOf:
>          st,lsco:
>            maxItems: 0
>  
> +        st,alarm:
> +          maxItems: 0
> +
>          clock-names: false
>  
>        required:
> @@ -95,6 +105,9 @@ allOf:
>          st,lsco:
>            maxItems: 0
>  
> +        st,alarm:
> +          maxItems: 0
> +
>        required:
>          - clock-names
>          - st,syscfg
> @@ -117,6 +130,9 @@ allOf:
>          st,lsco:
>            maxItems: 1
>  
> +        st,alarm:
> +          maxItems: 1
> +
>        required:
>          - clock-names
>  
> @@ -153,8 +169,9 @@ examples:
>        clocks = <&rcc RTCAPB>, <&rcc RTC>;
>        clock-names = "pclk", "rtc_ck";
>        interrupts = <GIC_SPI 3 IRQ_TYPE_LEVEL_HIGH>;
> +      st,alarm = <RTC_OUT1>;
>        st,lsco = <RTC_OUT2_RMP>;

Shouldn't that be exactly the opposite? You have two pins that can
output different functions. The property should be the pin and the value
the function. I'd go even further and I would say this is actually
pinmuxing.


-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/6] dt-bindings: rtc: stm32: add st,lsco optional property to select output
  2022-05-04 13:02 ` [PATCH 1/6] dt-bindings: rtc: stm32: add st,lsco optional property to select output Valentin Caron
@ 2022-05-16 23:52   ` Rob Herring
  0 siblings, 0 replies; 13+ messages in thread
From: Rob Herring @ 2022-05-16 23:52 UTC (permalink / raw)
  To: Valentin Caron
  Cc: Alessandro Zummo, Alexandre Belloni, Krzysztof Kozlowski,
	Alexandre Torgue, Gabriel Fernandez, Amelie Delaunay, linux-rtc,
	devicetree, linux-stm32, linux-arm-kernel, linux-kernel

On Wed, May 04, 2022 at 03:02:28PM +0200, Valentin Caron wrote:
> From: Amelie Delaunay <amelie.delaunay@foss.st.com>
> 
> STM32 RTC has three output pins: RTC_OUT1, RTC_OUT2 or RTC_OUT2_RMP.
> 
> RTC Low-Speed Clock Output (LSCO) can be output on RTC_OUT1 or
> RTC_OUT2_RMP.
> 
> This patch adds constants for RTC output bindings and adds st,lsco
> optional property for stm32 rtc driver, to select and enable LSCO.
> A pinctrl state is also optional to reserve pin for RTC output.
> 
> Signed-off-by: Amelie Delaunay <amelie.delaunay@foss.st.com>
> Signed-off-by: Valentin Caron <valentin.caron@foss.st.com>
> ---
>  .../devicetree/bindings/rtc/st,stm32-rtc.yaml | 20 +++++++++++++++++++
>  include/dt-bindings/rtc/rtc-stm32.h           | 14 +++++++++++++
>  2 files changed, 34 insertions(+)
>  create mode 100644 include/dt-bindings/rtc/rtc-stm32.h
> 
> diff --git a/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml b/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml
> index 764717ce1873..56d46ea35c5d 100644
> --- a/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml
> +++ b/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml
> @@ -52,6 +52,13 @@ properties:
>        override default rtc_ck parent clock phandle of the new parent clock of rtc_ck
>      maxItems: 1
>  
> +  st,lsco:
> +    $ref: "/schemas/types.yaml#/definitions/uint32"
> +    description: |
> +      To select and enable RTC Low Speed Clock Output.
> +      Refer to <include/dt-bindings/rtc/rtc-stm32.h> for the supported values.
> +      Pinctrl state named "default" may be defined to reserve pin for RTC output.
> +
>  allOf:
>    - if:
>        properties:
> @@ -65,6 +72,9 @@ allOf:
>            minItems: 1
>            maxItems: 1
>  
> +        st,lsco:
> +          maxItems: 0

If disallowing the property is what you wanted, then 'st,lsco: false' is 
the way. 'maxItems: 0' is never correct.

> +
>          clock-names: false
>  
>        required:
> @@ -82,6 +92,9 @@ allOf:
>            minItems: 2
>            maxItems: 2
>  
> +        st,lsco:
> +          maxItems: 0
> +
>        required:
>          - clock-names
>          - st,syscfg
> @@ -101,6 +114,9 @@ allOf:
>          assigned-clocks: false
>          assigned-clock-parents: false
>  
> +        st,lsco:
> +          maxItems: 1
> +
>        required:
>          - clock-names
>  
> @@ -130,12 +146,16 @@ examples:
>    - |
>      #include <dt-bindings/interrupt-controller/arm-gic.h>
>      #include <dt-bindings/clock/stm32mp1-clks.h>
> +    #include <dt-bindings/rtc/rtc-stm32.h>
>      rtc@5c004000 {
>        compatible = "st,stm32mp1-rtc";
>        reg = <0x5c004000 0x400>;
>        clocks = <&rcc RTCAPB>, <&rcc RTC>;
>        clock-names = "pclk", "rtc_ck";
>        interrupts = <GIC_SPI 3 IRQ_TYPE_LEVEL_HIGH>;
> +      st,lsco = <RTC_OUT2_RMP>;
> +      pinctrl-0 = <&rtc_out2_rmp_pins_a>;
> +      pinctrl-names = "default";
>      };
>  
>  ...
> diff --git a/include/dt-bindings/rtc/rtc-stm32.h b/include/dt-bindings/rtc/rtc-stm32.h
> new file mode 100644
> index 000000000000..2fd78c2e62d4
> --- /dev/null
> +++ b/include/dt-bindings/rtc/rtc-stm32.h
> @@ -0,0 +1,14 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * This header provides constants for STM32_RTC bindings.
> + */
> +
> +#ifndef _DT_BINDINGS_RTC_RTC_STM32_H
> +#define _DT_BINDINGS_RTC_RTC_STM32_H
> +
> +#define RTC_NO_OUT	0
> +#define RTC_OUT1	1
> +#define RTC_OUT2	2
> +#define RTC_OUT2_RMP	3
> +
> +#endif
> -- 
> 2.25.1
> 
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/6] dt-bindings: rtc: stm32: add alarm A out property to select output
  2022-05-04 20:27   ` Alexandre Belloni
@ 2022-05-23 12:34     ` Valentin CARON
  2022-06-24  8:35       ` Valentin CARON
  2022-07-22 16:02       ` Alexandre Belloni
  0 siblings, 2 replies; 13+ messages in thread
From: Valentin CARON @ 2022-05-23 12:34 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Alessandro Zummo, Rob Herring, Krzysztof Kozlowski,
	Alexandre Torgue, Gabriel Fernandez, Amelie Delaunay, linux-rtc,
	devicetree, linux-stm32, linux-arm-kernel, linux-kernel

Hi Alexandre,

On 5/4/22 22:27, Alexandre Belloni wrote:
> Hello,
>
> On 04/05/2022 15:06:13+0200, Valentin Caron wrote:
>> STM32 RTC can pulse some SOC pins when an alarm of RTC expires.
>>
>> This patch adds property to activate alarm A output. The pulse can
>> output on three pins RTC_OUT1, RTC_OUT2, RTC_OUT2_RMP
>> (PC13, PB2, PI8 on stm32mp15) (PC13, PB2, PI1 on stm32mp13).
>>
>> Signed-off-by: Valentin Caron <valentin.caron@foss.st.com>
>> ---
>>   .../devicetree/bindings/rtc/st,stm32-rtc.yaml | 19 ++++++++++++++++++-
>>   1 file changed, 18 insertions(+), 1 deletion(-)
>>
>> diff --git a/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml b/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml
>> index 56d46ea35c5d..71e02604e8de 100644
>> --- a/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml
>> +++ b/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml
>> @@ -59,6 +59,13 @@ properties:
>>         Refer to <include/dt-bindings/rtc/rtc-stm32.h> for the supported values.
>>         Pinctrl state named "default" may be defined to reserve pin for RTC output.
>>   
>> +  st,alarm:
>> +    $ref: "/schemas/types.yaml#/definitions/uint32"
>> +    description: |
>> +      To select and enable RTC Alarm A output.
>> +      Refer to <include/dt-bindings/rtc/rtc-stm32.h> for the supported values.
>> +      Pinctrl state named "default" may be defined to reserve pin for RTC output.
>> +
>>   allOf:
>>     - if:
>>         properties:
>> @@ -75,6 +82,9 @@ allOf:
>>           st,lsco:
>>             maxItems: 0
>>   
>> +        st,alarm:
>> +          maxItems: 0
>> +
>>           clock-names: false
>>   
>>         required:
>> @@ -95,6 +105,9 @@ allOf:
>>           st,lsco:
>>             maxItems: 0
>>   
>> +        st,alarm:
>> +          maxItems: 0
>> +
>>         required:
>>           - clock-names
>>           - st,syscfg
>> @@ -117,6 +130,9 @@ allOf:
>>           st,lsco:
>>             maxItems: 1
>>   
>> +        st,alarm:
>> +          maxItems: 1
>> +
>>         required:
>>           - clock-names
>>   
>> @@ -153,8 +169,9 @@ examples:
>>         clocks = <&rcc RTCAPB>, <&rcc RTC>;
>>         clock-names = "pclk", "rtc_ck";
>>         interrupts = <GIC_SPI 3 IRQ_TYPE_LEVEL_HIGH>;
>> +      st,alarm = <RTC_OUT1>;
>>         st,lsco = <RTC_OUT2_RMP>;
> Shouldn't that be exactly the opposite? You have two pins that can
> output different functions. The property should be the pin and the value
> the function. I'd go even further and I would say this is actually
> pinmuxing.
>
You're right, if the property is the pin and the value the function, 
this looks like a pinctrl node.
We choose to develop theses functionalities in the reverse order, to 
avoid the complexity of adding
the pinctrl framework to our driver. Moreover, LSCO and AlarmA may 
haven't a peripheral client and
this would probably require to also implement pinctrl hogging.

Is the implementation that we have proposed is acceptable regarding 
theses elements ?

Thank you,
Valentin


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/6] dt-bindings: rtc: stm32: add alarm A out property to select output
  2022-05-23 12:34     ` Valentin CARON
@ 2022-06-24  8:35       ` Valentin CARON
  2022-07-22 16:02       ` Alexandre Belloni
  1 sibling, 0 replies; 13+ messages in thread
From: Valentin CARON @ 2022-06-24  8:35 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Alessandro Zummo, Rob Herring, Krzysztof Kozlowski,
	Alexandre Torgue, Gabriel Fernandez, Amelie Delaunay, linux-rtc,
	devicetree, linux-stm32, linux-arm-kernel, linux-kernel

Hi Alexandre,

May I have your view regarding these new elements ?

Thank you,
Valentin

On 5/23/22 14:34, Valentin CARON wrote:
> Hi Alexandre,
>
> On 5/4/22 22:27, Alexandre Belloni wrote:
>> Hello,
>>
>> On 04/05/2022 15:06:13+0200, Valentin Caron wrote:
>>> STM32 RTC can pulse some SOC pins when an alarm of RTC expires.
>>>
>>> This patch adds property to activate alarm A output. The pulse can
>>> output on three pins RTC_OUT1, RTC_OUT2, RTC_OUT2_RMP
>>> (PC13, PB2, PI8 on stm32mp15) (PC13, PB2, PI1 on stm32mp13).
>>>
>>> Signed-off-by: Valentin Caron <valentin.caron@foss.st.com>
>>> ---
>>>   .../devicetree/bindings/rtc/st,stm32-rtc.yaml | 19 
>>> ++++++++++++++++++-
>>>   1 file changed, 18 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml 
>>> b/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml
>>> index 56d46ea35c5d..71e02604e8de 100644
>>> --- a/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml
>>> +++ b/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml
>>> @@ -59,6 +59,13 @@ properties:
>>>         Refer to <include/dt-bindings/rtc/rtc-stm32.h> for the 
>>> supported values.
>>>         Pinctrl state named "default" may be defined to reserve pin 
>>> for RTC output.
>>>   +  st,alarm:
>>> +    $ref: "/schemas/types.yaml#/definitions/uint32"
>>> +    description: |
>>> +      To select and enable RTC Alarm A output.
>>> +      Refer to <include/dt-bindings/rtc/rtc-stm32.h> for the 
>>> supported values.
>>> +      Pinctrl state named "default" may be defined to reserve pin 
>>> for RTC output.
>>> +
>>>   allOf:
>>>     - if:
>>>         properties:
>>> @@ -75,6 +82,9 @@ allOf:
>>>           st,lsco:
>>>             maxItems: 0
>>>   +        st,alarm:
>>> +          maxItems: 0
>>> +
>>>           clock-names: false
>>>           required:
>>> @@ -95,6 +105,9 @@ allOf:
>>>           st,lsco:
>>>             maxItems: 0
>>>   +        st,alarm:
>>> +          maxItems: 0
>>> +
>>>         required:
>>>           - clock-names
>>>           - st,syscfg
>>> @@ -117,6 +130,9 @@ allOf:
>>>           st,lsco:
>>>             maxItems: 1
>>>   +        st,alarm:
>>> +          maxItems: 1
>>> +
>>>         required:
>>>           - clock-names
>>>   @@ -153,8 +169,9 @@ examples:
>>>         clocks = <&rcc RTCAPB>, <&rcc RTC>;
>>>         clock-names = "pclk", "rtc_ck";
>>>         interrupts = <GIC_SPI 3 IRQ_TYPE_LEVEL_HIGH>;
>>> +      st,alarm = <RTC_OUT1>;
>>>         st,lsco = <RTC_OUT2_RMP>;
>> Shouldn't that be exactly the opposite? You have two pins that can
>> output different functions. The property should be the pin and the value
>> the function. I'd go even further and I would say this is actually
>> pinmuxing.
>>
> You're right, if the property is the pin and the value the function, 
> this looks like a pinctrl node.
> We choose to develop theses functionalities in the reverse order, to 
> avoid the complexity of adding
> the pinctrl framework to our driver. Moreover, LSCO and AlarmA may 
> haven't a peripheral client and
> this would probably require to also implement pinctrl hogging.
>
> Is the implementation that we have proposed is acceptable regarding 
> theses elements ?
>
> Thank you,
> Valentin
>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/6] dt-bindings: rtc: stm32: add alarm A out property to select output
  2022-05-23 12:34     ` Valentin CARON
  2022-06-24  8:35       ` Valentin CARON
@ 2022-07-22 16:02       ` Alexandre Belloni
  1 sibling, 0 replies; 13+ messages in thread
From: Alexandre Belloni @ 2022-07-22 16:02 UTC (permalink / raw)
  To: Valentin CARON
  Cc: Alessandro Zummo, Rob Herring, Krzysztof Kozlowski,
	Alexandre Torgue, Gabriel Fernandez, Amelie Delaunay, linux-rtc,
	devicetree, linux-stm32, linux-arm-kernel, linux-kernel

On 23/05/2022 14:34:22+0200, Valentin CARON wrote:
> Hi Alexandre,
> 
> On 5/4/22 22:27, Alexandre Belloni wrote:
> > Hello,
> > 
> > On 04/05/2022 15:06:13+0200, Valentin Caron wrote:
> > > STM32 RTC can pulse some SOC pins when an alarm of RTC expires.
> > > 
> > > This patch adds property to activate alarm A output. The pulse can
> > > output on three pins RTC_OUT1, RTC_OUT2, RTC_OUT2_RMP
> > > (PC13, PB2, PI8 on stm32mp15) (PC13, PB2, PI1 on stm32mp13).
> > > 
> > > Signed-off-by: Valentin Caron <valentin.caron@foss.st.com>
> > > ---
> > >   .../devicetree/bindings/rtc/st,stm32-rtc.yaml | 19 ++++++++++++++++++-
> > >   1 file changed, 18 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml b/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml
> > > index 56d46ea35c5d..71e02604e8de 100644
> > > --- a/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml
> > > +++ b/Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml
> > > @@ -59,6 +59,13 @@ properties:
> > >         Refer to <include/dt-bindings/rtc/rtc-stm32.h> for the supported values.
> > >         Pinctrl state named "default" may be defined to reserve pin for RTC output.
> > > +  st,alarm:
> > > +    $ref: "/schemas/types.yaml#/definitions/uint32"
> > > +    description: |
> > > +      To select and enable RTC Alarm A output.
> > > +      Refer to <include/dt-bindings/rtc/rtc-stm32.h> for the supported values.
> > > +      Pinctrl state named "default" may be defined to reserve pin for RTC output.
> > > +
> > >   allOf:
> > >     - if:
> > >         properties:
> > > @@ -75,6 +82,9 @@ allOf:
> > >           st,lsco:
> > >             maxItems: 0
> > > +        st,alarm:
> > > +          maxItems: 0
> > > +
> > >           clock-names: false
> > >         required:
> > > @@ -95,6 +105,9 @@ allOf:
> > >           st,lsco:
> > >             maxItems: 0
> > > +        st,alarm:
> > > +          maxItems: 0
> > > +
> > >         required:
> > >           - clock-names
> > >           - st,syscfg
> > > @@ -117,6 +130,9 @@ allOf:
> > >           st,lsco:
> > >             maxItems: 1
> > > +        st,alarm:
> > > +          maxItems: 1
> > > +
> > >         required:
> > >           - clock-names
> > > @@ -153,8 +169,9 @@ examples:
> > >         clocks = <&rcc RTCAPB>, <&rcc RTC>;
> > >         clock-names = "pclk", "rtc_ck";
> > >         interrupts = <GIC_SPI 3 IRQ_TYPE_LEVEL_HIGH>;
> > > +      st,alarm = <RTC_OUT1>;
> > >         st,lsco = <RTC_OUT2_RMP>;
> > Shouldn't that be exactly the opposite? You have two pins that can
> > output different functions. The property should be the pin and the value
> > the function. I'd go even further and I would say this is actually
> > pinmuxing.
> > 
> You're right, if the property is the pin and the value the function, this
> looks like a pinctrl node.
> We choose to develop theses functionalities in the reverse order, to avoid
> the complexity of adding
> the pinctrl framework to our driver. Moreover, LSCO and AlarmA may haven't a
> peripheral client and
> this would probably require to also implement pinctrl hogging.
> 
> Is the implementation that we have proposed is acceptable regarding theses
> elements ?
> 


I still think that the pin has to be the property and the function the value.

Or we could find a generic name and provide an array of pin, function
pair

Or, go for pinmuxing

My point here is that this is a common feature an RTCs and I don't want
every vendor to come up with their own properties.

Regards,

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-07-22 16:02 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-04 13:02 [PATCH 0/6] rtc: stm32: add alarm out and LSCO features Valentin Caron
2022-05-04 13:02 ` [PATCH 1/6] dt-bindings: rtc: stm32: add st,lsco optional property to select output Valentin Caron
2022-05-16 23:52   ` Rob Herring
2022-05-04 13:06 ` [PATCH 2/6] dt-bindings: rtc: stm32: add alarm A out " Valentin Caron
2022-05-04 15:42   ` Rob Herring
2022-05-04 20:27   ` Alexandre Belloni
2022-05-23 12:34     ` Valentin CARON
2022-06-24  8:35       ` Valentin CARON
2022-07-22 16:02       ` Alexandre Belloni
2022-05-04 13:06 ` [PATCH 3/6] rtc: stm32: add Low Speed Clock Output (LSCO) support Valentin Caron
2022-05-04 13:06 ` [PATCH 4/6] rtc: stm32: add alarm A out feature Valentin Caron
2022-05-04 13:06 ` [PATCH 5/6] ARM: dts: stm32: add RTC LSCO support on stm32mp157c-dk2 Valentin Caron
2022-05-04 13:06 ` [PATCH 6/6] ARM: dts: stm32: add RTC LSCO support on stm32mp135f-dk Valentin Caron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).