cs5535_gpio: gpio_chip.get should return the input value
Subsystems (3)
PATCH 1/1 cs5535_gpio: gpio_chip.get should return the input value
The gpio_chip.get() function for the CS5535 GPIO driver currently returns the output value instead of the input value.
This patch changes it to return the input value.
---
drivers/gpio/cs5535-gpio.c +1 -1
@@ -154,7 +154,7 @@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)
Quoted 9 lines · On Tue, 23 Feb 2010 16:55:17 -0600 Ben Gardner <[email protected]> wrote:
The
gpio_chip.get()function for the CS5535 GPIO driver currently returns the output value instead of the input value.
This patch changes it to return the input value.Signed-off-by Ben Gardner <[email protected]>---
drivers/gpio/cs5535-gpio.c line 160
Quoted 8 lines
drivers/gpio/cs5535-gpio.c +1
-1@@ -154,7 +154,7 @@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)
<presses F10>
What were the user-visible effects of this bug?
Quoted 10 lines
Quoted 10 lines
drivers/gpio/cs5535-gpio.c +1
-1@@ -154,7 +154,7 @@ 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); }
Quoted 5 lines
drivers/gpio/cs5535-gpio.c line 160
Quoted 1 line
drivers/gpio/cs5535-gpio.c +0
-0static void chip_gpio_set(struct gpio_chip *chip, unsigned offset, int val)<presses F10>
What were the user-visible effects of this bug?
The user-visible effects were that the input didn't work.
I use the CS5535 chip in a custom board that uses GPIO 25 and 26 as voltage monitoring inputs (external voltage comparators). Since the char-based cs5535-gpio is now deprecated, I'm trying out the gpio driver.
I export the GPIO pins via sysfs to access them from user-space. Reading the 'value' member didn't reflect the input.
Personally, I would prefer a separate sysfs entry for the output and the input, since the GPIO pins can be both outputs and inputs, but that would require a gpiolib change.
Since there doesn't appear to be a gpio maintainer, any change to that might be tricky.
Ben
Quoted 16 lines · On Wed, 24 Feb 2010 21:52:07 -0600 Ben Gardner <[email protected]> wrote:
Quoted 10 lines
Quoted 10 lines
drivers/gpio/cs5535-gpio.c +1
-1@@ -154,7 +154,7 @@ __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); __}Quoted 5 lines
drivers/gpio/cs5535-gpio.c line 160
Quoted 1 line
drivers/gpio/cs5535-gpio.c +0
-0__static void chip_gpio_set(struct gpio_chip *chip, unsigned offset, int val)<presses F10>
What were the user-visible effects of this bug?
Quoted 7 lines
The user-visible effects were that the input didn't work.
I use the CS5535 chip in a custom board that uses GPIO 25 and 26 as voltage monitoring inputs (external voltage comparators). Since the char-based cs5535-gpio is now deprecated, I'm trying out the gpio driver.
I export the GPIO pins via sysfs to access them from user-space. Reading the 'value' member didn't reflect the input.
OK, then in that case we'd want to backport this into 2.6.33.x and perhaps earlier?
Quoted 5 lines
Personally, I would prefer a separate sysfs entry for the output and the input, since the GPIO pins can be both outputs and inputs, but that would require a gpiolib change.
Since there doesn't appear to be a gpio maintainer, any change to that might be tricky.
Eh, we can cope. Propose a patch and cc lots of people..
Quoted 10 lines
Quoted 9 lines
Quoted 1 line
What were the user-visible effects of this bug?
The user-visible effects were that the input didn't work.
I use the CS5535 chip in a custom board that uses GPIO 25 and 26 as voltage monitoring inputs (external voltage comparators). Since the char-based cs5535-gpio is now deprecated, I'm trying out the gpio driver.
I export the GPIO pins via sysfs to access them from user-space. Reading the 'value' member didn't reflect the input.
Quoted 2 lines
OK, then in that case we'd want to backport this into 2.6.33.x and perhaps earlier?
It looks like the driver was added 15 Dec 2009, so it doesn't look like it existed in an earlier kernel.
Quoted 7 lines
Quoted 5 lines
Personally, I would prefer a separate sysfs entry for the output and the input, since the GPIO pins can be both outputs and inputs, but that would require a gpiolib change.
Since there doesn't appear to be a gpio maintainer, any change to that might be tricky.Eh, we can cope. Propose a patch and cc lots of people..
Will do.
Thanks,
Ben
Quoted 10 lines · On Wed, 24 Feb 2010 22:16:43 -0600 Ben Gardner <[email protected]> wrote:
Quoted 10 lines
Quoted 9 lines
Quoted 1 line
What were the user-visible effects of this bug?
The user-visible effects were that the input didn't work. I use the CS5535 chip in a custom board that uses GPIO 25 and 26 as voltage monitoring inputs (external voltage comparators). Since the char-based cs5535-gpio is now deprecated, I'm trying out the gpio driver.
I export the GPIO pins via sysfs to access them from user-space. Reading the 'value' member didn't reflect the input.
Quoted 5 lines
Quoted 2 lines
OK, then in that case we'd want to backport this into 2.6.33.x and perhaps earlier?
It looks like the driver was added 15 Dec 2009, so it doesn't look like it existed in an earlier kernel.
But it should definitely be added to 2.6.33.y.
Quoted 17 lines · On Tue, 23 Feb 2010 16:55:17 -0600 Ben Gardner <[email protected]> wrote:
The
gpio_chip.get()function for the CS5535 GPIO driver currently returns the output value instead of the input value. This patch changes it to return the input value.Signed-off-by Ben Gardner <[email protected]>---
drivers/gpio/cs5535-gpio.c +1
-1@@ -154,7 +154,7 @@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,
Quoted 1 line
int val)
Hm, you're probably right. Of course this breaks cs5535audio_olpc.c, since the GPIO isn't marked bidirectional (only output is enabled). I'll follow up w/ a patch.
PATCH 1/1 OLPC: ALSA: fix cs5535audio's MIC GPIO to enable input
In reply to Ben GardnerPreviously the MIC GPIO was set to output mode, and when checking the status after setting it we were checking OUTPUT_VAL. This worked, though I'm not quite sure why. Instead, if we actually check the READ_BACK value, it doesn't work unless the GPIO is in bidirectional mode. Thus, enable input mode as well.
--- sound/pci/cs5535audio/cs5535audio_olpc.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
sound/pci/cs5535audio/cs5535audio_olpc.c +1 -0
@@ -157,6 +157,7 @@ int __devinit olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97)return -EIO ; }gpio_direction_output (OLPC_GPIO_MIC_AC ,0 ); +gpio_direction_input (OLPC_GPIO_MIC_AC );/* drop the original AD1888 HPF control */ memset (&elem,0 ,sizeof (elem));
Signature · 1 line
1.5.6.5
Re: [PATCH] OLPC: ALSA: fix cs5535audio's MIC GPIO to enable input
Hi Andres,
Quoted 5 lines
Previously the MIC GPIO was set to output mode, and when checking the status after setting it we were checking
OUTPUT_VAL. This worked, though I'm not quite sure why. Instead, if we actually check theREAD_BACKvalue, it doesn't work unless the GPIO is in bidirectional mode. Thus, enable input mode as well.
The cs5535-gpio driver was reading output value, not the sensed input value. When that was fixed, this OLPC code failed because the input wasn't enabled, so the gpio_get_value() call didn't return anything useful. At reset the CS5535/6 GPIOs have both input and output disabled.
Quoted 10 lines
Signed-off-by Andres Salomon <[email protected]>---
sound/pci/cs5535audio/cs5535audio_olpc.c | 1 +1 files changed, 1 insertions(+), 0 deletions(-)sound/pci/cs5535audio/cs5535audio_olpc.c +0
-0
sound/pci/cs5535audio/cs5535audio_olpc.c int __devinit olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97) · line 163
Quoted 7 lines
sound/pci/cs5535audio/cs5535audio_olpc.c +1
-0@@ -157,6 +157,7 @@ int __devinit olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97) return -EIO; } gpio_direction_output(OLPC_GPIO_MIC_AC, 0); + gpio_direction_input(OLPC_GPIO_MIC_AC); /* drop the original AD1888 HPF control */ memset(&elem, 0, sizeof(elem));
This will only work because the cs5535-gpio driver and gpiolib are both 'broken'.
The problem with gpiolib is that it only allows a GPIO pin to be either an input or output, but not both.
It has two separate functions to configure the direction (gpio_direction_input/gpio_direction_output), where one should do (ie, gpio_set_direction).
Quoted 1 line
From what I can tell, when
direction_input()is called, the GPIO chip
is expected to disable the output and enable the input. If that really occurred, then the above code would still be broken.
The cs5535-gpio driver doesn't follow that input-or-output convention. It never disables the direction that wasn't requested.
I'm working on a gpiolib patch that will combine gpio_direction_output and gpio_direction_input into one function. That would enable the above driver to be 'obviously correct'.
Ben
Re: [PATCH] OLPC: ALSA: fix cs5535audio's MIC GPIO to enable input
On Fri, 26 Feb 2010 11:47:35 -0600
Ben Gardner <[email protected]> wrote:
[...]
Quoted 5 lines
I'm working on a gpiolib patch that will combine
gpio_direction_outputandgpio_direction_inputinto one function. That would enable the above driver to be 'obviously correct'.
Cool. I'm happy to help convert drivers if you want the help.
Re: [PATCH] OLPC: ALSA: fix cs5535audio's MIC GPIO to enable input
Quoted 5 lines
Quoted 3 lines
I'm working on a gpiolib patch that will combine
gpio_direction_outputandgpio_direction_inputinto one function. That would enable the above driver to be 'obviously correct'.Cool. I'm happy to help convert drivers if you want the help.
I'm not one to turn down help.
Lets see how the proposed changes I just sent off are received and go from there.
Ben
Re: [PATCH] OLPC: ALSA: fix cs5535audio's MIC GPIO to enable input
Quoted 2 lines
Lets see how the proposed changes I just sent off are received and go from there.
Based on the feedback from the other gpio patches, I'd like to do the following:
1) drop this patch (olpc-alsa-fix-cs5535audios-mic-gpio-to-enable-input.patch)
2) drop the patch that caused this patch to be created (cs5535_gpio-gpio_chipget-should-return-the-input-value.patch)
3) submit a new patch that contains the original change + the changes needed to adjust input/output settings to follow the spirit of gpiolib.
That way, there is one patch that fully fixes the issue and no window where the OLPC MIC stuff is broken.
Ben
Re: [PATCH] OLPC: ALSA: fix cs5535audio's MIC GPIO to enable input
Quoted 11 lines · On Mon, 1 Mar 2010 08:55:44 -0600 Ben Gardner <[email protected]> wrote:
Quoted 2 lines
Lets see how the proposed changes I just sent off are received and go from there.
Based on the feedback from the other gpio patches, I'd like to do the following:
1) drop this patch (olpc-alsa-fix-cs5535audios-mic-gpio-to-enable-input.patch)
2) drop the patch that caused this patch to be created (cs5535_gpio-gpio_chipget-should-return-the-input-value.patch)
3) submit a new patch that contains the original change + the changes needed to adjust input/output settings to follow the spirit of gpiolib.
Quoted 3 lines
That way, there is one patch that fully fixes the issue and no window where the OLPC MIC stuff is broken.
That'd be great, thanks!