From patchwork Wed Sep 20 11:50:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 142386 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp4096416vqi; Wed, 20 Sep 2023 05:24:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFwr53m7biSQJA7RO4mFTy8YRUXazOROa/RRfKC0MXJUvtXj0sURN5sOhxR1NBSuAKprOIc X-Received: by 2002:a17:902:ce81:b0:1c4:5a9:a45e with SMTP id f1-20020a170902ce8100b001c405a9a45emr3578204plg.27.1695212642161; Wed, 20 Sep 2023 05:24:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695212642; cv=none; d=google.com; s=arc-20160816; b=AuYpxvPAzT0sr6+FiRQ6C+zCZp4ORDNTBAcze87jkMf+u+mCw1o2hIW+cG8GvIyR33 kdpRBIo69J0rb96hEnCPBJcDiVrG48X66n5HPJ+fAMLy0DJnSSGEguLNAxwOtSHVGISm KUgRsc4G86aObwL0UMP3Z4ZCMmA7mbd5zaDOgcl7NqjfwqfvC9D8z2NYjh+39SqhQrVt 99JeSsq6AT16Pnf8Q8vl0qUkh0P/c1zir5xXYPIMAI4bWhCheQOn3BYurQQqPDajvCSk W8SJZvX3BuI/yPLEwZHTwwa4W2O7PF+eRKdc/AyStjDhbnlljVstWQjFKb3hf+5WjXUu 11JQ== 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=mHdi2C60cwq1WEKC/JrwbJRe1I0svdolwqmda/AQIco=; fh=qNJTVozd0zf7rDe9cmDiIud3XGAhSApqfqoTi+Gdd8I=; b=fIKS49Tb24mnXlhndWocCDLk7HewlIsOhVyGGdt+Ex8e31wH5H1pHoBjGNltXfq5AF EJFcnAmrdZ06yM4Qn+3y/t+IEH8KDJqzYA2YwPwcFCYPsAQ3sqhmXE97kxtZxEvAQYI2 jwTGbHaaoebAW4rnTTQqXPIxGP4utxn/wd9oIvy0/+6D+Lqe/NatKkZCdvP0zFWfB+iQ 5DsWkVG/jfq7qqbsbTBm0zwIo6fboFig+ebbmuLpS9+s7zNDDI2d+C8kJoaxiq16P5MG sjsudO+JE05iMWJi9ijo0YBWIxlwLB6tREtwv+gnB9c1z0llfSfDgRfOkJAmkmvBFCuK JcKw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id t11-20020a170902e1cb00b001bddcd8c6acsi11244790pla.311.2023.09.20.05.24.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 05:24:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 826AC8021E21; Wed, 20 Sep 2023 04:51:38 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234627AbjITLu6 (ORCPT + 26 others); Wed, 20 Sep 2023 07:50:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234588AbjITLu5 (ORCPT ); Wed, 20 Sep 2023 07:50:57 -0400 Received: from muru.com (muru.com [72.249.23.125]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CDE7FA3; Wed, 20 Sep 2023 04:50:51 -0700 (PDT) Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id D4CE980E0; Wed, 20 Sep 2023 11:50:49 +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 v2 1/2] dt-bindings: input: gpio-keys: Allow optional dedicated wakeirq Date: Wed, 20 Sep 2023 14:50:43 +0300 Message-ID: <20230920115044.53098-1-tony@atomide.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 20 Sep 2023 04:51:38 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777559291298748229 X-GMAIL-MSGID: 1777559291298748229 Allow configuring an optional dedicated wakeirq for gpio-keys that some SoCs have. Let's use the common interrupt naming "irq" and "wakeup" that we already have in use for some drivers and subsystems like i2c framework. Note that the gpio-keys interrupt property is optional. If only a gpio property is specified, the driver tries to translate the gpio into an interrupt. Signed-off-by: Tony Lindgren Reviewed-by: Rob Herring --- Changes since v1: - Run make dt_binding_check on the binding - Add better checks for interrupt-names as suggested by Rob, it is now required if two interrupts are configured - Add more decription entries - Add a new example for key-wakeup --- .../devicetree/bindings/input/gpio-keys.yaml | 41 ++++++++++++++++++- 1 file changed, 40 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,23 @@ patternProperties: maxItems: 1 interrupts: - maxItems: 1 + oneOf: + - items: + - description: Optional key interrupt or wakeup interrupt + - items: + - description: Key interrupt + - description: Wakeup interrupt + + interrupt-names: + description: + Optional interrupt names, can be used to specify a separate dedicated + wake-up interrupt in addition to the gpio irq + oneOf: + - items: + - enum: [ irq, wakeup ] + - items: + - const: irq + - const: wakeup label: description: Descriptive name of the key. @@ -97,6 +113,20 @@ patternProperties: - required: - gpios + allOf: + - if: + properties: + interrupts: + minItems: 2 + required: + - interrupts + then: + properties: + interrupt-names: + minItems: 2 + required: + - interrupt-names + dependencies: wakeup-event-action: [ wakeup-source ] linux,input-value: [ gpios ] @@ -137,6 +167,15 @@ examples: linux,code = <108>; interrupts = <1 IRQ_TYPE_EDGE_FALLING>; }; + + key-wakeup { + label = "GPIO Key WAKEUP"; + linux,code = <143>; + interrupts-extended = <&intc 2 IRQ_TYPE_EDGE_FALLING>, + <&intc_wakeup 0 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "irq", "wakeup"; + wakeup-source; + }; }; ... From patchwork Wed Sep 20 11:50:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 142372 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp4075767vqi; Wed, 20 Sep 2023 04:54:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGlJ0lH0DIfWBQds8pBrQ2cqJ+RNOM8EfEMGRDAXKsvT5Ip1BmOM/gOdLHecqPoNDiICpl9 X-Received: by 2002:a17:902:b591:b0:1c3:8464:cabd with SMTP id a17-20020a170902b59100b001c38464cabdmr1943361pls.12.1695210889364; Wed, 20 Sep 2023 04:54:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695210889; cv=none; d=google.com; s=arc-20160816; b=ARkUS1sJ8jL9qpd+o/C93sauNnD1rYrxEyGi+UjqlvQEuzd9NI49KGbJE3pgNp8sRy ITLQU41Z1bbYhAIhQ0lhQchPedqWesX3rvD6pey4QQJ0PAAl207syhkDfkmkeeYun3Jb M8NxthjEEEUEC/pTueQNzQ1ge5fTzyez+urWB1MikBfgIrLURop4X0acyqALSm5BxIyV NcNczQecDo+lBZOgWoVYiBrZa5dV+4II7JslV5IvkyuaFnBr8JCeS86v95soOkURBf1Q 2jxkklw68kFoxl+w/+Cj213s23IKb7pJzo7rcstPR5560OdXkrgqOioLXY7U4S1/QHhP MH6A== 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=HwLaQ+6HKpY/FNj+M2cMjUhGRyzQjB+L6YdXIw3ThMY=; fh=4u/NwaYCJqDVkYV7nM7yfXV2TONryeZvEIFFjJkIhjs=; b=TdY6diR2NKMo8NVHVd/XDV8VVmTVvhAM+6DAjq4e/B/imIu+qpehB5QfyBguQlM4Da 2zwMaAt5PaITErAMugTdfAmsz8gJU5Uzel/CHQU3dAQitG4NUZz5mCpJdqH03BzjaMqL 1dDdU0iNnqPU2FvucHHMpjnbqMfR3n0yO7ZLWwpTRhx4l6CW9fWOkSlL3yRpDnjpBulj F8ggrGHM6TSIhzsqgf3aJfUHNcgxOYK0Gmf0R5ExipUpqDVZTVH5fFzB36PELiJO11o1 I24xyvA28jgtHq9pCqEK2JidxepnbCXuyCuBFH7oRxkFbD+QJQuiSb85JrvV9duQlyD5 RenA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id t14-20020a1709027fce00b001c44be93994si6907003plb.164.2023.09.20.04.54.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 04:54:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id B5A7B81ADD6C; Wed, 20 Sep 2023 04:51:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234701AbjITLvD (ORCPT + 26 others); Wed, 20 Sep 2023 07:51:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234695AbjITLvB (ORCPT ); Wed, 20 Sep 2023 07:51:01 -0400 Received: from muru.com (muru.com [72.249.23.125]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 525EAB4; Wed, 20 Sep 2023 04:50:55 -0700 (PDT) Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 5731B810A; Wed, 20 Sep 2023 11:50:53 +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 v2 2/2] Input: gpio-keys - Add system suspend support for dedicated wakeirqs Date: Wed, 20 Sep 2023 14:50:44 +0300 Message-ID: <20230920115044.53098-2-tony@atomide.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230920115044.53098-1-tony@atomide.com> References: <20230920115044.53098-1-tony@atomide.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 20 Sep 2023 04:51:23 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777557453405587614 X-GMAIL-MSGID: 1777557453405587614 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 --- No changes since v1 --- 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; }; /**