Commit 98761ce4 authored by Uwe Kleine-König's avatar Uwe Kleine-König Committed by Thierry Reding

pwm: spear: Implement .apply() callback

Just using the previous callbacks to implment a similar procedure as the
legacy handling in the core.
Signed-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: default avatarThierry Reding <thierry.reding@gmail.com>
parent da0dea89
...@@ -75,7 +75,7 @@ static inline void spear_pwm_writel(struct spear_pwm_chip *chip, ...@@ -75,7 +75,7 @@ static inline void spear_pwm_writel(struct spear_pwm_chip *chip,
} }
static int spear_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, static int spear_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
int duty_ns, int period_ns) u64 duty_ns, u64 period_ns)
{ {
struct spear_pwm_chip *pc = to_spear_pwm_chip(chip); struct spear_pwm_chip *pc = to_spear_pwm_chip(chip);
u64 val, div, clk_rate; u64 val, div, clk_rate;
...@@ -163,10 +163,35 @@ static void spear_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) ...@@ -163,10 +163,35 @@ static void spear_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
clk_disable(pc->clk); clk_disable(pc->clk);
} }
static int spear_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
const struct pwm_state *state)
{
int err;
if (state->polarity != PWM_POLARITY_NORMAL)
return -EINVAL;
if (!state->enabled) {
if (pwm->state.enabled)
spear_pwm_disable(chip, pwm);
return 0;
}
if (state->period != pwm->state.period ||
state->duty_cycle != pwm->state.duty_cycle) {
err = spear_pwm_config(chip, pwm, state->duty_cycle, state->period);
if (err)
return err;
}
if (!pwm->state.enabled)
return spear_pwm_enable(chip, pwm);
return 0;
}
static const struct pwm_ops spear_pwm_ops = { static const struct pwm_ops spear_pwm_ops = {
.config = spear_pwm_config, .apply = spear_pwm_apply,
.enable = spear_pwm_enable,
.disable = spear_pwm_disable,
.owner = THIS_MODULE, .owner = THIS_MODULE,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment