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

Eric Bénard eric at eukrea.com
Sat Sep 28 15:12:53 CEST 2013


Hi Otavio,

Le Sat, 28 Sep 2013 00:24:16 -0300,
Otavio Salvador <otavio at 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 at 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


More information about the U-Boot mailing list