linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] backlight: pwm_bl: Fix GPIO out for unimplemented .get_direction()
@ 2017-03-22 17:21 Geert Uytterhoeven
  2017-03-23 21:11 ` Peter Ujfalusi
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Geert Uytterhoeven @ 2017-03-22 17:21 UTC (permalink / raw)
  To: Thierry Reding, Lee Jones, Daniel Thompson, Jingoo Han,
	Bartlomiej Zolnierkiewicz
  Cc: Peter Ujfalusi, Philipp Zabel, linux-pwm, linux-fbdev,
	linux-renesas-soc, linux-kernel, Geert Uytterhoeven

Commit 7613c922315e308a ("backlight: pwm_bl: Move the checks for initial
power state to a separate function") not just moved some code, but made
slight changes in semantics.

If a gpiochip doesn't implement the optional .get_direction() callback,
gpiod_get_direction always returns -EINVAL, which is never equal to
GPIOF_DIR_IN, leading to the GPIO not being configured for output.

To avoid this, invert the test and check for not GPIOF_DIR_OUT instead,
like the original code did.

This restores the display on r8a7740/armadillo.

Fixes: 7613c922315e308a ("backlight: pwm_bl: Move the checks for initial power state to a separate function")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/video/backlight/pwm_bl.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index d7efcb632f7d9dde..002f1ce22bd02032 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -297,14 +297,15 @@ static int pwm_backlight_probe(struct platform_device *pdev)
 	}
 
 	/*
-	 * If the GPIO is configured as input, change the direction to output
-	 * and set the GPIO as active.
+	 * If the GPIO is not known to be already configured as output, that
+	 * is, if gpiod_get_direction returns either GPIOF_DIR_IN or -EINVAL,
+	 * change the direction to output and set the GPIO as active.
 	 * Do not force the GPIO to active when it was already output as it
 	 * could cause backlight flickering or we would enable the backlight too
 	 * early. Leave the decision of the initial backlight state for later.
 	 */
 	if (pb->enable_gpio &&
-	    gpiod_get_direction(pb->enable_gpio) == GPIOF_DIR_IN)
+	    gpiod_get_direction(pb->enable_gpio) != GPIOF_DIR_OUT)
 		gpiod_direction_output(pb->enable_gpio, 1);
 
 	pb->power_supply = devm_regulator_get(&pdev->dev, "power");
-- 
2.7.4

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

* Re: [PATCH] backlight: pwm_bl: Fix GPIO out for unimplemented .get_direction()
  2017-03-22 17:21 [PATCH] backlight: pwm_bl: Fix GPIO out for unimplemented .get_direction() Geert Uytterhoeven
@ 2017-03-23 21:11 ` Peter Ujfalusi
  2017-03-24  9:13 ` Philipp Zabel
  2017-03-24 16:42 ` Daniel Thompson
  2 siblings, 0 replies; 6+ messages in thread
From: Peter Ujfalusi @ 2017-03-23 21:11 UTC (permalink / raw)
  To: Geert Uytterhoeven, Thierry Reding, Lee Jones, Daniel Thompson,
	Jingoo Han, Bartlomiej Zolnierkiewicz
  Cc: Philipp Zabel, linux-pwm, linux-fbdev, linux-renesas-soc, linux-kernel

On 03/22/2017 07:21 PM, Geert Uytterhoeven wrote:
> Commit 7613c922315e308a ("backlight: pwm_bl: Move the checks for initial
> power state to a separate function") not just moved some code, but made
> slight changes in semantics.
>
> If a gpiochip doesn't implement the optional .get_direction() callback,
> gpiod_get_direction always returns -EINVAL, which is never equal to
> GPIOF_DIR_IN, leading to the GPIO not being configured for output.

The platforms I have tested the gpio drivers do implement the get_direction() 
callback and I was not aware of this behaviour.

> To avoid this, invert the test and check for not GPIOF_DIR_OUT instead,
> like the original code did.
>
> This restores the display on r8a7740/armadillo.
>
> Fixes: 7613c922315e308a ("backlight: pwm_bl: Move the checks for initial power state to a separate function")
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

Reviewed-by: Peter Ujfalusi <peter.ujfalusi@ti.com>

> ---
>  drivers/video/backlight/pwm_bl.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
> index d7efcb632f7d9dde..002f1ce22bd02032 100644
> --- a/drivers/video/backlight/pwm_bl.c
> +++ b/drivers/video/backlight/pwm_bl.c
> @@ -297,14 +297,15 @@ static int pwm_backlight_probe(struct platform_device *pdev)
>  	}
>
>  	/*
> -	 * If the GPIO is configured as input, change the direction to output
> -	 * and set the GPIO as active.
> +	 * If the GPIO is not known to be already configured as output, that
> +	 * is, if gpiod_get_direction returns either GPIOF_DIR_IN or -EINVAL,
> +	 * change the direction to output and set the GPIO as active.
>  	 * Do not force the GPIO to active when it was already output as it
>  	 * could cause backlight flickering or we would enable the backlight too
>  	 * early. Leave the decision of the initial backlight state for later.
>  	 */
>  	if (pb->enable_gpio &&
> -	    gpiod_get_direction(pb->enable_gpio) == GPIOF_DIR_IN)
> +	    gpiod_get_direction(pb->enable_gpio) != GPIOF_DIR_OUT)
>  		gpiod_direction_output(pb->enable_gpio, 1);
>
>  	pb->power_supply = devm_regulator_get(&pdev->dev, "power");
>


