On Sun, Aug 23, 2020 at 12:45:12PM +0200, Sam Ravnborg wrote:
> Use backlight_{enable,disable} in the probe function to
> avoid hardcoding power handling in the driver.
> 
> Move platform_set_drvdata() up as the enable/disable call
> will trigger a callback to the driver.
> 
> Signed-off-by: Sam Ravnborg <s...@ravnborg.org>
> Cc: Lee Jones <lee.jo...@linaro.org>
> Cc: Daniel Thompson <daniel.thomp...@linaro.org>
> Cc: Jingoo Han <jingooh...@gmail.com>

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


> ---
>  drivers/video/backlight/gpio_backlight.c | 24 +++++++++++++++---------
>  1 file changed, 15 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/video/backlight/gpio_backlight.c 
> b/drivers/video/backlight/gpio_backlight.c
> index 6f78d928f054..dc9354dc5e6a 100644
> --- a/drivers/video/backlight/gpio_backlight.c
> +++ b/drivers/video/backlight/gpio_backlight.c
> @@ -53,6 +53,7 @@ static int gpio_backlight_probe(struct platform_device 
> *pdev)
>       struct backlight_device *bl;
>       struct gpio_backlight *gbl;
>       int ret, init_brightness, def_value;
> +     bool enable = false;
>  
>       gbl = devm_kzalloc(dev, sizeof(*gbl), GFP_KERNEL);
>       if (gbl == NULL)
> @@ -82,16 +83,22 @@ static int gpio_backlight_probe(struct platform_device 
> *pdev)
>               return PTR_ERR(bl);
>       }
>  
> -     /* Set the initial power state */
> -     if (!of_node || !of_node->phandle)
> +     platform_set_drvdata(pdev, bl);
> +
> +     /* Set the initial state */
> +     if (!of_node || !of_node->phandle) {
>               /* Not booted with device tree or no phandle link to the node */
> -             bl->props.power = def_value ? FB_BLANK_UNBLANK
> -                                         : FB_BLANK_POWERDOWN;
> -     else if (gpiod_get_direction(gbl->gpiod) == 0 &&
> -              gpiod_get_value_cansleep(gbl->gpiod) == 0)
> -             bl->props.power = FB_BLANK_POWERDOWN;
> +             if (def_value)
> +                     enable = true;
> +     } else if (!(gpiod_get_direction(gbl->gpiod) == 0 &&
> +                gpiod_get_value_cansleep(gbl->gpiod) == 0)) {
> +             enable = true;
> +     }
> +
> +     if (enable)
> +             backlight_enable(bl);
>       else
> -             bl->props.power = FB_BLANK_UNBLANK;
> +             backlight_disable(bl);
>  
>       bl->props.brightness = 1;
>  
> @@ -102,7 +109,6 @@ static int gpio_backlight_probe(struct platform_device 
> *pdev)
>               return ret;
>       }
>  
> -     platform_set_drvdata(pdev, bl);
>       return 0;
>  }
>  
> -- 
> 2.25.1
> 
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Reply via email to