@@ -597,6 +597,12 @@ int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state)
pwm->state.polarity = state->polarity;
}
+ if (!state->enabled && pwm->state.enabled) {
+ chip->ops->disable(chip, pwm);
+ pwm->state.enabled = false;
+ return 0;
+ }
+
if (state->period != pwm->state.period ||
state->duty_cycle != pwm->state.duty_cycle) {
err = chip->ops->config(pwm->chip, pwm,
@@ -609,16 +615,12 @@ int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state)
pwm->state.period = state->period;
}
- if (state->enabled != pwm->state.enabled) {
- if (state->enabled) {
- err = chip->ops->enable(chip, pwm);
- if (err)
- return err;
- } else {
- chip->ops->disable(chip, pwm);
- }
+ if (!pwm->state.enabled) {
+ err = chip->ops->enable(chip, pwm);
+ if (err)
+ return err;
- pwm->state.enabled = state->enabled;
+ pwm->state.enabled = true;
}
}
When a PWM is to be disabled, configuring the duty cycle and period before actually disabling the hardware might result in either a glitch or a delay. So check for disabling first and return early in this case. Link: https://lore.kernel.org/r/20210308093600.25455-1-u.kleine-koenig@pengutronix.de Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> --- drivers/pwm/core.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)