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

login
register
mail settings
Submitter Fabio Estevam
Date Sept. 28, 2013, 4:35 p.m.
Message ID <CAOMZO5AHGF7hfPOA-XsKQx-dHfXe=Lb4ywgNKOzC+b=3CEnDKg@mail.gmail.com>
Download mbox | patch
Permalink /patch/278751/
State RFC
Delegated to: Stefano Babic
Headers show

Comments

Fabio Estevam - Sept. 28, 2013, 4:35 p.m.
On Sat, Sep 28, 2013 at 10:12 AM, Eric Bénard <eric@eukrea.com> wrote:

> 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.

I agree with Eric.

Could you please test the patch below?

U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot
Otavio Salvador - Sept. 28, 2013, 7:05 p.m.
On Sat, Sep 28, 2013 at 1:35 PM, Fabio Estevam <festevam@gmail.com> wrote:
> On Sat, Sep 28, 2013 at 10:12 AM, Eric Bénard <eric@eukrea.com> wrote:
>
>> 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.
>
> I agree with Eric.
>
> Could you please test the patch below?
>
> --- a/drivers/gpio/mxc_gpio.c
> +++ b/drivers/gpio/mxc_gpio.c
> @@ -93,7 +93,7 @@ int gpio_get_value(unsigned gpio)
>  {
>         unsigned int port = GPIO_TO_PORT(gpio);
>         struct gpio_regs *regs;
> -       u32 val;
> +       u32 direction;
>
>         if (port >= ARRAY_SIZE(gpio_ports))
>                 return -1;
> @@ -102,9 +102,12 @@ int gpio_get_value(unsigned gpio)
>
>         regs = (struct gpio_regs *)gpio_ports[port];
>
> -       val = (readl(&regs->gpio_psr) >> gpio) & 0x01;
> +       direction = readl(&regs->gpio_dir);
>
> -       return val;
> +       if ((direction >> gpio) & 0x01)
> +               return (readl(&regs->gpio_dr) >> gpio) & 0x01; /* output mode */
> +       else
> +               return (readl(&regs->gpio_psr) >> gpio) & 0x01; /* input mode */
>  }

This did the trick!

I dropped this patch.

Patch

--- a/drivers/gpio/mxc_gpio.c
+++ b/drivers/gpio/mxc_gpio.c
@@ -93,7 +93,7 @@  int gpio_get_value(unsigned gpio)
 {
        unsigned int port = GPIO_TO_PORT(gpio);
        struct gpio_regs *regs;
-       u32 val;
+       u32 direction;

        if (port >= ARRAY_SIZE(gpio_ports))
                return -1;
@@ -102,9 +102,12 @@  int gpio_get_value(unsigned gpio)

        regs = (struct gpio_regs *)gpio_ports[port];

-       val = (readl(&regs->gpio_psr) >> gpio) & 0x01;
+       direction = readl(&regs->gpio_dir);

-       return val;
+       if ((direction >> gpio) & 0x01)
+               return (readl(&regs->gpio_dr) >> gpio) & 0x01; /* output mode */
+       else
+               return (readl(&regs->gpio_psr) >> gpio) & 0x01; /* input mode */
 }
_______________________________________________
U-Boot mailing list