diff mbox

[U-Boot,5/7] gpio-led: Fix __led_toggle support to first set GPIO as input

Message ID 1380338659-7896-5-git-send-email-otavio@ossystems.com.br
State Superseded
Headers show

Commit Message

Otavio Salvador Sept. 28, 2013, 3:24 a.m. UTC
The GPIO need to be set as input before reading its current value and
set back to output for setting it; this fixes the non-working
'led <id> toggle' for GPIO based LEDs.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
---
 drivers/misc/gpio_led.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Eric Benard Sept. 28, 2013, 1:12 p.m. UTC | #1
Hi Otavio,

Le Sat, 28 Sep 2013 00:24:16 -0300,
Otavio Salvador <otavio@ossystems.com.br> a écrit :

> The GPIO need to be set as input before reading its current value and
> set back to output for setting it; this fixes the non-working
> 'led <id> toggle' for GPIO based LEDs.
> 
> Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
> ---
>  drivers/misc/gpio_led.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/misc/gpio_led.c b/drivers/misc/gpio_led.c
> index 6afb986..1882751 100644
> --- a/drivers/misc/gpio_led.c
> +++ b/drivers/misc/gpio_led.c
> @@ -22,5 +22,6 @@ void __led_set(led_id_t mask, int state)
>  
>  void __led_toggle(led_id_t mask)
>  {
> -	gpio_set_value(mask, !gpio_get_value(mask));
> +	gpio_direction_input(mask);
> +	__led_set(mask, !gpio_get_value(mask));
>  }

How can that work on a hardware point of view ?
If you configure the gpio as an input it isn't any more driven as an
output so the value you read depends on the way the led is wired (and
maybe also on internal pull up/down) and not on the way it was
previously driven when the gpio was an output.

Maybe the real fix would be to check why gpio_get_value doesn't return
the level of the gpio when it's configured as an output.

Eric
diff mbox

Patch

diff --git a/drivers/misc/gpio_led.c b/drivers/misc/gpio_led.c
index 6afb986..1882751 100644
--- a/drivers/misc/gpio_led.c
+++ b/drivers/misc/gpio_led.c
@@ -22,5 +22,6 @@  void __led_set(led_id_t mask, int state)
 
 void __led_toggle(led_id_t mask)
 {
-	gpio_set_value(mask, !gpio_get_value(mask));
+	gpio_direction_input(mask);
+	__led_set(mask, !gpio_get_value(mask));
 }