Skip to content

Commit c449a8c

Browse files
Uwe Kleine-Königthierryreding
authored andcommitted
pwm: lpc18xx: Implement .apply() callback
To eventually get rid of all legacy drivers convert this driver to the modern world implementing .apply(). This pushes a variant of pwm_apply_legacy into the driver that was slightly simplified because the .set_polarity callback was a noop. There is no change in behavior. Signed-off-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent 758de66 commit c449a8c

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

drivers/pwm/pwm-lpc18xx-sct.c

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,7 @@ static int lpc18xx_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
226226
return 0;
227227
}
228228

229-
static int lpc18xx_pwm_set_polarity(struct pwm_chip *chip,
230-
struct pwm_device *pwm,
231-
enum pwm_polarity polarity)
232-
{
233-
return 0;
234-
}
235-
236-
static int lpc18xx_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
229+
static int lpc18xx_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm, enum pwm_polarity polarity)
237230
{
238231
struct lpc18xx_pwm_chip *lpc18xx_pwm = to_lpc18xx_pwm_chip(chip);
239232
struct lpc18xx_pwm_data *lpc18xx_data = &lpc18xx_pwm->channeldata[pwm->hwpwm];
@@ -249,7 +242,7 @@ static int lpc18xx_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
249242
LPC18XX_PWM_EVSTATEMSK(lpc18xx_data->duty_event),
250243
LPC18XX_PWM_EVSTATEMSK_ALL);
251244

252-
if (pwm_get_polarity(pwm) == PWM_POLARITY_NORMAL) {
245+
if (polarity == PWM_POLARITY_NORMAL) {
253246
set_event = lpc18xx_pwm->period_event;
254247
clear_event = lpc18xx_data->duty_event;
255248
res_action = LPC18XX_PWM_RES_SET;
@@ -308,11 +301,35 @@ static void lpc18xx_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
308301
clear_bit(lpc18xx_data->duty_event, &lpc18xx_pwm->event_map);
309302
}
310303

304+
static int lpc18xx_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
305+
const struct pwm_state *state)
306+
{
307+
int err;
308+
bool enabled = pwm->state.enabled;
309+
310+
if (state->polarity != pwm->state.polarity && pwm->state.enabled) {
311+
lpc18xx_pwm_disable(chip, pwm);
312+
enabled = false;
313+
}
314+
315+
if (!state->enabled) {
316+
if (enabled)
317+
lpc18xx_pwm_disable(chip, pwm);
318+
319+
return 0;
320+
}
321+
322+
err = lpc18xx_pwm_config(pwm->chip, pwm, state->duty_cycle, state->period);
323+
if (err)
324+
return err;
325+
326+
if (!enabled)
327+
err = lpc18xx_pwm_enable(chip, pwm, state->polarity);
328+
329+
return err;
330+
}
311331
static const struct pwm_ops lpc18xx_pwm_ops = {
312-
.config = lpc18xx_pwm_config,
313-
.set_polarity = lpc18xx_pwm_set_polarity,
314-
.enable = lpc18xx_pwm_enable,
315-
.disable = lpc18xx_pwm_disable,
332+
.apply = lpc18xx_pwm_apply,
316333
.request = lpc18xx_pwm_request,
317334
.free = lpc18xx_pwm_free,
318335
.owner = THIS_MODULE,

0 commit comments

Comments
 (0)