Commit d205a218 authored by Uwe Kleine-König's avatar Uwe Kleine-König Committed by Dmitry Torokhov

Input: rotary_encoder - support binary encoding of states

It's not advisable to use this encoding, but to support existing devices
add support for this to the driver.
Signed-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Acked-by: default avatarRob Herring <robh@kernel.org>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent f712a5a0
...@@ -20,6 +20,8 @@ Optional properties: ...@@ -20,6 +20,8 @@ Optional properties:
2: Half-period mode 2: Half-period mode
4: Quarter-period mode 4: Quarter-period mode
- wakeup-source: Boolean, rotary encoder can wake up the system. - 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: Deprecated properties:
- rotary-encoder,half-period: Makes the driver work on half-period mode. - rotary-encoder,half-period: Makes the driver work on half-period mode.
...@@ -34,6 +36,7 @@ Example: ...@@ -34,6 +36,7 @@ Example:
compatible = "rotary-encoder"; compatible = "rotary-encoder";
gpios = <&gpio 19 1>, <&gpio 20 0>; /* GPIO19 is inverted */ gpios = <&gpio 19 1>, <&gpio 20 0>; /* GPIO19 is inverted */
linux,axis = <0>; /* REL_X */ linux,axis = <0>; /* REL_X */
rotary-encoder,encoding = "gray";
rotary-encoder,relative-axis; rotary-encoder,relative-axis;
}; };
...@@ -42,5 +45,6 @@ Example: ...@@ -42,5 +45,6 @@ Example:
gpios = <&gpio 21 0>, <&gpio 22 0>; gpios = <&gpio 21 0>, <&gpio 22 0>;
linux,axis = <1>; /* ABS_Y */ linux,axis = <1>; /* ABS_Y */
rotary-encoder,steps = <24>; rotary-encoder,steps = <24>;
rotary-encoder,encoding = "binary";
rotary-encoder,rollover; rotary-encoder,rollover;
}; };
...@@ -28,6 +28,11 @@ ...@@ -28,6 +28,11 @@
#define DRV_NAME "rotary-encoder" #define DRV_NAME "rotary-encoder"
enum rotary_encoder_encoding {
ROTENC_GRAY,
ROTENC_BINARY,
};
struct rotary_encoder { struct rotary_encoder {
struct input_dev *input; struct input_dev *input;
...@@ -37,6 +42,7 @@ struct rotary_encoder { ...@@ -37,6 +42,7 @@ struct rotary_encoder {
u32 axis; u32 axis;
bool relative_axis; bool relative_axis;
bool rollover; bool rollover;
enum rotary_encoder_encoding encoding;
unsigned int pos; unsigned int pos;
...@@ -57,8 +63,9 @@ static unsigned int rotary_encoder_get_state(struct rotary_encoder *encoder) ...@@ -57,8 +63,9 @@ static unsigned int rotary_encoder_get_state(struct rotary_encoder *encoder)
for (i = 0; i < encoder->gpios->ndescs; ++i) { for (i = 0; i < encoder->gpios->ndescs; ++i) {
int val = gpiod_get_value_cansleep(encoder->gpios->desc[i]); int val = gpiod_get_value_cansleep(encoder->gpios->desc[i]);
/* convert from gray encoding to normal */ /* convert from gray encoding to normal */
if (ret & 1) if (encoder->encoding == ROTENC_GRAY && ret & 1)
val = !val; val = !val;
ret = ret << 1 | val; ret = ret << 1 | val;
...@@ -213,6 +220,20 @@ static int rotary_encoder_probe(struct platform_device *pdev) ...@@ -213,6 +220,20 @@ static int rotary_encoder_probe(struct platform_device *pdev)
encoder->rollover = encoder->rollover =
device_property_read_bool(dev, "rotary-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); device_property_read_u32(dev, "linux,axis", &encoder->axis);
encoder->relative_axis = encoder->relative_axis =
device_property_read_bool(dev, "rotary-encoder,relative-axis"); device_property_read_bool(dev, "rotary-encoder,relative-axis");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment