From patchwork Wed Feb 28 12:44:36 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: 129980 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp980870lja; Wed, 28 Feb 2018 04:45:19 -0800 (PST) X-Google-Smtp-Source: AH8x224cmhXxj62tnNLb8G4VU9RFNaWAUAsmX3dPDo83I4fXtgRSsiRotqYvquIHyAuZc0RWg1RT X-Received: by 10.98.192.74 with SMTP id x71mr17390883pff.21.1519821919550; Wed, 28 Feb 2018 04:45:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519821919; cv=none; d=google.com; s=arc-20160816; b=W4Bx7mU78/8D0XRrmNf+eFSco3GBcjgmKYwjyTmPvdcJDv1i+LZr8KUhh8nH6qNpfO rEvGskgflcSBgKqrFtoAEoMvUUVfuudO7C3yQMTiB9YwXmwu4Fh+TQKPqCRoX1NbvlCc Ao1tM+dKRncAov8oRbYDOgbvX2OwMbFF4uHPoRWOl8ZN47jD7H4J+y+ssdxXqxCEj9UE OgDpi+E1pt/ja5RXFY7Ya/zD16vipTOXUlXq1JJALZsDBX9omxLycB5m9AUgDhU1DURh jZwZJdWh0q8hF2a03eiOv6/7yw29pCoQ3FCqFIEzfNAQugvGp7Lx0DytaHaP7Mgwb75A /0sg== 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=mEWIedFHXSmRC/ed5N+9GLdHIc5JaKi+tE7TUqe2mto=; b=FiCjZc8XUqB9mq4ZvIml7Wiui6ufTI/aH1kdjjEJctwMRPHD7pNSlXCMMn2lrBnPU0 tRZJ2ohONuGGMODwdXMKJin9N53lJQHo22/z/szVZzD432ZRaA0NXpcoHk8/ipKayvTc AUFbYBGmx2UfK7RJpu4+RkHBxFJ0dVYrSyk/Yx9gdtcDbn4YQN31X66RpUjX2eH2qXjg ftRzLMjz6DRZKS4F8iXmdkm/GCqLeCTP8v4EHhzxEMInEXJ5Up7YkFTKp8eFs0fV9Ulg 5H1luiquoDnNxm5HAo4iYiMpEiISQygw0uSICerWF0cFNizAjNfBdR4ewIL1v8/fST1n c1KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=XkYGAGzL; spf=pass (google.com: best guess record for domain of linux-input-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-input-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 o27si1203853pfi.119.2018.02.28.04.45.19 for ; Wed, 28 Feb 2018 04:45:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-input-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=XkYGAGzL; spf=pass (google.com: best guess record for domain of linux-input-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-input-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 S1752340AbeB1MpS (ORCPT ); Wed, 28 Feb 2018 07:45:18 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:36279 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752232AbeB1MpR (ORCPT ); Wed, 28 Feb 2018 07:45:17 -0500 Received: by mail-pl0-f68.google.com with SMTP id 61-v6so1430377plf.3 for ; Wed, 28 Feb 2018 04:45:17 -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=PHB58ugZyHCrmN8anIQa/VSNJ5iqk7j285imOYhNisc=; b=XkYGAGzLLuDy4S2LJvX3wrjgUnksVjis+mv47FAkLwCB1WQJoXl0HdpXudGWUmXofK j4qdMDw57Bwi6i5ijlZxri49DN94wheCOZKYfPPFhdVIT5VyJwq0BwQLVdaTI2Eb6U0S YiVYIJFGstaUmBvtdCqtBaGkDz7nqpcsz18gk= 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=PHB58ugZyHCrmN8anIQa/VSNJ5iqk7j285imOYhNisc=; b=uGoufVtNoeALlIa8AzWJiOYJNFBtVznSfWo1ZR/kiAaYUYnvp3o7kM6D2dRSGJw4Nu hVGgBNnQX0fsuWjd9rYe9rTJnAi1M6/czzcBU5lsjYrnB5QRAv3VrYAGxMrrzWGZNq4t bsVqJlwsVNTI8ZFJai2EtU7Iak9d0R0KmDZp0Uvnf1Sj9wTU4CgcDRebIWdQUNzpLkIm ftxYcq7mResPX5iNWuaQavzHvdLbNR7xU/C08rjzO81Ezu18ZLTxcfD/rDNBz/swbsdW oxoPSFkAr/iKwlWDjH689lECQQ1sR5sNHOT5ya/Ew9WRqFwOw72rdi7t4hiV1Lw/Hmqp YRFw== X-Gm-Message-State: APf1xPBF+2Q40+mqmNGFUGR9aeuDrCjHD5C8ocdnWLSwtCPE4MFDjfIl e84dzyEtT03uoQjD8dPJ10kZvg== X-Received: by 2002:a17:902:5797:: with SMTP id l23-v6mr17577028pli.56.1519821916538; Wed, 28 Feb 2018 04:45:16 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id w24sm1491379pfl.14.2018.02.28.04.45.12 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Feb 2018 04:45:15 -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, arnd@arndb.de, baolin.wang@linaro.org Subject: [PATCH v3] Input: gpio_keys: Add level trigger support for GPIO keys Date: Wed, 28 Feb 2018 20:44:36 +0800 Message-Id: <826093167e8fb24723f474b0272f3dcab1b6a97e.1519821626.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 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 v2: - Use 'interrupt' property to indicate the irq type. Changes since v1: - Diable the GPIO irq until reversing the GPIO level type. --- drivers/input/keyboard/gpio_keys.c | 32 ++++++++++++++++++++++++++++++-- include/linux/gpio_keys.h | 3 +++ 2 files changed, 33 insertions(+), 2 deletions(-) -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-input" 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/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index 87e613d..9e05c80 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) { @@ -696,10 +717,17 @@ static void gpio_keys_close(struct input_dev *input) device_property_read_string(dev, "label", &pdata->name); device_for_each_child_node(dev, child) { - if (is_of_node(child)) + if (is_of_node(child)) { button->irq = irq_of_parse_and_map(to_of_node(child), 0); + if (button->irq) + button->level_trigger = + irq_get_trigger_type(button->irq) & + (IRQF_TRIGGER_HIGH | IRQF_TRIGGER_LOW) ? + true : false; + } + if (fwnode_property_read_u32(child, "linux,code", &button->code)) { dev_err(dev, "Button without keycode\n"); diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h index d06bf77..1286136 100644 --- a/include/linux/gpio_keys.h +++ b/include/linux/gpio_keys.h @@ -16,6 +16,8 @@ * @debounce_interval: debounce ticks interval in msecs * @can_disable: %true indicates that userspace is allowed to * disable button via sysfs + * @level_trigger: indicate if the button's interrupt type is + * level trigger or not * @value: axis value for %EV_ABS * @irq: Irq number in case of interrupt keys */ @@ -28,6 +30,7 @@ struct gpio_keys_button { int wakeup; int debounce_interval; bool can_disable; + bool level_trigger; int value; unsigned int irq; };