Skip to content

Commit

Permalink
pwm: samsung: Implement .apply() callback
Browse files Browse the repository at this point in the history
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 <u.kleine-koenig@pengutronix.de>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
  • Loading branch information
Uwe Kleine-König authored and Thierry Reding committed May 20, 2022
1 parent 762c4e7 commit daa986d
Showing 1 changed file with 42 additions and 12 deletions.
54 changes: 42 additions & 12 deletions drivers/pwm/pwm-samsung.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,6 @@ static int __pwm_samsung_config(struct pwm_chip *chip, struct pwm_device *pwm,
struct samsung_pwm_channel *chan = pwm_get_chip_data(pwm);
u32 tin_ns = chan->tin_ns, tcnt, tcmp, oldtcmp;

/*
* We currently avoid using 64bit arithmetic by using the
* fact that anything faster than 1Hz is easily representable
* by 32bits.
*/
if (period_ns > NSEC_PER_SEC)
return -ERANGE;

tcnt = readl(our_chip->base + REG_TCNTB(pwm->hwpwm));
oldtcmp = readl(our_chip->base + REG_TCMPB(pwm->hwpwm));

Expand Down Expand Up @@ -438,13 +430,51 @@ static int pwm_samsung_set_polarity(struct pwm_chip *chip,
return 0;
}

static int pwm_samsung_apply(struct pwm_chip *chip, struct pwm_device *pwm,
const struct pwm_state *state)
{
int err, enabled = pwm->state.enabled;

if (state->polarity != pwm->state.polarity) {
if (enabled) {
pwm_samsung_disable(chip, pwm);
enabled = false;
}

err = pwm_samsung_set_polarity(chip, pwm, state->polarity);
if (err)
return err;
}

if (!state->enabled) {
if (enabled)
pwm_samsung_disable(chip, pwm);

return 0;
}

/*
* We currently avoid using 64bit arithmetic by using the
* fact that anything faster than 1Hz is easily representable
* by 32bits.
*/
if (state->period > NSEC_PER_SEC)
return -ERANGE;

err = pwm_samsung_config(chip, pwm, state->duty_cycle, state->period);
if (err)
return err;

if (!pwm->state.enabled)
err = pwm_samsung_enable(chip, pwm);

return err;
}

static const struct pwm_ops pwm_samsung_ops = {
.request = pwm_samsung_request,
.free = pwm_samsung_free,
.enable = pwm_samsung_enable,
.disable = pwm_samsung_disable,
.config = pwm_samsung_config,
.set_polarity = pwm_samsung_set_polarity,
.apply = pwm_samsung_apply,
.owner = THIS_MODULE,
};

Expand Down

0 comments on commit daa986d

Please sign in to comment.