From patchwork Fri Feb 9 06:08:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "(Exiting) Baolin Wang" X-Patchwork-Id: 10208261 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 889ED60247 for ; Fri, 9 Feb 2018 06:09:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 767B42976F for ; Fri, 9 Feb 2018 06:09:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6AACD29797; Fri, 9 Feb 2018 06:09:09 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 4F5022976F for ; Fri, 9 Feb 2018 06:09:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750919AbeBIGJB (ORCPT ); Fri, 9 Feb 2018 01:09:01 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:36114 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750830AbeBIGI7 (ORCPT ); Fri, 9 Feb 2018 01:08:59 -0500 Received: by mail-pg0-f66.google.com with SMTP id j9so1893479pgv.3 for ; Thu, 08 Feb 2018 22:08:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=0Q3uPb8gySQcgsQtVQr2S/bAzu9nETicVrLVrKTSbf8=; b=WhEc8+uSGm1aegZ2Efr5F2dp8w4fgknn6B5KKl+uqsRMla+0RX3QghT/XnHGSpntqx 82+bDmTJjh1RM3cBCZ4UvgGNhmxgjeRVdRuBeptiJrtbxY81ZHMJM3YcjYYfLno1mNRC rD1ySu2j8+mFRQT3yzOoAT/67FYCHFFOyZQcw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=0Q3uPb8gySQcgsQtVQr2S/bAzu9nETicVrLVrKTSbf8=; b=avtne5ONQL3D23nqXFoAZFLUYb0m0qHHXChlPIBZZuStEguOTwodiqbUwjN+v8osjO Rw/GZk9MgSXvj3XcJk6X6I3jcDSbghrKZT0hEk8gZ8ZizlhOPed1ygQ5BlP1cWt7dAPj AaWh1kPoO8rajuvIWsrM/ad+21IkGnfywVLb7GASL30i41AB6rBpCSvNEnXeTnYej/yb Wy6mHggtCc0Ru5sY9m/evxtFOD6do/MmCxqpV29wl03m5GJ6QYoeb/ktIAiz101hLLpS ex5g4vh9vWmxL3THy9nmUQdjI6zEuqBs0xYznVTBbK5v+zyM1o4u5n/qzkFDK+RW/XC3 jaZg== X-Gm-Message-State: APf1xPDEb+524KbGtHsiFWKsvwTW9SOwtRNoYDaNJHia6ifRKb0gBYhL +WMkjZJdpQ7ILDP2PLxTxol0yA== X-Google-Smtp-Source: AH8x224EXPEitfsd8LsobSkqR5c+kgIjD8Whnbbgvr0NJfYFmBRODMkrS1jXrWyf9QjAYSmeQfmdyQ== X-Received: by 10.99.97.7 with SMTP id v7mr1479053pgb.104.1518156539285; Thu, 08 Feb 2018 22:08:59 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id t8sm3376800pgr.21.2018.02.08.22.08.55 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Feb 2018 22:08:58 -0800 (PST) From: Baolin Wang To: dmitry.torokhov@gmail.com, robh+dt@kernel.org, mark.rutland@arm.com Cc: gregkh@linuxfoundation.org, lumotuwe@gmail.com, arvind.yadav.cs@gmail.com, josephl@nvidia.com, kstewart@linuxfoundation.org, pombredanne@nexb.com, tglx@linutronix.de, linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, broonie@kernel.org, linus.walleij@linaro.org, baolin.wang@linaro.org Subject: [PATCH] Input: gpio_keys: Add level trigger support for GPIO keys Date: Fri, 9 Feb 2018 14:08:28 +0800 Message-Id: <6c53b9ccfd4a56fc1b00e243bb9e7cae9e124932.1518155780.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 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 On some platforms (such as Spreadtrum platform), the GPIO keys can only be triggered by level type. So this patch introduces one property to indicate if the GPIO trigger type is level trigger or edge trigger. Signed-off-by: Baolin Wang --- .../devicetree/bindings/input/gpio-keys.txt | 2 ++ drivers/input/keyboard/gpio_keys.c | 22 +++++++++++++++++++- include/linux/gpio_keys.h | 1 + 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/input/gpio-keys.txt b/Documentation/devicetree/bindings/input/gpio-keys.txt index a949404..e3104bd 100644 --- a/Documentation/devicetree/bindings/input/gpio-keys.txt +++ b/Documentation/devicetree/bindings/input/gpio-keys.txt @@ -29,6 +29,8 @@ Optional subnode-properties: - linux,can-disable: Boolean, indicates that button is connected to dedicated (not shared) interrupt which can be disabled to suppress events from the button. + - gpio-key,level-trigger: Boolean, indicates that button's interrupt + type is level trigger. Otherwise it is edge trigger as default. Example nodes: diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index 87e613d..d3b4bb6 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -385,6 +385,19 @@ static void gpio_keys_gpio_work_func(struct work_struct *work) struct gpio_button_data *bdata = container_of(work, struct gpio_button_data, work.work); + if (bdata->button->level_trigger) { + unsigned int trigger = + irq_get_trigger_type(bdata->irq) & ~IRQF_TRIGGER_MASK; + int state = gpiod_get_raw_value_cansleep(bdata->gpiod); + + if (state) + trigger |= IRQF_TRIGGER_LOW; + else + trigger |= IRQF_TRIGGER_HIGH; + + irq_set_irq_type(bdata->irq, trigger); + } + gpio_keys_gpio_report_event(bdata); if (bdata->button->wakeup) @@ -566,7 +579,11 @@ static int gpio_keys_setup_key(struct platform_device *pdev, INIT_DELAYED_WORK(&bdata->work, gpio_keys_gpio_work_func); isr = gpio_keys_gpio_isr; - irqflags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING; + if (button->level_trigger) + irqflags = gpiod_is_active_low(bdata->gpiod) ? + IRQF_TRIGGER_LOW : IRQF_TRIGGER_HIGH; + else + irqflags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING; } else { if (!button->irq) { @@ -721,6 +738,9 @@ static void gpio_keys_close(struct input_dev *input) button->can_disable = fwnode_property_read_bool(child, "linux,can-disable"); + button->level_trigger = + fwnode_property_read_bool(child, "gpio-key,level-trigger"); + if (fwnode_property_read_u32(child, "debounce-interval", &button->debounce_interval)) button->debounce_interval = 5; diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h index d06bf77..5095645 100644 --- a/include/linux/gpio_keys.h +++ b/include/linux/gpio_keys.h @@ -28,6 +28,7 @@ struct gpio_keys_button { int wakeup; int debounce_interval; bool can_disable; + bool level_trigger; int value; unsigned int irq; };