Re: [PATCH 1/2] gpiolib: introduce gpio_set_pullup

From: Felipe Balbi
Date: Fri Nov 25 2011 - 09:16:45 EST


Hi,

On Fri, Nov 25, 2011 at 03:08:39PM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@xxxxxxxxxxxx>
> Cc: Nicolas Ferre <nicolas.ferre@xxxxxxxxx>
> Cc: Grant Likely <grant.likely@xxxxxxxxxxxx>
> ---
> drivers/gpio/gpiolib.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
> include/asm-generic/gpio.h | 4 ++++
> include/linux/gpio.h | 5 +++++
> 3 files changed, 53 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index a971e3d..b7e5e75 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -1519,6 +1519,50 @@ fail:
> }
> EXPORT_SYMBOL_GPL(gpio_set_debounce);
>
> +/**
> + * gpio_set_pullup - sets @pullup for a @gpio
> + * @gpio: the gpio to set pullup
> + * @pullup: pullup level
> + */
> +int gpio_set_pullup(unsigned gpio, unsigned pullup)
> +{
> + unsigned long flags;
> + struct gpio_chip *chip;
> + struct gpio_desc *desc = &gpio_desc[gpio];
> + int status = -EINVAL;
> +
> + spin_lock_irqsave(&gpio_lock, flags);
> +
> + if (!gpio_is_valid(gpio))
> + goto fail;
> + chip = desc->chip;
> + if (!chip || !chip->set_pullup)
> + goto fail;
> + gpio -= chip->base;
> + if (gpio >= chip->ngpio)
> + goto fail;
> + status = gpio_ensure_requested(desc, gpio);
> + if (status < 0)
> + goto fail;
> +
> + /* now we know the gpio is valid and chip won't vanish */
> +
> + spin_unlock_irqrestore(&gpio_lock, flags);
> +
> + might_sleep_if(chip->can_sleep);
> +
> + return chip->set_pullup(chip, gpio, pullup);
> +
> +fail:
> + spin_unlock_irqrestore(&gpio_lock, flags);
> + if (status)
> + pr_debug("%s: gpio-%d status %d\n",
> + __func__, gpio, status);
> +
> + return status;
> +}
> +EXPORT_SYMBOL_GPL(gpio_set_pullup);

Maybe I'm missing something, but isn't it essentially what
gpio_set_value() does ? I mean, you set a pullup and you get '1' value
and set a pulldown and you get a '0' value ??

Without a proper description of the necessity for this change, I can't
easily tell them apart :-(

--
balbi

Attachment: signature.asc
Description: Digital signature