mbox series

[V3,0/2] pwm: Add GPIO PWM driver

Message ID 20240128163630.104725-1-wahrenst@gmx.net
Headers show
Series pwm: Add GPIO PWM driver | expand

Message

Stefan Wahren Jan. 28, 2024, 4:36 p.m. UTC
Add a software PWM which toggles a GPIO from a high-resolution timer.

Recent discussions in the Raspberry Pi community revealt that a lot
of users still use MMIO userspace tools for GPIO access. One argument
for this approach is the lack of a GPIO PWM kernel driver. So this
series tries to fill this gap.

This continues the work of Vincent Whitchurch [1], which is easier
to read and more consequent by rejecting sleeping GPIOs than Nicola's
approach [2].

The work has been tested on a Raspberry Pi 3 B+ and a cheap logic
analyzer.

V3:
 - rebase on top of v6.8-pwm-next
 - cherry-pick improvements from Nicola's series
 - try to address Uwe's, Linus' and Andy's comments
 - try to avoid GPIO glitches during probe
 - fix pwm_gpio_remove()
 - some code clean up's and comments

V2:
 - Rename gpio to gpios in binding
 - Calculate next expiry from expected current expiry rather than "now"
 - Only change configuration after current period ends
 - Implement get_state()
 - Add error message for probe failures
 - Stop PWM before unregister

[1] - https://lore.kernel.org/all/20200915135445.al75xmjxudj2rgcp@axis.com/T/
[2] - https://lore.kernel.org/all/20201205214353.xapax46tt5snzd2v@einstein.dilieto.eu/

Nicola Di Lieto (1):
  dt-bindings: pwm: Add pwm-gpio

Vincent Whitchurch (1):
  pwm: Add GPIO PWM driver

 .../devicetree/bindings/pwm/pwm-gpio.yaml     |  42 ++++
 drivers/pwm/Kconfig                           |  11 +
 drivers/pwm/Makefile                          |   1 +
 drivers/pwm/pwm-gpio.c                        | 221 ++++++++++++++++++
 4 files changed, 275 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pwm/pwm-gpio.yaml
 create mode 100644 drivers/pwm/pwm-gpio.c

--
2.34.1

Comments

Phil Howard Feb. 2, 2024, 1:19 p.m. UTC | #1
On Sun, 28 Jan 2024 at 16:37, Stefan Wahren <wahrenst@gmx.net> wrote:
>
> Add a software PWM which toggles a GPIO from a high-resolution timer.
>
> Recent discussions in the Raspberry Pi community revealt that a lot
> of users still use MMIO userspace tools for GPIO access. One argument
> for this approach is the lack of a GPIO PWM kernel driver. So this
> series tries to fill this gap.

*Thank you* for picking this up. I've been stuck down by covid but am aiming
to build and test this on a Pi 5 (with a gpio chip over PCIe) to see if it runs-
though I am fully expecting a PIO solution (using the Pi 5s RP1) to handle
PWM in this case, and hope to rely upon this gpio-pwm module for previous
iterations.

>
> This continues the work of Vincent Whitchurch [1], which is easier
> to read and more consequent by rejecting sleeping GPIOs than Nicola's
> approach [2].
>
> The work has been tested on a Raspberry Pi 3 B+ and a cheap logic
> analyzer.
>
> V3:
>  - rebase on top of v6.8-pwm-next
>  - cherry-pick improvements from Nicola's series
>  - try to address Uwe's, Linus' and Andy's comments
>  - try to avoid GPIO glitches during probe
>  - fix pwm_gpio_remove()
>  - some code clean up's and comments
>
> V2:
>  - Rename gpio to gpios in binding
>  - Calculate next expiry from expected current expiry rather than "now"
>  - Only change configuration after current period ends
>  - Implement get_state()
>  - Add error message for probe failures
>  - Stop PWM before unregister
>
> [1] - https://lore.kernel.org/all/20200915135445.al75xmjxudj2rgcp@axis.com/T/
> [2] - https://lore.kernel.org/all/20201205214353.xapax46tt5snzd2v@einstein.dilieto.eu/
>
> Nicola Di Lieto (1):
>   dt-bindings: pwm: Add pwm-gpio
>
> Vincent Whitchurch (1):
>   pwm: Add GPIO PWM driver
>
>  .../devicetree/bindings/pwm/pwm-gpio.yaml     |  42 ++++
>  drivers/pwm/Kconfig                           |  11 +
>  drivers/pwm/Makefile                          |   1 +
>  drivers/pwm/pwm-gpio.c                        | 221 ++++++++++++++++++
>  4 files changed, 275 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/pwm/pwm-gpio.yaml
>  create mode 100644 drivers/pwm/pwm-gpio.c
>
> --
> 2.34.1
>
Stefan Wahren Feb. 2, 2024, 8:13 p.m. UTC | #2
Hi Phil,

Am 02.02.24 um 14:19 schrieb Phil Howard:
> On Sun, 28 Jan 2024 at 16:37, Stefan Wahren <wahrenst@gmx.net> wrote:
>> Add a software PWM which toggles a GPIO from a high-resolution timer.
>>
>> Recent discussions in the Raspberry Pi community revealt that a lot
>> of users still use MMIO userspace tools for GPIO access. One argument
>> for this approach is the lack of a GPIO PWM kernel driver. So this
>> series tries to fill this gap.
> *Thank you* for picking this up. I've been stuck down by covid but am aiming
> to build and test this on a Pi 5 (with a gpio chip over PCIe) to see if it runs-
> though I am fully expecting a PIO solution (using the Pi 5s RP1) to handle
> PWM in this case, and hope to rely upon this gpio-pwm module for previous
> iterations.
i hope you are doing well.

