linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org,
	Rob Herring <robh+dt@kernel.org>,
	Rojhalat Ibrahim <imr@rtschenk.de>,
	Sylvain Rochet <sylvain.rochet@finsecur.com>,
	Johan Hovold <johan@kernel.org>,
	Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>,
	kernel@pengutronix.de, Daniel Mack <daniel@zonque.org>
Subject: Re: [PATCH v2] Input: rotary_encoder - support binary encoding of states
Date: Thu, 7 Apr 2016 11:15:13 -0700	[thread overview]
Message-ID: <20160407181513.GA7283@dtor-ws> (raw)
In-Reply-To: <1458806232-22403-1-git-send-email-u.kleine-koenig@pengutronix.de>

On Thu, Mar 24, 2016 at 08:57:12AM +0100, 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@pengutronix.de
>     
>      - switch format of dt properties to use strings
> 
>  .../devicetree/bindings/input/rotary-encoder.txt   |  4 ++++
>  drivers/input/misc/rotary_encoder.c                | 22 +++++++++++++++++++---
>  2 files changed, 23 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..d226d69a174a 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,13 @@ 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 && encoding[0] == 'b')

Why do we only match on first letter? I'd prefer we did better parsing
(i.e. only accepted valid encodings or no encoding property.

> +		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
> 

Thanks.

-- 
Dmitry
--
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

  parent reply	other threads:[~2016-04-07 18:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-24  7:57 [PATCH v2] Input: rotary_encoder - support binary encoding of states Uwe Kleine-König
2016-03-25 14:21 ` Rob Herring
2016-04-07 18:15 ` Dmitry Torokhov [this message]
2016-04-07 18:45   ` Uwe Kleine-König

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=20160407181513.GA7283@dtor-ws \
    --to=dmitry.torokhov@gmail.com \
    --cc=daniel@zonque.org \
    --cc=devicetree@vger.kernel.org \
    --cc=ezequiel@vanguardiasur.com.ar \
    --cc=imr@rtschenk.de \
    --cc=johan@kernel.org \
    --cc=kernel@pengutronix.de \
    --cc=linux-input@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=sylvain.rochet@finsecur.com \
    --cc=u.kleine-koenig@pengutronix.de \
    /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).