linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] video: backlight: Only set maximum brightness for gpio-backlight
@ 2021-07-08  9:10 Marek Vasut
  2021-07-09 11:03 ` Daniel Thompson
  0 siblings, 1 reply; 4+ messages in thread
From: Marek Vasut @ 2021-07-08  9:10 UTC (permalink / raw)
  To: dri-devel
  Cc: linux-fbdev, Marek Vasut, Daniel Thompson, Meghana Madhyastha,
	Noralf Trønnes, Sean Paul, Thierry Reding

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")
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Daniel Thompson <daniel.thompson@linaro.org>
Cc: Meghana Madhyastha <meghana.madhyastha@gmail.com>
Cc: Noralf Trønnes <noralf@tronnes.org>
Cc: Sean Paul <seanpaul@chromium.org>
Cc: Thierry Reding <treding@nvidia.com>
---
 drivers/video/backlight/backlight.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
index 537fe1b376ad7..dfb66171dec41 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -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;
 		}
 	}
-- 
2.30.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] video: backlight: Only set maximum brightness for gpio-backlight
  2021-07-08  9:10 [PATCH] video: backlight: Only set maximum brightness for gpio-backlight Marek Vasut
@ 2021-07-09 11:03 ` Daniel Thompson
  2021-07-09 13:19   ` Marek Vasut
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Thompson @ 2021-07-09 11:03 UTC (permalink / raw)
  To: Marek Vasut
  Cc: dri-devel, linux-fbdev, Meghana Madhyastha, Noralf Trønnes,
	Sean Paul, Thierry Reding

On Thu, Jul 08, 2021 at 11:10:58AM +0200, Marek Vasut wrote:
> 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")
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Daniel Thompson <daniel.thompson@linaro.org>
> Cc: Meghana Madhyastha <meghana.madhyastha@gmail.com>
> Cc: Noralf Trønnes <noralf@tronnes.org>
> Cc: Sean Paul <seanpaul@chromium.org>
> Cc: Thierry Reding <treding@nvidia.com>

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.



> ---
>  drivers/video/backlight/backlight.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
> index 537fe1b376ad7..dfb66171dec41 100644
> --- a/drivers/video/backlight/backlight.c
> +++ b/drivers/video/backlight/backlight.c
> @@ -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;
>  		}
>  	}
> -- 
> 2.30.2

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] video: backlight: Only set maximum brightness for gpio-backlight
  2021-07-09 11:03 ` Daniel Thompson
@ 2021-07-09 13:19   ` Marek Vasut
  2021-07-09 13:25     ` Noralf Trønnes
  0 siblings, 1 reply; 4+ messages in thread
From: Marek Vasut @ 2021-07-09 13:19 UTC (permalink / raw)
  To: Daniel Thompson
  Cc: dri-devel, linux-fbdev, Meghana Madhyastha, Noralf Trønnes,
	Sean Paul, Thierry Reding

On 7/9/21 1:03 PM, Daniel Thompson wrote:
> On Thu, Jul 08, 2021 at 11:10:58AM +0200, Marek Vasut wrote:
>> 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")
>> Signed-off-by: Marek Vasut <marex@denx.de>
>> Cc: Daniel Thompson <daniel.thompson@linaro.org>
>> Cc: Meghana Madhyastha <meghana.madhyastha@gmail.com>
>> Cc: Noralf Trønnes <noralf@tronnes.org>
>> Cc: Sean Paul <seanpaul@chromium.org>
>> Cc: Thierry Reding <treding@nvidia.com>
> 
> 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.

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

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] video: backlight: Only set maximum brightness for gpio-backlight
  2021-07-09 13:19   ` Marek Vasut
@ 2021-07-09 13:25     ` Noralf Trønnes
  0 siblings, 0 replies; 4+ messages in thread
From: Noralf Trønnes @ 2021-07-09 13:25 UTC (permalink / raw)
  To: Marek Vasut, Daniel Thompson
  Cc: dri-devel, linux-fbdev, Meghana Madhyastha, Sean Paul, Thierry Reding



Den 09.07.2021 15.19, skrev Marek Vasut:
> On 7/9/21 1:03 PM, Daniel Thompson wrote:
>> On Thu, Jul 08, 2021 at 11:10:58AM +0200, Marek Vasut wrote:
>>> 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")
>>> Signed-off-by: Marek Vasut <marex@denx.de>
>>> Cc: Daniel Thompson <daniel.thompson@linaro.org>
>>> Cc: Meghana Madhyastha <meghana.madhyastha@gmail.com>
>>> Cc: Noralf Trønnes <noralf@tronnes.org>
>>> Cc: Sean Paul <seanpaul@chromium.org>
>>> Cc: Thierry Reding <treding@nvidia.com>
>>
>> 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.
> 
> 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.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-07-09 13:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-08  9:10 [PATCH] video: backlight: Only set maximum brightness for gpio-backlight Marek Vasut
2021-07-09 11:03 ` Daniel Thompson
2021-07-09 13:19   ` Marek Vasut
2021-07-09 13:25     ` Noralf Trønnes

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox