Received: by 10.223.185.116 with SMTP id b49csp4052643wrg; Mon, 19 Feb 2018 10:13:00 -0800 (PST) X-Google-Smtp-Source: AH8x224Lv5CT3Ojpuw56F/dlGF63keWXAb3p3SFo4GNDb2k9mogJ6W0n0B057fXkdr5E80xm/nOn X-Received: by 2002:a17:902:8349:: with SMTP id z9-v6mr3191062pln.163.1519063980742; Mon, 19 Feb 2018 10:13:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519063980; cv=none; d=google.com; s=arc-20160816; b=k4syvTxM3ysoJhYGdzHd9iG7uwSo+EZCze+80aUcjIzPLHjlzUVFOW+82CRCz92hDl Rsr3hy9A/QK+FihAzpOsqhoWuQrO8bzImqqoZDoU6NnpZ+Lm7crevdqbWZpsWyMHaFPX AzWVFLDY1I2H7r6hAr+dQdP5UwaMk3D6mWwwl3mZCz4caO1BTaa9fnAI+J9L0cHp8UhC QBqkyirbX44V+/F26kpbsMQpP207cNzOv4bK6TVWu9jHCTlsIUWUTsCWV/+hhMnL9h/p 4yW90B4piPt+alwg2JF6LKwVLlaX+mQTD3gbD9/fBOoaGF0HBQPbfme51ygq+o+vqaP6 awhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=BgwuyqUh2PTb9rEqfI8XBvsB/UDFahUgnOfcGv/cjlo=; b=VAPDaliPNiNvYQwaFijZNjs8xNw+eHXmdBsyO6+kMa20uBNe/Ul/7e1brzWopDts+u 2pQtFPtYQSwyFUvSftZ4DXUuhSOlljVYB3l0J3jYedTgRCS/vPmtV4A/p+ATY4Fy0YtL INBmhKfNKQ/+Leihdf4XWIWLsQKMcQ9YB8C4Fgt8utkWX4zR+WzWEemyENA4EgjxU15c eQLff97x4lpUXFKvVexHbU0901PETxVBWLHL0x1NjBwVP6IzNZYe+Ii0hk2uRKb2SC+R u68qYyEYzKOcWTFD2ws18AjQMhE1Sv5042llxRkH8ZegPX9tg0msO2tpbC6fHazX7NxB H4Sg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u186si4041189pgc.462.2018.02.19.10.12.46; Mon, 19 Feb 2018 10:13:00 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753415AbeBSSMH (ORCPT + 99 others); Mon, 19 Feb 2018 13:12:07 -0500 Received: from mail-ot0-f193.google.com ([74.125.82.193]:35220 "EHLO mail-ot0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753185AbeBSSMF (ORCPT ); Mon, 19 Feb 2018 13:12:05 -0500 Received: by mail-ot0-f193.google.com with SMTP id p8so6387936otf.2; Mon, 19 Feb 2018 10:12:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=BgwuyqUh2PTb9rEqfI8XBvsB/UDFahUgnOfcGv/cjlo=; b=PAgnXpso/BqCm/fJaIjuT/58AVrYnEjNr0CrDba/JyAVulQHTRgXQsvdqa6BR6L651 +lIds2yTE7T1/CF3aw96xsUaDncEKJIMpdXBMasVKOPDVnKuv65tlfe/8bLCdWJ9EYOQ /hCR+PeBr7ON0ofx/Hb7mYOCnV1/VfY4x9ss9CkUwl4yvCUQ7kym6T7IUafTXMT+Buh3 2L2HceXZ8BlUiaL6HlAxAiUbInSQj9vJE9bODoNqAuNOX4yHc3klneJ3OqSDNCiYKS6n 6Xr5ZxcDfn9v5jvkxAxQ2n9Hre5no8y+pKzYpe0wkhBgNjkhvqwMidC5Cb2heWbTeD54 26kg== X-Gm-Message-State: APf1xPDY+B9jgzoF3sfXXfuLQBBhKeVSMg8cSSBVBK/NZCeIjUYiu5Iy IHXzBIQ2kfkkS2IN6/EjVA== X-Received: by 10.157.87.201 with SMTP id q9mr3310oti.1.1519063924422; Mon, 19 Feb 2018 10:12:04 -0800 (PST) Received: from localhost (216-188-254-6.dyn.grandenetworks.net. [216.188.254.6]) by smtp.gmail.com with ESMTPSA id u67sm562020oig.21.2018.02.19.10.12.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 19 Feb 2018 10:12:03 -0800 (PST) Date: Mon, 19 Feb 2018 12:11:59 -0600 From: Rob Herring To: Baolin Wang Cc: dmitry.torokhov@gmail.com, mark.rutland@arm.com, 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 Subject: Re: [PATCH v2] Input: gpio_keys: Add level trigger support for GPIO keys Message-ID: <20180219181159.tzbhhvbvpc236qma@rob-hp-laptop> References: <7fc26df245d56fd2014532b56e67630e76e2c513.1518316248.git.baolin.wang@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7fc26df245d56fd2014532b56e67630e76e2c513.1518316248.git.baolin.wang@linaro.org> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Feb 11, 2018 at 02:55:04PM +0800, Baolin Wang wrote: > 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. If the parent interrupt controller only supports a certain trigger, then it should ignore setting the trigger type. > > 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(-) > > 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. No. Just use 'interrupts' instead of 'gpios' and specify the trigger type. Or put both if you need to read the state. > > 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; > }; > -- > 1.7.9.5 >