Skip to content

Commit ec00cd5

Browse files
Uwe Kleine-Königthierryreding
authored andcommitted
pwm: renesas-tpu: Implement .apply() callback
To eventually get rid of all legacy drivers convert this driver to the modern world implementing .apply(). As pwm->state might not be updated in tpu_pwm_apply() before calling tpu_pwm_config(), an additional parameter is needed for tpu_pwm_config() to not change the implemented logic. Signed-off-by: Uwe Kleine-König <[email protected]> Reviewed-by: Geert Uytterhoeven <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent ff4bcd5 commit ec00cd5

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

drivers/pwm/pwm-renesas-tpu.c

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ static void tpu_pwm_free(struct pwm_chip *chip, struct pwm_device *_pwm)
242242
}
243243

244244
static int tpu_pwm_config(struct pwm_chip *chip, struct pwm_device *_pwm,
245-
int duty_ns, int period_ns)
245+
int duty_ns, int period_ns, bool enabled)
246246
{
247247
static const unsigned int prescalers[] = { 1, 4, 16, 64 };
248248
struct tpu_pwm_device *pwm = pwm_get_chip_data(_pwm);
@@ -293,7 +293,7 @@ static int tpu_pwm_config(struct pwm_chip *chip, struct pwm_device *_pwm,
293293
pwm->duty = duty;
294294

295295
/* If the channel is disabled we're done. */
296-
if (!pwm_is_enabled(_pwm))
296+
if (!enabled)
297297
return 0;
298298

299299
if (duty_only && pwm->timer_on) {
@@ -366,13 +366,45 @@ static void tpu_pwm_disable(struct pwm_chip *chip, struct pwm_device *_pwm)
366366
tpu_pwm_timer_stop(pwm);
367367
}
368368

369+
static int tpu_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
370+
const struct pwm_state *state)
371+
{
372+
int err;
373+
bool enabled = pwm->state.enabled;
374+
375+
if (state->polarity != pwm->state.polarity) {
376+
if (enabled) {
377+
tpu_pwm_disable(chip, pwm);
378+
enabled = false;
379+
}
380+
381+
err = tpu_pwm_set_polarity(chip, pwm, state->polarity);
382+
if (err)
383+
return err;
384+
}
385+
386+
if (!state->enabled) {
387+
if (enabled)
388+
tpu_pwm_disable(chip, pwm);
389+
390+
return 0;
391+
}
392+
393+
err = tpu_pwm_config(pwm->chip, pwm,
394+
state->duty_cycle, state->period, enabled);
395+
if (err)
396+
return err;
397+
398+
if (!enabled)
399+
err = tpu_pwm_enable(chip, pwm);
400+
401+
return err;
402+
}
403+
369404
static const struct pwm_ops tpu_pwm_ops = {
370405
.request = tpu_pwm_request,
371406
.free = tpu_pwm_free,
372-
.config = tpu_pwm_config,
373-
.set_polarity = tpu_pwm_set_polarity,
374-
.enable = tpu_pwm_enable,
375-
.disable = tpu_pwm_disable,
407+
.apply = tpu_pwm_apply,
376408
.owner = THIS_MODULE,
377409
};
378410

0 commit comments

Comments
 (0)