diff mbox series

[v3,2/2] backlight: lm3630a: convert to atomic PWM API and check for errors

Message ID 20210621122148.116863-3-u.kleine-koenig@pengutronix.de
State New
Headers show
Series backlight: lm3630a: convert to atomic PWM API | expand

Commit Message

Uwe Kleine-König June 21, 2021, 12:21 p.m. UTC
The practical upside here is that this only needs a single API call to
program the hardware which (depending on the underlaying hardware) can
be more effective and prevents glitches.

Up to now the return value of the pwm functions was ignored. Fix this
and propagate the error to the caller.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/video/backlight/lm3630a_bl.c | 42 +++++++++++++---------------
 1 file changed, 19 insertions(+), 23 deletions(-)

Comments

Lee Jones June 22, 2021, 1:12 p.m. UTC | #1
On Mon, 21 Jun 2021, Uwe Kleine-König wrote:

> The practical upside here is that this only needs a single API call to
> program the hardware which (depending on the underlaying hardware) can
> be more effective and prevents glitches.
> 
> Up to now the return value of the pwm functions was ignored. Fix this
> and propagate the error to the caller.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>  drivers/video/backlight/lm3630a_bl.c | 42 +++++++++++++---------------
>  1 file changed, 19 insertions(+), 23 deletions(-)

Fixed the subject line and applied, thanks.
Uwe Kleine-König June 24, 2021, 8:10 p.m. UTC | #2
Hi Lee,

On Tue, Jun 22, 2021 at 02:12:57PM +0100, Lee Jones wrote:
> On Mon, 21 Jun 2021, Uwe Kleine-König wrote:

> 

> > The practical upside here is that this only needs a single API call to

> > program the hardware which (depending on the underlaying hardware) can

> > be more effective and prevents glitches.

> > 

> > Up to now the return value of the pwm functions was ignored. Fix this

> > and propagate the error to the caller.

> > 

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

> > ---

> >  drivers/video/backlight/lm3630a_bl.c | 42 +++++++++++++---------------

> >  1 file changed, 19 insertions(+), 23 deletions(-)

> 

> Fixed the subject line and applied, thanks.


It's not obvious to me what needed fixing here, and I don't find where
you the patches, neither in next nor in
https://git.kernel.org/pub/scm/linux/kernel/git/lee/backlight.git; so I
cannot check what you actually changed.

I assume you did s/lm3630a/lm3630a_bl/ ? I didn't because it felt
tautological.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
Lee Jones June 25, 2021, 8:44 a.m. UTC | #3
On Thu, 24 Jun 2021, Uwe Kleine-König wrote:

> Hi Lee,

> 

> On Tue, Jun 22, 2021 at 02:12:57PM +0100, Lee Jones wrote:

> > On Mon, 21 Jun 2021, Uwe Kleine-König wrote:

> > 

> > > The practical upside here is that this only needs a single API call to

> > > program the hardware which (depending on the underlaying hardware) can

> > > be more effective and prevents glitches.

> > > 

> > > Up to now the return value of the pwm functions was ignored. Fix this

> > > and propagate the error to the caller.

> > > 

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

> > > ---

> > >  drivers/video/backlight/lm3630a_bl.c | 42 +++++++++++++---------------

> > >  1 file changed, 19 insertions(+), 23 deletions(-)

> > 

> > Fixed the subject line and applied, thanks.

> 

> It's not obvious to me what needed fixing here, and I don't find where

> you the patches, neither in next nor in

> https://git.kernel.org/pub/scm/linux/kernel/git/lee/backlight.git; so I

> cannot check what you actually changed.

> 

> I assume you did s/lm3630a/lm3630a_bl/ ? I didn't because it felt

> tautological.


No, but perhaps I should have.  Format goes:

<backlight>: <driver_file_name>: <Subject starting with uppercase>

Where <driver_file_name> has the file extension removed.

