-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
Describe the bug
Attempting to set a duty cycle in the range (0,15) or (period-15,period) on a PWM device configured using the pwm-pio-rp1 driver fails, with the driver returning -EINVAL.
It looks like this is intentional behaviour since driver has a resolution limit of 15ns, so the ..._apply function early-exits if the requested duty cycle is within a single resolution step of the upper or lower limit. The values 0 and period are allowed, however. All valid values are floor'd to the prior integer multiple of the resolution.
drivers/pwm/pwm-pio-rp1.c#L104
I've possibly missed a more fundamental reason but I'm not entirely sure if this is a necessary guard, especially since it prevents some other drivers (such as pwm-fan) from building on top of this one. I've tested a change locally that removes the restriction, which seems to work fine. Change is here for reference.
Steps to reproduce the behaviour
- Enable a PIO PWM instance, e.g
dtoverlay=pwm-pio. - Enable & configure the PWM device, e.g.:
cd /sys/class/pwm/pwmchip1- `echo "0" > export
echo "40000" > pwm0/periodecho "20000" > pwm0/duty_cycleecho "1" > pwm0/enable
- Attempt to set a duty cycle between (0,15) and (39985,40000)
Observe that the write attempt fails with -EINVAL and the PWM output does not change:
$ echo "1" > duty_cycle
-bash: echo: write error: Invalid argument
Device (s)
Raspberry Pi 5
System
$ cat /etc/rpi-issue
Raspberry Pi reference 2024-11-19
Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, 891df1e21ed2b6099a2e6a13e26c91dea44b34d4, stage2
$ vcgencmd version
2025/11/05 17:37:18
Copyright (c) 2012 Broadcom
version 57db150d (release) (embedded)
$ uname -a
Linux moodercade 6.12.57-v8-16k+ #1920 SMP PREEMPT Tue Nov 4 10:17:18 GMT 2025 aarch64 GNU/Linux
Logs
No response
Additional context
No response