From patchwork Fri Aug 11 11:04:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 134442 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp1032080vqi; Fri, 11 Aug 2023 04:57:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHh/bfdYPl06Zd1nuAJ5acgYu4YxNTEuxwGUhg1eOU64v2ERlKoUhqE/Y2imuCKO1L6EDKo X-Received: by 2002:a05:6a00:1486:b0:687:40bd:561 with SMTP id v6-20020a056a00148600b0068740bd0561mr1764043pfu.20.1691755054545; Fri, 11 Aug 2023 04:57:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691755054; cv=none; d=google.com; s=arc-20160816; b=VEJPdGQEHTBMSPjAS2Raw5NIi3ekOx9a9QsShE/OPf2vfitbfAi2RftvJWIm7NdQXc 1tdeyJn6hAR2C0FpVX4/JSH/LZxRgC37IOgkLOAjsrA/jY/VNAtOKZojaQf2TeX6kzQb XmpSWKzrrpsXE0D3ZFDcOQDF18aPt3YaB5JLZX60hSsrwMhPYyt3AT0RDgKCFtgvLRVy 1CDQsVdUZX6WngLuGepeHq1sGuPQVYFnm/Zo4v2djt8A7myEHpfHwXaBUn333r8pwdlN YWaQ8l0aRQGuiVyT248YlfGrCOueZdTs9Ky1kL2VNN2Uig/G+u0bm2gXQd8bj7OLDGoo e6rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=LeQ+XbohlUmVSFtOnZZlPkqTu6LIEFn0XlNFpE2JXX4=; fh=b7Uwy7wdgJjggQw4v4a3KPJfz/TnfJhA0MIztKXpdt4=; b=yphoIiEpwfVMDvlUvXHZeyIjXRYMENIQCpBDEwartfvlHxpmcWxEpKHBy2Q22x70A/ xiUtcMLnh1ikU3OM44Hi34fL9TvIk1DpYFfNikWG61UPvGFSgU+tuffeMvMYuoaXOsx3 nhOZ2s4a+QkyZdAa7qPitPwEhuUGy68Y2NbE/SkX4cpLfvBUyzrJsmSuMREfQNbK815C jMy6zMz264L+wWgxoMEy5Hgu0CIbXZ7Btwpytq5YJw5aAuGdbFfMBoZ4rpwjPTyXdDPu kFBEMddAk/5RdVINj9uqT6i8BRtkskFFnG17QUU4xaz8kUMNtbCVhVau5A+QE7iWxFBj KuZw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bn13-20020a056a00324d00b006738dfbaf42si3143562pfb.374.2023.08.11.04.57.21; Fri, 11 Aug 2023 04:57:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234216AbjHKLEk (ORCPT + 99 others); Fri, 11 Aug 2023 07:04:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233288AbjHKLEj (ORCPT ); Fri, 11 Aug 2023 07:04:39 -0400 Received: from muru.com (muru.com [72.249.23.125]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EF35DE54; Fri, 11 Aug 2023 04:04:38 -0700 (PDT) Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 4EBC980F1; Fri, 11 Aug 2023 11:04:37 +0000 (UTC) From: Tony Lindgren To: Dmitry Torokhov Cc: Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/2] dt-bindings: input: gpio-keys: Allow optional dedicated wakeirq Date: Fri, 11 Aug 2023 14:04:31 +0300 Message-ID: <20230811110432.3968-1-tony@atomide.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773933747661516276 X-GMAIL-MSGID: 1773933747661516276 Allow configuring optional dedicated wakeirq that some SoCs have. Let's use the interrupt naming "irq" and "wakeup" that we already have in use for some drivers and subsystems like i2c. Signed-off-by: Tony Lindgren --- .../devicetree/bindings/input/gpio-keys.yaml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/input/gpio-keys.yaml b/Documentation/devicetree/bindings/input/gpio-keys.yaml --- a/Documentation/devicetree/bindings/input/gpio-keys.yaml +++ b/Documentation/devicetree/bindings/input/gpio-keys.yaml @@ -31,7 +31,17 @@ patternProperties: maxItems: 1 interrupts: - maxItems: 1 + description: + Optional interrupts if different from the gpio interrupt + maxItems: 2 + + interrupt-names: + description: + Optional interrupt names, can be used to specify a separate + dedicated wake-up interrupt + items: + -const: irq + -const: wakeup label: description: Descriptive name of the key. @@ -130,6 +140,9 @@ examples: label = "GPIO Key UP"; linux,code = <103>; gpios = <&gpio1 0 1>; + interrupts-extended = <&intc_wakeup 0 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "wakeup"; + wakeup-source; }; key-down { From patchwork Fri Aug 11 11:04:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 134449 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp1036922vqi; Fri, 11 Aug 2023 05:03:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHv4dS22svp7tHt2er76SKO9YzzOhF2bbrAumjqbZd5ko5PzXsR/syFyB/zwoWNVgTtAf1f X-Received: by 2002:a05:6a21:35c8:b0:135:6ef6:171 with SMTP id ba8-20020a056a2135c800b001356ef60171mr1854187pzc.39.1691755436206; Fri, 11 Aug 2023 05:03:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691755436; cv=none; d=google.com; s=arc-20160816; b=dL6/jTn7c2sQpiJqQ4+jt1ASvytnEjShVgfIpZ0gwkzNWOpG2eqsVQH7IrgncZNwdB GPpbto3zLsmBzJBWnSp5rXRkZnxl7OFCnbvIy/JEKU61Qd1H1uoUFzQjCQvaAK2aRdwy CU97CB2+93EIYXryBrYr2FxL3vRohljwkoLiLq1k66P+wyD+8FRvEwve+2Rxe0ihmQ45 rGfkYn6HgbXdNWOA1PobHeo5b6uDiIit9xD/F054TY3TjIGlgo8RFOSXT1H86YBbVOV/ gjc6Yozztkqj80A25aPDTz8O0ozFG/M9Hy+7gxF3GfLwIz+tUDbvu0buOgynEYOSO5S5 XrOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=JQo8+B/6cvVaKtgiESPPeDbKW6qlYTcjalhlfywUC4M=; fh=xaycfA2Rx2PgxjUJEz4TwyQhpEpaVqLLfyPtmRWlt6U=; b=yXqi/4AnnNVAlXpvmJ0kgAci62myUScOWcbYPEsu6Q+PnYiVXqHfwuXQvpPJ4ypkab egMB5jIHaAsN/HwE9F2IsZUUuz0JiewiGdmHx+/gBcDxix2Kl29o8heiHvm52vh1ocRg rsaQ42QtZK5buiuqP1GTtxUYClXxLtXN79gpQBDfT4ijF+JdU5RuCLUfzUNANTdz/Rot zydV1fN0pLpzhTvcREen2lezBc4Zq3HMbRAtLLzD/DWL4aixUkaDB4gJgJkdQe4WL+yt v38awVMS7nQT02JO9z4eG2pFZMnotZVRuKuCqTXqmhBzahru0Q6raRO+RfGGbS+Oncm7 8/WA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z19-20020a63e113000000b0055c872b768fsi3182566pgh.531.2023.08.11.05.03.32; Fri, 11 Aug 2023 05:03:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233288AbjHKLEp (ORCPT + 99 others); Fri, 11 Aug 2023 07:04:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234530AbjHKLEn (ORCPT ); Fri, 11 Aug 2023 07:04:43 -0400 Received: from muru.com (muru.com [72.249.23.125]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BA2F1FD; Fri, 11 Aug 2023 04:04:42 -0700 (PDT) Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id CAAA0820B; Fri, 11 Aug 2023 11:04:40 +0000 (UTC) From: Tony Lindgren To: Dmitry Torokhov Cc: Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Dhruva Gole Subject: [PATCH 2/2] Input: gpio-keys - Add system suspend support for dedicated wakeirqs Date: Fri, 11 Aug 2023 14:04:32 +0300 Message-ID: <20230811110432.3968-2-tony@atomide.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230811110432.3968-1-tony@atomide.com> References: <20230811110432.3968-1-tony@atomide.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773934148475930679 X-GMAIL-MSGID: 1773934148475930679 Some SoCs have a separate dedicated wake-up interrupt controller that can be used to wake up the system from deeper idle states. We already support configuring a separate interrupt for a gpio-keys button to be used with a gpio line. However, we are lacking support system suspend for cases where a separate interrupt needs to be used in deeper sleep modes. Because of it's nature, gpio-keys does not know about the runtime PM state of the button gpios, and may have several gpio buttons configured for each gpio-keys device instance. Implementing runtime PM support for gpio-keys does not help, and we cannot use drivers/base/power/wakeirq.c support. We need to implement custom wakeirq support for gpio-keys. For handling a dedicated wakeirq for system suspend, we enable and disable it with gpio_keys_enable_wakeup() and gpio_keys_disable_wakeup() that we already use based on device_may_wakeup(). Some systems may have a dedicated wakeirq that can also be used as the main interrupt, this is already working for gpio-keys. Let's add some wakeirq related comments while at it as the usage with a gpio line and separate interrupt line may not be obvious. Tested-by: Dhruva Gole Signed-off-by: Tony Lindgren --- drivers/input/keyboard/gpio_keys.c | 69 ++++++++++++++++++++++++++++-- include/linux/gpio_keys.h | 2 + 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -45,7 +45,9 @@ struct gpio_button_data { unsigned int software_debounce; /* in msecs, for GPIO-driven buttons */ unsigned int irq; + unsigned int wakeirq; unsigned int wakeup_trigger_type; + spinlock_t lock; bool disabled; bool key_pressed; @@ -511,6 +513,7 @@ static int gpio_keys_setup_key(struct platform_device *pdev, struct gpio_button_data *bdata = &ddata->data[idx]; irq_handler_t isr; unsigned long irqflags; + const char *wakedesc; int irq; int error; @@ -575,6 +578,14 @@ static int gpio_keys_setup_key(struct platform_device *pdev, !gpiod_cansleep(bdata->gpiod); } + /* + * If an interrupt was specified, use it instead of the gpio + * interrupt and use the gpio for reading the state. A separate + * interrupt may be used as the main button interrupt for + * runtime PM to detect events also in deeper idle states. If a + * dedicated wakeirq is used for system suspend only, see below + * for bdata->wakeirq setup. + */ if (button->irq) { bdata->irq = button->irq; } else { @@ -672,6 +683,36 @@ static int gpio_keys_setup_key(struct platform_device *pdev, return error; } + if (!button->wakeirq) + return 0; + + /* Use :wakeup suffix like drivers/base/power/wakeirq.c does */ + wakedesc = devm_kasprintf(dev, GFP_KERNEL, "%s:wakeup", desc); + if (!wakedesc) + return -ENOMEM; + + bdata->wakeirq = button->wakeirq; + irqflags |= IRQF_NO_SUSPEND; + + /* + * Wakeirq shares the handler with the main interrupt, it's only + * active during system suspend. See gpio_keys_button_enable_wakeup() + * and gpio_keys_button_disable_wakeup(). + */ + error = devm_request_any_context_irq(dev, bdata->wakeirq, isr, + irqflags, wakedesc, bdata); + if (error < 0) { + dev_err(dev, "Unable to claim wakeirq %d; error %d\n", + bdata->irq, error); + return error; + } + + /* + * Disable wakeirq until suspend. IRQF_NO_AUTOEN won't work if + * IRQF_SHARED was set based on !button->can_disable. + */ + disable_irq_nosync(bdata->wakeirq); + return 0; } @@ -728,7 +769,7 @@ gpio_keys_get_devtree_pdata(struct device *dev) struct gpio_keys_platform_data *pdata; struct gpio_keys_button *button; struct fwnode_handle *child; - int nbuttons; + int nbuttons, irq; nbuttons = device_get_child_node_count(dev); if (nbuttons == 0) @@ -750,9 +791,19 @@ gpio_keys_get_devtree_pdata(struct device *dev) device_property_read_string(dev, "label", &pdata->name); device_for_each_child_node(dev, child) { - if (is_of_node(child)) - button->irq = - irq_of_parse_and_map(to_of_node(child), 0); + if (is_of_node(child)) { + irq = of_irq_get_byname(to_of_node(child), "irq"); + if (irq > 0) + button->irq = irq; + + irq = of_irq_get_byname(to_of_node(child), "wakeup"); + if (irq > 0) + button->wakeirq = irq; + + if (!button->irq && !button->wakeirq) + button->irq = + irq_of_parse_and_map(to_of_node(child), 0); + } if (fwnode_property_read_u32(child, "linux,code", &button->code)) { @@ -921,6 +972,11 @@ gpio_keys_button_enable_wakeup(struct gpio_button_data *bdata) } } + if (bdata->wakeirq) { + enable_irq(bdata->wakeirq); + disable_irq_nosync(bdata->irq); + } + return 0; } @@ -929,6 +985,11 @@ gpio_keys_button_disable_wakeup(struct gpio_button_data *bdata) { int error; + if (bdata->wakeirq) { + enable_irq(bdata->irq); + disable_irq_nosync(bdata->wakeirq); + } + /* * The trigger type is always both edges for gpio-based keys and we do * not support changing wakeup trigger for interrupt-based keys. diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h --- a/include/linux/gpio_keys.h +++ b/include/linux/gpio_keys.h @@ -21,6 +21,7 @@ struct device; * disable button via sysfs * @value: axis value for %EV_ABS * @irq: Irq number in case of interrupt keys + * @wakeirq: Optional dedicated wake-up interrupt */ struct gpio_keys_button { unsigned int code; @@ -34,6 +35,7 @@ struct gpio_keys_button { bool can_disable; int value; unsigned int irq; + unsigned int wakeirq; }; /**