Skip to content

Commit b8971b3

Browse files
Uwe Kleine-Königclaudiubeznea
authored andcommitted
pwm: atmel-tcb: Implement .apply callback
This is just pushing down the core's compat code down into the driver using the legacy callback nearly unchanged. The call to .enable() was just dropped from .config() because .apply() calls it unconditionally. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
1 parent 7431853 commit b8971b3

1 file changed

Lines changed: 25 additions & 8 deletions

File tree

drivers/pwm/pwm-atmel-tcb.c

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -362,20 +362,37 @@ static int atmel_tcb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
362362
tcbpwm->div = i;
363363
tcbpwm->duty = duty;
364364

365-
/* If the PWM is enabled, call enable to apply the new conf */
366-
if (pwm_is_enabled(pwm))
367-
atmel_tcb_pwm_enable(chip, pwm);
368-
369365
return 0;
370366
}
371367

368+
static int atmel_tcb_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
369+
const struct pwm_state *state)
370+
{
371+
int duty_cycle, period;
372+
int ret;
373+
374+
/* This function only sets a flag in driver data */
375+
atmel_tcb_pwm_set_polarity(chip, pwm, state->polarity);
376+
377+
if (!state->enabled) {
378+
atmel_tcb_pwm_disable(chip, pwm);
379+
return 0;
380+
}
381+
382+
period = state->period < INT_MAX ? state->period : INT_MAX;
383+
duty_cycle = state->duty_cycle < INT_MAX ? state->duty_cycle : INT_MAX;
384+
385+
ret = atmel_tcb_pwm_config(chip, pwm, duty_cycle, period);
386+
if (ret)
387+
return ret;
388+
389+
return atmel_tcb_pwm_enable(chip, pwm);
390+
}
391+
372392
static const struct pwm_ops atmel_tcb_pwm_ops = {
373393
.request = atmel_tcb_pwm_request,
374394
.free = atmel_tcb_pwm_free,
375-
.config = atmel_tcb_pwm_config,
376-
.set_polarity = atmel_tcb_pwm_set_polarity,
377-
.enable = atmel_tcb_pwm_enable,
378-
.disable = atmel_tcb_pwm_disable,
395+
.apply = atmel_tcb_pwm_apply,
379396
.owner = THIS_MODULE,
380397
};
381398

0 commit comments

Comments
 (0)