Received: by 10.223.176.5 with SMTP id f5csp293126wra; Thu, 8 Feb 2018 22:09:57 -0800 (PST) X-Google-Smtp-Source: AH8x227ZHq6ggkSHiI7qApXmcfxS6g3quVposcDWSzWHqqbNcm23jaho0yo0lsyT9dJ3fglpfBcg X-Received: by 10.99.149.8 with SMTP id p8mr1409603pgd.186.1518156597552; Thu, 08 Feb 2018 22:09:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518156597; cv=none; d=google.com; s=arc-20160816; b=xfGhyEKSG449s0NI+cmGb18Nxzt4HnspmBkA5/F2rW2+/xFkU1myRjIk9V6p1PqL1m PSuyE7LpJXqk5Ekj109KaJCkdbKo/Etcoy5vT3wsyb/jJNbineQug+IGCWgPVdau1dua aAcH5Zx4ZQnQUs0x6VdfyslUJOOUF/J+N6BDNHXBkBlaSu86uYh80edoagqC4e7iTqCY Ij2hg99FciAfgncZ5+ZItkwAT+hrZQ74qp3aLtJCYTuFPHNQpuou2U5Uygz1hgSyheA7 imbLzoRe8eul9ymPtFqP3BLjF/0DJ8URyqtWq/QGrMFLR0AUygvGlgzJnuLtzrvtXfyN VDQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=0Q3uPb8gySQcgsQtVQr2S/bAzu9nETicVrLVrKTSbf8=; b=Pz+Tvpb88rHtpX2+cWo6Om9LmcZURR9QrPEBccIeZM11aoJwrArYqNd+lj63y/tP+G oC6wxxvKP4qk4YSkJLL592fItYp4H9qgBhhogqTvNamShO2JnSyKO7dKgu4VooyghgS4 rOyCW7dGnfq5Uc80vp4ZKG/pqkwRCjmmcgAIu9thj+o7Hva/UQuAztZLiiaspzOMoabX UroMwNux5TXJnaEpevLNkCRXDzBuy82PA6Kd34KPULuGp87NZGcmlTJ4r7rTxgv9chul 9Yk54REIGG6rnbClKDf+HonR8AaWfsq9Vv1er39H7RA0f7O/a7tH0sGySb1gep+8vFjX UDYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WhEc8+uS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h1-v6si1088199pls.571.2018.02.08.22.09.42; Thu, 08 Feb 2018 22:09:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WhEc8+uS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751005AbeBIGJC (ORCPT + 99 others); Fri, 9 Feb 2018 01:09:02 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:34783 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750878AbeBIGI7 (ORCPT ); Fri, 9 Feb 2018 01:08:59 -0500 Received: by mail-pg0-f65.google.com with SMTP id s73so2972251pgc.1 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=P22/SYZtWxSPEKY5urwaf3/tdqcaTlIruHZz5d1GS2uBymGRk/FkjcNQfYQPkGu1rU OsD1bRCtiOPapm1eav8bHRaArIm1+8gg3CjYiw3ey4SVWYCKOzVaWPYWiy5UKX0D+CXb TQHdqpE+8DEPwz22dQeqy+8HasjTPHK1rleuByrGKgKic0nK6yHu/eKAELqxI56zxCzX JJYl6JWOGQ3uPTZ9Tbh6DbI3PMiEHE1IbW59OkNxNdmhVoLqqJxKZTXNkq5kpJ+lJClC iZEuACFSu/V7k3ABrhI8HeQ99xadfew1/MgUr9D/CFaFy7t/T6uKu0eC1gQpGYmUBKxm JiBg== X-Gm-Message-State: APf1xPDDFP5XPNpWSfF1BkzKbJS+Cpd7l0EDT0zCiP2p6Q9PaYJW6zPl JjBFpVFBHM7K7QQSBS31E5atdw== 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; }; -- 1.7.9.5