From patchwork Tue Jan 31 07:55:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Holmberg X-Patchwork-Id: 9546681 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0523D60236 for ; Tue, 31 Jan 2017 07:55:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7AF92815E for ; Tue, 31 Jan 2017 07:55:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D9BB628249; Tue, 31 Jan 2017 07:55:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35F582815E for ; Tue, 31 Jan 2017 07:55:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750776AbdAaHza (ORCPT ); Tue, 31 Jan 2017 02:55:30 -0500 Received: from sub5.mail.dreamhost.com ([208.113.200.129]:40562 "EHLO homiemail-a44.g.dreamhost.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750790AbdAaHzY (ORCPT ); Tue, 31 Jan 2017 02:55:24 -0500 Received: from homiemail-a44.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a44.g.dreamhost.com (Postfix) with ESMTP id 7BD246000626; Mon, 30 Jan 2017 23:55:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pixelmunchies.com; h=date :from:to:cc:subject:message-id:mime-version:content-type; s= pixelmunchies.com; bh=B31cdVdhwHBI4eNYb6Bbw2iPg5Q=; b=oT76gZUXjW o5Px62ZAQswBu35VW5dyYANPq4RBJLIudm82S4z+DftXgjyOQ9YUvIHIjD46TpCs PEEd9CpWhmd7GAl00EBLLs2wiW0MEbMd76e3HjoPw2GEqN4LIZ12NW6lbAFiG+WC VmIPc/JqOuyj9AD27pdnuG8hrmkwgaj1k= Received: from Gaia (unknown [84.216.235.201]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: hans@pixelmunchies.com) by homiemail-a44.g.dreamhost.com (Postfix) with ESMTPSA id E1B926000602; Mon, 30 Jan 2017 23:55:21 -0800 (PST) Date: Tue, 31 Jan 2017 08:55:19 +0100 From: Hans Holmberg To: Dmitry Torokhov Cc: Guenter Roeck , Rob Herring , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: [RFC PATCH v2] Input: gpio_keys - add dt abs/rel button support Message-ID: <20170131075516.GA4462@Gaia> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This change adds support for specifying device tree buttons emitting abs/rel events. ABS events were previously supported, but only via platform data, so add the missing device tree property to allow axis values to be emitted with abs/rel events. Also emit 0 on button releases for REL and ABS keys. This is a must-have for supporting digital joysticks, and aligns the driver whith gpio-keys-polled. Finally, report min/max values for abs axes to the input framework. Signed-off-by: Hans Holmberg --- RFC because it alters the behaviour of abs-buttons making them un-sticky, reporting 0 on button releases - just like gpio-keys-polled. FWIW, i've looked through the in-tree board files and not found a single occurence of abs gpio-buttons. Changes since v1: * Corrected cc list - now the mailing lists are looped in. .../devicetree/bindings/input/gpio-keys.txt | 50 +++++++++++++++++++++- drivers/input/keyboard/gpio_keys.c | 29 +++++++++++-- 2 files changed, 75 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/input/gpio-keys.txt b/Documentation/devicetree/bindings/input/gpio-keys.txt index a949404..1b53eed 100644 --- a/Documentation/devicetree/bindings/input/gpio-keys.txt +++ b/Documentation/devicetree/bindings/input/gpio-keys.txt @@ -22,6 +22,13 @@ both at the same time. Specifying both properties is allowed. Optional subnode-properties: - linux,input-type: Specify event type this button/key generates. If not specified defaults to <1> == EV_KEY. + - linux,input-value: If linux,input-type is EV_ABS or EV_REL then this + value is sent for events this button generates when pressed. + EV_ABS/EV_REL axis will generate an event with a value of 0 when + all buttons with linux,input-type == type and linux,code == axis + are released. This value is interpreted as a signed 32 bit value, + e.g. to make a button generate a value of -1 use: + linux,input-value = <0xffffffff>; /* -1 */ - debounce-interval: Debouncing interval time in milliseconds. If not specified defaults to 5. - wakeup-source: Boolean, button can wake-up the system. @@ -47,4 +54,45 @@ Example nodes: linux,code = <108>; interrupts = <1 IRQ_TYPE_LEVEL_HIGH 7>; }; - ... + ... + + gpio-joystick: { + compatible = "gpio-keys"; + + pinctrl-names = "default"; + pinctrl-0 = <&my_pins>; + + up { + gpios = <&gpio 26 1>; + linux,input-type = ; + linux,code = ; + linux,input-value = <0xffffffff>; + }; + + down { + gpios = <&gpio 13 1>; + linux,input-type = ; + linux,code = ; + linux,input-value = <1>; + }; + + left { + gpios = <&gpio 6 1>; + linux,input-type = ; + linux,code = ; + linux,input-value = <0xffffffff>; + }; + + right { + gpios = <&gpio 5 1>; + linux,input-type = ; + linux,code = ; + linux,input-value = <0x1>; + }; + + trigger_button { + gpios = <&gpio 12 1>; + linux,code = ; + }; + }; + ... diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index 9c92cdf..06d6902 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -370,9 +370,11 @@ static void gpio_keys_gpio_report_event(struct gpio_button_data *bdata) return; } - if (type == EV_ABS) { + if (type == EV_ABS || type == EV_REL) { if (state) input_event(input, type, button->code, button->value); + else + input_event(input, type, button->code, 0); } else { input_event(input, type, *bdata->code, state); } @@ -584,6 +586,14 @@ static int gpio_keys_setup_key(struct platform_device *pdev, *bdata->code = button->code; input_set_capability(input, button->type ?: EV_KEY, *bdata->code); + if (button->type == EV_ABS) { + if (input_abs_get_max(input, button->code) < button->value) + input_abs_set_max(input, button->code, button->value); + + if (input_abs_get_min(input, button->code) > button->value) + input_abs_set_min(input, button->code, button->value); + } + /* * Install custom action to cancel release timer and * workqueue item. @@ -667,6 +677,7 @@ static void gpio_keys_close(struct input_dev *input) struct gpio_keys_button *button; struct fwnode_handle *child; int nbuttons; + int error; nbuttons = device_get_child_node_count(dev); if (nbuttons == 0) @@ -701,9 +712,21 @@ static void gpio_keys_close(struct input_dev *input) fwnode_property_read_string(child, "label", &button->desc); - if (fwnode_property_read_u32(child, "linux,input-type", - &button->type)) + error = fwnode_property_read_u32(child, "linux,input-type", + &button->type); + if (error) { button->type = EV_KEY; + } else { + error = fwnode_property_read_u32(child, + "linux,input-value", + &button->value); + if ((button->type == EV_ABS || button->type == EV_REL) + && error) { + dev_err(dev, + "EV_ABS/EV_REL button without value\n"); + return ERR_PTR(-EINVAL); + } + } button->wakeup = fwnode_property_read_bool(child, "wakeup-source") ||