Am Sonntag, den 03.04.2011, 04:43 -0400 schrieb Mike Frysinger:
> The Blackfin gpio command isn't terribly Blackfin-specific.  So generalize
> the few pieces into two new optional helpers:
>       name_to_gpio() - turn a string name into a GPIO #
>       gpio_status() - display current pin bindings (think /proc/gpio)
> 
> Once these pieces are pulled out, we can relocate the cmd_gpio.c into the
> common directory.
> 
> Signed-off-by: Mike Frysinger <[email protected]>
Tested-by: Andreas Pretzsch <[email protected]>

Verified on Blackfin BF561 with full port range.


> --- a/arch/blackfin/include/asm/gpio.h
> +++ b/arch/blackfin/include/asm/gpio.h
> @@ -196,6 +196,59 @@ static inline int gpio_is_valid(int number)
>       return number >= 0 && number < MAX_BLACKFIN_GPIOS;
>  }
>  
> +#include <linux/ctype.h>
> +
> +static inline int name_to_gpio(const char *name)
> +{
> +     int port_base;
> +
> +     if (tolower(*name) == 'p') {
> +             ++name;
> +
> +             switch (tolower(*name)) {
> +#ifdef GPIO_PA0
> +             case 'a': port_base = GPIO_PA0; break;
> +#endif
> +#ifdef GPIO_PB0
> +             case 'b': port_base = GPIO_PB0; break;
> +#endif
> +#ifdef GPIO_PC0
> +             case 'c': port_base = GPIO_PC0; break;
> +#endif
> +#ifdef GPIO_PD0
> +             case 'd': port_base = GPIO_PD0; break;
> +#endif
> +#ifdef GPIO_PE0
> +             case 'e': port_base = GPIO_PE0; break;
> +#endif
> +#ifdef GPIO_PF0
> +             case 'f': port_base = GPIO_PF0; break;
> +#endif
> +#ifdef GPIO_PG0
> +             case 'g': port_base = GPIO_PG0; break;
> +#endif
> +#ifdef GPIO_PH0
> +             case 'h': port_base = GPIO_PH0; break;
> +#endif
> +#ifdef GPIO_PI0
> +             case 'i': port_base = GPIO_PI0; break;
> +#endif
> +#ifdef GPIO_PJ
> +             case 'j': port_base = GPIO_PJ0; break;
> +#endif
> +             default:  return -1;
> +             }
> +
> +             ++name;
> +     } else
> +             port_base = 0;
> +
> +     return port_base + simple_strtoul(name, NULL, 10);

Remark: Leads to an oom access when exceeding the processor number of
GPIOs, e.g. PF48 on a BF561. IMHO, no problem but only a cosmetic issue,
not worth adding an additional per-cpu check.
In the end, no difference to other user errors like an invalid memory
address.


-- 

carpe noctem engineering
Ingenieurbuero fuer Hard- & Software-Entwicklung Andreas Pretzsch
Dipl.-Ing. (FH) Andreas Pretzsch          Tel. +49-(0)731-5521572
Hahnengasse 3                             Fax: +49-(0)731-5521573
89073 Ulm, Germany                        email: [email protected]

_______________________________________________
U-Boot mailing list
[email protected]
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to