Skip to contentSkip to conversation

Fix IMX PWM period setting

PATCH In review Krebs, Olaf 2 participants 2 messages Nov 3, 2025 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 20251103064813.522840-1-user@jenkins

#1 lore raw

PATCH v3 1/1 Fix IMX PWM period setting

From: Olaf Krebs <[email protected]>

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
---
 drivers/pwm/pwm-imx-tpm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pwm/pwm-imx-tpm.c +1 -1
@@ -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

#2 lore raw

Hello Olaf,

Quoted 32 lines · Olaf

From: Olaf Krebs <[email protected]>

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>;
			};
		};
	};
	...
Quoted 6 lines

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

checkpatch is still unhappy with your patch. That might be (at least partially) the fault of your MUA or MTA.

Quoted 8 lines
---
 drivers/pwm/pwm-imx-tpm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

drivers/pwm/pwm-imx-tpm.c static int pwm_imx_tpm_apply_hw(struct pwm_chip *chip, · line 194

Quoted 6 lines
drivers/pwm/pwm-imx-tpm.c +1 -1
@@ -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:

Quoted 1 line

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