-- 
Péter

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

* Re: [PATCH] backlight: pwm_bl: Fix GPIO out for unimplemented .get_direction()
  2017-03-22 17:21 [PATCH] backlight: pwm_bl: Fix GPIO out for unimplemented .get_direction() Geert Uytterhoeven
  2017-03-23 21:11 ` Peter Ujfalusi
@ 2017-03-24  9:13 ` Philipp Zabel
  2017-03-24 16:42 ` Daniel Thompson
  2 siblings, 0 replies; 6+ messages in thread
From: Philipp Zabel @ 2017-03-24  9:13 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Thierry Reding, Lee Jones, Daniel Thompson, Jingoo Han,
	Bartlomiej Zolnierkiewicz, Peter Ujfalusi, linux-pwm,
	linux-fbdev, linux-renesas-soc, linux-kernel

On Wed, 2017-03-22 at 18:21 +0100, Geert Uytterhoeven wrote:
> Commit 7613c922315e308a ("backlight: pwm_bl: Move the checks for initial
> power state to a separate function") not just moved some code, but made
> slight changes in semantics.
> 
> If a gpiochip doesn't implement the optional .get_direction() callback,
> gpiod_get_direction always returns -EINVAL, which is never equal to
> GPIOF_DIR_IN, leading to the GPIO not being configured for output.
>
> To avoid this, invert the test and check for not GPIOF_DIR_OUT instead,
> like the original code did.
> 
> This restores the display on r8a7740/armadillo.
> 
> Fixes: 7613c922315e308a ("backlight: pwm_bl: Move the checks for initial power state to a separate function")
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

Acked-by: Philipp Zabel <p.zabel@pengutronix.de>

regards
Philipp

> ---
>  drivers/video/backlight/pwm_bl.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
> index d7efcb632f7d9dde..002f1ce22bd02032 100644
> --- a/drivers/video/backlight/pwm_bl.c
> +++ b/drivers/video/backlight/pwm_bl.c
> @@ -297,14 +297,15 @@ static int pwm_backlight_probe(struct platform_device *pdev)
>  	}
>  
>  	/*
> -	 * If the GPIO is configured as input, change the direction to output
> -	 * and set the GPIO as active.
> +	 * If the GPIO is not known to be already configured as output, that
> +	 * is, if gpiod_get_direction returns either GPIOF_DIR_IN or -EINVAL,
> +	 * change the direction to output and set the GPIO as active.
>  	 * Do not force the GPIO to active when it was already output as it
>  	 * could cause backlight flickering or we would enable the backlight too
>  	 * early. Leave the decision of the initial backlight state for later.
>  	 */
>  	if (pb->enable_gpio &&
> -	    gpiod_get_direction(pb->enable_gpio) == GPIOF_DIR_IN)
> +	    gpiod_get_direction(pb->enable_gpio) != GPIOF_DIR_OUT)
>  		gpiod_direction_output(pb->enable_gpio, 1);
>  
>  	pb->power_supply = devm_regulator_get(&pdev->dev, "power");

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

* Re: [PATCH] backlight: pwm_bl: Fix GPIO out for unimplemented .get_direction()
  2017-03-22 17:21 [PATCH] backlight: pwm_bl: Fix GPIO out for unimplemented .get_direction() Geert Uytterhoeven
  2017-03-23 21:11 ` Peter Ujfalusi
  2017-03-24  9:13 ` Philipp Zabel
@ 2017-03-24 16:42 ` Daniel Thompson
  2017-03-24 16:43   ` Daniel Thompson
  2 siblings, 1 reply; 6+ messages in thread
From: Daniel Thompson @ 2017-03-24 16:42 UTC (permalink / raw)
  To: Geert Uytterhoeven, Thierry Reding, Lee Jones, Jingoo Han,
	Bartlomiej Zolnierkiewicz
  Cc: Peter Ujfalusi, Philipp Zabel, linux-pwm, linux-fbdev,
	linux-renesas-soc, linux-kernel

On 22/03/17 17:21, Geert Uytterhoeven wrote:
> Commit 7613c922315e308a ("backlight: pwm_bl: Move the checks for initial
> power state to a separate function") not just moved some code, but made
> slight changes in semantics.
>
> If a gpiochip doesn't implement the optional .get_direction() callback,
> gpiod_get_direction always returns -EINVAL, which is never equal to
> GPIOF_DIR_IN, leading to the GPIO not being configured for output.
>
> To avoid this, invert the test and check for not GPIOF_DIR_OUT instead,
> like the original code did.
>
> This restores the display on r8a7740/armadillo.
>
> Fixes: 7613c922315e308a ("backlight: pwm_bl: Move the checks for initial power state to a separate function")
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

Acked-by: Daniel Thommpson <daniel.thompson@linaro.org>


> ---
>  drivers/video/backlight/pwm_bl.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
> index d7efcb632f7d9dde..002f1ce22bd02032 100644
> --- a/drivers/video/backlight/pwm_bl.c
> +++ b/drivers/video/backlight/pwm_bl.c
> @@ -297,14 +297,15 @@ static int pwm_backlight_probe(struct platform_device *pdev)
>  	}
>
>  	/*
> -	 * If the GPIO is configured as input, change the direction to output
> -	 * and set the GPIO as active.
> +	 * If the GPIO is not known to be already configured as output, that
> +	 * is, if gpiod_get_direction returns either GPIOF_DIR_IN or -EINVAL,
> +	 * change the direction to output and set the GPIO as active.
>  	 * Do not force the GPIO to active when it was already output as it
>  	 * could cause backlight flickering or we would enable the backlight too
>  	 * early. Leave the decision of the initial backlight state for later.
>  	 */
>  	if (pb->enable_gpio &&
> -	    gpiod_get_direction(pb->enable_gpio) == GPIOF_DIR_IN)
> +	    gpiod_get_direction(pb->enable_gpio) != GPIOF_DIR_OUT)
>  		gpiod_direction_output(pb->enable_gpio, 1);
>
>  	pb->power_supply = devm_regulator_get(&pdev->dev, "power");
>

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

* Re: [PATCH] backlight: pwm_bl: Fix GPIO out for unimplemented .get_direction()
  2017-03-24 16:42 ` Daniel Thompson
