[PATCH v2 04/24] backlight: gpio: Introduce backlight_{enable, disable}

Sam Ravnborg sam at ravnborg.org
Sun Aug 23 10:45:12 UTC 2020


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 <sam at ravnborg.org>
Cc: Lee Jones <lee.jones at linaro.org>
Cc: Daniel Thompson <daniel.thompson at linaro.org>
Cc: Jingoo Han <jingoohan1 at gmail.com>
---
 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



More information about the dri-devel mailing list