Commit c4b5be98 authored by Felipe Balbi's avatar Felipe Balbi Committed by Linus Torvalds

gpiolib: introduce set_debounce method

A few architectures, like OMAP, allow you to set a debouncing time for the
gpio before generating the IRQ.  Teach gpiolib about that.

Mark said:
: 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.

David said:
: I looked at adding debounce support to the generic GPIO calls (and thus
: gpiolib) some time back, but decided against it.  I forget why at this
: time (check list archives) but it wasn't because of lack of utility in
: certain contexts.
:
: One thing to watch out for is just how variable the hardware capabilities
: are.  Atmel GPIOs have something like a fixed number of 32K clock cycles
: for debounce, twl4030 had something odd, OMAPs were more like the Atmel
: chips but with a different clock.  In some cases debouncing had to be
: ganged, not per-GPIO.  And so forth.
Signed-off-by: default avatarFelipe Balbi <felipe.balbi@nokia.com>
Cc: Tony Lindgren <tony@atomide.com>
Cc: David Brownell <david-b@pacbell.net>
Reviewed-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 796a8e42
...@@ -1447,6 +1447,49 @@ int gpio_direction_output(unsigned gpio, int value) ...@@ -1447,6 +1447,49 @@ int gpio_direction_output(unsigned gpio, int value)
} }
EXPORT_SYMBOL_GPL(gpio_direction_output); 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);
/* I/O calls are only valid after configuration completed; the relevant /* I/O calls are only valid after configuration completed; the relevant
* "is this a valid GPIO" error checks should already have been done. * "is this a valid GPIO" error checks should already have been done.
......
...@@ -90,6 +90,9 @@ struct gpio_chip { ...@@ -90,6 +90,9 @@ struct gpio_chip {
unsigned offset); unsigned offset);
int (*direction_output)(struct gpio_chip *chip, int (*direction_output)(struct gpio_chip *chip,
unsigned offset, int value); unsigned offset, int value);
int (*set_debounce)(struct gpio_chip *chip,
unsigned offset, unsigned debounce);
void (*set)(struct gpio_chip *chip, void (*set)(struct gpio_chip *chip,
unsigned offset, int value); unsigned offset, int value);
...@@ -123,6 +126,8 @@ extern void gpio_free(unsigned gpio); ...@@ -123,6 +126,8 @@ extern void gpio_free(unsigned gpio);
extern int gpio_direction_input(unsigned gpio); extern int gpio_direction_input(unsigned gpio);
extern int gpio_direction_output(unsigned gpio, int value); extern int gpio_direction_output(unsigned gpio, int value);
extern int gpio_set_debounce(unsigned gpio, unsigned debounce);
extern int gpio_get_value_cansleep(unsigned gpio); extern int gpio_get_value_cansleep(unsigned gpio);
extern void gpio_set_value_cansleep(unsigned gpio, int value); extern void gpio_set_value_cansleep(unsigned gpio, int value);
......
...@@ -51,6 +51,11 @@ static inline int gpio_direction_output(unsigned gpio, int value) ...@@ -51,6 +51,11 @@ static inline int gpio_direction_output(unsigned gpio, int value)
return -ENOSYS; return -ENOSYS;
} }
static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
{
return -ENOSYS;
}
static inline int gpio_get_value(unsigned gpio) static inline int gpio_get_value(unsigned gpio)
{ {
/* GPIO can never have been requested or set as {in,out}put */ /* GPIO can never have been requested or set as {in,out}put */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment