Skip to contentSkip to conversation

input: rotary-encoder: add DT bindings

PATCH In review Daniel Mack 2 participants 5 messages Jul 24, 2012 – Jul 25, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 input: rotary-encoder: add DT bindings

This adds devicetree bindings to the rotary encoder driver and some documenation about how to use them. Tested on a PXA3xx platform.

---
 .../devicetree/bindings/input/rotary-encoder.txt   |   37 ++++++++++++
 drivers/input/misc/rotary_encoder.c                |   63 +++++++++++++++++++-
 2 files changed, 99 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/input/rotary-encoder.txt
Documentation/devicetree/bindings/input/rotary-encoder.txt new file +37 -0
new file mode 100644
index 0000000..dd1f634
@@ -0,0 +1,37 @@
+Rotary encoder DT bindings
+
+Required properties:
+- gpios: a spec for two GPIOs to be used
+
+Optional properties:
+- linux,axis: the input subsystem axis to map to this rotary encoder.
+  Defaults to 0 (ABS_X / REL_X)
+- rotary-encoder,steps: Number of steps in a full turnaround of the
+  encoder. Only relevant for absolute axis. Defaults to 24 which is a
+  typical value for such devices.
+- rotary-encoder,relative-axis: register a relative axis rather than an
+  absolute one. Relative axis will only generate +1/-1 events on the input
+  device, hence no steps need to be passed.
+- rotary-encoder,rollover: Automatic rollove when the rotary value becomes
+  greater than the specified steps or smaller than 0. For absolute axis only.
+- rotary-encoder,half-period: Makes the driver work on half-period mode.
+
+See Documentation/input/rotary-encoder.txt for more information.
+
+Example:
+
+		rotary@0 {
+			compatible = "rotary-encoder";
+			gpios = <&gpio 19 1>, <&gpio 20 0>; /* GPIO19 is inverted */
+			linux,axis = <0>; /* REL_X */
+			rotary-encoder,relative-axis;
+		};
+
+		rotary@1 {
+			compatible = "rotary-encoder";
+			gpios = <&gpio 21 0>, <&gpio 22 0>;
+			linux,axis = <1>; /* ABS_Y */
+			rotary-encoder,steps = <24>;
+			rotary-encoder,rollover;
+		};
+
drivers/input/misc/rotary_encoder.c +62 -1

88 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 2/2 input: rotary-encoder: defer calls gpio_to_irq()

Don't call gpio_to_irq() on GPIOs before gpio_request() succeeded on them. This avoids Ooopses with incorrect DT bindings.

---
 drivers/input/misc/rotary_encoder.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/input/misc/rotary_encoder.c +3 -2
index 350cbd1..474b04f 100644
@@ -223,8 +223,6 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev)
 
 	encoder->input = input;
 	encoder->pdata = pdata;
-	encoder->irq_a = gpio_to_irq(pdata->gpio_a);
-	encoder->irq_b = gpio_to_irq(pdata->gpio_b);
 
 	/* create and register the input driver */
 	input->name = pdev->name;
@@ -275,6 +273,9 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev)
 		goto exit_free_gpio_a;
 	}
 
+	encoder->irq_a = gpio_to_irq(pdata->gpio_a);
+	encoder->irq_b = gpio_to_irq(pdata->gpio_b);
+
 	/* request the IRQs */
 	if (pdata->half_period) {
 		handler = &rotary_encoder_half_period_irq;
Signature · 1 line
1.7.10.4
Reviewed-by on v1 2/2
#2 lore raw

RE: [PATCH 2/2] input: rotary-encoder: defer calls gpio_to_irq()

Quoted 22 lines · Daniel Mack

Don't call gpio_to_irq() on GPIOs before gpio_request() succeeded on them. This avoids Ooopses with incorrect DT bindings.

---
 drivers/input/misc/rotary_encoder.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/input/misc/rotary_encoder.c +0 -2
index 350cbd1..474b04f 100644
@@ -223,8 +223,6 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev)
 
 	encoder->input = input;
 	encoder->pdata = pdata;
