From patchwork Tue Mar 22 21:08:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 8645691 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id AF413C0553 for ; Tue, 22 Mar 2016 21:18:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C77C320396 for ; Tue, 22 Mar 2016 21:18:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D9F7B2037C for ; Tue, 22 Mar 2016 21:18:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751362AbcCVVSk (ORCPT ); Tue, 22 Mar 2016 17:18:40 -0400 Received: from arcturus.kleine-koenig.org ([78.47.169.190]:56269 "EHLO arcturus.kleine-koenig.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751286AbcCVVSj (ORCPT ); Tue, 22 Mar 2016 17:18:39 -0400 X-Greylist: delayed 595 seconds by postgrey-1.27 at vger.kernel.org; Tue, 22 Mar 2016 17:18:39 EDT Received: by arcturus.kleine-koenig.org (Postfix, from userid 1000) id 1A2AC96BBD; Tue, 22 Mar 2016 22:08:38 +0100 (CET) From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: linux-input@vger.kernel.org, devicetree@vger.kernel.org, Dmitry Torokhov Cc: kernel@pengutronix.de, Ezequiel Garcia , Sylvain Rochet , Johan Hovold , Daniel Mack , Rojhalat Ibrahim Subject: [PATCH] Input: rotary_encoder - support binary encoding of states Date: Tue, 22 Mar 2016 22:08:34 +0100 Message-Id: <1458680914-4533-1-git-send-email-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.7.0 MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 A plain binary encoding has some downsides compared to the usual Gray encoding, but that doesn't stop hardware engineers to eventually use it. So implement support for this encoding in the rotary encoder driver. Signed-off-by: Uwe Kleine-König --- Hello, an alternative to define this difference in the device tree is to use something like: rotary-encoder,encoding = "binary"; or rotary-encoder,encoding = ; instead of a property rotary-encoder,encoding-binary; . While the two first solutions make it obvious that there can only be one encoding, they IMHO look ugly, so I went for the property without value. What do you think? Best regards Uwe .../devicetree/bindings/input/rotary-encoder.txt | 2 ++ drivers/input/misc/rotary_encoder.c | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/input/rotary-encoder.txt b/Documentation/devicetree/bindings/input/rotary-encoder.txt index 6c9f0c8a846c..4a96e4a32503 100644 --- a/Documentation/devicetree/bindings/input/rotary-encoder.txt +++ b/Documentation/devicetree/bindings/input/rotary-encoder.txt @@ -20,6 +20,8 @@ Optional properties: 2: Half-period mode 4: Quarter-period mode - wakeup-source: Boolean, rotary encoder can wake up the system. +- rotary-encoder,encoding-binary: The device uses binary states instead of + gray encoding (which is the default). Deprecated properties: - rotary-encoder,half-period: Makes the driver work on half-period mode. diff --git a/drivers/input/misc/rotary_encoder.c b/drivers/input/misc/rotary_encoder.c index 96c486de49e0..ce43a59ca41a 100644 --- a/drivers/input/misc/rotary_encoder.c +++ b/drivers/input/misc/rotary_encoder.c @@ -28,6 +28,11 @@ #define DRV_NAME "rotary-encoder" +enum rotary_encoder_encoding { + ROTENC_GRAY, + ROTENC_BINARY, +}; + struct rotary_encoder { struct input_dev *input; @@ -37,6 +42,7 @@ struct rotary_encoder { u32 axis; bool relative_axis; bool rollover; + enum rotary_encoder_encoding encoding; unsigned int pos; @@ -57,9 +63,11 @@ static unsigned rotary_encoder_get_state(struct rotary_encoder *encoder) for (i = 0; i < encoder->gpios->ndescs; ++i) { int val = gpiod_get_value_cansleep(encoder->gpios->desc[i]); - /* convert from gray encoding to normal */ - if (ret & 1) - val = !val; + + if (encoder->encoding == ROTENC_GRAY) + /* convert from gray encoding to normal */ + if (ret & 1) + val = !val; ret = ret << 1 | val; } @@ -213,6 +221,11 @@ static int rotary_encoder_probe(struct platform_device *pdev) encoder->rollover = device_property_read_bool(dev, "rotary-encoder,rollover"); + if (device_property_read_bool(dev, "rotary-encoder,encoding-binary")) + encoder->encoding = ROTENC_BINARY; + else + encoder->encoding = ROTENC_GRAY; + device_property_read_u32(dev, "linux,axis", &encoder->axis); encoder->relative_axis = device_property_read_bool(dev, "rotary-encoder,relative-axis");