There will be small functional changes in V4. Since this series based on
Linux 6.8 and there is no RPi 5 mainline support, you will need to apply
it on top of rpi-6.8.y.

Should i wait for your test results (no pressure) before sending V4?
>
>> This continues the work of Vincent Whitchurch [1], which is easier
>> to read and more consequent by rejecting sleeping GPIOs than Nicola's
>> approach [2].
>>
>> The work has been tested on a Raspberry Pi 3 B+ and a cheap logic
>> analyzer.
>>
>> V3:
>>   - rebase on top of v6.8-pwm-next
>>   - cherry-pick improvements from Nicola's series
>>   - try to address Uwe's, Linus' and Andy's comments
>>   - try to avoid GPIO glitches during probe
>>   - fix pwm_gpio_remove()
>>   - some code clean up's and comments
>>
>> V2:
>>   - Rename gpio to gpios in binding
>>   - Calculate next expiry from expected current expiry rather than "now"
>>   - Only change configuration after current period ends
>>   - Implement get_state()
>>   - Add error message for probe failures
>>   - Stop PWM before unregister
>>
>> [1] - https://lore.kernel.org/all/20200915135445.al75xmjxudj2rgcp@axis.com/T/
>> [2] - https://lore.kernel.org/all/20201205214353.xapax46tt5snzd2v@einstein.dilieto.eu/
>>
>> Nicola Di Lieto (1):
>>    dt-bindings: pwm: Add pwm-gpio
>>
>> Vincent Whitchurch (1):
>>    pwm: Add GPIO PWM driver
>>
>>   .../devicetree/bindings/pwm/pwm-gpio.yaml     |  42 ++++
>>   drivers/pwm/Kconfig                           |  11 +
>>   drivers/pwm/Makefile                          |   1 +
>>   drivers/pwm/pwm-gpio.c                        | 221 ++++++++++++++++++
>>   4 files changed, 275 insertions(+)
>>   create mode 100644 Documentation/devicetree/bindings/pwm/pwm-gpio.yaml
>>   create mode 100644 drivers/pwm/pwm-gpio.c
>>
>> --
>> 2.34.1
>>
Phil Howard Feb. 4, 2024, 7:21 p.m. UTC | #3
On Fri, 2 Feb 2024 at 20:13, Stefan Wahren <wahrenst@gmx.net> wrote:
>
> Hi Phil,
>
> Am 02.02.24 um 14:19 schrieb Phil Howard:
> > On Sun, 28 Jan 2024 at 16:37, Stefan Wahren <wahrenst@gmx.net> wrote:
> >> Add a software PWM which toggles a GPIO from a high-resolution timer.
> >>
> >> Recent discussions in the Raspberry Pi community revealt that a lot
> >> of users still use MMIO userspace tools for GPIO access. One argument
> >> for this approach is the lack of a GPIO PWM kernel driver. So this
> >> series tries to fill this gap.
> > *Thank you* for picking this up. I've been stuck down by covid but am aiming
> > to build and test this on a Pi 5 (with a gpio chip over PCIe) to see if it runs-
> > though I am fully expecting a PIO solution (using the Pi 5s RP1) to handle
> > PWM in this case, and hope to rely upon this gpio-pwm module for previous
> > iterations.
> i hope you are doing well.
>
> There will be small functional changes in V4. Since this series based on
> Linux 6.8 and there is no RPi 5 mainline support, you will need to apply
> it on top of rpi-6.8.y.

I've got as far as applying the patches and building myself a 6.8.y kernel,
just dragging the ol' brain kicking and screaming into dts world again.

>
> Should i wait for your test results (no pressure) before sending V4?

Don't wait on my account- (no really, it's chaos here)- send away!

> >
> >> This continues the work of Vincent Whitchurch [1], which is easier
> >> to read and more consequent by rejecting sleeping GPIOs than Nicola's
> >> approach [2].
> >>
> >> The work has been tested on a Raspberry Pi 3 B+ and a cheap logic
> >> analyzer.
> >>
> >> V3:
> >>   - rebase on top of v6.8-pwm-next
> >>   - cherry-pick improvements from Nicola's series
> >>   - try to address Uwe's, Linus' and Andy's comments
> >>   - try to avoid GPIO glitches during probe
> >>   - fix pwm_gpio_remove()
> >>   - some code clean up's and comments
> >>
> >> V2:
> >>   - Rename gpio to gpios in binding
> >>   - Calculate next expiry from expected current expiry rather than "now"
> >>   - Only change configuration after current period ends
> >>   - Implement get_state()
> >>   - Add error message for probe failures
> >>   - Stop PWM before unregister
> >>
> >> [1] - https://lore.kernel.org/all/20200915135445.al75xmjxudj2rgcp@axis.com/T/
> >> [2] - https://lore.kernel.org/all/20201205214353.xapax46tt5snzd2v@einstein.dilieto.eu/
> >>
> >> Nicola Di Lieto (1):
> >>    dt-bindings: pwm: Add pwm-gpio
> >>
> >> Vincent Whitchurch (1):
> >>    pwm: Add GPIO PWM driver
> >>
> >>   .../devicetree/bindings/pwm/pwm-gpio.yaml     |  42 ++++
> >>   drivers/pwm/Kconfig                           |  11 +
> >>   drivers/pwm/Makefile                          |   1 +
> >>   drivers/pwm/pwm-gpio.c                        | 221 ++++++++++++++++++
> >>   4 files changed, 275 insertions(+)
> >>   create mode 100644 Documentation/devicetree/bindings/pwm/pwm-gpio.yaml
> >>   create mode 100644 drivers/pwm/pwm-gpio.c
> >>
> >> --
> >> 2.34.1
> >>
>