driver: pwm: Implement .apply() callback
To eventually get rid of all legacy drivers convert this driver to the modern world implementing .apply(). The commit which brings these changes is `5ec803edcb703fe379836f13560b79dfac79b01d` on the uplink kernel. Bug: 332793240 Change-Id: I385f487c474ca2d52a9f3bb4e8afc3843eb4d9f8 Signed-off-by: Karan Bhagoji <karan.rb@samsung.com> Signed-off-by: Hyunki Koo <hyunki00.koo@samsung.com>
This commit is contained in:
parent
f887b383c2
commit
f11cfb0398
1 changed files with 43 additions and 4 deletions
|
@ -603,13 +603,52 @@ static int pwm_samsung_capture(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||||
return 0;
|
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 = {
|
static const struct pwm_ops pwm_samsung_ops = {
|
||||||
.request = pwm_samsung_request,
|
.request = pwm_samsung_request,
|
||||||
.free = pwm_samsung_free,
|
.free = pwm_samsung_free,
|
||||||
.enable = pwm_samsung_enable,
|
.apply = pwm_samsung_apply,
|
||||||
.disable = pwm_samsung_disable,
|
|
||||||
.config = pwm_samsung_config,
|
|
||||||
.set_polarity = pwm_samsung_set_polarity,
|
|
||||||
.capture = pwm_samsung_capture,
|
.capture = pwm_samsung_capture,
|
||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue