From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: linux-input@vger.kernel.org, devicetree@vger.kernel.org,
Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: kernel@pengutronix.de,
Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>,
Sylvain Rochet <sylvain.rochet@finsecur.com>,
Johan Hovold <johan@kernel.org>, Daniel Mack <daniel@zonque.org>,
Rojhalat Ibrahim <imr@rtschenk.de>
Subject: [PATCH] Input: rotary_encoder - support binary encoding of states
Date: Tue, 22 Mar 2016 22:08:34 +0100 [thread overview]
Message-ID: <1458680914-4533-1-git-send-email-u.kleine-koenig@pengutronix.de> (raw)
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 <u.kleine-koenig@pengutronix.de>
---
Hello,
an alternative to define this difference in the device tree is to use
something like:
rotary-encoder,encoding = "binary";
or
rotary-encoder,encoding = <ROTARY_ENCODER_ENCODING_BINARY>;
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");
--
2.7.0
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next reply other threads:[~2016-03-22 21:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-22 21:08 Uwe Kleine-König [this message]
[not found] ` <1458680914-4533-1-git-send-email-u.kleine-koenig-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2016-03-22 22:50 ` [PATCH] Input: rotary_encoder - support binary encoding of states Ezequiel Garcia
2016-03-23 0:47 ` Rob Herring
2016-03-23 6:49 ` Uwe Kleine-König
2016-03-23 12:46 ` Rob Herring
2016-03-23 13:06 ` Daniel Mack
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1458680914-4533-1-git-send-email-u.kleine-koenig@pengutronix.de \
--to=u.kleine-koenig@pengutronix.de \
--cc=daniel@zonque.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=ezequiel@vanguardiasur.com.ar \
--cc=imr@rtschenk.de \
--cc=johan@kernel.org \
--cc=kernel@pengutronix.de \
--cc=linux-input@vger.kernel.org \
--cc=sylvain.rochet@finsecur.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).