Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Uwe Kleine-König and committed by
Dmitry Torokhov
d205a218 f712a5a0

+26 -1
+4
Documentation/devicetree/bindings/input/rotary-encoder.txt
··· 20 20 2: Half-period mode 21 21 4: Quarter-period mode 22 22 - wakeup-source: Boolean, rotary encoder can wake up the system. 23 + - rotary-encoder,encoding: String, the method used to encode steps. 24 + Supported are "gray" (the default and more common) and "binary". 23 25 24 26 Deprecated properties: 25 27 - rotary-encoder,half-period: Makes the driver work on half-period mode. ··· 36 34 compatible = "rotary-encoder"; 37 35 gpios = <&gpio 19 1>, <&gpio 20 0>; /* GPIO19 is inverted */ 38 36 linux,axis = <0>; /* REL_X */ 37 + rotary-encoder,encoding = "gray"; 39 38 rotary-encoder,relative-axis; 40 39 }; 41 40 ··· 45 42 gpios = <&gpio 21 0>, <&gpio 22 0>; 46 43 linux,axis = <1>; /* ABS_Y */ 47 44 rotary-encoder,steps = <24>; 45 + rotary-encoder,encoding = "binary"; 48 46 rotary-encoder,rollover; 49 47 };
+22 -1
drivers/input/misc/rotary_encoder.c
··· 28 28 29 29 #define DRV_NAME "rotary-encoder" 30 30 31 + enum rotary_encoder_encoding { 32 + ROTENC_GRAY, 33 + ROTENC_BINARY, 34 + }; 35 + 31 36 struct rotary_encoder { 32 37 struct input_dev *input; 33 38 ··· 42 37 u32 axis; 43 38 bool relative_axis; 44 39 bool rollover; 40 + enum rotary_encoder_encoding encoding; 45 41 46 42 unsigned int pos; 47 43 ··· 63 57 64 58 for (i = 0; i < encoder->gpios->ndescs; ++i) { 65 59 int val = gpiod_get_value_cansleep(encoder->gpios->desc[i]); 60 + 66 61 /* convert from gray encoding to normal */ 67 - if (ret & 1) 62 + if (encoder->encoding == ROTENC_GRAY && ret & 1) 68 63 val = !val; 69 64 70 65 ret = ret << 1 | val; ··· 219 212 220 213 encoder->rollover = 221 214 device_property_read_bool(dev, "rotary-encoder,rollover"); 215 + 216 + if (!device_property_present(dev, "rotary-encoder,encoding") || 217 + !device_property_match_string(dev, "rotary-encoder,encoding", 218 + "gray")) { 219 + dev_info(dev, "gray"); 220 + encoder->encoding = ROTENC_GRAY; 221 + } else if (!device_property_match_string(dev, "rotary-encoder,encoding", 222 + "binary")) { 223 + dev_info(dev, "binary"); 224 + encoder->encoding = ROTENC_BINARY; 225 + } else { 226 + dev_err(dev, "unknown encoding setting\n"); 227 + return -EINVAL; 228 + } 222 229 223 230 device_property_read_u32(dev, "linux,axis", &encoder->axis); 224 231 encoder->relative_axis =