Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport the upstream PWM GPIO driver from 6.11 to rpi-6.6.y #6450

Merged
merged 3 commits into from
Nov 2, 2024

Conversation

timg236
Copy link
Contributor

@timg236 timg236 commented Nov 1, 2024

Backport this driver to provide bit bashed PWM support on an arbitrary GPIO pin.

On Pi5 this is considerably faster than doing this from user space but this is still constrained somewhat by PCIe latency and jitter if the PCIe link is under a high load (e.g. USB3). This should still be suitable for simple applications like servos.

commit 7f61257 upstream.

Add a software PWM which toggles a GPIO from a high-resolution timer.

This will naturally not be as accurate or as efficient as a hardware
PWM, but it is useful in some cases.  I have for example used it for
evaluating LED brightness handling (via leds-pwm) on a board where the
LED was just hooked up to a GPIO, and for a simple verification of the
timer frequency on another platform.

Since high-resolution timers are used, sleeping GPIO chips are not
supported and are rejected in the probe function.

Signed-off-by: Vincent Whitchurch <[email protected]>
Co-developed-by: Stefan Wahren <[email protected]>
Signed-off-by: Stefan Wahren <[email protected]>
Co-developed-by: Linus Walleij <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
Signed-off-by: Linus Walleij <[email protected]>
Reviewed-by: Dhruva Gole <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Uwe Kleine-König <[email protected]>
Signed-off-by: Tim Gover <[email protected]>

pwm: Backport pwm-gpio.c to rpi-6.6.y
@pelwell
Copy link
Contributor

pelwell commented Nov 1, 2024

The usual set of defconfigs is:

arm bcmrpi_defconfig
arm bcm2709_defconfig
arm bcm2711_defconfig
arm64 bcm2711_defconfig
arm64 bcm2712_defconfig
arm64 bcmrpi3_defconfig

We don't use bcmrpi3_defconfig - it was originally user-constributed before we embraced 64-bit builds, but I've been keeping it up-to-date with the others.

Enable the PWM GPIO module in Raspberry Pi kernels.

Signed-off-by: Tim Gover <[email protected]>
@pelwell pelwell merged commit ff0fe12 into raspberrypi:rpi-6.6.y Nov 2, 2024
11 of 12 checks passed
@timg236
Copy link
Contributor Author

timg236 commented Nov 4, 2024

@Gadgetoid FYI, the backport of the pwm-gpio should be in rpi-update relatively soon.

It worked ok on a Pi5 with a MG946 servo and seemed solid under normal loads. Maxing out the PCIe link can cause a very small but observable wobble on the servo.

@Gadgetoid
Copy link
Contributor

Thank you!

Can confirm this works from source (rpi-update hasn't got the memo just yet).

From my earlier testing jitter and accuracy were lightyears ahead of the common userspace software PWM alternatives.

It's just a shame the /sys/class/pwm interface is a disaster. I don't know how far out the switch to the character device ABI is, but it'll be welcome.

popcornmix added a commit to raspberrypi/firmware that referenced this pull request Nov 5, 2024
popcornmix added a commit to raspberrypi/rpi-firmware that referenced this pull request Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants