Skip to contentSkip to conversation

video: backlight: Only set maximum brightness for gpio-backlight

PATCH In review Marek Vasut 3 participants 4 messages Jul 8, 2021 – Jul 9, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 video: backlight: Only set maximum brightness for gpio-backlight

The note in c2adda27d202f ("video: backlight: Add of_find_backlight helper in backlight.c") says that gpio-backlight uses brightness as power state. Other backlight drivers do not, so limit this workaround to gpio-backlight.

This fixes the case where e.g. pwm-backlight can perfectly well be set to brightness 0 on boot in DT, which without this patch leads to the display brightness to be max instead of off.

Fixes c2adda27d202f ("video: backlight: Add of_find_backlight helper in backlight.c")
Cc Daniel Thompson <[email protected]>
Cc Meghana Madhyastha <[email protected]>
Cc Noralf Trønnes <[email protected]>
Cc Sean Paul <[email protected]>
Cc Thierry Reding <[email protected]>
---
 drivers/video/backlight/backlight.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/video/backlight/backlight.c +4 -1
index 537fe1b376ad7..dfb66171dec41 100644
@@ -676,6 +676,7 @@ EXPORT_SYMBOL(of_find_backlight_by_node);
 static struct backlight_device *of_find_backlight(struct device *dev)
 {
 	struct backlight_device *bd = NULL;
+	bool is_gpio_backlight = false;
 	struct device_node *np;
 
 	if (!dev)
@@ -685,6 +686,8 @@ static struct backlight_device *of_find_backlight(struct device *dev)
 		np = of_parse_phandle(dev->of_node, "backlight", 0);
 		if (np) {
 			bd = of_find_backlight_by_node(np);
+			is_gpio_backlight =
+				of_device_is_compatible(np, "gpio-backlight");
 			of_node_put(np);
 			if (!bd)
 				return ERR_PTR(-EPROBE_DEFER);
@@ -692,7 +695,7 @@ static struct backlight_device *of_find_backlight(struct device *dev)
 			 * Note: gpio_backlight uses brightness as
 			 * power state during probe
 			 */
-			if (!bd->props.brightness)
+			if (is_gpio_backlight && !bd->props.brightness)
 				bd->props.brightness = bd->props.max_brightness;
 		}
 	}
Signature · 1 line
2.30.2
#1 lore raw
Quoted 8 lines · Marek Vasut

The note in c2adda27d202f ("video: backlight: Add of_find_backlight helper in backlight.c") says that gpio-backlight uses brightness as power state. Other backlight drivers do not, so limit this workaround to gpio-backlight.

This fixes the case where e.g. pwm-backlight can perfectly well be set to brightness 0 on boot in DT, which without this patch leads to the display brightness to be max instead of off.

Quoted 7 lines
Fixes c2adda27d202f ("video: backlight: Add of_find_backlight helper in backlight.c")
Cc Daniel Thompson <[email protected]>
Cc Meghana Madhyastha <[email protected]>
Cc Noralf Trønnes <[email protected]>
Cc Sean Paul <[email protected]>
Cc Thierry Reding <[email protected]>

I have to admit that this patch really does makes it clear just how nasty the hack in of_find_backlight() currently is.

Moreover I think it is also be obsolete. gpio-backlight power mode handling was pretty broken when this code was introduced. It was fixed in 2019 by ec665b756e6f ("backlight: gpio backlight: Correct initial power state handling") by trying to match the behaviour of PWM backlight. The new code always sets the brightness to 1 so I think we can just remove the hack from of_find_backlight() since I think it is unreachable.

Daniel.

Quoted 36 lines
---
 drivers/video/backlight/backlight.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/video/backlight/backlight.c +4 -1
