* [PATCH v4] Input: rotary_encoder - support binary encoding of states
@ 2016-07-19 19:38 Uwe Kleine-König
2016-07-20 13:19 ` Rob Herring
0 siblings, 1 reply; 2+ messages in thread
From: Uwe Kleine-König @ 2016-07-19 19:38 UTC (permalink / raw)
To: linux-input, devicetree, Dmitry Torokhov, Rob Herring; +Cc: kernel
It's not advisable to use this encoding, but to support existing devices
add support for this to the driver.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
Notes:
Changes since (implicit) v1, sent with
Message-Id: 1458680914-4533-1-git-send-email-u.kleine-koenig <at> pengutronix.de
- switch format of dt properties to use strings
Changes since v2, sent with
Message-Id: 1458806232-22403-1-git-send-email-u.kleine-koenig <at> pengutronix.de
- be more strict about parsing the encoding string
Changes since v3, sent with
Message-Id: 1460055528-13814-1-git-send-email-u.kleine-koenig@pengutronix.de
- use device_property_match_string to parse device tree as requested
by Rob Herring.
.../devicetree/bindings/input/rotary-encoder.txt | 4 ++++
drivers/input/misc/rotary_encoder.c | 23 +++++++++++++++++++++-
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/Documentation/devicetree/bindings/input/rotary-encoder.txt b/Documentation/devicetree/bindings/input/rotary-encoder.txt
index 6c9f0c8a846c..e85ce3dea480 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: String, the method used to encode steps.
+ Supported are "gray" (the default and more common) and "binary".
Deprecated properties:
- rotary-encoder,half-period: Makes the driver work on half-period mode.
@@ -34,6 +36,7 @@ Example:
compatible = "rotary-encoder";
gpios = <&gpio 19 1>, <&gpio 20 0>; /* GPIO19 is inverted */
linux,axis = <0>; /* REL_X */
+ rotary-encoder,encoding = "gray";
rotary-encoder,relative-axis;
};
@@ -42,5 +45,6 @@ Example:
gpios = <&gpio 21 0>, <&gpio 22 0>;
linux,axis = <1>; /* ABS_Y */
rotary-encoder,steps = <24>;
+ rotary-encoder,encoding = "binary";
rotary-encoder,rollover;
};
diff --git a/drivers/input/misc/rotary_encoder.c b/drivers/input/misc/rotary_encoder.c
index c7fc8d4fb080..1588aecafff7 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,8 +63,9 @@ static unsigned int 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)
+ if (encoder->encoding == ROTENC_GRAY && ret & 1)
val = !val;
ret = ret << 1 | val;
@@ -213,6 +220,20 @@ static int rotary_encoder_probe(struct platform_device *pdev)
encoder->rollover =
device_property_read_bool(dev, "rotary-encoder,rollover");
+ if (!device_property_present(dev, "rotary-encoder,encoding") ||
+ !device_property_match_string(dev, "rotary-encoder,encoding",
+ "gray")) {
+ dev_info(dev, "gray");
+ encoder->encoding = ROTENC_GRAY;
+ } else if (!device_property_match_string(dev, "rotary-encoder,encoding",
+ "binary")) {
+ dev_info(dev, "binary");
+ encoder->encoding = ROTENC_BINARY;
+ } else {
+ dev_err(dev, "unknown encoding setting\n");
+ return -EINVAL;
+ }
+
device_property_read_u32(dev, "linux,axis", &encoder->axis);
encoder->relative_axis =
device_property_read_bool(dev, "rotary-encoder,relative-axis");
--
2.8.1
--
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] 2+ messages in thread
* Re: [PATCH v4] Input: rotary_encoder - support binary encoding of states
2016-07-19 19:38 [PATCH v4] Input: rotary_encoder - support binary encoding of states Uwe Kleine-König
@ 2016-07-20 13:19 ` Rob Herring
0 siblings, 0 replies; 2+ messages in thread
From: Rob Herring @ 2016-07-20 13:19 UTC (permalink / raw)
To: Uwe Kleine-König; +Cc: linux-input, devicetree, Dmitry Torokhov, kernel
On Tue, Jul 19, 2016 at 09:38:39PM +0200, Uwe Kleine-König wrote:
> It's not advisable to use this encoding, but to support existing devices
> add support for this to the driver.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> Notes:
> Changes since (implicit) v1, sent with
> Message-Id: 1458680914-4533-1-git-send-email-u.kleine-koenig <at> pengutronix.de
>
> - switch format of dt properties to use strings
>
> Changes since v2, sent with
> Message-Id: 1458806232-22403-1-git-send-email-u.kleine-koenig <at> pengutronix.de
>
> - be more strict about parsing the encoding string
>
> Changes since v3, sent with
> Message-Id: 1460055528-13814-1-git-send-email-u.kleine-koenig@pengutronix.de
>
> - use device_property_match_string to parse device tree as requested
> by Rob Herring.
>
> .../devicetree/bindings/input/rotary-encoder.txt | 4 ++++
> drivers/input/misc/rotary_encoder.c | 23 +++++++++++++++++++++-
> 2 files changed, 26 insertions(+), 1 deletion(-)
Acked-by: Rob Herring <robh@kernel.org>
--
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 [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-07-20 13:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-19 19:38 [PATCH v4] Input: rotary_encoder - support binary encoding of states Uwe Kleine-König
2016-07-20 13:19 ` Rob Herring
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).