From patchwork Sun Feb 11 06:55:04 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: 127904 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp2115804ljc; Sat, 10 Feb 2018 22:55:42 -0800 (PST) X-Google-Smtp-Source: AH8x2251NCvjJ1jQ0pr0GEGNTDw0K5V2aN5Gup8zu0pGLzXZljsbT4onk19P7xARo74mZbyjZgXD X-Received: by 2002:a17:902:8a97:: with SMTP id p23-v6mr7397955plo.74.1518332141960; Sat, 10 Feb 2018 22:55:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518332141; cv=none; d=google.com; s=arc-20160816; b=S55uo1/Ezm33qZzHaVUmX0t52bBf+YpHjC7nfwKPBb8kCSDrQjKEhRqUn9yUNE2LFR h9R0LyczD/9DM6e8ZOH/qMsqZWS9p8TaN7WuLKGYQUP0dIha5/Th9zQ9eBiTIvBvoqdm nSXO+s9wPnVov0Bt8BPOAn0Khs/sbmClzAc4BBZpv64JcwX12AX/VAxqfNTO2d1j897E NFgiFx2//MUWZthH6gd96H1Pcs9PX2B8QeDWV/Mgnx2RitQyYRgPO926R0XgpDQ39N4N w+ORmEVseIFqx1pTxryS7aM4uIsQogTUBNGtvWPSBqeMPNIoYeAFRQzs0NS8maWOfQfR ORtQ== 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=spA82rsnSz7YjAwCpyZ0O/+7BszjB9WEhxD7EaF+eJo=; b=QEkd6KKCjHzBbM7uIejN4Rn32eESy+MAt0rIEdDXf9nAshROi+MB5dLfydxxf2tFFD ZFzg+hAUsRcmoBTVVhtD6sOEx8HjMGiiVuE8aUcoHxnUCk/+33BBqgSaGPJSuEhdb3jm aOrqRJ+0WN4u4bcCJ76ygdl+4a6wk0E1vbK0p4D0PWB6P0zLzGo1KhoJ764nu9B4si5n pzM4n+khk3rl2ZxidhpfVYUq4XeOt9HxvxN0Sa6pXMaJFYuML3M1U4iWg3nWX1usvklD xDS6gQxI2CM3dDqFFU+9wz3TW+8HoVAu13ShONwgYM/sVFiBW4YKIqm0T48CI2H5jN2+ oKNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=dkuvnzSO; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=fail (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 u188si1841883pgb.648.2018.02.10.22.55.40; Sat, 10 Feb 2018 22:55:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=dkuvnzSO; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752450AbeBKGzh (ORCPT + 6 others); Sun, 11 Feb 2018 01:55:37 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:45173 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752217AbeBKGzg (ORCPT ); Sun, 11 Feb 2018 01:55:36 -0500 Received: by mail-pg0-f68.google.com with SMTP id m136so5685626pga.12 for ; Sat, 10 Feb 2018 22:55:36 -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=tQ8sP6z9GC2+zIHcZaVMgbpRZcgIb+mPHO8lsNT9SfU=; b=dkuvnzSOH6bhy+VJZnLVADOlNvamQBDhDR6Sd1fkVqnrGX2Y/7afF5oL3OVQiyjtbg 39UkVQyYMmDOLC+RnHR/IA9HajJhrLbk3OHh8hkPXQM78OAC9ZgrEorK5MBuSKJbfm+7 DISXllizkrU4yTd8ggWda+xo1ENywG/S2kBKs= 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=tQ8sP6z9GC2+zIHcZaVMgbpRZcgIb+mPHO8lsNT9SfU=; b=TSm8BHsZg1Qe2gRSrvi9a4gU2qhRd+IEhZoTzCMLV/v9d0mQWKqrn+W7EcsJqEk61d K8dlOtLRfILqLfhOuvqNS1RY0Ao5lmUZsM71L+FRbl9Y7vdJ8aBC6k0Q0Vz3/mmRfaOK D3uqGwJBR1kuhxMLg2V0G5dfhc/LONrTqmwlVn8Z8A4bJzSBD6+bYgspQiFGbnLSYgBW 5YNZHz5x4Tu82kpOGAAvFPwj6i83SLR6XT7XTTNCWF2+AhX7+GfdAg/A3qCzgj9PE2dO xhihg7YG343CG5obqdtJF7Zn8YJICs5hlOPWNn9lBQhrz9a5RBe38lu+bo51h+ZLB7wx aYEQ== X-Gm-Message-State: APf1xPDd+1kk1cRRthI75TmSmQyoQ5c1riT5db5eT3yZ21zdsXR3hHbw rcOgN5+540Pylga+9B+8SoCvmA== X-Received: by 10.99.53.193 with SMTP id c184mr6384473pga.180.1518332135612; Sat, 10 Feb 2018 22:55:35 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id w70sm15936213pfa.187.2018.02.10.22.55.31 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Feb 2018 22:55:34 -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 v2] Input: gpio_keys: Add level trigger support for GPIO keys Date: Sun, 11 Feb 2018 14:55:04 +0800 Message-Id: <7fc26df245d56fd2014532b56e67630e76e2c513.1518316248.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@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 --- Changes since v1: - Diable the GPIO irq until reversing the GPIO level type. --- .../devicetree/bindings/input/gpio-keys.txt | 2 ++ drivers/input/keyboard/gpio_keys.c | 26 +++++++++++++++++++- include/linux/gpio_keys.h | 1 + 3 files changed, 28 insertions(+), 1 deletion(-) -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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..218698a 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -385,6 +385,20 @@ 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); + enable_irq(bdata->irq); + } + gpio_keys_gpio_report_event(bdata); if (bdata->button->wakeup) @@ -397,6 +411,9 @@ static irqreturn_t gpio_keys_gpio_isr(int irq, void *dev_id) BUG_ON(irq != bdata->irq); + if (bdata->button->level_trigger) + disable_irq_nosync(bdata->irq); + if (bdata->button->wakeup) { const struct gpio_keys_button *button = bdata->button; @@ -566,7 +583,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 +742,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; };