Received: by 10.223.185.116 with SMTP id b49csp2691124wrg; Mon, 12 Feb 2018 14:14:20 -0800 (PST) X-Google-Smtp-Source: AH8x224gdqmU1p7PVj/irOmE4iC3W8AIZiLGtIXSaoXmdh3cANf1SxSCWSd+g1ZdSpHRUTUPWAZ8 X-Received: by 10.99.103.129 with SMTP id b123mr10144297pgc.177.1518473660519; Mon, 12 Feb 2018 14:14:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518473660; cv=none; d=google.com; s=arc-20160816; b=BFFBO7UI8h91T3LtZ44//T2rYMQ1yHrqCPEpOEI9useM3Yk8yT1R11K4jDDgCj/Wqq CaPHxgTOl13pCLgly5UKU/9Ei1ojiMkPPfKmI/6hc5xxSJdjkFGFbbgntPl8qt/ivgjf rs2RhPGlNtNyul/QHFu0/avBXJ/SFRrjgu51FZop9DXIjoyBmIaL+sEQZYKBJ8R9SgU+ 3OGkVmHjAH9Z1GuPsIAYgZyWNRPEZ8ok3cE1jNbkXYEaL5Q04ndqhbzRQFpRn3iHu5T/ H/9EKkctxXXglyvf1GmXV30ttuJL3B6QaZuXV1axoZgEFFMzfJTFTOoYuCgaLu7JI3TM Lv3w== 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:dkim-signature:arc-authentication-results; bh=7V3pbAWEEZifCPJB/aQ9S7OfgV0CSdBu1gPTWjq2G7w=; b=FoCofTHfh4lUmM5GvlLFnQJ2r7o+Z5p6OVhkCiHTPMgRiXtOdbhEEZ/IFAqX+x4Toc WX36HLXxUb8EnTSpLv+pYfL8WQsv0kaHs5Hkv+N6xCGYx/Ryr3qDfQmMpiPazEwO5pS0 LrOVNGlo9Xx4o994259v6+CclqnR51fc3ftINqsJDAI8SQ3KvnvaBROwzgfR7uOZW+au Z+POcoyJtSfRShfIR0xWjep+TZ/+EnyrazHhubA0bcFGA2kEliKnTFw7hnPLGnjuuwlj i2SBpGdIQagMePMITXunTWsBMmFeYwrVAAiZv3E10B7mEAuMsNfIn23gWxAJpTcPMTBL PWxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=V2zQ6bxT; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q15si344203pgc.727.2018.02.12.14.14.05; Mon, 12 Feb 2018 14:14:20 -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=@chromium.org header.s=google header.b=V2zQ6bxT; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932627AbeBLWNZ (ORCPT + 99 others); Mon, 12 Feb 2018 17:13:25 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:41160 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932563AbeBLWNS (ORCPT ); Mon, 12 Feb 2018 17:13:18 -0500 Received: by mail-pg0-f65.google.com with SMTP id t4so7380122pgp.8 for ; Mon, 12 Feb 2018 14:13:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=7V3pbAWEEZifCPJB/aQ9S7OfgV0CSdBu1gPTWjq2G7w=; b=V2zQ6bxTo1+AWsu8QS3pl3IYTdv1j70+247zAn27hnz4wYlNTxe5RAZw3hwBRaaqbr wonzhY6iqVZDAWTg97GKMHjeKgftQh+EkRY6UX17nQSxgMIdq+7UwTO/x7IzdB8IWDsa FgMp8JJoHvrJGtqRDYmaWLZVxgpoNHIWsmHJM= 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=7V3pbAWEEZifCPJB/aQ9S7OfgV0CSdBu1gPTWjq2G7w=; b=PTHz9iejq+oDxU0RKMf6B9ot1IG4BFX+N7sySDPYP015EOo5Cuh9Io4Rip1v3+X5aQ EblTr+/ZrPHWtTPOdnqVt5beLDBOVPLv4JMQVukHGef7pnRX9LvUYmBllN6NudjHq2cL AAXL+MzNcwssnr6TaR1wRwoKCF+cbYwjhtYIqU/s9JVxrRJmHRTop2siAIzIOGGKHFhH g9F2uMTHyOKEp/d3bRLK8qdxKSMXhDonXNqpLyhCr9AuZNFCDmFXRDcUyy0SpW41uwuJ hzdskfzd6URmYrl5AXqGLpl8sD0AVmSs1ywW16KOORitTmno3XOO2g6nR+J8t4ebc4xg jGzQ== X-Gm-Message-State: APf1xPBmDukz/e/0rxB53UPmdVf9Cg94CT64IlsRnLRdBw/d372oNarj VE7zlGb+b2FjVkStGiLzlRypFw== X-Received: by 10.98.25.207 with SMTP id 198mr13065454pfz.83.1518473598094; Mon, 12 Feb 2018 14:13:18 -0800 (PST) Received: from ban.mtv.corp.google.com ([2620:0:1000:1501:da1a:a5c1:68e:d948]) by smtp.gmail.com with ESMTPSA id p1sm26530633pgr.44.2018.02.12.14.13.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Feb 2018 14:13:17 -0800 (PST) Date: Mon, 12 Feb 2018 14:13:15 -0800 From: Brian Norris To: Jeffy Chen Cc: linux-kernel@vger.kernel.org, briannorris@google.com, dtor@google.com, dianders@google.com, Enric Balletbo i Serra , Thomas Gleixner , Joseph Lo , stephen lu , Dmitry Torokhov , Kate Stewart , linux-input@vger.kernel.org, Greg Kroah-Hartman , Philippe Ombredanne , Arvind Yadav Subject: Re: [PATCH v2 1/3] Input: gpio-keys - add support for wakeup event action Message-ID: <20180212221309.GA66974@ban.mtv.corp.google.com> References: <20180210110907.5504-1-jeffy.chen@rock-chips.com> <20180210110907.5504-2-jeffy.chen@rock-chips.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180210110907.5504-2-jeffy.chen@rock-chips.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jeffy, On Sat, Feb 10, 2018 at 07:09:05PM +0800, Jeffy Chen wrote: > Add support for specifying event actions to trigger wakeup when using > the gpio-keys input device as a wakeup source. > > This would allow the device to configure when to wakeup the system. For > example a gpio-keys input device for pen insert, may only want to wakeup > the system when ejecting the pen. > > Suggested-by: Brian Norris > Signed-off-by: Jeffy Chen > --- > > Changes in v2: > Specify wakeup event action instead of irq trigger type as Brian > suggested. > > drivers/input/keyboard/gpio_keys.c | 27 +++++++++++++++++++++++++++ > include/linux/gpio_keys.h | 2 ++ > include/uapi/linux/input-event-codes.h | 9 +++++++++ > 3 files changed, 38 insertions(+) > > diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c > index 87e613dc33b8..5c57339d3999 100644 > --- a/drivers/input/keyboard/gpio_keys.c > +++ b/drivers/input/keyboard/gpio_keys.c > @@ -45,6 +45,8 @@ struct gpio_button_data { > unsigned int software_debounce; /* in msecs, for GPIO-driven buttons */ > > unsigned int irq; > + unsigned int irq_trigger_type; > + unsigned int wakeup_trigger_type; > spinlock_t lock; > bool disabled; > bool key_pressed; > @@ -540,6 +542,8 @@ static int gpio_keys_setup_key(struct platform_device *pdev, > } > > if (bdata->gpiod) { > + int active_low = gpiod_is_active_low(bdata->gpiod); > + > if (button->debounce_interval) { > error = gpiod_set_debounce(bdata->gpiod, > button->debounce_interval * 1000); > @@ -568,6 +572,16 @@ static int gpio_keys_setup_key(struct platform_device *pdev, > isr = gpio_keys_gpio_isr; > irqflags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING; > > + switch (button->wakeup_event_action) { > + case EV_ACT_ASSERTED: > + bdata->wakeup_trigger_type = active_low ? > + IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING; > + break; > + case EV_ACT_DEASSERTED: > + bdata->wakeup_trigger_type = active_low ? > + IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING; > + break; What about EV_ACT_ANY? And default case? I think for ANY, we're OK letting suspend/resume not reconfigure the trigger type, but maybe a comment here to note that? > + } > } else { What about the 'else' case? Shouldn't we try to handle that? Brian > if (!button->irq) { > dev_err(dev, "Found button without gpio or irq\n"); > @@ -618,6 +632,8 @@ static int gpio_keys_setup_key(struct platform_device *pdev, > return error; > } > > + bdata->irq_trigger_type = irq_get_trigger_type(bdata->irq); > + > return 0; > } > > @@ -718,6 +734,9 @@ gpio_keys_get_devtree_pdata(struct device *dev) > /* legacy name */ > fwnode_property_read_bool(child, "gpio-key,wakeup"); > > + fwnode_property_read_u32(child, "wakeup-event-action", > + &button->wakeup_event_action); > + > button->can_disable = > fwnode_property_read_bool(child, "linux,can-disable"); > > @@ -854,6 +873,10 @@ static int __maybe_unused gpio_keys_suspend(struct device *dev) > if (device_may_wakeup(dev)) { > for (i = 0; i < ddata->pdata->nbuttons; i++) { > struct gpio_button_data *bdata = &ddata->data[i]; > + > + if (bdata->button->wakeup && bdata->wakeup_trigger_type) > + irq_set_irq_type(bdata->irq, > + bdata->wakeup_trigger_type); > if (bdata->button->wakeup) > enable_irq_wake(bdata->irq); > bdata->suspended = true; > @@ -878,6 +901,10 @@ static int __maybe_unused gpio_keys_resume(struct device *dev) > if (device_may_wakeup(dev)) { > for (i = 0; i < ddata->pdata->nbuttons; i++) { > struct gpio_button_data *bdata = &ddata->data[i]; > + > + if (bdata->button->wakeup && bdata->wakeup_trigger_type) > + irq_set_irq_type(bdata->irq, > + bdata->irq_trigger_type); > if (bdata->button->wakeup) > disable_irq_wake(bdata->irq); > bdata->suspended = false; > diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h > index d06bf77400f1..7160df54a6fe 100644 > --- a/include/linux/gpio_keys.h > +++ b/include/linux/gpio_keys.h > @@ -13,6 +13,7 @@ struct device; > * @desc: label that will be attached to button's gpio > * @type: input event type (%EV_KEY, %EV_SW, %EV_ABS) > * @wakeup: configure the button as a wake-up source > + * @wakeup_event_action: event action to trigger wakeup > * @debounce_interval: debounce ticks interval in msecs > * @can_disable: %true indicates that userspace is allowed to > * disable button via sysfs > @@ -26,6 +27,7 @@ struct gpio_keys_button { > const char *desc; > unsigned int type; > int wakeup; > + int wakeup_event_action; > int debounce_interval; > bool can_disable; > int value; > diff --git a/include/uapi/linux/input-event-codes.h b/include/uapi/linux/input-event-codes.h > index 53fbae27b280..d7917b0bd438 100644 > --- a/include/uapi/linux/input-event-codes.h > +++ b/include/uapi/linux/input-event-codes.h > @@ -32,6 +32,15 @@ > #define INPUT_PROP_CNT (INPUT_PROP_MAX + 1) > > /* > + * Event action types > + */ > +#define EV_ACT_ANY 0x00 /* asserted or deasserted */ > +#define EV_ACT_ASSERTED 0x01 /* asserted */ > +#define EV_ACT_DEASSERTED 0x02 /* deasserted */ > +#define EV_ACT_MAX 0x02 > +#define EV_ACT_CNT (EV_ACT_MAX+1) > + > +/* > * Event types > */ > > -- > 2.11.0 > >