From patchwork Mon Oct 30 17:40:49 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: 10032961 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 4ED7760291 for ; Mon, 30 Oct 2017 17:41:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DD4E288B9 for ; Mon, 30 Oct 2017 17:41:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 32B5628915; Mon, 30 Oct 2017 17:41:02 +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 BC67B288B9 for ; Mon, 30 Oct 2017 17:41:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932724AbdJ3Rk7 (ORCPT ); Mon, 30 Oct 2017 13:40:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35496 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932673AbdJ3Rk5 (ORCPT ); Mon, 30 Oct 2017 13:40:57 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BE7477EA8E; Mon, 30 Oct 2017 17:40:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BE7477EA8E Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=hdegoede@redhat.com Received: from shalem.localdomain.com (ovpn-116-133.ams2.redhat.com [10.36.116.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id C9F0A600C9; Mon, 30 Oct 2017 17:40:56 +0000 (UTC) From: Hans de Goede To: Dmitry Torokhov , Benjamin Tissoires Cc: Hans de Goede , linux-input@vger.kernel.org Subject: [PATCH v3 3/4] Input: gpio_keys - Allow suppression of input events for wakeup button presses Date: Mon, 30 Oct 2017 18:40:49 +0100 Message-Id: <20171030174050.30375-3-hdegoede@redhat.com> In-Reply-To: <20171030174050.30375-1-hdegoede@redhat.com> References: <20171030174050.30375-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Oct 2017 17:40:57 +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 In some cases it is undesirable for a wakeup button to send input events to userspace if pressed to wakeup the system (if pressed during suspend). A typical example of this is the power-button on laptops / tablets, sending a KEY_POWER event to userspace when woken up with the power-button will cause userspace to immediately suspend the system again which is undesirable. For power-buttons attached to a PMIC, or handled by e.g. ACPI, not sending an input event in this case is take care of by the PMIC / ACPI hardware / code. But in the case of a GPIO button we need to explicitly suppress the sending of the input event. This commit supports this by adding a suppress_evdev_events_on_wakeup bool to struct gpio_keys_button, which platform code can set to suppress the input events for presses of wakeup keys during suspend. Signed-off-by: Hans de Goede --- Changes in v2: -This is a rewrite if my "Input: gpio_keys - Do not report wake button presses as evdev events" patch. -Instead of unconditionally ignoring presses of all wake-up buttons during suspend, this rewrite makes this configurable per button -This version uses a timer to delay clearing the suspended flag for software debouncing, rather then jiffy compare magic Changes in v3: -Get rid of the need to have a timer all-together -Rename the flag from no_wakeup_events to suppress_evdev_events_on_wakeup --- drivers/input/keyboard/gpio_keys.c | 13 +++++++++++++ include/linux/gpio_keys.h | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index 9b51aa56cc83..3beff91f1a4c 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -373,6 +373,10 @@ static void gpio_keys_gpio_report_event(struct gpio_button_data *bdata) return; } + if (bdata->button->suppress_evdev_events_on_wakeup && + bdata->ddata->suspended && state) + return; + if (type == EV_ABS) { if (state) input_event(input, type, button->code, button->value); @@ -400,6 +404,10 @@ static irqreturn_t gpio_keys_gpio_isr(int irq, void *dev_id) BUG_ON(irq != bdata->irq); + if (bdata->button->suppress_evdev_events_on_wakeup && + bdata->ddata->suspended) + return IRQ_HANDLED; + if (bdata->button->wakeup) { const struct gpio_keys_button *button = bdata->button; @@ -445,6 +453,10 @@ static irqreturn_t gpio_keys_irq_isr(int irq, void *dev_id) BUG_ON(irq != bdata->irq); + if (bdata->button->suppress_evdev_events_on_wakeup && + bdata->ddata->suspended) + return IRQ_HANDLED; + spin_lock_irqsave(&bdata->lock, flags); if (!bdata->key_pressed) { @@ -894,6 +906,7 @@ static int __maybe_unused gpio_keys_resume(struct device *dev) if (error) return error; + /* Sync state before clearing suspended, so it knows this is a resume */ gpio_keys_report_state(ddata); ddata->suspended = false; return 0; diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h index 0b71024c082c..e05fe0902358 100644 --- a/include/linux/gpio_keys.h +++ b/include/linux/gpio_keys.h @@ -15,6 +15,9 @@ struct device; * @debounce_interval: debounce ticks interval in msecs * @can_disable: %true indicates that userspace is allowed to * disable button via sysfs + * @suppress_evdev_events_on_wakeup: For wake-up source buttons only, if %true + * then no evdev-events will be generated if pressed while + * suspended * @value: axis value for %EV_ABS * @irq: Irq number in case of interrupt keys */ @@ -27,6 +30,7 @@ struct gpio_keys_button { int wakeup; int debounce_interval; bool can_disable; + bool suppress_evdev_events_on_wakeup; int value; unsigned int irq; };