Skip to content

Commit 0ee11b8

Browse files
Uwe Kleine-Königthierryreding
authored andcommitted
pwm: img: 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 <[email protected]> Tested-by: Hauke Mehrtens <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent 5e93d77 commit 0ee11b8

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

drivers/pwm/pwm-img.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,33 @@ static void img_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
184184
pm_runtime_put_autosuspend(chip->dev);
185185
}
186186

187+
static int img_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
188+
const struct pwm_state *state)
189+
{
190+
int err;
191+
192+
if (state->polarity != PWM_POLARITY_NORMAL)
193+
return -EINVAL;
194+
195+
if (!state->enabled) {
196+
if (pwm->state.enabled)
197+
img_pwm_disable(chip, pwm);
198+
199+
return 0;
200+
}
201+
202+
err = img_pwm_config(pwm->chip, pwm, state->duty_cycle, state->period);
203+
if (err)
204+
return err;
205+
206+
if (!pwm->state.enabled)
207+
err = img_pwm_enable(chip, pwm);
208+
209+
return err;
210+
}
211+
187212
static const struct pwm_ops img_pwm_ops = {
188-
.config = img_pwm_config,
189-
.enable = img_pwm_enable,
190-
.disable = img_pwm_disable,
213+
.apply = img_pwm_apply,
191214
.owner = THIS_MODULE,
192215
};
193216

0 commit comments

Comments
 (0)