* [PATCH v3] Input: rotary_encoder - support binary encoding of states
@ 2016-04-07 18:58 Uwe Kleine-König
2016-04-07 22:45 ` Rob Herring
0 siblings, 1 reply; 4+ messages in thread
From: Uwe Kleine-König @ 2016-04-07 18:58 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@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@pengutronix.de
- be more strict about parsing the encoding string
.../devicetree/bindings/input/rotary-encoder.txt | 4 ++++
drivers/input/misc/rotary_encoder.c | 26 +++++++++++++++++++---
2 files changed, 27 insertions(+), 3 deletions(-)
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 96c486de49e0..1e17e28188c6 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 binary */
+ if (ret & 1)
+ val = !val;
ret = ret << 1 | val;
}
@@ -183,6 +191,7 @@ static int rotary_encoder_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev;
struct rotary_encoder *encoder;
struct input_dev *input;
+ const char *encoding;
irq_handler_t handler;
u32 steps_per_period;
unsigned int i;
@@ -213,6 +222,17 @@ static int rotary_encoder_probe(struct platform_device *pdev)
encoder->rollover =
device_property_read_bool(dev, "rotary-encoder,rollover");
+ err = device_property_read_string(dev, "rotary-encoder,encoding",
+ &encoding);
+ if (!err && !strcmp(encoding, "binary")) {
+ encoder->encoding = ROTENC_BINARY;
+ } else if (err || !strcmp(encoding, "gray")) {
+ encoder->encoding = ROTENC_GRAY;
+ } else {
+ dev_err(dev, "unknown encoding setting");
+ 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.0.rc3
--
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] 4+ messages in thread
* Re: [PATCH v3] Input: rotary_encoder - support binary encoding of states
2016-04-07 18:58 [PATCH v3] Input: rotary_encoder - support binary encoding of states Uwe Kleine-König
@ 2016-04-07 22:45 ` Rob Herring
[not found] ` <CAL_JsqLfQQu69LcsFuJkKmjppp047vW5Ga+y5XiDAAG-Weh6ug-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: Rob Herring @ 2016-04-07 22:45 UTC (permalink / raw)
To: Uwe Kleine-König
Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org,
Dmitry Torokhov, kernel@pengutronix.de
On Thu, Apr 7, 2016 at 1:58 PM, Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> 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>
> ---
Ack for the binding, but...
> @@ -213,6 +222,17 @@ static int rotary_encoder_probe(struct platform_device *pdev)
> encoder->rollover =
> device_property_read_bool(dev, "rotary-encoder,rollover");
>
> + err = device_property_read_string(dev, "rotary-encoder,encoding",
> + &encoding);
> + if (!err && !strcmp(encoding, "binary")) {
> + encoder->encoding = ROTENC_BINARY;
> + } else if (err || !strcmp(encoding, "gray")) {
> + encoder->encoding = ROTENC_GRAY;
> + } else {
> + dev_err(dev, "unknown encoding setting");
> + return -EINVAL;
device_property_match_string() here instead.
> + }
> +
> device_property_read_u32(dev, "linux,axis", &encoder->axis);
> encoder->relative_axis =
> device_property_read_bool(dev, "rotary-encoder,relative-axis");
--
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] 4+ messages in thread
* Re: [PATCH v3] Input: rotary_encoder - support binary encoding of states
[not found] ` <CAL_JsqLfQQu69LcsFuJkKmjppp047vW5Ga+y5XiDAAG-Weh6ug-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2016-04-08 6:40 ` Uwe Kleine-König
[not found] ` <20160408064058.GC10108-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: Uwe Kleine-König @ 2016-04-08 6:40 UTC (permalink / raw)
To: Rob Herring
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Dmitry Torokhov, kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org,
linux-input-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Hello Rob,
On Thu, Apr 07, 2016 at 05:45:00PM -0500, Rob Herring wrote:
> On Thu, Apr 7, 2016 at 1:58 PM, Uwe Kleine-König
> <u.kleine-koenig-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> 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-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> > ---
>
> Ack for the binding, but...
Thanks. Actually I already had your ack for v2 and only dropped it to
make you look over the patch again :-)
> > @@ -213,6 +222,17 @@ static int rotary_encoder_probe(struct platform_device *pdev)
> > encoder->rollover =
> > device_property_read_bool(dev, "rotary-encoder,rollover");
> >
> > + err = device_property_read_string(dev, "rotary-encoder,encoding",
> > + &encoding);
> > + if (!err && !strcmp(encoding, "binary")) {
> > + encoder->encoding = ROTENC_BINARY;
> > + } else if (err || !strcmp(encoding, "gray")) {
> > + encoder->encoding = ROTENC_GRAY;
> > + } else {
> > + dev_err(dev, "unknown encoding setting");
> > + return -EINVAL;
>
> device_property_match_string() here instead.
With the added downside that the property is parsed at least twice from
dt, right? This is not a hot path, but still I wonder if it simplyfies
the driver code enough to be worth the effort?
Also this seems to have a different semantic and allows the property to
be an array.
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] Input: rotary_encoder - support binary encoding of states
[not found] ` <20160408064058.GC10108-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
@ 2016-04-11 15:32 ` Rob Herring
0 siblings, 0 replies; 4+ messages in thread
From: Rob Herring @ 2016-04-11 15:32 UTC (permalink / raw)
To: Uwe Kleine-König
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Dmitry Torokhov, kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org,
linux-input-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
On Fri, Apr 08, 2016 at 08:40:58AM +0200, Uwe Kleine-König wrote:
> Hello Rob,
>
> On Thu, Apr 07, 2016 at 05:45:00PM -0500, Rob Herring wrote:
> > On Thu, Apr 7, 2016 at 1:58 PM, Uwe Kleine-König
> > <u.kleine-koenig-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> 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-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> > > ---
> >
> > Ack for the binding, but...
>
> Thanks. Actually I already had your ack for v2 and only dropped it to
> make you look over the patch again :-)
>
> > > @@ -213,6 +222,17 @@ static int rotary_encoder_probe(struct platform_device *pdev)
> > > encoder->rollover =
> > > device_property_read_bool(dev, "rotary-encoder,rollover");
> > >
> > > + err = device_property_read_string(dev, "rotary-encoder,encoding",
> > > + &encoding);
> > > + if (!err && !strcmp(encoding, "binary")) {
> > > + encoder->encoding = ROTENC_BINARY;
> > > + } else if (err || !strcmp(encoding, "gray")) {
> > > + encoder->encoding = ROTENC_GRAY;
> > > + } else {
> > > + dev_err(dev, "unknown encoding setting");
> > > + return -EINVAL;
> >
> > device_property_match_string() here instead.
>
> With the added downside that the property is parsed at least twice from
> dt, right? This is not a hot path, but still I wonder if it simplyfies
> the driver code enough to be worth the effort?
IMO, yes.
> Also this seems to have a different semantic and allows the property to
> be an array.
It is not really the kernel's job to validate crap in bindings. If you
put '"binary", "gray"' in your DT, then the kernel may or may not handle
that.
Rob
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-04-11 15:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-07 18:58 [PATCH v3] Input: rotary_encoder - support binary encoding of states Uwe Kleine-König
2016-04-07 22:45 ` Rob Herring
[not found] ` <CAL_JsqLfQQu69LcsFuJkKmjppp047vW5Ga+y5XiDAAG-Weh6ug-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-04-08 6:40 ` Uwe Kleine-König
[not found] ` <20160408064058.GC10108-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2016-04-11 15:32 ` 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).