mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: linux-kernel@vger.kernel.org
Cc: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>,
	Nicolas Ferre <nicolas.ferre@atmel.com>,
	Grant Likely <grant.likely@secretlab.ca>
Subject: [PATCH 2/2] gpiolib: introduce gpio_set_deglitch
Date: Fri, 25 Nov 2011 15:08:40 +0100	[thread overview]
Message-ID: <1322230120-14120-2-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <1322230120-14120-1-git-send-email-plagnioj@jcrosoft.com>

this will allow to manage the Glitch Input Filter
as present on AT91 as example

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: Grant Likely <grant.likely@secretlab.ca>
---
 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 b7e5e75..d2b1833 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1563,6 +1563,50 @@ fail:
 }
 EXPORT_SYMBOL_GPL(gpio_set_pullup);
 
+/**
+ * gpio_set_deglitch - sets @deglitch for a @gpio
+ * @gpio: the gpio to set deglitch
+ * @deglitch: deglitch level
+ */
+int gpio_set_deglitch(unsigned gpio, unsigned deglitch)
+{
+	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_deglitch)
+		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_deglitch(chip, gpio, deglitch);
+
+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_deglitch);
+
 /* 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 085ef16..20a9786 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -110,6 +110,9 @@ struct gpio_chip {
 	int			(*set_pullup)(struct gpio_chip *chip,
 						unsigned offset, unsigned pullup);
 
+	int			(*set_deglitch)(struct gpio_chip *chip,
+						unsigned offset, unsigned deglitch);
+
 	void			(*set)(struct gpio_chip *chip,
 						unsigned offset, int value);
 
@@ -159,6 +162,7 @@ extern int gpio_direction_output(unsigned gpio, int value);
 
 extern int gpio_set_debounce(unsigned gpio, unsigned debounce);
 extern int gpio_set_pullup(unsigned gpio, unsigned pullup);
+extern int gpio_set_deglitch(unsigned gpio, unsigned deglitch);
 
 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 5c786e7..bfbc3d7 100644
--- a/include/linux/gpio.h
+++ b/include/linux/gpio.h
@@ -95,6 +95,11 @@ static inline int gpio_set_pullup(unsigned gpio, unsigned pullup)
 	return -ENOSYS;
 }
 
+static inline int gpio_set_deglitch(unsigned gpio, unsigned deglitch)
+{
+	return -ENOSYS;
+}
+
 static inline int gpio_get_value(unsigned gpio)
 {
 	/* GPIO can never have been requested or set as {in,out}put */
-- 
1.7.7


  reply	other threads:[~2011-11-25 14:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-25 14:08 [PATCH 1/2] gpiolib: introduce gpio_set_pullup Jean-Christophe PLAGNIOL-VILLARD
2011-11-25 14:08 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2011-11-25 14:14   ` [PATCH 2/2] gpiolib: introduce gpio_set_deglitch Felipe Balbi
2011-11-25 15:00     ` Jean-Christophe PLAGNIOL-VILLARD
2011-11-25 14:16 ` [PATCH 1/2] gpiolib: introduce gpio_set_pullup Felipe Balbi
2011-11-25 14:23   ` Jean-Christophe PLAGNIOL-VILLARD
2011-11-25 14:59     ` Felipe Balbi
2011-11-25 15:34 ` Mark Brown
2011-11-27  9:35   ` Igor Grinberg
2011-11-29  2:37     ` Jean-Christophe PLAGNIOL-VILLARD
2011-11-29 16:51       ` Stephen Warren
2011-12-05 15:40         ` Jean-Christophe PLAGNIOL-VILLARD
2011-12-05 15:56           ` Mark Brown

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=1322230120-14120-2-git-send-email-plagnioj@jcrosoft.com \
    --to=plagnioj@jcrosoft.com \
    --cc=grant.likely@secretlab.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicolas.ferre@atmel.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

all inboxes | Powered by JetHome®