All of lore.kernel.org
 help / color / mirror / Atom feed
From: Felipe Balbi <felipe.balbi@nokia.com>
To: ext David Brownell <david-b@pacbell.net>
Cc: "Balbi Felipe (Nokia-D/Helsinki)" <felipe.balbi@nokia.com>,
	Mark Brown <broonie@opensource.wolfsonmicro.com>,
	Linux OMAP Mailing List <linux-omap@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Tony Lindgren <tony@atomide.com>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH 1/5] gpiolib: introduce set_debounce method
Date: Fri, 21 May 2010 09:49:25 +0300	[thread overview]
Message-ID: <20100521064925.GF925@nokia.com> (raw)
In-Reply-To: <598314.1671.qm@web180305.mail.gq1.yahoo.com>

On Fri, May 21, 2010 at 12:50:41AM +0200, ext David Brownell wrote:
>
>> 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.
>
>True.
>
>Not all GPIOs have hardware debounce though, so offering this
>capability sort of begs the question of where/how to provide a
>software debounce mechanism too...

how about adding a flag for supported features and if that hardware 
doesn't support we simply return, or fallback to software emulation if 
chosen by the user. Something like the feature flags for the i2c bus 
drivers.

I mean something like:

diff --git a/arch/arm/plat-omap/gpio.c b/arch/arm/plat-omap/gpio.c
index 95f92b0..ae03f6f 100644
--- a/arch/arm/plat-omap/gpio.c
+++ b/arch/arm/plat-omap/gpio.c
@@ -1855,6 +1855,7 @@ static int __init _omap_gpio_init(void)
                 bank->chip.get = gpio_get;
                 bank->chip.direction_output = gpio_output;
                 bank->chip.set_debounce = gpio_debounce;
+               bank->chip->flags = GPIO_FLAG_DEBOUNCE;
                 bank->chip.set = gpio_set;
                 bank->chip.to_irq = gpio_2irq;
                 if (bank_is_mpuio(bank)) {
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index cd85fd1..ed1ed74 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1461,9 +1461,14 @@ int gpio_set_debounce(unsigned gpio, unsigned debounce)
  
         spin_lock_irqsave(&gpio_lock, flags);
  
+       chip = desc->chip;
+       if (!(chip->flags & GPIO_FLAG_DEBOUNCE)) {
+               spin_unlock_irqrestore(&gpio_lock, flags);
+               return 0;
+       }
+
         if (!gpio_is_valid(gpio))
                 goto fail;
-       chip = desc->chip;
         if (!chip || !chip->set || !chip->set_debounce)
                 goto fail;
         gpio -= chip->base;
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index ce3eb87..26c0aa2 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -32,6 +32,8 @@ struct device;
  struct seq_file;
  struct module;
  
+#define GPIO_FLAG_DEBOUNCE     (1 << 0)
+
  /**
   * struct gpio_chip - abstract a GPIO controller
   * @label: for diagnostics
@@ -61,6 +63,7 @@ struct module;
   *      names for the GPIOs in this chip. Any entry in the array
   *      may be NULL if there is no alias for the GPIO, however the
   *      array must be @ngpio entries long.
+ * @flags: a bitmap for supported features by that particular gpio chip.
   *
   * A gpio_chip can help platforms abstract various sources of GPIOs so
   * they can all be accessed through a common programing interface.
@@ -104,6 +107,7 @@ struct gpio_chip {
         char                    **names;
         unsigned                can_sleep:1;
         unsigned                exported:1;
+       unsigned                flags;
  };
  
  extern const char *gpiochip_is_requested(struct gpio_chip *chip,

that could be used later for adding debounce emulation for chips that 
doesn't support hw debouncing.

-- 
balbi

DefectiveByDesign.org

  reply	other threads:[~2010-05-21  6:53 UTC|newest]

Thread overview: 28+ 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 ` [PATCH 1/5] gpiolib: introduce set_debounce method felipe.balbi
2010-05-20 18:06   ` 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-20 22:50       ` David Brownell
2010-05-21  6:49       ` Felipe Balbi [this message]
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 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=20100521064925.GF925@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.