index 537fe1b376ad7..dfb66171dec41 100644
@@ -676,6 +676,7 @@ EXPORT_SYMBOL(of_find_backlight_by_node);
 static struct backlight_device *of_find_backlight(struct device *dev)
 {
 	struct backlight_device *bd = NULL;
+	bool is_gpio_backlight = false;
 	struct device_node *np;
 
 	if (!dev)
@@ -685,6 +686,8 @@ static struct backlight_device *of_find_backlight(struct device *dev)
 		np = of_parse_phandle(dev->of_node, "backlight", 0);
 		if (np) {
 			bd = of_find_backlight_by_node(np);
+			is_gpio_backlight =
+				of_device_is_compatible(np, "gpio-backlight");
 			of_node_put(np);
 			if (!bd)
 				return ERR_PTR(-EPROBE_DEFER);
@@ -692,7 +695,7 @@ static struct backlight_device *of_find_backlight(struct device *dev)
 			 * Note: gpio_backlight uses brightness as
 			 * power state during probe
 			 */
-			if (!bd->props.brightness)
+			if (is_gpio_backlight && !bd->props.brightness)
 				bd->props.brightness = bd->props.max_brightness;
 		}
 	}
Signature · 1 line
2.30.2
#2 lore raw
Quoted 20 lines · Daniel Thompson
Quoted 8 lines · Marek Vasut

The note in c2adda27d202f ("video: backlight: Add of_find_backlight helper in backlight.c") says that gpio-backlight uses brightness as power state. Other backlight drivers do not, so limit this workaround to gpio-backlight.

This fixes the case where e.g. pwm-backlight can perfectly well be set to brightness 0 on boot in DT, which without this patch leads to the display brightness to be max instead of off.

Quoted 7 lines
Fixes c2adda27d202f ("video: backlight: Add of_find_backlight helper in backlight.c")
Cc Daniel Thompson <[email protected]>
Cc Meghana Madhyastha <[email protected]>
Cc Noralf Trønnes <[email protected]>
Cc Sean Paul <[email protected]>
Cc Thierry Reding <[email protected]>

I have to admit that this patch really does makes it clear just how nasty the hack in of_find_backlight() currently is.

Quoted 7 lines

Moreover I think it is also be obsolete. gpio-backlight power mode handling was pretty broken when this code was introduced. It was fixed in 2019 by ec665b756e6f ("backlight: gpio backlight: Correct initial power state handling") by trying to match the behaviour of PWM backlight. The new code always sets the brightness to 1 so I think we can just remove the hack from of_find_backlight() since I think it is unreachable.

I assume by "new code" you mean the fixed gpio-backlight driver ?

Dropping the whole code after the Note: is fine by me.

#3 lore raw

Den 09.07.2021 15.19, skrev Marek Vasut:

Quoted 35 lines · Daniel Thompson
Quoted 26 lines · Marek Vasut
Quoted 13 lines

The note in c2adda27d202f ("video: backlight: Add of_find_backlight helper
in backlight.c") says that gpio-backlight uses brightness as power state.
Other backlight drivers do not, so limit this workaround to gpio-backlight.

This fixes the case where e.g. pwm-backlight can perfectly well be set to
brightness 0 on boot in DT, which without this patch leads to the display
brightness to be max instead of off.

Quoted 8 lines
Fixes c2adda27d202f ("video: backlight: Add of_find_backlight helper

in backlight.c")

Cc Daniel Thompson <[email protected]>
Cc Meghana Madhyastha <[email protected]>
Cc Noralf Trønnes <[email protected]>
Cc Sean Paul <[email protected]>
Cc Thierry Reding <[email protected]>

I have to admit that this patch really does makes it clear just how nasty the hack in of_find_backlight() currently is.

Quoted 7 lines

Moreover I think it is also be obsolete. gpio-backlight power mode handling was pretty broken when this code was introduced. It was fixed in 2019 by ec665b756e6f ("backlight: gpio backlight: Correct initial power state handling") by trying to match the behaviour of PWM backlight.  The new code always sets the brightness to 1 so I think we can just remove the hack from of_find_backlight() since I think it is unreachable.

Quoted 3 lines

I assume by "new code" you mean the fixed gpio-backlight driver ?

Dropping the whole code after the Note: is fine by me.

I haven't actually tested it, but when I saw the patch that Daniel points to, it looked like this work around could be removed. I haven't got time to tests it, but I will ack a patch that removes the hack.

Noralf.