Skip to content

Commit daa986d

Browse files
Uwe Kleine-Königthierryreding
authored andcommitted
pwm: samsung: Implement .apply() callback
To eventually get rid of all legacy drivers convert this driver to the modern world implementing .apply(). The size check for state->period is moved to .apply() to make sure that the values of state->duty_cycle and state->period are passed to pwm_samsung_config without change while they are discarded to int. Signed-off-by: Uwe Kleine-König <[email protected]> Reviewed-by: Krzysztof Kozlowski <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent 762c4e7 commit daa986d

File tree

1 file changed

+42
-12
lines changed

1 file changed

+42
-12
lines changed

drivers/pwm/pwm-samsung.c

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,6 @@ static int __pwm_samsung_config(struct pwm_chip *chip, struct pwm_device *pwm,
321321
struct samsung_pwm_channel *chan = pwm_get_chip_data(pwm);
322322
u32 tin_ns = chan->tin_ns, tcnt, tcmp, oldtcmp;
323323

324-
/*
325-
* We currently avoid using 64bit arithmetic by using the
326-
* fact that anything faster than 1Hz is easily representable
327-
* by 32bits.
328-
*/
329-
if (period_ns > NSEC_PER_SEC)
330-
return -ERANGE;
331-
332324
tcnt = readl(our_chip->base + REG_TCNTB(pwm->hwpwm));
333325
oldtcmp = readl(our_chip->base + REG_TCMPB(pwm->hwpwm));
334326

@@ -438,13 +430,51 @@ static int pwm_samsung_set_polarity(struct pwm_chip *chip,
438430
return 0;
439431
}
440432

433+
static int pwm_samsung_apply(struct pwm_chip *chip, struct pwm_device *pwm,
434+
const struct pwm_state *state)
435+
{
436+
int err, enabled = pwm->state.enabled;
437+
438+
if (state->polarity != pwm->state.polarity) {
439+
if (enabled) {
440+
pwm_samsung_disable(chip, pwm);
441+
enabled = false;
442+
}
443+
444+
err = pwm_samsung_set_polarity(chip, pwm, state->polarity);
445+
if (err)
446+
return err;
447+
}
448+
449+
if (!state->enabled) {
450+
if (enabled)
451+
pwm_samsung_disable(chip, pwm);
452+
453+
return 0;
454+
}
455+
456+
/*
457+
* We currently avoid using 64bit arithmetic by using the
458+
* fact that anything faster than 1Hz is easily representable
459+
* by 32bits.
460+
*/
461+
if (state->period > NSEC_PER_SEC)
462+
return -ERANGE;
463+
464+
err = pwm_samsung_config(chip, pwm, state->duty_cycle, state->period);
465+
if (err)
466+
return err;
467+
468+
if (!pwm->state.enabled)
469+
err = pwm_samsung_enable(chip, pwm);
470+
471+
return err;
472+
}
473+
441474
static const struct pwm_ops pwm_samsung_ops = {
442475
.request = pwm_samsung_request,
443476
.free = pwm_samsung_free,
444-
.enable = pwm_samsung_enable,
445-
.disable = pwm_samsung_disable,
446-
.config = pwm_samsung_config,
447-
.set_polarity = pwm_samsung_set_polarity,
477+
.apply = pwm_samsung_apply,
448478
.owner = THIS_MODULE,
449479
};
450480

0 commit comments

Comments
 (0)