Hello,

Thanks for your patch.
It fixes a real bug, but I have some comments below.

On 6/2/26 6:09 AM, Johannes Schneider wrote:
> From: Thomas Haemmerle <[email protected]>
> 
> PWM backlight DT nodes for board displays often omit the power-supply 
> regulator
> (the rail is always-on) or use enable-gpios without a supply. The driver
> previously treated both as mandatory and returned -ENODEV if either was 
> absent,
> blocking display initialisation on devices which use an always-on 3.3V supply
> and no separate backlight enable regulator.
> 
> Guard the regulator enable/disable calls with a NULL check, handle
> -ENODEV from regulator_get() as "no supply present", and use GPIOD_ASIS
> for enable GPIO so the initial pin state is not disturbed.
> 
> Also improve the "Cannot find PWM device" error message to print the
> actual error pointer so probe failures are diagnosable.
> 
> Assisted-by: Claude:claude-sonnet-4-6
> Signed-of-by: Thomas Haemmerle <[email protected]>
> ---
>  drivers/video/backlight-pwm.c | 16 ++++++++++------
>  drivers/video/backlight.c     |  3 ++-
>  drivers/video/fsl-ldb.c       |  2 +-
>  3 files changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/video/backlight-pwm.c b/drivers/video/backlight-pwm.c
> index d3c81114e0..9c8fcfbe93 100644
> --- a/drivers/video/backlight-pwm.c
> +++ b/drivers/video/backlight-pwm.c
> @@ -37,7 +37,8 @@ static int backlight_pwm_enable(struct pwm_backlight 
> *pwm_backlight)
>       if (ret)
>               return ret;
>  
> -     regulator_enable(pwm_backlight->power);
> +     if (pwm_backlight->power)
> +             regulator_enable(pwm_backlight->power);

Not needed, regulator_enable gracefully handles a NULL pointer.

>  
>       gpiod_direction_output(pwm_backlight->enable_gpio, true);
>  
> @@ -55,7 +56,8 @@ static int backlight_pwm_disable(struct pwm_backlight 
> *pwm_backlight)
>  
>       ret = gpiod_direction_output(pwm_backlight->enable_gpio, false);
>       if (!ret) {
> -             regulator_disable(pwm_backlight->power);
> +             if (pwm_backlight->power)
> +                     regulator_disable(pwm_backlight->power);

Likewise.

>  
>               /*
>                * Only disable PWM when an enable gpio is present.
> @@ -148,7 +150,7 @@ static int pwm_backlight_parse_dt(struct device *dev,
>               pwm_backlight->backlight.brightness_max = pwm_backlight->scale;
>       }
>  
> -     pwm_backlight->enable_gpio = gpiod_get_optional(dev, "enable-gpios", 0);
> +     pwm_backlight->enable_gpio = gpiod_get_optional(dev, "enable", 
> GPIOD_ASIS);

While the commit message doesn't point it out, use of enable-gpios here
is a bug.

Fixes: 4c7238df6866 ("video: backlight-pwm: switch to gpiod functions")

>  
>       return 0;
>  }
> @@ -161,7 +163,7 @@ static int backlight_pwm_of_probe(struct device *dev)
>  
>       pwm = of_pwm_request(dev->of_node, NULL);
>       if (IS_ERR(pwm)) {
> -             dev_err(dev, "Cannot find PWM device\n");
> +             dev_err(dev, "Cannot find PWM device: %pe\n", pwm);
>               return PTR_ERR(pwm);

return dev_errp_probe(dev, pwm, "Cannot find PWM device\n");

>       }
>  
> @@ -175,8 +177,10 @@ static int backlight_pwm_of_probe(struct device *dev)
>  
>       pwm_backlight->power = regulator_get(dev, "power");

regulator_get_optional()

>       if (IS_ERR(pwm_backlight->power)) {
> -             dev_err(dev, "Cannot find regulator\n");
> -             return PTR_ERR(pwm_backlight->power);
> +             if (PTR_ERR(pwm_backlight->power) != -ENODEV)
> +                     return dev_errp_probe(dev, pwm_backlight->power,
> +                                           "power supply\n");
> +             pwm_backlight->power = NULL;
>       }
>  
>       pwm_backlight->backlight.slew_time_ms = 100;
> diff --git a/drivers/video/backlight.c b/drivers/video/backlight.c
> index 6d8146ee5a..bf7d40b59a 100644
> --- a/drivers/video/backlight.c
> +++ b/drivers/video/backlight.c
> @@ -94,8 +94,9 @@ int backlight_register(struct backlight_device *bl)
>  struct backlight_device *of_backlight_find(struct device_node *node)
>  {
>       struct backlight_device *bl;
> +     int ret;
>  
> -     of_device_ensure_probed(node);
> +     ret = of_device_ensure_probed(node);

ret is never evaluated, so this change serves no purpose.

It's also not needed, because the iteration below will either find a
backlight or it won't find one. You can equally well just cast this to
(void) here.

>  
>       class_for_each_container_of_device(&backlight_class, bl, dev)
>               if (bl->node == node)
> diff --git a/drivers/video/fsl-ldb.c b/drivers/video/fsl-ldb.c
> index 0ab720032c..09804ac329 100644
> --- a/drivers/video/fsl-ldb.c
> +++ b/drivers/video/fsl-ldb.c
> @@ -287,7 +287,7 @@ static int fsl_ldb_probe(struct device *dev)
>  
>       /* Only DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS is supported */
>  
> -     dev_info(dev, "LVDS channel pixel swap not supported.\n");
> +     dev_dbg(dev, "LVDS channel pixel swap not supported.\n");


Cheers,
Ahmad

>  
>       fsl_ldb->vpl.node = dev->of_node;
>       fsl_ldb->vpl.ioctl = &fsl_ldb_ioctl;

-- 
Pengutronix e.K.                  |                             |
Steuerwalder Str. 21              | http://www.pengutronix.de/  |
31137 Hildesheim, Germany         | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |


Reply via email to