linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v6] backlight: lp855x: Switch to atomic PWM API
@ 2021-11-04 17:58 Maíra Canal
  2021-11-05 10:40 ` Uwe Kleine-König
  2021-11-05 13:18 ` Daniel Thompson
  0 siblings, 2 replies; 3+ messages in thread
From: Maíra Canal @ 2021-11-04 17:58 UTC (permalink / raw)
  To: daniel.thompson, lee.jones, 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 simplify conditional loop
V2 -> V3: Fix assignment of NULL variable
V3 -> V4: Replace division for pwm_set_relative_duty_cycle
V4 -> V5: Fix overwrite of state.period
V5 -> V6: Fix duty cycle rounding and set period outside conditional loop
---
 drivers/video/backlight/lp855x_bl.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/drivers/video/backlight/lp855x_bl.c b/drivers/video/backlight/lp855x_bl.c
index e94932c69f54..8f893cf0cfde 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,16 @@ 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);
+	} else {
+		pwm_get_state(lp->pwm, &state);
 	}
 
-	pwm_config(lp->pwm, duty, period);
-	if (duty)
-		pwm_enable(lp->pwm);
-	else
-		pwm_disable(lp->pwm);
+	state.period = lp->pdata->period_ns;
+	state.duty_cycle = div_u64(br * state.period, 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] 3+ messages in thread

* Re: [PATCH v6] backlight: lp855x: Switch to atomic PWM API
  2021-11-04 17:58 [PATCH v6] backlight: lp855x: Switch to atomic PWM API Maíra Canal
@ 2021-11-05 10:40 ` Uwe Kleine-König
  2021-11-05 13:18 ` Daniel Thompson
  1 sibling, 0 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2021-11-05 10:40 UTC (permalink / raw)
  To: Maíra Canal
  Cc: daniel.thompson, lee.jones, jingoohan1, thierry.reding,
	dri-devel, linux-fbdev, linux-kernel, linux-pwm

[-- Attachment #1: Type: text/plain, Size: 487 bytes --]

Hello,

On Thu, Nov 04, 2021 at 02:58:38PM -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>

LGTM,

Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Thanks
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v6] backlight: lp855x: Switch to atomic PWM API
  2021-11-04 17:58 [PATCH v6] backlight: lp855x: Switch to atomic PWM API Maíra Canal
  2021-11-05 10:40 ` Uwe Kleine-König
@ 2021-11-05 13:18 ` Daniel Thompson
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Thompson @ 2021-11-05 13:18 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 Thu, Nov 04, 2021 at 02:58:38PM -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>

Reviewed-by: Daniel Thompson <daniel.thompson@linaro.org>


Daniel.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-05 13:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-04 17:58 [PATCH v6] backlight: lp855x: Switch to atomic PWM API Maíra Canal
2021-11-05 10:40 ` Uwe Kleine-König
2021-11-05 13:18 ` 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).