From: felipe.balbi@nokia.com
To: Linux OMAP Mailing List <linux-omap@vger.kernel.org>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Tony Lindgren <tony@atomide.com>,
David Brownell <david-b@pacbell.net>,
Andrew Morton <akpm@linux-foundation.org>,
Mark Brown <broonie@opensource.wolfsonmicro.com>,
Felipe Balbi <felipe.balbi@nokia.com>
Subject: [PATCH 1/5] gpiolib: introduce set_debounce method
Date: Mon, 17 May 2010 13:02:30 +0300 [thread overview]
Message-ID: <1274090554-19420-2-git-send-email-felipe.balbi@nokia.com> (raw)
In-Reply-To: <1274090554-19420-1-git-send-email-felipe.balbi@nokia.com>
From: Felipe Balbi <felipe.balbi@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@nokia.com>
---
drivers/gpio/gpiolib.c | 43 +++++++++++++++++++++++++++++++++++++++++++
include/asm-generic/gpio.h | 5 +++++
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 eb0c3fe..cd85fd1 100644
--- 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);
/* I/O calls are only valid after configuration completed; the relevant
* "is this a valid GPIO" error checks should already have been done.
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index 979c6a5..ce3eb87 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -88,6 +88,9 @@ struct gpio_chip {
unsigned offset);
int (*direction_output)(struct gpio_chip *chip,
unsigned offset, int value);
+ int (*set_debounce)(struct gpio_chip *chip,
+ unsigned offset, unsigned debounce);
+
void (*set)(struct gpio_chip *chip,
unsigned offset, int value);
@@ -121,6 +124,8 @@ extern void gpio_free(unsigned gpio);
extern int gpio_direction_input(unsigned gpio);
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 void gpio_set_value_cansleep(unsigned gpio, int value);
diff --git a/include/linux/gpio.h b/include/linux/gpio.h
index 4e949a5..03f616b 100644
--- a/include/linux/gpio.h
+++ b/include/linux/gpio.h
@@ -51,6 +51,11 @@ static inline int gpio_direction_output(unsigned gpio, int value)
return -ENOSYS;
}
+static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
+{
+ return -ENOSYS;
+}
+
static inline int gpio_get_value(unsigned gpio)
{
/* GPIO can never have been requested or set as {in,out}put */
--
1.7.1
next prev parent reply other threads:[~2010-05-17 10:05 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-17 10:02 [PATCH 0/6] teach gpiolib about gpio debouncing felipe.balbi
2010-05-17 10:02 ` felipe.balbi [this message]
2010-05-20 18:06 ` [PATCH 1/5] gpiolib: introduce set_debounce method Andrew Morton
2010-05-20 18:52 ` Felipe Balbi
2010-05-20 19:04 ` Alan Cox
2010-05-20 19:16 ` Andrew Morton
2010-05-20 20:51 ` Alan Cox
2010-05-20 19:45 ` Mark Brown
2010-05-20 22:50 ` David Brownell
2010-05-21 6:49 ` Felipe Balbi
2010-05-21 10:11 ` Alan Cox
2010-05-21 13:14 ` David Brownell
2010-05-21 13:34 ` Alan Cox
2010-05-21 13:23 ` David Brownell
2010-05-21 10:05 ` Alan Cox
2010-05-17 10:02 ` [PATCH 2/5] arm: omap: gpio: implement " felipe.balbi
2010-05-17 10:02 ` [PATCH 3/5] arm: omap: switch over to gpio_set_debounce felipe.balbi
2010-06-16 17:26 ` Grazvydas Ignotas
2010-06-17 4:45 ` Felipe Balbi
2010-06-20 17:03 ` Grazvydas Ignotas
2010-06-20 21:12 ` Felipe Balbi
2010-05-17 10:02 ` [PATCH 4/5] arm: omap: remove the unused omap_gpio_set_debounce methods felipe.balbi
2010-05-17 10:02 ` [PATCH 5/5] arm: omap: move all gpio defines to plat/gpio.h felipe.balbi
2010-05-17 10:08 ` Felipe Balbi
2010-05-20 18:04 ` [PATCH 0/6] teach gpiolib about gpio debouncing Andrew Morton
2010-05-20 18:55 ` Felipe Balbi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1274090554-19420-2-git-send-email-felipe.balbi@nokia.com \
--to=felipe.balbi@nokia.com \
--cc=akpm@linux-foundation.org \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=david-b@pacbell.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=tony@atomide.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).