@ 2017-03-24 16:43   ` Daniel Thompson
  2017-03-27 14:27     ` Lee Jones
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Thompson @ 2017-03-24 16:43 UTC (permalink / raw)
  To: Geert Uytterhoeven, Thierry Reding, Lee Jones, Jingoo Han,
	Bartlomiej Zolnierkiewicz
  Cc: Peter Ujfalusi, Philipp Zabel, linux-pwm, linux-fbdev,
	linux-renesas-soc, linux-kernel

On 24/03/17 16:42, Daniel Thompson wrote:
> On 22/03/17 17:21, Geert Uytterhoeven wrote:
>> Commit 7613c922315e308a ("backlight: pwm_bl: Move the checks for initial
>> power state to a separate function") not just moved some code, but made
>> slight changes in semantics.
>>
>> If a gpiochip doesn't implement the optional .get_direction() callback,
>> gpiod_get_direction always returns -EINVAL, which is never equal to
>> GPIOF_DIR_IN, leading to the GPIO not being configured for output.
>>
>> To avoid this, invert the test and check for not GPIOF_DIR_OUT instead,
>> like the original code did.
>>
>> This restores the display on r8a7740/armadillo.
>>
>> Fixes: 7613c922315e308a ("backlight: pwm_bl: Move the checks for
>> initial power state to a separate function")
>> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
>
> Acked-by: Daniel Thommpson <daniel.thompson@linaro.org>

Actually, it would be better if there only one m...

Acked-by: Daniel Thompson <daniel.thompson@linaro.org>


Daniel.

>
>
>> ---
>>  drivers/video/backlight/pwm_bl.c | 7 ++++---
>>  1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/video/backlight/pwm_bl.c
>> b/drivers/video/backlight/pwm_bl.c
>> index d7efcb632f7d9dde..002f1ce22bd02032 100644
>> --- a/drivers/video/backlight/pwm_bl.c
>> +++ b/drivers/video/backlight/pwm_bl.c
>> @@ -297,14 +297,15 @@ static int pwm_backlight_probe(struct
>> platform_device *pdev)
>>      }
>>
>>      /*
>> -     * If the GPIO is configured as input, change the direction to
>> output
>> -     * and set the GPIO as active.
>> +     * If the GPIO is not known to be already configured as output, that
>> +     * is, if gpiod_get_direction returns either GPIOF_DIR_IN or
>> -EINVAL,
>> +     * change the direction to output and set the GPIO as active.
>>       * Do not force the GPIO to active when it was already output as it
>>       * could cause backlight flickering or we would enable the
>> backlight too
>>       * early. Leave the decision of the initial backlight state for
>> later.
>>       */
>>      if (pb->enable_gpio &&
>> -        gpiod_get_direction(pb->enable_gpio) == GPIOF_DIR_IN)
>> +        gpiod_get_direction(pb->enable_gpio) != GPIOF_DIR_OUT)
>>          gpiod_direction_output(pb->enable_gpio, 1);
>>
>>      pb->power_supply = devm_regulator_get(&pdev->dev, "power");
>>
>

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

