Skip to content

Commit 5f027d9

Browse files
Uwe Kleine-Königthierryreding
authored andcommitted
pwm: tiehrpwm: Implement .apply() callback
To eventually get rid of all legacy drivers convert this driver to the modern world implementing .apply(). This just pushes down a slightly optimized variant of how legacy drivers are handled in the core. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
1 parent 6b94ee6 commit 5f027d9

1 file changed

Lines changed: 35 additions & 5 deletions

File tree

drivers/pwm/pwm-tiehrpwm.c

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static void configure_polarity(struct ehrpwm_pwm_chip *pc, int chan)
216216
* duty_ns = 10^9 * (ps_divval * duty_cycles) / PWM_CLK_RATE
217217
*/
218218
static int ehrpwm_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
219-
int duty_ns, int period_ns)
219+
u64 duty_ns, u64 period_ns)
220220
{
221221
struct ehrpwm_pwm_chip *pc = to_ehrpwm_pwm_chip(chip);
222222
u32 period_cycles, duty_cycles;
@@ -401,12 +401,42 @@ static void ehrpwm_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
401401
pc->period_cycles[pwm->hwpwm] = 0;
402402
}
403403

404+
static int ehrpwm_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
405+
const struct pwm_state *state)
406+
{
407+
int err;
408+
bool enabled = pwm->state.enabled;
409+
410+
if (state->polarity != pwm->state.polarity) {
411+
if (enabled) {
412+
ehrpwm_pwm_disable(chip, pwm);
413+
enabled = false;
414+
}
415+
416+
err = ehrpwm_pwm_set_polarity(chip, pwm, state->polarity);
417+
if (err)
418+
return err;
419+
}
420+
421+
if (!state->enabled) {
422+
if (enabled)
423+
ehrpwm_pwm_disable(chip, pwm);
424+
return 0;
425+
}
426+
427+
err = ehrpwm_pwm_config(chip, pwm, state->duty_cycle, state->period);
428+
if (err)
429+
return err;
430+
431+
if (!enabled)
432+
err = ehrpwm_pwm_enable(chip, pwm);
433+
434+
return err;
435+
}
436+
404437
static const struct pwm_ops ehrpwm_pwm_ops = {
405438
.free = ehrpwm_pwm_free,
406-
.config = ehrpwm_pwm_config,
407-
.set_polarity = ehrpwm_pwm_set_polarity,
408-
.enable = ehrpwm_pwm_enable,
409-
.disable = ehrpwm_pwm_disable,
439+
.apply = ehrpwm_pwm_apply,
410440
.owner = THIS_MODULE,
411441
};
412442

0 commit comments

Comments
 (0)