From patchwork Fri Sep 13 21:52:40 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benson Leung X-Patchwork-Id: 2892491 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 699539F1C0 for ; Fri, 13 Sep 2013 21:52:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 765B820266 for ; Fri, 13 Sep 2013 21:52:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 580AA20263 for ; Fri, 13 Sep 2013 21:52:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756166Ab3IMVwt (ORCPT ); Fri, 13 Sep 2013 17:52:49 -0400 Received: from mail-pa0-f54.google.com ([209.85.220.54]:49153 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755634Ab3IMVws (ORCPT ); Fri, 13 Sep 2013 17:52:48 -0400 Received: by mail-pa0-f54.google.com with SMTP id kx10so3066243pab.27 for ; Fri, 13 Sep 2013 14:52:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=B1/MitTulTCDj7IJcGT6xX1YP2kQga77Af6WtVW0riA=; b=YzXWs+MtN9uO0KuEsoTmIzNvG65Hss/nXjJw9aihkpeMmHniRMr8LP4/QIBwNoW5+g pBoNnpCOaOvwF5vKfzalAaUQ4fdEYntFPVCKBpqNvnQj6HhSr/aLP5hC434XyW89yXOk U7FU/EDfag8Kooh5UrLR73oMWXo+ilP4c3tXA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=B1/MitTulTCDj7IJcGT6xX1YP2kQga77Af6WtVW0riA=; b=Y1TI5ounKSZg2f6537Zbl2u4nKvEoD8Pj94ABlH0X3T7SzXLVJBQejfJaRBcOty5Yi V1KU4CurPVIhv0UtYalEdsfhQKumTvip7CAekaI/cfj6H+s+rYj8NL1XN7tcyPuXCsd4 Qngxyoakzx/zoU+xt2dma47BpvUyhYHZUvAtwC0AtrhPm/oDjbsa/WVaimm5aAi62XU3 +UMGcjxUsMqNOYpNi19gPxVFL9geOXjuGr9zgv0gpCLfyQ9aCbIVKEO8Zye0Fx7HvjZo xBGgRz8omQyyNg1p68XkJhwVcJt3DSH98Poq/ZzO+J8aZV9WxsDloIqSDBxtFbXoaZOQ i3Pg== X-Gm-Message-State: ALoCoQkiZkNAsB+FSe4fB1bGsAQ6nsFbBGbc6vRUVkRqm5FHjy70Vxc85q+MdU3tIt0qdBnq2mvF X-Received: by 10.68.221.233 with SMTP id qh9mr15709828pbc.103.1379109168171; Fri, 13 Sep 2013 14:52:48 -0700 (PDT) Received: from laughingman.mtv.corp.google.com (laughingman.mtv.corp.google.com [172.22.73.99]) by mx.google.com with ESMTPSA id sy2sm13996155pbc.16.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Sep 2013 14:52:47 -0700 (PDT) From: Benson Leung To: dmitry.torokhov@gmail.com, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, david@protonic.nl Cc: bleung@chromium.org, dianders@chromium.org Subject: [PATCH] Input: gpio_keys - wakeup_trigger Date: Fri, 13 Sep 2013 14:52:40 -0700 Message-Id: <1379109160-32437-1-git-send-email-bleung@chromium.org> X-Mailer: git-send-email 1.8.4 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Allow wakeup_trigger to be defined per gpio button. Currently, all gpio buttons are set up as IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING. It may be more appropriate to only wake the system on one edge, for example if the gpio is for a Lid Switch. Signed-off-by: Benson Leung Reviewed-by: Doug Anderson --- .../devicetree/bindings/gpio/gpio_keys.txt | 7 +++++++ drivers/input/keyboard/gpio_keys.c | 23 ++++++++++++++++++++-- include/linux/gpio_keys.h | 3 +++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/gpio/gpio_keys.txt b/Documentation/devicetree/bindings/gpio/gpio_keys.txt index 5c2c021..243f569 100644 --- a/Documentation/devicetree/bindings/gpio/gpio_keys.txt +++ b/Documentation/devicetree/bindings/gpio/gpio_keys.txt @@ -20,6 +20,13 @@ Optional subnode-properties: - debounce-interval: Debouncing interval time in milliseconds. If not specified defaults to 5. - gpio-key,wakeup: Boolean, button can wake-up the system. + - gpio-key,wakeup-trigger : Specifies the type of wakeup behavior. + <1> == Rising Edge Trigger + <2> == Falling Edge Trigger + <3> == Both Rising and Falling Edge Trigger + <4> == Level High Trigger + <8> == Level Low Trigger + If not specified, defaults to <3> == Both Rising and Falling. Example nodes: diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index 440ce32..28b6992 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -40,6 +40,7 @@ struct gpio_button_data { spinlock_t lock; bool disabled; bool key_pressed; + unsigned long irqflags; }; struct gpio_keys_drvdata { @@ -493,6 +494,8 @@ static int gpio_keys_setup_key(struct platform_device *pdev, irqflags = 0; } + bdata->irqflags = irqflags; + input_set_capability(input, button->type ?: EV_KEY, button->code); /* @@ -643,6 +646,9 @@ gpio_keys_get_devtree_pdata(struct device *dev) if (of_property_read_u32(pp, "debounce-interval", &button->debounce_interval)) button->debounce_interval = 5; + + of_property_read_u32(pp, "gpio-key,wakeup-trigger", + &button->wakeup_trigger); } if (pdata->nbuttons == 0) { @@ -811,8 +817,14 @@ static int 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) + if (bdata->button->wakeup) { + unsigned int flags; + flags = bdata->button->wakeup_trigger & + IRQF_TRIGGER_MASK; + if (flags && flags != bdata->irqflags) + irq_set_irq_type(bdata->irq, flags); enable_irq_wake(bdata->irq); + } } } else { mutex_lock(&input->mutex); @@ -834,8 +846,15 @@ static int 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) + if (bdata->button->wakeup) { + unsigned int flags; + flags = bdata->button->wakeup_trigger & + IRQF_TRIGGER_MASK; disable_irq_wake(bdata->irq); + if (flags && flags != bdata->irqflags) + irq_set_irq_type(bdata->irq, + bdata->irqflags); + } } } else { mutex_lock(&input->mutex); diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h index a7e977f..d8d5a4f 100644 --- a/include/linux/gpio_keys.h +++ b/include/linux/gpio_keys.h @@ -15,6 +15,9 @@ struct gpio_keys_button { bool can_disable; int value; /* axis value for EV_ABS */ unsigned int irq; /* Irq number in case of interrupt keys */ + + /* trigger value (IRQF_TRIGGER_*) while used as a wake-up source */ + unsigned int wakeup_trigger; }; struct gpio_keys_platform_data {