Skip to content

Commit 5e93d77

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

File tree

1 file changed

+54
-8
lines changed

1 file changed

+54
-8
lines changed

drivers/pwm/pwm-twl.c

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ static inline struct twl_pwm_chip *to_twl(struct pwm_chip *chip)
5858
}
5959

6060
static int twl_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
61-
int duty_ns, int period_ns)
61+
u64 duty_ns, u64 period_ns)
6262
{
63-
int duty_cycle = DIV_ROUND_UP(duty_ns * TWL_PWM_MAX, period_ns) + 1;
63+
int duty_cycle = DIV64_U64_ROUND_UP(duty_ns * TWL_PWM_MAX, period_ns) + 1;
6464
u8 pwm_config[2] = { 1, 0 };
6565
int base, ret;
6666

@@ -279,19 +279,65 @@ static void twl6030_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
279279
mutex_unlock(&twl->mutex);
280280
}
281281

282+
static int twl4030_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
283+
const struct pwm_state *state)
284+
{
285+
int err;
286+
287+
if (state->polarity != PWM_POLARITY_NORMAL)
288+
return -EINVAL;
289+
290+
if (!state->enabled) {
291+
if (pwm->state.enabled)
292+
twl4030_pwm_disable(chip, pwm);
293+
294+
return 0;
295+
}
296+
297+
err = twl_pwm_config(pwm->chip, pwm, state->duty_cycle, state->period);
298+
if (err)
299+
return err;
300+
301+
if (!pwm->state.enabled)
302+
err = twl4030_pwm_enable(chip, pwm);
303+
304+
return err;
305+
}
306+
307+
static int twl6030_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
308+
const struct pwm_state *state)
309+
{
310+
int err;
311+
312+
if (state->polarity != PWM_POLARITY_NORMAL)
313+
return -EINVAL;
314+
315+
if (!state->enabled) {
316+
if (pwm->state.enabled)
317+
twl6030_pwm_disable(chip, pwm);
318+
319+
return 0;
320+
}
321+
322+
err = twl_pwm_config(pwm->chip, pwm, state->duty_cycle, state->period);
323+
if (err)
324+
return err;
325+
326+
if (!pwm->state.enabled)
327+
err = twl6030_pwm_enable(chip, pwm);
328+
329+
return err;
330+
}
331+
282332
static const struct pwm_ops twl4030_pwm_ops = {
283-
.config = twl_pwm_config,
284-
.enable = twl4030_pwm_enable,
285-
.disable = twl4030_pwm_disable,
333+
.apply = twl4030_pwm_apply,
286334
.request = twl4030_pwm_request,
287335
.free = twl4030_pwm_free,
288336
.owner = THIS_MODULE,
289337
};
290338

291339
static const struct pwm_ops twl6030_pwm_ops = {
292-
.config = twl_pwm_config,
293-
.enable = twl6030_pwm_enable,
294-
.disable = twl6030_pwm_disable,
340+
.apply = twl6030_pwm_apply,
295341
.owner = THIS_MODULE,
296342
};
297343

0 commit comments

Comments
 (0)