Skip to contentSkip to conversation

input/misc: rotary-encoder: Set gpio direction

PATCH Applied Andrew Clayton 5 participants 7 messages Feb 8, 2010 – Feb 11, 2010

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

PATCH 1/1 input/misc: rotary-encoder: Set gpio direction

While trying to get a rotary encoder working under a beagle board using the drivers/input/misc/rotary-encoder.c driver, we found that even with the right pin mux settings configured through /sys/kernel/debug/omap_mux/*, i.e INPUT_PULLUP and MODE4, the gpio_get_value() functions only ever returned 1.

By explicitly calling gpio_direction_input() after each requested gpio, the driver started working and started returning correct input events.

The following is the patch that works for us. What do you think?

Cheers,
Andrew

Set the gpio direction to input for each requested gpio.

Even with the correct pin mux settings, you still need to explicitly set the gpio direction. Call gpio_direction_input() after each requested gpio.

---

drivers/input/misc/rotary_encoder.c +14 -0
index 3b9f588..4ae0793 100644
@@ -152,6 +152,13 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev)
 		goto exit_unregister_input;
 	}
 
+	err = gpio_direction_input(pdata->gpio_a);
+	if (err) {
+		dev_err(&pdev->dev, "unable to set GPIO %d for input\n",
+			pdata->gpio_a);
+		goto exit_unregister_input;
+	}
+
 	err = gpio_request(pdata->gpio_b, DRV_NAME);
 	if (err) {
 		dev_err(&pdev->dev, "unable to request GPIO %d\n",
@@ -159,6 +166,13 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev)
 		goto exit_free_gpio_a;
 	}
 
+	err = gpio_direction_input(pdata->gpio_b);
+	if (err) {
+		dev_err(&pdev->dev, "unable to set GPIO %d for input\n",
+			pdata->gpio_b);
+		goto exit_free_gpio_a;
+	}
+
 	/* request the IRQs */
 	err = request_irq(encoder->irq_a, &rotary_encoder_irq,
 			  IORESOURCE_IRQ_HIGHEDGE | IORESOURCE_IRQ_LOWEDGE,
Tested-by on v1 1/1
#1 lore raw
Quoted 10 lines · Andrew Clayton

While trying to get a rotary encoder working under a beagle board using the drivers/input/misc/rotary-encoder.c driver, we found that even with the right pin mux settings configured through /sys/kernel/debug/omap_mux/*, i.e INPUT_PULLUP and MODE4, the gpio_get_value() functions only ever returned 1.

By explicitly calling gpio_direction_input() after each requested gpio, the driver started working and started returning correct input events.

The following is the patch that works for us. What do you think?

On the ep93xx the gpio's default as inputs. The gpio's must default as outputs on the beagle board. I never noticed the missing direction set call.

Quoted 44 lines

Cheers,
Andrew

Set the gpio direction to input for each requested gpio.

Even with the correct pin mux settings, you still need to explicitly set the gpio direction. Call gpio_direction_input() after each requested gpio.

---

drivers/input/misc/rotary_encoder.c +14 -0
index 3b9f588..4ae0793 100644
@@ -152,6 +152,13 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev)
 		goto exit_unregister_input;
 	}
 
+	err = gpio_direction_input(pdata->gpio_a);
+	if (err) {
+		dev_err(&pdev->dev, "unable to set GPIO %d for input\n",
+			pdata->gpio_a);
+		goto exit_unregister_input;
+	}
+
 	err = gpio_request(pdata->gpio_b, DRV_NAME);
 	if (err) {
 		dev_err(&pdev->dev, "unable to request GPIO %d\n",
@@ -159,6 +166,13 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev)
 		goto exit_free_gpio_a;
 	}
 
+	err = gpio_direction_input(pdata->gpio_b);
+	if (err) {
+		dev_err(&pdev->dev, "unable to set GPIO %d for input\n",
+			pdata->gpio_b);
+		goto exit_free_gpio_a;
+	}
+
 	/* request the IRQs */
 	err = request_irq(encoder->irq_a, &rotary_encoder_irq,
 			  IORESOURCE_IRQ_HIGHEDGE | IORESOURCE_IRQ_LOWEDGE,
Acked-by on v1 1/1
#2 lore raw
In reply to Andrew Clayton
Quoted 10 lines · Andrew Clayton

While trying to get a rotary encoder working under a beagle board using the drivers/input/misc/rotary-encoder.c driver, we found that even with the right pin mux settings configured through /sys/kernel/debug/omap_mux/*, i.e INPUT_PULLUP and MODE4, the gpio_get_value() functions only ever returned 1.

By explicitly calling gpio_direction_input() after each requested gpio, the driver started working and started returning correct input events.

The following is the patch that works for us. What do you think?

Yep, that looks good to me, thanks!

Quoted 40 lines

Set the gpio direction to input for each requested gpio.

Even with the correct pin mux settings, you still need to explicitly set the gpio direction. Call gpio_direction_input() after each requested gpio.

---

drivers/input/misc/rotary_encoder.c +14 -0
index 3b9f588..4ae0793 100644
@@ -152,6 +152,13 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev)
 		goto exit_unregister_input;
 	}
 
+	err = gpio_direction_input(pdata->gpio_a);
+	if (err) {
+		dev_err(&pdev->dev, "unable to set GPIO %d for input\n",
+			pdata->gpio_a);
+		goto exit_unregister_input;
+	}
+
 	err = gpio_request(pdata->gpio_b, DRV_NAME);
 	if (err) {
 		dev_err(&pdev->dev, "unable to request GPIO %d\n",
@@ -159,6 +166,13 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev)
 		goto exit_free_gpio_a;
 	}
 
+	err = gpio_direction_input(pdata->gpio_b);
+	if (err) {
+		dev_err(&pdev->dev, "unable to set GPIO %d for input\n",
+			pdata->gpio_b);
+		goto exit_free_gpio_a;
+	}
+
 	/* request the IRQs */
 	err = request_irq(encoder->irq_a, &rotary_encoder_irq,
 			  IORESOURCE_IRQ_HIGHEDGE | IORESOURCE_IRQ_LOWEDGE,
maintainer
#3 lore raw
Quoted 7 lines · Daniel Mack
Quoted 6 lines · Andrew Clayton

While trying to get a rotary encoder working under a beagle board using the drivers/input/misc/rotary-encoder.c driver, we found that even with the right pin mux settings configured through /sys/kernel/debug/omap_mux/*, i.e INPUT_PULLUP and MODE4, the gpio_get_value() functions only ever returned 1.

Quoted 8 lines
Quoted 4 lines

By explicitly calling gpio_direction_input() after each requested gpio, the driver started working and started returning correct input events.

The following is the patch that works for us. What do you think?

Yep, that looks good to me, thanks!

.33 material or hold off till .34?

Signature · 1 line
Dmitry
#4 lore raw
Quoted 11 lines · Dmitry Torokhov
Quoted 10 lines · Daniel Mack
Quoted 9 lines · Andrew Clayton

While trying to get a rotary encoder working under a beagle board using the drivers/input/misc/rotary-encoder.c driver, we found that even with the right pin mux settings configured through /sys/kernel/debug/omap_mux/*, i.e INPUT_PULLUP and MODE4, the gpio_get_value() functions only ever returned 1.

By explicitly calling gpio_direction_input() after each requested gpio, the driver started working and started returning correct input events.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

The following is the patch that works for us. What do you think?

Yep, that looks good to me, thanks!

.33 material or hold off till .34?

Hmm, it doesn't fix any existing upstream platform, so I think it should be fine for .34.

Thanks,
Daniel

maintainer Applied
#5 lore raw
Quoted 14 lines · Daniel Mack
Quoted 13 lines · Dmitry Torokhov
Quoted 12 lines · Daniel Mack
Quoted 10 lines · Andrew Clayton

While trying to get a rotary encoder working under a beagle board using the drivers/input/misc/rotary-encoder.c driver, we found that even with the right pin mux settings configured through /sys/kernel/debug/omap_mux/*, i.e INPUT_PULLUP and MODE4, the gpio_get_value() functions only ever returned 1.

By explicitly calling gpio_direction_input() after each requested gpio, the driver started working and started returning correct input events.

The following is the patch that works for us. What do you think?

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

Yep, that looks good to me, thanks!

.33 material or hold off till .34?

Hmm, it doesn't fix any existing upstream platform, so I think it should be fine for .34.

Applied to 'next' then, thank you.

Signature · 1 line
Dmitry
#6 lore raw
In reply to Andrew Clayton
Quoted 10 lines · Andrew Clayton

While trying to get a rotary encoder working under a beagle board using the drivers/input/misc/rotary-encoder.c driver, we found that even with the right pin mux settings configured through /sys/kernel/debug/omap_mux/*, i.e INPUT_PULLUP and MODE4, the gpio_get_value() functions only ever returned 1.

By explicitly calling gpio_direction_input() after each requested gpio, the driver started working and started returning correct input events.

The following is the patch that works for us. What do you think?

Adding my Signed-off-by tag:

Quoted 44 lines

Cheers,
Andrew

Set the gpio direction to input for each requested gpio.

Even with the correct pin mux settings, you still need to explicitly set the gpio direction. Call gpio_direction_input() after each requested gpio.

---

drivers/input/misc/rotary_encoder.c +14 -0
index 3b9f588..4ae0793 100644
@@ -152,6 +152,13 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev)
 		goto exit_unregister_input;
 	}
 
+	err = gpio_direction_input(pdata->gpio_a);
+	if (err) {
+		dev_err(&pdev->dev, "unable to set GPIO %d for input\n",
+			pdata->gpio_a);
+		goto exit_unregister_input;
+	}
+
 	err = gpio_request(pdata->gpio_b, DRV_NAME);
 	if (err) {
 		dev_err(&pdev->dev, "unable to request GPIO %d\n",
@@ -159,6 +166,13 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev)
 		goto exit_free_gpio_a;
 	}
 
+	err = gpio_direction_input(pdata->gpio_b);
+	if (err) {
+		dev_err(&pdev->dev, "unable to set GPIO %d for input\n",
+			pdata->gpio_b);
+		goto exit_free_gpio_a;
+	}
+
 	/* request the IRQs */
 	err = request_irq(encoder->irq_a, &rotary_encoder_irq,
 			  IORESOURCE_IRQ_HIGHEDGE | IORESOURCE_IRQ_LOWEDGE,