Skip to contentSkip to conversation

pwm: mxs: Fix zero duty cycle

PATCH In review Fabio Estevam 2 participants 2 messages Sep 22, 2023

Subsystems (2)
lore
Share & tools
lore

Fabio Estevam

author reviewer
#0 lore raw

PATCH 1/1 pwm: mxs: Fix zero duty cycle

From: Fabio Estevam <[email protected]>

Currently, when a duty cycle of zero is requested, the PWM stops getting updated. This causes the minimal brightness of an LED to not turned off completely as expected.

For example, driving an LED via led-pwm and running:

echo 255 > /sys/class/leds/red/brightness

makes the LED to go to its maximum brightness as expected.

After running:

echo 0 > /sys/class/leds/red/brightness

The PWM controlled LED does not turn off. Instead, the LED brightness stays at its maximum.

The reason for this behavior is that when brightness is set to 0, state->enabled goes to 0 and the PWM is disabled by setting the PWM_CTRL + CLR register.

Fix this problem by keeping the PWM controller turned on, even in the case when a zero duty cycle is requested.

Fixes bf29c2ff82fd ("pwm: mxs: Implement ->apply()")
---
 drivers/pwm/pwm-mxs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pwm/pwm-mxs.c +1 -1
index 766dbc58dad8..f8ad616eaba2 100644
@@ -65,7 +65,7 @@ static int mxs_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
 			return ret;
 	}
 
-	if (!state->enabled && pwm_is_enabled(pwm))
+	if (pwm_is_enabled(pwm))
 		writel(1 << pwm->hwpwm, mxs->base + PWM_CTRL + CLR);
 
 	rate = clk_get_rate(mxs->clk);
Signature · 1 line
2.34.1
#1 lore raw

Hello Fabio,

Quoted 39 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

Currently, when a duty cycle of zero is requested, the PWM stops getting updated. This causes the minimal brightness of an LED to not turned off completely as expected.

For example, driving an LED via led-pwm and running:

echo 255 > /sys/class/leds/red/brightness

makes the LED to go to its maximum brightness as expected.

After running:

echo 0 > /sys/class/leds/red/brightness

The PWM controlled LED does not turn off. Instead, the LED brightness stays at its maximum.

The reason for this behavior is that when brightness is set to 0, state->enabled goes to 0 and the PWM is disabled by setting the PWM_CTRL + CLR register.

Fix this problem by keeping the PWM controller turned on, even in the case when a zero duty cycle is requested.

Fixes bf29c2ff82fd ("pwm: mxs: Implement ->apply()")
---
 drivers/pwm/pwm-mxs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pwm/pwm-mxs.c +0 -0
index 766dbc58dad8..f8ad616eaba2 100644

drivers/pwm/pwm-mxs.c static int mxs_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, · line 71

Quoted 8 lines
drivers/pwm/pwm-mxs.c +1 -1
@@ -65,7 +65,7 @@ static int mxs_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
 			return ret;
 	}
 
-	if (!state->enabled && pwm_is_enabled(pwm))
+	if (pwm_is_enabled(pwm))
 		writel(1 << pwm->hwpwm, mxs->base + PWM_CTRL + CLR);
 
 	rate = clk_get_rate(mxs->clk);

This patch is wrong. I'll prepare a better fix.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |