Skip to content

Commit 6d45374

Browse files
Uwe Kleine-Königthierryreding
authored andcommitted
pwm: ep93xx: Implement .apply callback
To ease review this reuses the formerly implemented callbacks. Signed-off-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent 868f13b commit 6d45374

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

drivers/pwm/pwm-ep93xx.c

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,48 @@ static void ep93xx_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
156156
clk_disable(ep93xx_pwm->clk);
157157
}
158158

159+
static int ep93xx_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
160+
const struct pwm_state *state)
161+
{
162+
int ret;
163+
bool enabled = state->enabled;
164+
165+
if (state->polarity != pwm->state.polarity) {
166+
if (enabled) {
167+
ep93xx_pwm_disable(chip, pwm);
168+
enabled = false;
169+
}
170+
171+
ret = ep93xx_pwm_polarity(chip, pwm, state->polarity);
172+
if (ret)
173+
return ret;
174+
}
175+
176+
if (!state->enabled) {
177+
if (enabled)
178+
ep93xx_pwm_disable(chip, pwm);
179+
180+
return 0;
181+
}
182+
183+
if (state->period != pwm->state.period ||
184+
state->duty_cycle != pwm->state.duty_cycle) {
185+
ret = ep93xx_pwm_config(chip, pwm, (int)state->duty_cycle,
186+
(int)state->period);
187+
if (ret)
188+
return ret;
189+
}
190+
191+
if (!enabled)
192+
return ep93xx_pwm_enable(chip, pwm);
193+
194+
return 0;
195+
}
196+
159197
static const struct pwm_ops ep93xx_pwm_ops = {
160198
.request = ep93xx_pwm_request,
161199
.free = ep93xx_pwm_free,
162-
.config = ep93xx_pwm_config,
163-
.set_polarity = ep93xx_pwm_polarity,
164-
.enable = ep93xx_pwm_enable,
165-
.disable = ep93xx_pwm_disable,
200+
.apply = ep93xx_pwm_apply,
166201
.owner = THIS_MODULE,
167202
};
168203

0 commit comments

Comments
 (0)