aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/input/rotary-encoder.rst85
1 files changed, 44 insertions, 41 deletions
diff --git a/Documentation/input/rotary-encoder.rst b/Documentation/input/rotary-encoder.rst
index 4695bea67f9b..b07b20a295ac 100644
--- a/Documentation/input/rotary-encoder.rst
+++ b/Documentation/input/rotary-encoder.rst
@@ -81,48 +81,51 @@ Board integration
81 81
82To use this driver in your system, register a platform_device with the 82To use this driver in your system, register a platform_device with the
83name 'rotary-encoder' and associate the IRQs and some specific platform 83name 'rotary-encoder' and associate the IRQs and some specific platform
84data with it. 84data with it. Because the driver uses generic device properties, this can
85be done either via device tree, ACPI, or using static board files, like in
86example below:
85 87
86struct rotary_encoder_platform_data is declared in 88::
87include/linux/rotary-encoder.h and needs to be filled with the number of
88steps the encoder has and can carry information about externally inverted
89signals (because of an inverting buffer or other reasons). The encoder
90can be set up to deliver input information as either an absolute or relative
91axes. For relative axes the input event returns +/-1 for each step. For
92absolute axes the position of the encoder can either roll over between zero
93and the number of steps or will clamp at the maximum and zero depending on
94the configuration.
95 89
96Because GPIO to IRQ mapping is platform specific, this information must 90 /* board support file example */
97be given in separately to the driver. See the example below.
98 91
99:: 92 #include <linux/input.h>
93 #include <linux/gpio/machine.h>
94 #include <linux/property.h>
95
96 #define GPIO_ROTARY_A 1
97 #define GPIO_ROTARY_B 2
98
99 static struct gpiod_lookup_table rotary_encoder_gpios = {
100 .dev_id = "rotary-encoder.0",
101 .table = {
102 GPIO_LOOKUP_IDX("gpio-0",
103 GPIO_ROTARY_A, NULL, 0, GPIO_ACTIVE_LOW),
104 GPIO_LOOKUP_IDX("gpio-0",
105 GPIO_ROTARY_B, NULL, 1, GPIO_ACTIVE_HIGH),
106 { },
107 },
108 };
109
110 static const struct property_entry rotary_encoder_properties[] __initconst = {
111 PROPERTY_ENTRY_INTEGER("rotary-encoder,steps-per-period", u32, 24),
112 PROPERTY_ENTRY_INTEGER("linux,axis", u32, ABS_X),
113 PROPERTY_ENTRY_INTEGER("rotary-encoder,relative_axis", u32, 0),
114 { },
115 };
116
117 static struct platform_device rotary_encoder_device = {
118 .name = "rotary-encoder",
119 .id = 0,
120 };
121
122 ...
123
124 gpiod_add_lookup_table(&rotary_encoder_gpios);
125 device_add_properties(&rotary_encoder_device, rotary_encoder_properties);
126 platform_device_register(&rotary_encoder_device);
127
128 ...
100 129
101 /* board support file example */ 130Please consult device tree binding documentation to see all properties
102 131supported by the driver.
103 #include <linux/input.h>
104 #include <linux/rotary_encoder.h>
105
106 #define GPIO_ROTARY_A 1
107 #define GPIO_ROTARY_B 2
108
109 static struct rotary_encoder_platform_data my_rotary_encoder_info = {
110 .steps = 24,
111 .axis = ABS_X,
112 .relative_axis = false,
113 .rollover = false,
114 .gpio_a = GPIO_ROTARY_A,
115 .gpio_b = GPIO_ROTARY_B,
116 .inverted_a = 0,
117 .inverted_b = 0,
118 .half_period = false,
119 .wakeup_source = false,
120 };
121
122 static struct platform_device rotary_encoder_device = {
123 .name = "rotary-encoder",
124 .id = 0,
125 .dev = {
126 .platform_data = &my_rotary_encoder_info,
127 }
128 };