* [PATCH] pwm: img: Implement .apply() callback
@ 2021-10-29 10:56 Uwe Kleine-König
2021-11-07 17:24 ` Hauke Mehrtens
2021-11-17 16:15 ` Thierry Reding
0 siblings, 2 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2021-10-29 10:56 UTC (permalink / raw)
To: Thierry Reding, Lee Jones; +Cc: linux-pwm, kernel, Hauke Mehrtens
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 <u.kleine-koenig@pengutronix.de>
---
drivers/pwm/pwm-img.c | 29 ++++++++++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/drivers/pwm/pwm-img.c b/drivers/pwm/pwm-img.c
index f97f82548293..1f3d6346ab86 100644
--- a/drivers/pwm/pwm-img.c
+++ b/drivers/pwm/pwm-img.c
@@ -184,10 +184,33 @@ static void img_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
pm_runtime_put_autosuspend(chip->dev);
}
+static int img_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)
+ img_pwm_disable(chip, pwm);
+
+ return 0;
+ }
+
+ err = img_pwm_config(pwm->chip, pwm, state->duty_cycle, state->period);
+ if (err)
+ return err;
+
+ if (!pwm->state.enabled)
+ err = img_pwm_enable(chip, pwm);
+
+ return err;
+}
+
static const struct pwm_ops img_pwm_ops = {
- .config = img_pwm_config,
- .enable = img_pwm_enable,
- .disable = img_pwm_disable,
+ .apply = img_pwm_apply,
.owner = THIS_MODULE,
};
base-commit: 3906fe9bb7f1a2c8667ae54e967dc8690824f4ea
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] pwm: img: Implement .apply() callback
2021-10-29 10:56 [PATCH] pwm: img: Implement .apply() callback Uwe Kleine-König
@ 2021-11-07 17:24 ` Hauke Mehrtens
2021-11-17 16:15 ` Thierry Reding
1 sibling, 0 replies; 3+ messages in thread
From: Hauke Mehrtens @ 2021-11-07 17:24 UTC (permalink / raw)
To: Uwe Kleine-König, Thierry Reding, Lee Jones; +Cc: linux-pwm, kernel
On 10/29/21 12:56 PM, Uwe Kleine-König wrote:
> 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 <u.kleine-koenig@pengutronix.de>
I applied this patch on top of kernel 5.10 and the system still boots up
on the CI40 and I can make a LED blink.
Tested-by: Hauke Mehrtens <hauke@hauke-m.de>
> ---
> drivers/pwm/pwm-img.c | 29 ++++++++++++++++++++++++++---
> 1 file changed, 26 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/pwm/pwm-img.c b/drivers/pwm/pwm-img.c
> index f97f82548293..1f3d6346ab86 100644
> --- a/drivers/pwm/pwm-img.c
> +++ b/drivers/pwm/pwm-img.c
> @@ -184,10 +184,33 @@ static void img_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
> pm_runtime_put_autosuspend(chip->dev);
> }
>
> +static int img_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)
> + img_pwm_disable(chip, pwm);
> +
> + return 0;
> + }
> +
> + err = img_pwm_config(pwm->chip, pwm, state->duty_cycle, state->period);
> + if (err)
> + return err;
> +
> + if (!pwm->state.enabled)
> + err = img_pwm_enable(chip, pwm);
> +
> + return err;
> +}
> +
> static const struct pwm_ops img_pwm_ops = {
> - .config = img_pwm_config,
> - .enable = img_pwm_enable,
> - .disable = img_pwm_disable,
> + .apply = img_pwm_apply,
> .owner = THIS_MODULE,
> };
>
>
> base-commit: 3906fe9bb7f1a2c8667ae54e967dc8690824f4ea
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] pwm: img: Implement .apply() callback
2021-10-29 10:56 [PATCH] pwm: img: Implement .apply() callback Uwe Kleine-König
2021-11-07 17:24 ` Hauke Mehrtens
@ 2021-11-17 16:15 ` Thierry Reding
1 sibling, 0 replies; 3+ messages in thread
From: Thierry Reding @ 2021-11-17 16:15 UTC (permalink / raw)
To: Uwe Kleine-König; +Cc: Lee Jones, linux-pwm, kernel, Hauke Mehrtens
[-- Attachment #1: Type: text/plain, Size: 589 bytes --]
On Fri, Oct 29, 2021 at 12:56:17PM +0200, Uwe Kleine-König wrote:
> 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 <u.kleine-koenig@pengutronix.de>
> ---
> drivers/pwm/pwm-img.c | 29 ++++++++++++++++++++++++++---
> 1 file changed, 26 insertions(+), 3 deletions(-)
I'm not sure if this type of conversion is all that useful, but I've
applied this anyway, thanks.
Thierry
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-11-17 16:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-29 10:56 [PATCH] pwm: img: Implement .apply() callback Uwe Kleine-König
2021-11-07 17:24 ` Hauke Mehrtens
2021-11-17 16:15 ` Thierry Reding
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.