From patchwork Fri Dec 3 13:35:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 12655227 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AD56C433F5 for ; Fri, 3 Dec 2021 13:35:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381025AbhLCNin (ORCPT ); Fri, 3 Dec 2021 08:38:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381179AbhLCNig (ORCPT ); Fri, 3 Dec 2021 08:38:36 -0500 Received: from michel.telenet-ops.be (michel.telenet-ops.be [IPv6:2a02:1800:110:4::f00:18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA581C061792 for ; Fri, 3 Dec 2021 05:35:12 -0800 (PST) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed10:3191:9890:620a:6f4]) by michel.telenet-ops.be with bizsmtp id RpbA2600D3eLghq06pbAZm; Fri, 03 Dec 2021 14:35:10 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1mt8iT-002LQX-Rt; Fri, 03 Dec 2021 14:35:09 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1mt8iT-000kke-6z; Fri, 03 Dec 2021 14:35:09 +0100 From: Geert Uytterhoeven To: Dmitry Torokhov , Rob Herring , Marc Zyngier Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 1/3] dt-bindings: input: gpio-keys: Fix interrupts in example Date: Fri, 3 Dec 2021 14:35:06 +0100 Message-Id: <47ecd2d8efcf09f8ab47de87a7bcfafc82208776.1638538079.git.geert+renesas@glider.be> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org The "interrupts" property in the example looks weird: - The type is not in the last cell, - Level interrupts don't work well with gpio-keys, as they keep the interrupt asserted as long as the key is pressed, causing an interrupt storm. Use a more realistic falling-edge interrupt instead. Signed-off-by: Geert Uytterhoeven --- Documentation/devicetree/bindings/input/gpio-keys.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/input/gpio-keys.yaml b/Documentation/devicetree/bindings/input/gpio-keys.yaml index 060a309ff8e7c757..dbe7ecc19ccb9423 100644 --- a/Documentation/devicetree/bindings/input/gpio-keys.yaml +++ b/Documentation/devicetree/bindings/input/gpio-keys.yaml @@ -142,7 +142,7 @@ examples: down { label = "GPIO Key DOWN"; linux,code = <108>; - interrupts = <1 IRQ_TYPE_LEVEL_HIGH 7>; + interrupts = <1 IRQ_TYPE_EDGE_FALLING>; }; }; From patchwork Fri Dec 3 13:35:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 12655225 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81CFDC4332F for ; Fri, 3 Dec 2021 13:35:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381122AbhLCNin (ORCPT ); Fri, 3 Dec 2021 08:38:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381184AbhLCNii (ORCPT ); Fri, 3 Dec 2021 08:38:38 -0500 Received: from albert.telenet-ops.be (albert.telenet-ops.be [IPv6:2a02:1800:110:4::f00:1a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A317BC0617A1 for ; Fri, 3 Dec 2021 05:35:13 -0800 (PST) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed10:3191:9890:620a:6f4]) by albert.telenet-ops.be with bizsmtp id RpbA2600A3eLghq06pbAhz; Fri, 03 Dec 2021 14:35:11 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1mt8iT-002LQY-Ph; Fri, 03 Dec 2021 14:35:09 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1mt8iT-000kkk-7l; Fri, 03 Dec 2021 14:35:09 +0100 From: Geert Uytterhoeven To: Dmitry Torokhov , Rob Herring , Marc Zyngier Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 2/3] Input: gpio-keys - Use input_report_key() Date: Fri, 3 Dec 2021 14:35:07 +0100 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org Use the input_report_key() helper instead of open-coding the same operation. Signed-off-by: Geert Uytterhoeven --- drivers/input/keyboard/gpio_keys.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index fc706918d7b103cb..ab077dfb90a76ac3 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -456,7 +456,7 @@ static enum hrtimer_restart gpio_keys_irq_timer(struct hrtimer *t) struct input_dev *input = bdata->input; if (bdata->key_pressed) { - input_event(input, EV_KEY, *bdata->code, 0); + input_report_key(input, *bdata->code, 0); input_sync(input); bdata->key_pressed = false; } @@ -478,11 +478,11 @@ static irqreturn_t gpio_keys_irq_isr(int irq, void *dev_id) if (bdata->button->wakeup) pm_wakeup_event(bdata->input->dev.parent, 0); - input_event(input, EV_KEY, *bdata->code, 1); + input_report_key(input, *bdata->code, 1); input_sync(input); if (!bdata->release_delay) { - input_event(input, EV_KEY, *bdata->code, 0); + input_report_key(input, *bdata->code, 0); input_sync(input); goto out; } From patchwork Fri Dec 3 13:35:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 12655231 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF27DC4332F for ; Fri, 3 Dec 2021 13:35:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381067AbhLCNir (ORCPT ); Fri, 3 Dec 2021 08:38:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381105AbhLCNin (ORCPT ); Fri, 3 Dec 2021 08:38:43 -0500 Received: from albert.telenet-ops.be (albert.telenet-ops.be [IPv6:2a02:1800:110:4::f00:1a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E3A0C06173E for ; Fri, 3 Dec 2021 05:35:18 -0800 (PST) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed10:3191:9890:620a:6f4]) by albert.telenet-ops.be with bizsmtp id RpbA260083eLghq06pbAhy; Fri, 03 Dec 2021 14:35:11 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1mt8iT-002LQZ-La; Fri, 03 Dec 2021 14:35:09 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1mt8iT-000kks-8R; Fri, 03 Dec 2021 14:35:09 +0100 From: Geert Uytterhoeven To: Dmitry Torokhov , Rob Herring , Marc Zyngier Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH RFC 3/3] Input: gpio-keys - Fix ghost events with both-edge irqs Date: Fri, 3 Dec 2021 14:35:08 +0100 Message-Id: <356b31ade897af77a06d6567601f038f56b3b2a2.1638538079.git.geert+renesas@glider.be> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org When using interrupts instead of GPIOs, the driver auto-generates key-release events, either immediately or after a delay. This works fine with rising-edge or falling-edge interrupts, but causes ghost events with both-edge interrupts. Indeed, the driver will generate a pair of key press/release events when pressing the key, and another pair when releasing the key. Fix this by not auto-generating key-release events for both-edge interrupts. Rename release_delay to auto_release_delay to clarify its use. Note that unlike with GPIOs, the driver cannot know the state of the key at initialization time, or after resume. Hence the driver assumes the key is not pressed at initialization time, and does not reconfigure the trigger type for wakeup. Signed-off-by: Geert Uytterhoeven --- Tested on rskrza1. Are these limitations acceptable? Or should users only use rising-edge or falling-edge interrupts? There are several existing users of IRQ_TYPE_EDGE_BOTH. --- drivers/input/keyboard/gpio_keys.c | 34 +++++++++++++++++++----------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index ab077dfb90a76ac3..dfcbedec226cb4cf 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -38,7 +38,8 @@ struct gpio_button_data { unsigned short *code; struct hrtimer release_timer; - unsigned int release_delay; /* in msecs, for IRQ-only buttons */ + int auto_release_delay; /* in msecs, for IRQ-only buttons */ + /* a negative value means no auto-release */ struct delayed_work work; struct hrtimer debounce_timer; @@ -474,25 +475,25 @@ static irqreturn_t gpio_keys_irq_isr(int irq, void *dev_id) spin_lock_irqsave(&bdata->lock, flags); - if (!bdata->key_pressed) { + if (!bdata->key_pressed || bdata->auto_release_delay < 0) { if (bdata->button->wakeup) pm_wakeup_event(bdata->input->dev.parent, 0); - input_report_key(input, *bdata->code, 1); + input_report_key(input, *bdata->code, !bdata->key_pressed); input_sync(input); - if (!bdata->release_delay) { + if (!bdata->auto_release_delay) { input_report_key(input, *bdata->code, 0); input_sync(input); goto out; } - bdata->key_pressed = true; + bdata->key_pressed = !bdata->key_pressed; } - if (bdata->release_delay) + if (bdata->auto_release_delay > 0) hrtimer_start(&bdata->release_timer, - ms_to_ktime(bdata->release_delay), + ms_to_ktime(bdata->auto_release_delay), HRTIMER_MODE_REL_HARD); out: spin_unlock_irqrestore(&bdata->lock, flags); @@ -630,7 +631,6 @@ static int gpio_keys_setup_key(struct platform_device *pdev, return -EINVAL; } - bdata->release_delay = button->debounce_interval; hrtimer_init(&bdata->release_timer, CLOCK_REALTIME, HRTIMER_MODE_REL_HARD); bdata->release_timer.function = gpio_keys_irq_timer; @@ -638,10 +638,20 @@ static int gpio_keys_setup_key(struct platform_device *pdev, isr = gpio_keys_irq_isr; irqflags = 0; - /* - * For IRQ buttons, there is no interrupt for release. - * So we don't need to reconfigure the trigger type for wakeup. - */ + if (irq_get_trigger_type(bdata->irq) == IRQ_TYPE_EDGE_BOTH) { + bdata->auto_release_delay = -1; + /* + * Unlike with GPIOs, we do not know what the state of + * the key is at initialization time, or after resume. + * So we don't reconfigure the trigger type for wakeup. + */ + } else { + bdata->auto_release_delay = button->debounce_interval; + /* + * There is no interrupt for release. So we don't + * need to reconfigure the trigger type for wakeup. + */ + } } bdata->code = &ddata->keymap[idx];