On Sun, Jun 20, 2021 at 09:39:28PM +0200, 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-koe...@pengutronix.de>
> ---
>  drivers/video/backlight/lm3630a_bl.c | 34 +++++++++++++---------------
>  1 file changed, 16 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/video/backlight/lm3630a_bl.c 
> b/drivers/video/backlight/lm3630a_bl.c
> index 16a2658a72e1..99eb8277149b 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);

My apologies for overlooking this at v1 (and even when reviewing the first of
the v2 patchs) but...  this fixes the code for bank A. Bank B also requires 
exactly
the same set of fixes!


Daniel.

Reply via email to