devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Input: rotary_encoder - support binary encoding of states
@ 2016-03-22 21:08 Uwe Kleine-König
       [not found] ` <1458680914-4533-1-git-send-email-u.kleine-koenig-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Uwe Kleine-König @ 2016-03-22 21:08 UTC (permalink / raw)
  To: linux-input, devicetree, Dmitry Torokhov
  Cc: kernel, Ezequiel Garcia, Sylvain Rochet, Johan Hovold,
	Daniel Mack, Rojhalat Ibrahim

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-03-23 13:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-22 21:08 [PATCH] Input: rotary_encoder - support binary encoding of states Uwe Kleine-König
     [not found] ` <1458680914-4533-1-git-send-email-u.kleine-koenig-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2016-03-22 22:50   ` 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

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).