[PATCH v3] Fix IMX PWM period setting
Uwe Kleine-König
u.kleine-koenig at baylibre.com
Mon Nov 3 02:19:52 PST 2025
Hello Olaf,
On Mon, Nov 03, 2025 at 06:50:20AM +0000, Krebs, Olaf wrote:
> From: Olaf Krebs <okr at smgw.emh-meter.de>
>
> If a second PWM is requested by a driver before the first is configured, trying to configure any of these results in .user_count > 1 and thus the configuration fails.
> Fix that by only erroring out by additionally checking if the period is actually configured.
>
> Exapmle: Using of 3 PWM channels to control a RGB LED.
>
> DTS-Config for an imx93-Board:
> ...
> led-controller {
> compatible = "pwm-leds-multicolor";
> multi-led {
> label = "RGBled";
> color = <LED_COLOR_ID_RGB>;
> function = LED_FUNCTION_INDICATOR;
> max-brightness = <255>;
> led-red {
> pwms = <&tpm5 0 1000000 PWM_POLARITY_INVERTED>;
> color = <LED_COLOR_ID_RED>;
> };
> led-green {
> pwms = <&tpm6 2 1000000 PWM_POLARITY_INVERTED>;
> color = <LED_COLOR_ID_GREEN>;
> };
> led-blue {
> pwms = <&tpm5 1 1000000 PWM_POLARITY_INVERTED>;
> color = <LED_COLOR_ID_BLUE>;
> };
> };
> };
> ...
>
> Without this patch, an BUSY-error message is generated during initialization.
>
> [ 7.395326] leds_pwm_multicolor led-controller: error -EBUSY: failed to set led PWM value for (null)
> [ 7.405167] leds_pwm_multicolor led-controller: probe with driver leds_pwm_multicolor failed with error -16
>
> Signed-off-by: Olaf krebs <olaf.krebs at emh-metering.com>
checkpatch is still unhappy with your patch. That might be (at least
partially) the fault of your MUA or MTA.
> ---
> drivers/pwm/pwm-imx-tpm.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/pwm/pwm-imx-tpm.c b/drivers/pwm/pwm-imx-tpm.c index 5b399de16d60..411daa7711f1 100644
> --- a/drivers/pwm/pwm-imx-tpm.c
> +++ b/drivers/pwm/pwm-imx-tpm.c
> @@ -190,7 +190,7 @@ static int pwm_imx_tpm_apply_hw(struct pwm_chip *chip,
> * there are multiple channels in use with different
> * period settings.
> */
> - if (tpm->user_count > 1)
> + if ((tpm->user_count > 1) && (tpm->real_period != 0))
> return -EBUSY;
Repeating my review for v2:
> Please drop the added parenthesis.
Have you considered "I wonder if a saner check would involve
enable_count instead of user_count."?
Best regards
Uwe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20251103/8472594d/attachment.sig>
More information about the linux-arm-kernel
mailing list