summaryrefslogtreecommitdiff
path: root/drivers/pwm/pwm-ep93xx.c
diff options
context:
space:
mode:
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>2021-06-23 17:02:39 +0300
committerThierry Reding <thierry.reding@gmail.com>2021-06-30 20:12:20 +0300
commit6d45374af539c84d17cfcf5a4e96bc4b2ca421e6 (patch)
tree97f1a9830dd8153a4754ec3f9c739e2fa41c2b07 /drivers/pwm/pwm-ep93xx.c
parent868f13bdea3304362dd882f216ba30a8bf4c10c8 (diff)
downloadlinux-6d45374af539c84d17cfcf5a4e96bc4b2ca421e6.tar.xz
pwm: ep93xx: Implement .apply callback
To ease review this reuses the formerly implemented callbacks. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Diffstat (limited to 'drivers/pwm/pwm-ep93xx.c')
-rw-r--r--drivers/pwm/pwm-ep93xx.c43
1 files changed, 39 insertions, 4 deletions
diff --git a/drivers/pwm/pwm-ep93xx.c b/drivers/pwm/pwm-ep93xx.c
index 4ca70794ad96..3ef4b41bfd66 100644
--- a/drivers/pwm/pwm-ep93xx.c
+++ b/drivers/pwm/pwm-ep93xx.c
@@ -156,13 +156,48 @@ static void ep93xx_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
clk_disable(ep93xx_pwm->clk);
}
+static int ep93xx_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
+ const struct pwm_state *state)
+{
+ int ret;
+ bool enabled = state->enabled;
+
+ if (state->polarity != pwm->state.polarity) {
+ if (enabled) {
+ ep93xx_pwm_disable(chip, pwm);
+ enabled = false;
+ }
+
+ ret = ep93xx_pwm_polarity(chip, pwm, state->polarity);
+ if (ret)
+ return ret;
+ }
+
+ if (!state->enabled) {
+ if (enabled)
+ ep93xx_pwm_disable(chip, pwm);
+
+ return 0;
+ }
+
+ if (state->period != pwm->state.period ||
+ state->duty_cycle != pwm->state.duty_cycle) {
+ ret = ep93xx_pwm_config(chip, pwm, (int)state->duty_cycle,
+ (int)state->period);
+ if (ret)
+ return ret;
+ }
+
+ if (!enabled)
+ return ep93xx_pwm_enable(chip, pwm);
+
+ return 0;
+}
+
static const struct pwm_ops ep93xx_pwm_ops = {
.request = ep93xx_pwm_request,
.free = ep93xx_pwm_free,
- .config = ep93xx_pwm_config,
- .set_polarity = ep93xx_pwm_polarity,
- .enable = ep93xx_pwm_enable,
- .disable = ep93xx_pwm_disable,
+ .apply = ep93xx_pwm_apply,
.owner = THIS_MODULE,
};