-- 
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog
diff mbox series

Patch

diff --git a/drivers/video/backlight/lm3630a_bl.c b/drivers/video/backlight/lm3630a_bl.c
index 7140b0d98082..f377dfdd9868 100644
--- a/drivers/video/backlight/lm3630a_bl.c
+++ b/drivers/video/backlight/lm3630a_bl.c
@@ -52,6 +52,7 @@  struct lm3630a_chip {
 	struct gpio_desc *enable_gpio;
 	struct regmap *regmap;
 	struct pwm_device *pwmd;
+	struct pwm_state pwmd_state;
 };
 
 /* i2c access */
@@ -167,16 +168,19 @@  static int lm3630a_intr_config(struct lm3630a_chip *pchip)
 	return rval;
 }
 
-static void lm3630a_pwm_ctrl(struct lm3630a_chip *pchip, int br, int br_max)
+static int lm3630a_pwm_ctrl(struct lm3630a_chip *pchip, int br, int br_max)
 {
-	unsigned int period = pchip->pdata->pwm_period;
-	unsigned int duty = br * period / br_max;
+	int err;
 
-	pwm_config(pchip->pwmd, duty, period);
-	if (duty)
-		pwm_enable(pchip->pwmd);
-	else
-		pwm_disable(pchip->pwmd);
+	pchip->pwmd_state.period = pchip->pdata->pwm_period;
+
+	err = pwm_set_relative_duty_cycle(&pchip->pwmd_state, br, br_max);
+	if (err)
+		return err;
+
+	pchip->pwmd_state.enabled = pchip->pwmd_state.duty_cycle ? true : false;
+
+	return pwm_apply_state(pchip->pwmd, &pchip->pwmd_state);
 }
 
 /* update and get brightness */
@@ -187,11 +191,9 @@  static int lm3630a_bank_a_update_status(struct backlight_device *bl)
 	enum lm3630a_pwm_ctrl pwm_ctrl = pchip->pdata->pwm_ctrl;
 
 	/* pwm control */
-	if ((pwm_ctrl & LM3630A_PWM_BANK_A) != 0) {
-		lm3630a_pwm_ctrl(pchip, bl->props.brightness,
-				 bl->props.max_brightness);
-		return 0;
-	}
+	if ((pwm_ctrl & LM3630A_PWM_BANK_A) != 0)
+		return lm3630a_pwm_ctrl(pchip, bl->props.brightness,
+					bl->props.max_brightness);
 
 	/* disable sleep */
 	ret = lm3630a_update(pchip, REG_CTRL, 0x80, 0x00);
@@ -264,11 +266,9 @@  static int lm3630a_bank_b_update_status(struct backlight_device *bl)
 	enum lm3630a_pwm_ctrl pwm_ctrl = pchip->pdata->pwm_ctrl;
 
 	/* pwm control */
-	if ((pwm_ctrl & LM3630A_PWM_BANK_B) != 0) {
-		lm3630a_pwm_ctrl(pchip, bl->props.brightness,
-				 bl->props.max_brightness);
-		return 0;
-	}
+	if ((pwm_ctrl & LM3630A_PWM_BANK_B) != 0)
+		return lm3630a_pwm_ctrl(pchip, bl->props.brightness,
+					bl->props.max_brightness);
 
 	/* disable sleep */
 	ret = lm3630a_update(pchip, REG_CTRL, 0x80, 0x00);
@@ -563,11 +563,7 @@  static int lm3630a_probe(struct i2c_client *client,
 			return PTR_ERR(pchip->pwmd);
 		}
 
-		/*
-		 * FIXME: pwm_apply_args() should be removed when switching to
-		 * the atomic PWM API.
-		 */
-		pwm_apply_args(pchip->pwmd);
+		pwm_init_state(pchip->pwmd, &pchip->pwmd_state);
 	}
 
 	/* interrupt enable  : irq 0 is not allowed */