Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp979319ybi; Fri, 14 Jun 2019 06:39:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqz4aWxeebgac+BG0OiTw7zoULj4NGR5RjcOTDwpfR+TNsJS++AFfEikuv2wu/1KZ+/tu/+R X-Received: by 2002:a17:902:54d:: with SMTP id 71mr91104076plf.140.1560519543225; Fri, 14 Jun 2019 06:39:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560519543; cv=none; d=google.com; s=arc-20160816; b=N3xthwYitMSlCMVMqBAN60igvavV180rYvYNjRj5daEiDh/oWeLXIXEmLq1bnePecO VS96ZWoWMe2AQKldRyb4Re+avinmi+OMXCXkVtxZqCCySH6/lVhdeL36KU4ZpLUkSMCP 7TqniswujcoXASg8d9gPZi63c1jiD/JGEPvD2fQjM7KB3i4MzPp068sB4HVz8ADCazTY DS0CJtdb2YebMzydPvvfBuxuaJPZk5xuRsJCBq4eBH7mT3pJsx1fcYlXpfRiMpqnEtxU bnpll2V9/ZR1We6As3doBQMq2dWp1DNtC/YW/JEVfmqsvgg/pIxL8WRAC66N/tbt+bU9 AItw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=/7/guhW367XBas9Ygicya39t9mL+v+5p+X5tq2ed/yk=; b=XGvPjXneZkXXLMz7p8JQKWrCWLTfVhWCA7nOOgKUAKksj9Wn+H1yXfXJPZUvNZQLHp uji85KdHLEKMlzB2E8f6QgWkAojpwquLGTxo8BgoL67FsUPoKhVbBG4ijXQiapmuTsHf t8yqNsqGYmM9NGqNPbJ/G1wmjlTn4nA7BJvmsvNc5EFFyHr45G/x/U0ZBnwuu1pDIG9p LI6ZolsoFY7Dv9KepjrBey/XiaoXUZD+Ovc/hrYdJdm8BpDV+3j3FrrrLakOLhHRddAM mIzeJL6vjol/abViHWGZ8s1EjwaSuOgTUENp4GaNdn9psVCiSdeTngGaSRi7zTv5Ubzl wCpA== 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 f9si2476811pfd.110.2019.06.14.06.38.46; Fri, 14 Jun 2019 06:39:03 -0700 (PDT) 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 S1728201AbfFNNhQ (ORCPT + 99 others); Fri, 14 Jun 2019 09:37:16 -0400 Received: from relay10.mail.gandi.net ([217.70.178.230]:55719 "EHLO relay10.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727827AbfFNNhQ (ORCPT ); Fri, 14 Jun 2019 09:37:16 -0400 Received: from dell-desktop.home (aaubervilliers-681-1-81-150.w90-88.abo.wanadoo.fr [90.88.23.150]) (Authenticated sender: mylene.josserand@bootlin.com) by relay10.mail.gandi.net (Postfix) with ESMTPSA id F3057240008; Fri, 14 Jun 2019 13:37:07 +0000 (UTC) From: =?UTF-8?q?Myl=C3=A8ne=20Josserand?= To: dmitry.torokhov@gmail.com, robh+dt@kernel.org, mark.rutland@arm.com Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, mylene.josserand@bootlin.com, thomas.petazzoni@bootlin.com Subject: [PATCH v1] Input: rotary-encoder - Add gpio as push button Date: Fri, 14 Jun 2019 15:36:51 +0200 Message-Id: <20190614133651.28396-1-mylene.josserand@bootlin.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add the support of a gpio that can be defined as a push button. Thanks to that, it is possible to emit a keycode in case of a "push" event, if the rotary supports that. The keycode to emit is defined using "linux,code" property (such as in gpio-keys). Signed-off-by: Mylène Josserand --- .../devicetree/bindings/input/rotary-encoder.txt | 5 +++ drivers/input/misc/rotary_encoder.c | 50 ++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/Documentation/devicetree/bindings/input/rotary-encoder.txt b/Documentation/devicetree/bindings/input/rotary-encoder.txt index a644408b33b8..1cfce5d0b5c4 100644 --- a/Documentation/devicetree/bindings/input/rotary-encoder.txt +++ b/Documentation/devicetree/bindings/input/rotary-encoder.txt @@ -22,6 +22,9 @@ Optional properties: - wakeup-source: Boolean, rotary encoder can wake up the system. - rotary-encoder,encoding: String, the method used to encode steps. Supported are "gray" (the default and more common) and "binary". +- push-gpio: a gpio to be used as a detection of a push from the rotary. +- linux,code: keycode to emit with the push-gpio of this rotary encoder. + Required property in case "push-gpio"'s one is used. Deprecated properties: - rotary-encoder,half-period: Makes the driver work on half-period mode. @@ -47,4 +50,6 @@ Example: rotary-encoder,steps = <24>; rotary-encoder,encoding = "binary"; rotary-encoder,rollover; + push-gpio = <&gpio 20 0>; + linux-code = <28> /* KEY_ENTER */ }; diff --git a/drivers/input/misc/rotary_encoder.c b/drivers/input/misc/rotary_encoder.c index d748897bf5e9..556995fb7dde 100644 --- a/drivers/input/misc/rotary_encoder.c +++ b/drivers/input/misc/rotary_encoder.c @@ -47,8 +47,10 @@ struct rotary_encoder { unsigned int pos; struct gpio_descs *gpios; + struct gpio_desc *gpio_push; unsigned int *irq; + unsigned int code; bool armed; signed char dir; /* 1 - clockwise, -1 - CCW */ @@ -56,6 +58,23 @@ struct rotary_encoder { unsigned int last_stable; }; +static irqreturn_t rotary_push_irq(int irq, void *dev_id) +{ + struct rotary_encoder *encoder = dev_id; + int val; + + mutex_lock(&encoder->access_mutex); + + val = gpiod_get_value_cansleep(encoder->gpio_push); + + input_report_key(encoder->input, encoder->code, val); + input_sync(encoder->input); + + mutex_unlock(&encoder->access_mutex); + + return IRQ_HANDLED; +} + static unsigned int rotary_encoder_get_state(struct rotary_encoder *encoder) { int i; @@ -190,6 +209,7 @@ static int rotary_encoder_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct rotary_encoder *encoder; struct input_dev *input; + unsigned int irq_push; irq_handler_t handler; u32 steps_per_period; unsigned int i; @@ -250,6 +270,20 @@ static int rotary_encoder_probe(struct platform_device *pdev) return -EINVAL; } + encoder->gpio_push = devm_gpiod_get_optional(dev, "push", GPIOD_IN); + if (IS_ERR(encoder->gpio_push)) { + dev_err(dev, "unable to get gpio-push\n"); + return PTR_ERR(encoder->gpio_push); + } + + if (encoder->gpio_push) { + if (device_property_read_u32(dev, "linux,code", + &encoder->code)) { + dev_err(dev, "gpio-push without keycode\n"); + return -EINVAL; + } + } + input = devm_input_allocate_device(dev); if (!input) return -ENOMEM; @@ -306,6 +340,22 @@ static int rotary_encoder_probe(struct platform_device *pdev) } } + if (encoder->gpio_push) { + input_set_capability(encoder->input, EV_KEY, encoder->code); + + irq_push = gpiod_to_irq(encoder->gpio_push); + err = devm_request_threaded_irq(dev, irq_push, + NULL, rotary_push_irq, + IRQF_TRIGGER_RISING | + IRQF_TRIGGER_FALLING | + IRQF_ONESHOT, + DRV_NAME, encoder); + if (err) { + dev_err(dev, "unable to request IRQ %d\n", irq_push); + return err; + } + } + err = input_register_device(input); if (err) { dev_err(dev, "failed to register input device\n"); -- 2.11.0