From 8680126258e84a95fb6c7673a7a0f0627e96669d Mon Sep 17 00:00:00 2001 From: Ivan Podogov Date: Wed, 26 Oct 2022 17:57:02 +0100 Subject: [PATCH] Fix pwm-gpio build error See issue https://github.com/tobetter/linux/issues/39: legacy drivers were deprecated in https://github.com/tobetter/linux/commit/0829c35dc5346e90f428de61896362b51ab58296 --- drivers/pwm/pwm-gpio.c | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/drivers/pwm/pwm-gpio.c b/drivers/pwm/pwm-gpio.c index 6707a5dbe5fb13..a17ba55e27913d 100644 --- a/drivers/pwm/pwm-gpio.c +++ b/drivers/pwm/pwm-gpio.c @@ -134,12 +134,44 @@ static void gpio_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) gpio_pwm_off(gpio_data); } +static int gpio_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, + const struct pwm_state *state) +{ + int err; + bool enabled = pwm->state.enabled; + + if (state->polarity != pwm->state.polarity) { + if (enabled) { + gpio_pwm_disable(chip, pwm); + enabled = false; + } + + err = gpio_pwm_set_polarity(chip, pwm, state->polarity); + if (err) + return err; + } + + if (!state->enabled) { + if (enabled) + gpio_pwm_disable(chip, pwm); + + return 0; + } + + err = gpio_pwm_config(pwm->chip, pwm, + state->duty_cycle, state->period); + if (err) + return err; + + if (!enabled) + err = gpio_pwm_enable(chip, pwm); + + return err; +} + static const struct pwm_ops gpio_pwm_ops = { - .config = gpio_pwm_config, - .set_polarity = gpio_pwm_set_polarity, - .enable = gpio_pwm_enable, - .disable = gpio_pwm_disable, - .owner = THIS_MODULE, + .apply = gpio_pwm_apply, + .owner = THIS_MODULE, }; static int gpio_pwm_probe(struct platform_device *pdev)