[PATCH] Fix IMX PWM period setting

Krebs, Olaf posted 1 patch 3 months, 1 week ago
There is a newer version of this series
drivers/pwm/pwm-imx-tpm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] Fix IMX PWM period setting
Posted by Krebs, Olaf 3 months, 1 week ago
From: Olaf Krebs <okr@smgw.emh-meter.de>

We use 3 PWM channels to control an RGB LED. 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

Our 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>;
			};
		};
	};
	...

Signed-off-by: Olaf krebs <olaf.krebs@emh-metering.com>
---
 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;
 
 		val = readl(tpm->base + PWM_IMX_TPM_SC);
--
2.47.3
Re: [PATCH] Fix IMX PWM period setting
Posted by Uwe Kleine-König 3 months, 1 week ago
Hello,

please version your patch revision, i.e. you should have put "v2" in the
subject. The easiest way to achieve that is by passing -v2 to `git
format-patch` (or `git send-email` if you use that directly). So for the
next revision use -v3.

On Thu, Oct 30, 2025 at 11:53:27AM +0000, Krebs, Olaf wrote:
> From: Olaf Krebs <okr@smgw.emh-meter.de>
> 
> We use 3 PWM channels to control an RGB LED. 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
> 
> Our 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>;
> 			};
> 		};
> 	};
> 	...

I would prefer something like the following text here:

	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.

> Signed-off-by: Olaf krebs <olaf.krebs@emh-metering.com>

S-o-b missmatch. Do you know checkpatch? That one also wails:
WARNING: Prefer a maximum 75 chars per line (possible unwrapped commit description?)

> ---
>  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;

Please drop the added parenthesis.

Thinking about the error here, I wonder if a saner check would involve
enable_count instead of user_count.

>  		val = readl(tpm->base + PWM_IMX_TPM_SC);

Best regards
Uwe