linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpio: cs5535-gpio: fix input direction
@ 2010-03-01 16:04 Ben Gardner
  2010-03-01 19:41 ` Andres Salomon
  0 siblings, 1 reply; 2+ messages in thread
From: Ben Gardner @ 2010-03-01 16:04 UTC (permalink / raw)
  To: Andrew Morton, Andres Salomon; +Cc: linux-kernel, David Brownell, Mark Brown

gpio: cs5535-gpio: fix input direction

The cs5535-gpio driver's get() function was returning the output value.
This means that the GPIO pins would never work as an input, even if configured
as an input.
The driver should return the READ_BACK value, which is the sensed line value.
To make that work when the direction is 'output', INPUT_ENABLE needs to be set.

In addition, the driver was not disabling OUTPUT_ENABLE when the
direction is set to 'input'. That would cause the GPIO to continue to
drive the pin if the direction was ever set to output.

This issue was noticed when attempting to use the gpiolib driver to read
an external input. I had previously been using the char/cs5535-gpio driver.

This patch should also be applied to 2.6.33.x, as that is the first version
that contains the gpio/cs5535-gpio driver.

Signed-off-by: Ben Gardner <gardner.ben@gmail.com>
CC: Andres Salomon <dilinger@collabora.co.uk>
CC: Andrew Morton <akpm@linux-foundation.org>
CC: David Brownell <dbrownell@users.sourceforge.net>
CC: Mark Brown <broonie@opensource.wolfsonmicro.com>
---
This patch replaces the following patches:
cs5535_gpio-gpio_chipget-should-return-the-input-value.patch
olpc-alsa-fix-cs5535audios-mic-gpio-to-enable-input.patch

References:
http://lkml.org/lkml/2010/2/27/253
http://lkml.org/lkml/2010/2/23/311
http://lkml.org/lkml/2010/2/26/335

 drivers/gpio/cs5535-gpio.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/gpio/cs5535-gpio.c b/drivers/gpio/cs5535-gpio.c
index 0fdbe94..0c3c498 100644
--- a/drivers/gpio/cs5535-gpio.c
+++ b/drivers/gpio/cs5535-gpio.c
@@ -154,7 +154,7 @@ static int chip_gpio_request(struct gpio_chip *c,
unsigned offset)

 static int chip_gpio_get(struct gpio_chip *chip, unsigned offset)
 {
-	return cs5535_gpio_isset(offset, GPIO_OUTPUT_VAL);
+	return cs5535_gpio_isset(offset, GPIO_READ_BACK);
 }

 static void chip_gpio_set(struct gpio_chip *chip, unsigned offset, int val)
@@ -172,6 +172,7 @@ static int chip_direction_input(struct gpio_chip
*c, unsigned offset)

 	spin_lock_irqsave(&chip->lock, flags);
 	__cs5535_gpio_set(chip, offset, GPIO_INPUT_ENABLE);
+	__cs5535_gpio_clear(chip, offset, GPIO_OUTPUT_ENABLE);
 	spin_unlock_irqrestore(&chip->lock, flags);

 	return 0;
@@ -184,6 +185,7 @@ static int chip_direction_output(struct gpio_chip
*c, unsigned offset, int val)

 	spin_lock_irqsave(&chip->lock, flags);

+	__cs5535_gpio_set(chip, offset, GPIO_INPUT_ENABLE);
 	__cs5535_gpio_set(chip, offset, GPIO_OUTPUT_ENABLE);
 	if (val)
 		__cs5535_gpio_set(chip, offset, GPIO_OUTPUT_VAL);
-- 
1.6.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] gpio: cs5535-gpio: fix input direction
  2010-03-01 16:04 [PATCH] gpio: cs5535-gpio: fix input direction Ben Gardner
@ 2010-03-01 19:41 ` Andres Salomon
  0 siblings, 0 replies; 2+ messages in thread
From: Andres Salomon @ 2010-03-01 19:41 UTC (permalink / raw)
  To: Ben Gardner; +Cc: Andrew Morton, linux-kernel, David Brownell, Mark Brown

On Mon, 1 Mar 2010 10:04:19 -0600
Ben Gardner <gardner.ben@gmail.com> wrote:

> gpio: cs5535-gpio: fix input direction
> 
> The cs5535-gpio driver's get() function was returning the output value.
> This means that the GPIO pins would never work as an input, even if configured
> as an input.
> The driver should return the READ_BACK value, which is the sensed line value.
> To make that work when the direction is 'output', INPUT_ENABLE needs to be set.
> 
> In addition, the driver was not disabling OUTPUT_ENABLE when the
> direction is set to 'input'. That would cause the GPIO to continue to
> drive the pin if the direction was ever set to output.
> 
> This issue was noticed when attempting to use the gpiolib driver to read
> an external input. I had previously been using the char/cs5535-gpio driver.
> 
> This patch should also be applied to 2.6.33.x, as that is the first version
> that contains the gpio/cs5535-gpio driver.
> 
> Signed-off-by: Ben Gardner <gardner.ben@gmail.com>
> CC: Andres Salomon <dilinger@collabora.co.uk>

Looked it over and tested it, seems fine to me.  Thanks!


Acked-by: Andres Salomon <dilinger@collabora.co.uk>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-03-01 19:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-01 16:04 [PATCH] gpio: cs5535-gpio: fix input direction Ben Gardner
2010-03-01 19:41 ` Andres Salomon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).