From patchwork Wed Mar 8 08:54:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 9610615 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D3B936046A for ; Wed, 8 Mar 2017 09:04:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C81582026B for ; Wed, 8 Mar 2017 09:04:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BCA43284CB; Wed, 8 Mar 2017 09:04:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 53DA02026B for ; Wed, 8 Mar 2017 09:04:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751902AbdCHJES (ORCPT ); Wed, 8 Mar 2017 04:04:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36740 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751603AbdCHJEQ (ORCPT ); Wed, 8 Mar 2017 04:04:16 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8052264DA3; Wed, 8 Mar 2017 08:54:21 +0000 (UTC) Received: from shalem.localdomain.com (ovpn-116-110.ams2.redhat.com [10.36.116.110]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v288sFGQ001390; Wed, 8 Mar 2017 03:54:20 -0500 From: Hans de Goede To: Dmitry Torokhov Cc: Hans de Goede , linux-input@vger.kernel.org Subject: [PATCH resend 4/4] Input: gpio_keys - Do not report wake button presses as evdev events Date: Wed, 8 Mar 2017 09:54:13 +0100 Message-Id: <20170308085413.5185-5-hdegoede@redhat.com> In-Reply-To: <20170308085413.5185-1-hdegoede@redhat.com> References: <20170308085413.5185-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 08 Mar 2017 08:54:21 +0000 (UTC) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If a button is a wake button, it may still be bouncing from the press to wakeup the device by the time the gpio interrupts get enabled again and / or the gpio_keys_report_state call from gpio_keys_resume may find the button still pressed and report this as a new press. This is undesirable, esp. since the powerbutton on tablets is typically a wakeup source and uses the gpio_keys driver on some tablets, leading to userspace immediately re-suspending the tablet after the powerbutton is pressed, due to it seeing a powerbutton press. This commit ignores wakeup button presses for the first 1 second after resume (and while resumed, as the workqueue may run before the resume function runs), avoiding this problem. Signed-off-by: Hans de Goede --- Note: maybe we should make WAKE_DEBOUNCE part of gpio_keys_button and only do this when drivers / platform-data set this to a non-zero value ? --- drivers/input/keyboard/gpio_keys.c | 49 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index da3d362..e1488b5 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -31,6 +31,8 @@ #include #include +#define WAKE_DEBOUNCE msecs_to_jiffies(1000) + struct gpio_button_data { const struct gpio_keys_button *button; struct input_dev *input; @@ -44,10 +46,14 @@ struct gpio_button_data { struct delayed_work work; unsigned int software_debounce; /* in msecs, for GPIO-driven buttons */ + unsigned long resume_time; /* in jiffies, for wakeup buttons */ + unsigned int irq; spinlock_t lock; bool disabled; bool key_pressed; + bool suspended; + bool resume_time_valid; }; struct gpio_keys_drvdata { @@ -356,6 +362,27 @@ static struct attribute_group gpio_keys_attr_group = { .attrs = gpio_keys_attrs, }; +static bool gpio_keys_ignore_wakeup_button_press(struct gpio_button_data *bdata) +{ + unsigned long flags; + bool ret = false; + + if (!bdata->button->wakeup) + return ret; + + spin_lock_irqsave(&bdata->lock, flags); + + if (bdata->suspended) + ret = true; /* Our resume method did not run yet */ + else if (bdata->resume_time_valid && + time_before(jiffies, bdata->resume_time + WAKE_DEBOUNCE)) + ret = true; /* Assume this is a wakeup press and ignore */ + + spin_unlock_irqrestore(&bdata->lock, flags); + + return ret; +} + static void gpio_keys_gpio_report_event(struct gpio_button_data *bdata) { const struct gpio_keys_button *button = bdata->button; @@ -370,6 +397,9 @@ static void gpio_keys_gpio_report_event(struct gpio_button_data *bdata) return; } + if (state && gpio_keys_ignore_wakeup_button_press(bdata)) + return; + if (type == EV_ABS) { if (state) input_event(input, type, button->code, button->value); @@ -429,6 +459,9 @@ static irqreturn_t gpio_keys_irq_isr(int irq, void *dev_id) BUG_ON(irq != bdata->irq); + if (gpio_keys_ignore_wakeup_button_press(bdata)) + return IRQ_HANDLED; + spin_lock_irqsave(&bdata->lock, flags); if (!bdata->key_pressed) { @@ -848,13 +881,18 @@ static int __maybe_unused gpio_keys_suspend(struct device *dev) { struct gpio_keys_drvdata *ddata = dev_get_drvdata(dev); struct input_dev *input = ddata->input; + unsigned long flags; int i; if (device_may_wakeup(dev)) { for (i = 0; i < ddata->pdata->nbuttons; i++) { struct gpio_button_data *bdata = &ddata->data[i]; - if (bdata->button->wakeup) + if (bdata->button->wakeup) { + spin_lock_irqsave(&bdata->lock, flags); + bdata->suspended = true; + spin_unlock_irqrestore(&bdata->lock, flags); enable_irq_wake(bdata->irq); + } } } else { mutex_lock(&input->mutex); @@ -870,14 +908,21 @@ static int __maybe_unused gpio_keys_resume(struct device *dev) { struct gpio_keys_drvdata *ddata = dev_get_drvdata(dev); struct input_dev *input = ddata->input; + unsigned long flags; int error = 0; int i; if (device_may_wakeup(dev)) { for (i = 0; i < ddata->pdata->nbuttons; i++) { struct gpio_button_data *bdata = &ddata->data[i]; - if (bdata->button->wakeup) + if (bdata->button->wakeup) { disable_irq_wake(bdata->irq); + spin_lock_irqsave(&bdata->lock, flags); + bdata->resume_time = jiffies; + bdata->resume_time_valid = true; + bdata->suspended = false; + spin_unlock_irqrestore(&bdata->lock, flags); + } } } else { mutex_lock(&input->mutex);