From: Andrew Morton on
On Mon, 17 May 2010 13:02:30 +0300
felipe.balbi(a)nokia.com wrote:

> From: Felipe Balbi <felipe.balbi(a)nokia.com>
>
> Few architectures, like OMAP, allow you to set
> a debouncing time for the gpio before generating
> the IRQ. Teach gpiolib about that.
>
> ...
>
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -1447,6 +1447,49 @@ fail:
> }
> EXPORT_SYMBOL_GPL(gpio_direction_output);
>
> +/**
> + * gpio_set_debounce - sets @debounce time for a @gpio
> + * @gpio: the gpio to set debounce time
> + * @debounce: debounce time is microseconds
> + */
> +int gpio_set_debounce(unsigned gpio, unsigned debounce)
> +{
> + 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 || !chip->set_debounce)
> + 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(extra_checks && chip->can_sleep);
> +
> + return chip->set_debounce(chip, gpio, debounce);
> +
> +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_debounce);

nitlet: I suspect this function is taking gpio_lock sooner than it
strictly needs to. Find-tuning that would decrease contention by an
insignificant amount ;)

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Felipe Balbi on
Hi,

On Thu, May 20, 2010 at 11:06:00AM -0700, Andrew Morton wrote:
> nitlet: I suspect this function is taking gpio_lock sooner than it
> strictly needs to. Find-tuning that would decrease contention by an
> insignificant amount ;)

heh, I can post another version if you like, but this is pretty much
what other functions are doing, just following the 'standard'.

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

> > +EXPORT_SYMBOL_GPL(gpio_set_debounce);
>
> nitlet: I suspect this function is taking gpio_lock sooner than it
> strictly needs to. Find-tuning that would decrease contention by an
> insignificant amount ;)

We need this for Intel MID boxes as well Andrew - so its a generic need.

Alan

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Andrew Morton on
On Thu, 20 May 2010 20:04:17 +0100
Alan Cox <alan(a)lxorguk.ukuu.org.uk> wrote:

>
> > > +EXPORT_SYMBOL_GPL(gpio_set_debounce);
> >
> > nitlet: I suspect this function is taking gpio_lock sooner than it
> > strictly needs to. Find-tuning that would decrease contention by an
> > insignificant amount ;)
>
> We need this for Intel MID boxes as well Andrew - so its a generic need.
>

Thanks.

I'm still wobbling on the 35-vs-36 line. Is that a big need or a
little need? What user-visible problem does it solve, etc?

Did anyone test it on the MID boxes?

etc ;)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Mark Brown on
On Mon, May 17, 2010 at 01:02:30PM +0300, felipe.balbi(a)nokia.com wrote:
> From: Felipe Balbi <felipe.balbi(a)nokia.com>
>
> Few architectures, like OMAP, allow you to set
> a debouncing time for the gpio before generating
> the IRQ. Teach gpiolib about that.
>
> Signed-off-by: Felipe Balbi <felipe.balbi(a)nokia.com>

Reviewed-by: Mark Brown <broonie(a)opensource.wolfsonmicro.com>

This would be generally useful for embedded systems, especially where
the interrupt concerned is a wake source. It allows drivers to avoid
spurious interrupts from noisy sources so if the hardware supports it
the driver can avoid having to explicitly wait for the signal to become
stable and software has to cope with fewer events. We've lived without
it for quite some time, though.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/