* Re: [PATCH] backlight: pwm_bl: Fix GPIO out for unimplemented .get_direction()
  2017-03-24 16:43   ` Daniel Thompson
@ 2017-03-27 14:27     ` Lee Jones
  0 siblings, 0 replies; 6+ messages in thread
From: Lee Jones @ 2017-03-27 14:27 UTC (permalink / raw)
  To: Daniel Thompson
  Cc: Geert Uytterhoeven, Thierry Reding, Jingoo Han,
	Bartlomiej Zolnierkiewicz, Peter Ujfalusi, Philipp Zabel,
	linux-pwm, linux-fbdev, linux-renesas-soc, linux-kernel

On Fri, 24 Mar 2017, Daniel Thompson wrote:

> On 24/03/17 16:42, Daniel Thompson wrote:
> > On 22/03/17 17:21, Geert Uytterhoeven wrote:
> > > Commit 7613c922315e308a ("backlight: pwm_bl: Move the checks for initial
> > > power state to a separate function") not just moved some code, but made
> > > slight changes in semantics.
> > > 
> > > If a gpiochip doesn't implement the optional .get_direction() callback,
> > > gpiod_get_direction always returns -EINVAL, which is never equal to
> > > GPIOF_DIR_IN, leading to the GPIO not being configured for output.
> > > 
> > > To avoid this, invert the test and check for not GPIOF_DIR_OUT instead,
> > > like the original code did.
> > > 
> > > This restores the display on r8a7740/armadillo.
> > > 
> > > Fixes: 7613c922315e308a ("backlight: pwm_bl: Move the checks for
> > > initial power state to a separate function")
> > > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> > 
> > Acked-by: Daniel Thommpson <daniel.thompson@linaro.org>
> 
> Actually, it would be better if there only one m...
> 
> Acked-by: Daniel Thompson <daniel.thompson@linaro.org>

You probably don't want to be typing out your Acks manually every
time.  Can you set a key combination in your editor?

> > > ---
> > >  drivers/video/backlight/pwm_bl.c | 7 ++++---
> > >  1 file changed, 4 insertions(+), 3 deletions(-)
> > > 
> > > diff --git a/drivers/video/backlight/pwm_bl.c
> > > b/drivers/video/backlight/pwm_bl.c
> > > index d7efcb632f7d9dde..002f1ce22bd02032 100644
> > > --- a/drivers/video/backlight/pwm_bl.c
> > > +++ b/drivers/video/backlight/pwm_bl.c
> > > @@ -297,14 +297,15 @@ static int pwm_backlight_probe(struct
> > > platform_device *pdev)
> > >      }
> > > 
> > >      /*
> > > -     * If the GPIO is configured as input, change the direction to
> > > output
> > > -     * and set the GPIO as active.
> > > +     * If the GPIO is not known to be already configured as output, that
> > > +     * is, if gpiod_get_direction returns either GPIOF_DIR_IN or
> > > -EINVAL,
> > > +     * change the direction to output and set the GPIO as active.
> > >       * Do not force the GPIO to active when it was already output as it
> > >       * could cause backlight flickering or we would enable the
> > > backlight too
> > >       * early. Leave the decision of the initial backlight state for
> > > later.
> > >       */
> > >      if (pb->enable_gpio &&
> > > -        gpiod_get_direction(pb->enable_gpio) == GPIOF_DIR_IN)
> > > +        gpiod_get_direction(pb->enable_gpio) != GPIOF_DIR_OUT)
> > >          gpiod_direction_output(pb->enable_gpio, 1);
> > > 
> > >      pb->power_supply = devm_regulator_get(&pdev->dev, "power");
> > > 
> > 
> 

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

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

end of thread, other threads:[~2017-03-27 14:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-22 17:21 [PATCH] backlight: pwm_bl: Fix GPIO out for unimplemented .get_direction() Geert Uytterhoeven
2017-03-23 21:11 ` Peter Ujfalusi
2017-03-24  9:13 ` Philipp Zabel
2017-03-24 16:42 ` Daniel Thompson
2017-03-24 16:43   ` Daniel Thompson
2017-03-27 14:27     ` Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).