* [PATCH v4] backlight: lp855x: Switch to atomic PWM API
@ 2021-11-01 13:19 Maíra Canal
2021-11-02 16:00 ` Daniel Thompson
0 siblings, 1 reply; 2+ messages in thread
From: Maíra Canal @ 2021-11-01 13:19 UTC (permalink / raw)
To: lee.jones, daniel.thompson, jingoohan1, thierry.reding, u.kleine-koenig
Cc: dri-devel, linux-fbdev, linux-kernel, linux-pwm
Remove legacy PWM interface (pwm_config, pwm_enable, pwm_disable) and
replace it for the atomic PWM API.
Signed-off-by: Maíra Canal <maira.canal@usp.br>
---
V1 -> V2: Initialize variable and simply conditional loop
V2 -> V3: Fix assignment of NULL variable
V3 -> V4: Replace division for pwm_set_relative_duty_cycle
---
drivers/video/backlight/lp855x_bl.c | 20 ++++++++------------
1 file changed, 8 insertions(+), 12 deletions(-)
diff --git a/drivers/video/backlight/lp855x_bl.c b/drivers/video/backlight/lp855x_bl.c
index e94932c69f54..bbf24564082a 100644
--- a/drivers/video/backlight/lp855x_bl.c
+++ b/drivers/video/backlight/lp855x_bl.c
@@ -233,9 +233,8 @@ static int lp855x_configure(struct lp855x *lp)
static void lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br)
{
- unsigned int period = lp->pdata->period_ns;
- unsigned int duty = br * period / max_br;
struct pwm_device *pwm;
+ struct pwm_state state;
/* request pwm device with the consumer name */
if (!lp->pwm) {
@@ -245,18 +244,15 @@ static void lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br)
lp->pwm = pwm;
- /*
- * FIXME: pwm_apply_args() should be removed when switching to
- * the atomic PWM API.
- */
- pwm_apply_args(pwm);
+ pwm_init_state(lp->pwm, &state);
+ state.period = lp->pdata->period_ns;
}
- pwm_config(lp->pwm, duty, period);
- if (duty)
- pwm_enable(lp->pwm);
- else
- pwm_disable(lp->pwm);
+ pwm_get_state(lp->pwm, &state);
+ pwm_set_relative_duty_cycle(&state, br, max_br);
+ state.enabled = state.duty_cycle;
+
+ pwm_apply_state(lp->pwm, &state);
}
static int lp855x_bl_update_status(struct backlight_device *bl)
--
2.31.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v4] backlight: lp855x: Switch to atomic PWM API
2021-11-01 13:19 [PATCH v4] backlight: lp855x: Switch to atomic PWM API Maíra Canal
@ 2021-11-02 16:00 ` Daniel Thompson
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Thompson @ 2021-11-02 16:00 UTC (permalink / raw)
To: Maíra Canal
Cc: lee.jones, jingoohan1, thierry.reding, u.kleine-koenig,
dri-devel, linux-fbdev, linux-kernel, linux-pwm
On Mon, Nov 01, 2021 at 10:19:21AM -0300, Maíra Canal wrote:
> Remove legacy PWM interface (pwm_config, pwm_enable, pwm_disable) and
> replace it for the atomic PWM API.
>
> Signed-off-by: Maíra Canal <maira.canal@usp.br>
> ---
> V1 -> V2: Initialize variable and simply conditional loop
> V2 -> V3: Fix assignment of NULL variable
> V3 -> V4: Replace division for pwm_set_relative_duty_cycle
> ---
> drivers/video/backlight/lp855x_bl.c | 20 ++++++++------------
> 1 file changed, 8 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/video/backlight/lp855x_bl.c b/drivers/video/backlight/lp855x_bl.c
> index e94932c69f54..bbf24564082a 100644
> --- a/drivers/video/backlight/lp855x_bl.c
> +++ b/drivers/video/backlight/lp855x_bl.c
> @@ -233,9 +233,8 @@ static int lp855x_configure(struct lp855x *lp)
>
> static void lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br)
> {
> - unsigned int period = lp->pdata->period_ns;
> - unsigned int duty = br * period / max_br;
> struct pwm_device *pwm;
> + struct pwm_state state;
>
> /* request pwm device with the consumer name */
> if (!lp->pwm) {
> @@ -245,18 +244,15 @@ static void lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br)
>
> lp->pwm = pwm;
>
> - /*
> - * FIXME: pwm_apply_args() should be removed when switching to
> - * the atomic PWM API.
> - */
> - pwm_apply_args(pwm);
> + pwm_init_state(lp->pwm, &state);
> + state.period = lp->pdata->period_ns;
> }
>
> - pwm_config(lp->pwm, duty, period);
> - if (duty)
> - pwm_enable(lp->pwm);
> - else
> - pwm_disable(lp->pwm);
> + pwm_get_state(lp->pwm, &state);
Should this be:
} else {
pwm_get_state(lp->pwm, &state);
}
As currently written this will clobber the state.period that was set
above.
Daniel.
> + pwm_set_relative_duty_cycle(&state, br, max_br);
> + state.enabled = state.duty_cycle;
> +
> + pwm_apply_state(lp->pwm, &state);
> }
>
> static int lp855x_bl_update_status(struct backlight_device *bl)
> --
> 2.31.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-11-02 16:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-01 13:19 [PATCH v4] backlight: lp855x: Switch to atomic PWM API Maíra Canal
2021-11-02 16:00 ` Daniel Thompson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).