[U-Boot] [PATCH] nios2: add gpio_is_valid

Thomas Chou thomas at wytron.com.tw
Mon Dec 27 15:51:10 CET 2010


On 12/27/2010 07:35 PM, Sergei Shtylyov wrote:
> Hello.
>
> On 27-12-2010 5:46, Thomas Chou wrote:
>
>> Signed-off-by: Thomas Chou<thomas at wytron.com.tw>
> [...]
>
>> diff --git a/arch/nios2/include/asm/gpio.h
>> b/arch/nios2/include/asm/gpio.h
>> index 36a7132..4b21c8f 100644
>> --- a/arch/nios2/include/asm/gpio.h
>> +++ b/arch/nios2/include/asm/gpio.h
>> @@ -52,6 +52,11 @@ static inline void gpio_set_value(unsigned gpio,
>> int value)
>> {
>> writel(value ? 3 : 2, CONFIG_SYS_GPIO_BASE + (gpio<< 2));
>> }
>> +
>> +static inline int gpio_is_valid(int number)
>> +{
>> + return ((unsigned)number) < CONFIG_SYS_GPIO_WIDTH;
>
> No need to have parens around '(unsigned)number'.
>
>> diff --git a/board/altera/nios2-generic/gpio.c
>> b/board/altera/nios2-generic/gpio.c
>> index 8c639ce..4a30564 100644
>> --- a/board/altera/nios2-generic/gpio.c
>> +++ b/board/altera/nios2-generic/gpio.c
> [...]
>> @@ -62,4 +63,9 @@ void gpio_set_value(unsigned gpio, int value)
>> pio_data_reg&= ~mask;
>> writel(pio_data_reg, ALTERA_PIO_DATA);
>> }
>> +
>> +int gpio_is_valid(int number)
>> +{
>> + return ((unsigned)number) < ALTERA_PIO_WIDTH;
>
> Same here...
>
> WBR, Sergei
>

Hi Sergei,

The casting is needed as the arg is type int, and we might use -1 to 
indicate no-such-gpio as they come from linux asm-generic/gpio.h.

Best regards,
Thomas

/*
  * "valid" GPIO numbers are nonnegative and may be passed to
  * setup routines like gpio_request().  only some valid numbers
  * can successfully be requested and used.
  *
  * Invalid GPIO numbers are useful for indicating no-such-GPIO in
  * platform data and other tables.
  */

static inline int gpio_is_valid(int number)
{
	return ((unsigned)number) < ARCH_NR_GPIOS;
}



More information about the U-Boot mailing list