Skip to content

Commit 758de66

Browse files
Uwe Kleine-Königthierryreding
authored andcommitted
pwm: mediatek: Implement .apply() callback
To eventually get rid of all legacy drivers convert this driver to the modern world implementing .apply(). This just pushed a variant of pwm_apply_legacy() into the driver that was slightly simplified because the driver doesn't provide a .set_polarity() callback. Signed-off-by: Uwe Kleine-König <[email protected]> Reviewed-by: AngeloGioacchino Del Regno <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent 5fa3b87 commit 758de66

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

drivers/pwm/pwm-mediatek.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,33 @@ static void pwm_mediatek_disable(struct pwm_chip *chip, struct pwm_device *pwm)
198198
pwm_mediatek_clk_disable(chip, pwm);
199199
}
200200

201+
static int pwm_mediatek_apply(struct pwm_chip *chip, struct pwm_device *pwm,
202+
const struct pwm_state *state)
203+
{
204+
int err;
205+
206+
if (state->polarity != PWM_POLARITY_NORMAL)
207+
return -EINVAL;
208+
209+
if (!state->enabled) {
210+
if (pwm->state.enabled)
211+
pwm_mediatek_disable(chip, pwm);
212+
213+
return 0;
214+
}
215+
216+
err = pwm_mediatek_config(pwm->chip, pwm, state->duty_cycle, state->period);
217+
if (err)
218+
return err;
219+
220+
if (!pwm->state.enabled)
221+
err = pwm_mediatek_enable(chip, pwm);
222+
223+
return err;
224+
}
225+
201226
static const struct pwm_ops pwm_mediatek_ops = {
202-
.config = pwm_mediatek_config,
203-
.enable = pwm_mediatek_enable,
204-
.disable = pwm_mediatek_disable,
227+
.apply = pwm_mediatek_apply,
205228
.owner = THIS_MODULE,
206229
};
207230

0 commit comments

Comments
 (0)