Skip to content

Commit 5fa3b87

Browse files
Uwe Kleine-Königthierryreding
authored andcommitted
pwm: lpc32xx: 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]> Signed-off-by: Thierry Reding <[email protected]>
1 parent fd3ddd4 commit 5fa3b87

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

drivers/pwm/pwm-lpc32xx.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,33 @@ static void lpc32xx_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
8888
clk_disable_unprepare(lpc32xx->clk);
8989
}
9090

91+
static int lpc32xx_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
92+
const struct pwm_state *state)
93+
{
94+
int err;
95+
96+
if (state->polarity != PWM_POLARITY_NORMAL)
97+
return -EINVAL;
98+
99+
if (!state->enabled) {
100+
if (pwm->state.enabled)
101+
lpc32xx_pwm_disable(chip, pwm);
102+
103+
return 0;
104+
}
105+
106+
err = lpc32xx_pwm_config(pwm->chip, pwm, state->duty_cycle, state->period);
107+
if (err)
108+
return err;
109+
110+
if (!pwm->state.enabled)
111+
err = lpc32xx_pwm_enable(chip, pwm);
112+
113+
return err;
114+
}
115+
91116
static const struct pwm_ops lpc32xx_pwm_ops = {
92-
.config = lpc32xx_pwm_config,
93-
.enable = lpc32xx_pwm_enable,
94-
.disable = lpc32xx_pwm_disable,
117+
.apply = lpc32xx_pwm_apply,
95118
.owner = THIS_MODULE,
96119
};
97120

0 commit comments

Comments
 (0)