Received: by 10.223.185.116 with SMTP id b49csp94377wrg; Sat, 10 Feb 2018 03:11:09 -0800 (PST) X-Google-Smtp-Source: AH8x226o/pdfDd3E885xiDCxjjaoJnw45Lyc5jZQdPxdIj+1wJpTfPeKQ57BV6/G5BNEpqECyRF7 X-Received: by 2002:a17:902:9005:: with SMTP id a5-v6mr5295373plp.251.1518261069711; Sat, 10 Feb 2018 03:11:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518261069; cv=none; d=google.com; s=arc-20160816; b=loFW+2Wvr19G5ZP31IByemIdCkU79i6lQgoHuMUqNortJYQ1etaptfxqOylJwenUW6 o1C3LJrEVh8jWdJvi5VnrQMH518yNl3A0v9KRKfUb+2GmTEzi9ps1I3iobyPSi0g0Vwq ebok6z/x5AB+FYlIZcnt7coeC+KxZ6tvM5EEGDaah7MQnr3vHuA984ku118FQ8qHevmO DW5HJwOAXoIDlMhb7kts6beqhOWgayIgxuuQJpCJ+RQESe4lfB9PiSIozD7+8mljSQvW 9E+TXDwmfZo8X9vQO8+c7gztIzoaWbyZoDuDtVCladu6/QyDAq6nPDBUJXRQEUV/6km4 qc0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=UnLWS10Du+PZmIdC0JBy936WtMEvDFRI4ps9N/nhE24=; b=KS8ShjqhbeDtnNW6Dc6Pm6hPBc7z7WE3Yr/dG0qwmX8URg2xCmjM1Bbv1+1i1dbAj5 MMhOwBDLcNhDachPPsjbt6MtJxjOa8/tBE8HEcQ6HZ8CY04CscKKZSoH9jvZqyYcOU7f LTJZ9kjUgHfoVtqcb9bowB/Wd2VHIu/EUGvYwrFT4+kKbIz4vIvBSLT/nH/mNJMsCk8Y Sce7BIGzRCAszWt1JR4BJlNczli3Ugi6SHbP1IHo/0YZb42VcRWXdjSNp3arVq0OM7OV 97GWG1d4e9jBQLaf2Qy0Xh97PaSpnXDkNsaRNeg1aZY2wdHzlySXPBsNM6sWIAr1xFs8 6OMg== 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 m87si3181137pfk.383.2018.02.10.03.10.55; Sat, 10 Feb 2018 03:11:09 -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 S1751512AbeBJLKJ (ORCPT + 99 others); Sat, 10 Feb 2018 06:10:09 -0500 Received: from regular1.263xmail.com ([211.150.99.131]:33199 "EHLO regular1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751028AbeBJLKI (ORCPT ); Sat, 10 Feb 2018 06:10:08 -0500 Received: from jeffy.chen?rock-chips.com (unknown [192.168.167.73]) by regular1.263xmail.com (Postfix) with ESMTP id 5F44661EE; Sat, 10 Feb 2018 19:09:58 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from localhost (localhost [127.0.0.1]) by smtp.263.net (Postfix) with ESMTPA id 6C02E308; Sat, 10 Feb 2018 19:09:55 +0800 (CST) X-RL-SENDER: jeffy.chen@rock-chips.com X-FST-TO: linux-kernel@vger.kernel.org X-SENDER-IP: 103.29.142.67 X-LOGIN-NAME: jeffy.chen@rock-chips.com X-UNIQUE-TAG: X-ATTACHMENT-NUM: 0 X-SENDER: cjf@rock-chips.com X-DNS-TYPE: 0 Received: from localhost (unknown [103.29.142.67]) by smtp.263.net (Postfix) whith ESMTP id 2418584A6X; Sat, 10 Feb 2018 19:09:59 +0800 (CST) From: Jeffy Chen To: linux-kernel@vger.kernel.org Cc: briannorris@google.com, dtor@google.com, dianders@google.com, Jeffy Chen , 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: [PATCH v2 1/3] Input: gpio-keys - add support for wakeup event action Date: Sat, 10 Feb 2018 19:09:05 +0800 Message-Id: <20180210110907.5504-2-jeffy.chen@rock-chips.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180210110907.5504-1-jeffy.chen@rock-chips.com> References: <20180210110907.5504-1-jeffy.chen@rock-chips.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; + } } else { 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