From patchwork Sat Jun 26 17:33:56 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grazvydas Ignotas X-Patchwork-Id: 108216 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o5QHYCxx012244 for ; Sat, 26 Jun 2010 17:34:12 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753515Ab0FZReI (ORCPT ); Sat, 26 Jun 2010 13:34:08 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:61128 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753395Ab0FZReG (ORCPT ); Sat, 26 Jun 2010 13:34:06 -0400 Received: by wyb38 with SMTP id 38so886884wyb.19 for ; Sat, 26 Jun 2010 10:34:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer; bh=qHzq3Dmm+ge24moI8e38uXPHKuqfLl7/kmJ42WfC3wA=; b=ZDEPM3XxiMF49tXCgBl6lU5uxtaZ+MuBkeEdQ/XH90tN9NJQS+8F74siBWlFagoqvL KRdYWeW7/ts05Puu32PWSi8wAUQA0YWK8zZcC9u1Yp5u8ok8PvTA9w54ZB3n4HuSisqf iJ/f/elhhsmZc619Sc1vYoRGfny7Xdaosl0QM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=idbHd/uJoZW+NiTrbKEy5CRZFxvx1U0TIXWQTU2linNaJUlSSKekFJDQQjOCjEJqYh P7gyx5y0bGrQ1A9gU0ruRqJPA4po9ayOc+mRV9qMuzh71pEKB5uh3fMV+WQCwj9g/TGw FNZCFu4aVt++rhnqr80ry3brMxdi1YdP3sdiM= Received: by 10.227.127.193 with SMTP id h1mr1921596wbs.15.1277573640873; Sat, 26 Jun 2010 10:34:00 -0700 (PDT) Received: from localhost.localdomain (ip-88-119-226-136.static.b4net.lt [88.119.226.136]) by mx.google.com with ESMTPS id w21sm3539824weq.45.2010.06.26.10.33.59 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 26 Jun 2010 10:34:00 -0700 (PDT) From: Grazvydas Ignotas To: linux-input@vger.kernel.org Cc: Dmitry Torokhov , Felipe Balbi , Grazvydas Ignotas Subject: [PATCH] Input: gpio-keys - add gpiolib debounce support Date: Sat, 26 Jun 2010 20:33:56 +0300 Message-Id: <1277573636-10345-1-git-send-email-notasas@gmail.com> X-Mailer: git-send-email 1.6.3.3 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Sat, 26 Jun 2010 17:34:40 +0000 (UTC) diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index b8213fd..a9fd147 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -31,6 +31,7 @@ struct gpio_button_data { struct input_dev *input; struct timer_list timer; struct work_struct work; + int timer_debounce; /* in msecs */ bool disabled; }; @@ -109,7 +110,7 @@ static void gpio_keys_disable_button(struct gpio_button_data *bdata) * Disable IRQ and possible debouncing timer. */ disable_irq(gpio_to_irq(bdata->button->gpio)); - if (bdata->button->debounce_interval) + if (bdata->timer_debounce) del_timer_sync(&bdata->timer); bdata->disabled = true; @@ -347,9 +348,9 @@ static irqreturn_t gpio_keys_isr(int irq, void *dev_id) BUG_ON(irq != gpio_to_irq(button->gpio)); - if (button->debounce_interval) + if (bdata->timer_debounce) mod_timer(&bdata->timer, - jiffies + msecs_to_jiffies(button->debounce_interval)); + jiffies + msecs_to_jiffies(bdata->timer_debounce)); else schedule_work(&bdata->work); @@ -383,6 +384,14 @@ static int __devinit gpio_keys_setup_key(struct platform_device *pdev, goto fail3; } + if (button->debounce_interval) { + error = gpio_set_debounce(button->gpio, + button->debounce_interval * 1000); + /* use timer if gpiolib doesn't provide debounce */ + if (error < 0) + bdata->timer_debounce = button->debounce_interval; + } + irq = gpio_to_irq(button->gpio); if (irq < 0) { error = irq; @@ -498,7 +507,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev) fail2: while (--i >= 0) { free_irq(gpio_to_irq(pdata->buttons[i].gpio), &ddata->data[i]); - if (pdata->buttons[i].debounce_interval) + if (ddata->data[i].timer_debounce) del_timer_sync(&ddata->data[i].timer); cancel_work_sync(&ddata->data[i].work); gpio_free(pdata->buttons[i].gpio); @@ -526,7 +535,7 @@ static int __devexit gpio_keys_remove(struct platform_device *pdev) for (i = 0; i < pdata->nbuttons; i++) { int irq = gpio_to_irq(pdata->buttons[i].gpio); free_irq(irq, &ddata->data[i]); - if (pdata->buttons[i].debounce_interval) + if (ddata->data[i].timer_debounce) del_timer_sync(&ddata->data[i].timer); cancel_work_sync(&ddata->data[i].work); gpio_free(pdata->buttons[i].gpio);