[PATCH] Give gpiolib an implementation of gpio_is_valid() - Kernel

This is a discussion on [PATCH] Give gpiolib an implementation of gpio_is_valid() - Kernel ; Platforms which use generic (NOP) gpio routines get an implementation of gpio_is_valid() (in linux/gpio.h) but the people who actually use gpio don't get one. Roll an implementation for gpiolib based on gpio_request(); this ought to do for most people. Signed-off-by: ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: [PATCH] Give gpiolib an implementation of gpio_is_valid()

  1. [PATCH] Give gpiolib an implementation of gpio_is_valid()


    Platforms which use generic (NOP) gpio routines get an implementation of
    gpio_is_valid() (in linux/gpio.h) but the people who actually use gpio
    don't get one. Roll an implementation for gpiolib based on
    gpio_request(); this ought to do for most people.

    Signed-off-by: Ben Nizette
    ---
    diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
    index d8db2f8..137688c 100644
    --- a/drivers/gpio/gpiolib.c
    +++ b/drivers/gpio/gpiolib.c
    @@ -158,6 +158,34 @@ int gpiochip_remove(struct gpio_chip *chip)
    }
    EXPORT_SYMBOL_GPL(gpiochip_remove);

    +/**
    + * gpio_is_valid() - check if a gpio number actually corresponds to a gpio
    + * @number: the gpio number to test
    + *
    + * Returns 1 if the gpio is valid, 0 otherwise.
    + */
    +int gpio_is_valid(int number)
    +{
    + struct gpio_desc *desc;
    + int ret = 0;
    + unsigned long flags;
    +
    + spin_lock_irqsave(&gpio_lock, flags);
    +
    + if (number >= ARCH_NR_GPIOS)
    + goto done;
    +
    + desc = &gpio_desc[number];
    + if (desc->chip == NULL)
    + goto done;
    +
    + ret = 1;
    +
    +done:
    + spin_unlock_irqrestore(&gpio_lock, flags);
    + return ret;
    +}
    +EXPORT_SYMBOL_GPL(gpio_is_valid);

    /* These "optional" allocation calls help prevent drivers from stomping
    * on each other, and help provide better diagnostics in debugfs.
    diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
    index f29a502..8c26523 100644
    --- a/include/asm-generic/gpio.h
    +++ b/include/asm-generic/gpio.h
    @@ -75,6 +75,8 @@ extern int __must_check gpiochip_remove(struct gpio_chip *chip);
    /* Always use the library code for GPIO management calls,
    * or when sleeping may be involved.
    */
    +extern int gpio_is_valid(int number);
    +
    extern int gpio_request(unsigned gpio, const char *label);
    extern void gpio_free(unsigned gpio);


    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  2. Re: [PATCH] Give gpiolib an implementation of gpio_is_valid()

    On Saturday 26 April 2008, Ben Nizette wrote:
    > Platforms which use generic (NOP) gpio routines get an implementation of
    > gpio_is_valid() (in linux/gpio.h) but the people who actually use gpio
    > don't get one. *Roll an implementation for gpiolib based on
    > gpio_request(); this ought to do for most people.


    There's already a gpio_is_valid() patch in the MM merge queue;
    it comes with the documentation, and covers implementations which
    include the header (for cansleep stubs) but
    don't use gpiolib.

    So, please wait till RC1, by which time I expect Andrew's queue
    will be relatively depleted.

    - Dave
    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  3. Re: [PATCH] Give gpiolib an implementation of gpio_is_valid()


    On Sat, 2008-04-26 at 09:12 -0700, David Brownell wrote:
    > On Saturday 26 April 2008, Ben Nizette wrote:
    > > Platforms which use generic (NOP) gpio routines get an implementation of
    > > gpio_is_valid() (in linux/gpio.h) but the people who actually use gpio
    > > don't get one. Roll an implementation for gpiolib based on
    > > gpio_request(); this ought to do for most people.

    >
    > There's already a gpio_is_valid() patch in the MM merge queue;
    > it comes with the documentation, and covers implementations which
    > include the header (for cansleep stubs) but
    > don't use gpiolib.
    >
    > So, please wait till RC1, by which time I expect Andrew's queue
    > will be relatively depleted.
    >

    Righteo, thanks and sorry for being impatient :-)

    --Ben.

    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

+ Reply to Thread