-	encoder->irq_a = gpio_to_irq(pdata->gpio_a);
-	encoder->irq_b = gpio_to_irq(pdata->gpio_b);
 
 	/* create and register the input driver */
 	input->name = pdev->name;

drivers/input/misc/rotary_encoder.c static int __devinit rotary_encoder_probe(struct platform_device *pdev) · line 281

Quoted 9 lines
drivers/input/misc/rotary_encoder.c +3 -0
@@ -275,6 +273,9 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev)
 		goto exit_free_gpio_a;
 	}
 
+	encoder->irq_a = gpio_to_irq(pdata->gpio_a);
+	encoder->irq_b = gpio_to_irq(pdata->gpio_b);
+
 	/* request the IRQs */
 	if (pdata->half_period) {
 		handler = &rotary_encoder_half_period_irq;

Daniel,

You might want to put this patch first before adding the DT binding stuff.

You also might consider using gpio_request_one() or even the devm_* version, instead of doing the gpio_request() followed by the gpio_direction_input().

Actually, if you convert the probe to use the managed resource devm_* stuff it would really cleanup the error path and the remove.

Regardless...

#3 lore raw

Re: [PATCH 2/2] input: rotary-encoder: defer calls gpio_to_irq()

Quoted 38 lines · H Hartley Sweeten
Quoted 22 lines · Daniel Mack

Don't call gpio_to_irq() on GPIOs before gpio_request() succeeded on them. This avoids Ooopses with incorrect DT bindings.

---
 drivers/input/misc/rotary_encoder.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/input/misc/rotary_encoder.c +0 -2
index 350cbd1..474b04f 100644
@@ -223,8 +223,6 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev)
 
 	encoder->input = input;
 	encoder->pdata = pdata;
-	encoder->irq_a = gpio_to_irq(pdata->gpio_a);
-	encoder->irq_b = gpio_to_irq(pdata->gpio_b);
 
 	/* create and register the input driver */
 	input->name = pdev->name;

drivers/input/misc/rotary_encoder.c static int __devinit rotary_encoder_probe(struct platform_device *pdev) · line 281

Quoted 9 lines
drivers/input/misc/rotary_encoder.c +3 -0
@@ -275,6 +273,9 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev)
 		goto exit_free_gpio_a;
 	}
 
+	encoder->irq_a = gpio_to_irq(pdata->gpio_a);
+	encoder->irq_b = gpio_to_irq(pdata->gpio_b);
+
 	/* request the IRQs */
 	if (pdata->half_period) {
 		handler = &rotary_encoder_half_period_irq;

Daniel,

You might want to put this patch first before adding the DT binding stuff.

Quoted 6 lines

You also might consider using gpio_request_one() or even the devm_* version, instead of doing the gpio_request() followed by the gpio_direction_input().

Actually, if you convert the probe to use the managed resource devm_* stuff it would really cleanup the error path and the remove.

Yes, you're right. Thanks for the hint. New version coming up. Does your
Reviewed-by: still apply?

Daniel

#4 lore raw

RE: [PATCH 2/2] input: rotary-encoder: defer calls gpio_to_irq()

Quoted 8 lines · Daniel Mack
Quoted 7 lines · H Hartley Sweeten

You might want to put this patch first before adding the DT binding stuff.

You also might consider using gpio_request_one() or even the devm_* version, instead of doing the gpio_request() followed by the gpio_direction_input().

Quoted 5 lines
Quoted 2 lines

Actually, if you convert the probe to use the managed resource devm_* stuff it would really cleanup the error path and the remove.

Yes, you're right. Thanks for the hint. New version coming up. Does your
Reviewed-by: still apply?

As pointed out by Dmitry, the devm_* stuff will not work with this driver.

Please update the patch to just use the gpio_request_one() and I'll review it again.

Sorry about that.

Hartley