mbox series

[v3,0/4] rtc: stm32: add pinctrl interface to handle RTC outs

Message ID 20240722160022.454226-1-valentin.caron@foss.st.com (mailing list archive)
Headers show
Series rtc: stm32: add pinctrl interface to handle RTC outs | expand

Message

Valentin Caron July 22, 2024, 4 p.m. UTC
This series adds a pinctrl/pinmux interface to control STM32 RTC outputs.

Theses two signals output are possible:
 - LSCO (Low Speed Clock Output) that allow to output LSE clock on a pin.
   On STM32MPU 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.

First attempt [1] was based on 'st,' vendor properties, this one is based
on pinctrl and pinmux framework.

As device-trees will be upstreamed separately, here is an example:

stm32-pinctrl {
    rtc_rsvd_pins_a: rtc-rsvd-0 {
        pins {
            pinmux = <STM32_PINMUX('B', 2, AF1)>, /* OUT2 */
                     <STM32_PINMUX('I', 8, ANALOG)>; /* OUT2_RMP */
        };
    };
};

stm32-rtc {
    pinctrl-0 = <&rtc_rsvd_pins_a &rtc_alarma_pins_a>;

    /* Enable by foo-device */
    rtc_lsco_pins_a: rtc-lsco-0 {
        pins = "out2_rmp";
        function = "lsco";
    };

    /* Enable by stm32-rtc hog */
    rtc_alarma_pins_a: rtc-alarma-0 {
        pins = "out2";
        function = "alarm-a";
    };
};

foo-device {
    pinctrl-0 = <&rtc_lsco_pins_a>;
};

[1] https://lore.kernel.org/linux-arm-kernel/20220504130617.331290-5-valentin.caron@foss.st.com/t/#m37935e92315e22bbe085775096175afc05b7ff09

Since v2:
 - Modify Kconfig after (a lot of) robots alert:
     + https://lore.kernel.org/oe-kbuild-all/202407190654.I3RI7WfP-lkp@intel.com/
     + https://lore.kernel.org/oe-kbuild-all/202407191258.1oitwwMV-lkp@intel.com/
     + https://lore.kernel.org/oe-kbuild-all/202407200400.NnW2fJ0q-lkp@intel.com/
     + https://lore.kernel.org/oe-kbuild-all/202407181525.BRNKqmNf-lkp@intel.com/
     + https://lore.kernel.org/oe-kbuild-all/202407191830.8bh5dJ09-lkp@intel.com/
   Make RTC_DRV_STM32 depends on OF, PINCTRL and COMMON_CLK as they are menuconfig entry.
   Make RTC_DRV_STM32 select PINCONF, PINCONF_GENERIC and PINMUX as they config entry.
   
Since v1:
 - Select PINMUX and PINCONF_GENERIC to solve:
   https://lore.kernel.org/oe-kbuild-all/202407130943.ie6n2Orh-lkp@intel.com/
 - Make stm32_rtc_pinctrl_pins as static to solve:
   https://lore.kernel.org/oe-kbuild-all/202407130612.OEicZbNE-lkp@intel.com/
 - Change "depends on" to "select" COMMON_CLK config
 - Modify regex in dt-binding to avoid properties like "rtc--123" as valid ones.

Valentin Caron (4):
  dt-bindings: rtc: stm32: describe pinmux nodes
  rtc: stm32: add pinctrl and pinmux interfaces
  rtc: stm32: add Low Speed Clock Output (LSCO) support
  rtc: stm32: add alarm A out feature

 .../devicetree/bindings/rtc/st,stm32-rtc.yaml |  28 ++
 drivers/rtc/Kconfig                           |   6 +
 drivers/rtc/rtc-stm32.c                       | 281 ++++++++++++++++++
 3 files changed, 315 insertions(+)

Comments

Linus Walleij July 26, 2024, 8:37 p.m. UTC | #1
Hi Valentin,

On Mon, Jul 22, 2024 at 6:02 PM Valentin Caron
<valentin.caron@foss.st.com> wrote:

> This series adds a pinctrl/pinmux interface to control STM32 RTC outputs.

Interesting! I think it is the first pin controller outside on
drivers/pinctrl in the kernel tree.

Please include me and the linux-gpio@vger.kernel.org list in
subsequent postings, I want to be sure what gets merged here
and I only noticed this from the LWN driver patches summary.

> As device-trees will be upstreamed separately, here is an example:
>
> stm32-pinctrl {
>     rtc_rsvd_pins_a: rtc-rsvd-0 {
>         pins {
>             pinmux = <STM32_PINMUX('B', 2, AF1)>, /* OUT2 */
>                      <STM32_PINMUX('I', 8, ANALOG)>; /* OUT2_RMP */
>         };
>     };
> };
>
> stm32-rtc {
>     pinctrl-0 = <&rtc_rsvd_pins_a &rtc_alarma_pins_a>;

So the first one is a generic pin control setting and the second
one is a hog for the pins defined by the device itself.

It's clever, and works. Nice work!

(There should probably be a comment in the device tree to say
what is going on so people reading it are not confused.)

>     /* Enable by foo-device */
>     rtc_lsco_pins_a: rtc-lsco-0 {
>         pins = "out2_rmp";
>         function = "lsco";
>     };
>
>     /* Enable by stm32-rtc hog */
>     rtc_alarma_pins_a: rtc-alarma-0 {
>         pins = "out2";
>         function = "alarm-a";
>     };

Yours,
Linus Walleij
Alexandre Belloni July 26, 2024, 9:29 p.m. UTC | #2
Hello Linus,

On 26/07/2024 22:37:21+0200, Linus Walleij wrote:
> On Mon, Jul 22, 2024 at 6:02 PM Valentin Caron
> <valentin.caron@foss.st.com> wrote:
> 
> > This series adds a pinctrl/pinmux interface to control STM32 RTC outputs.
> 
> Interesting! I think it is the first pin controller outside on
> drivers/pinctrl in the kernel tree.

Actually, we have rtc-omap which does this too. I've been pushing for
more RTC to do this instead of defining custom dt bindings to do what
boils down to pinmuxing.

> 
> Please include me and the linux-gpio@vger.kernel.org list in
> subsequent postings, I want to be sure what gets merged here
> and I only noticed this from the LWN driver patches summary.


I'll also ensure you get copied on pinctrl related patches.
Alexandre Belloni Aug. 14, 2024, 9:39 a.m. UTC | #3
On Mon, 22 Jul 2024 18:00:18 +0200, Valentin Caron wrote:
> This series adds a pinctrl/pinmux interface to control STM32 RTC outputs.
> 
> Theses two signals output are possible:
>  - LSCO (Low Speed Clock Output) that allow to output LSE clock on a pin.
>    On STM32MPU 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.
> 
> [...]

Applied, thanks!

[1/4] dt-bindings: rtc: stm32: describe pinmux nodes
      https://git.kernel.org/abelloni/c/5b19519d4e6f
[2/4] rtc: stm32: add pinctrl and pinmux interfaces
      https://git.kernel.org/abelloni/c/16ad2bc09efb
[3/4] rtc: stm32: add Low Speed Clock Output (LSCO) support
      https://git.kernel.org/abelloni/c/bb7b0df2be5c
[4/4] rtc: stm32: add alarm A out feature
      https://git.kernel.org/abelloni/c/04dcadb87da6

Best regards,