* [PATCH v2] gpiolib: return 0 or 1 in gpiod_get_value*() functions
@ 2015-11-30 17:30 ` Jose Diaz de Grenu de Pedro
0 siblings, 0 replies; 4+ messages in thread
From: Jose Diaz de Grenu de Pedro @ 2015-11-30 17:30 UTC (permalink / raw)
To: linux-gpio
Cc: linux-kernel, linus.walleij, gnurou, jose.diazdegrenudepedro,
hector.palacios
Commit 79a9becda894 moved the awareness of active low state
into the gpiod_get_value*() functions, but it only inverts the
GPIO's raw value when it is active low. If the GPIO is active
high, the gpiod_get_value*() functions return the raw value of
the register, which can be any positive value.
This patch does a double inversion when the GPIO is active high
to make sure either 0 or 1 is returned by these functions.
Signed-off-by: Jose Diaz de Grenu de Pedro <Jose.DiazdeGrenudePedro@digi.com>
Signed-off-by: Hector Palacios <hector.palacios@digi.com>
---
change in v2:
- add missing semicolon
---
drivers/gpio/gpiolib.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 50c4922fe53a..bd96f0457ba8 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1981,9 +1981,9 @@ int gpiod_get_value(const struct gpio_desc *desc)
value = _gpiod_get_raw_value(desc);
if (test_bit(FLAG_ACTIVE_LOW, &desc->flags))
- value = !value;
-
- return value;
+ return !value;
+ else
+ return !!value;
}
EXPORT_SYMBOL_GPL(gpiod_get_value);
@@ -2224,9 +2224,9 @@ int gpiod_get_value_cansleep(const struct gpio_desc *desc)
value = _gpiod_get_raw_value(desc);
if (test_bit(FLAG_ACTIVE_LOW, &desc->flags))
- value = !value;
-
- return value;
+ return !value;
+ else
+ return !!value;
}
EXPORT_SYMBOL_GPL(gpiod_get_value_cansleep);
--
2.6.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2] gpiolib: return 0 or 1 in gpiod_get_value*() functions
@ 2015-11-30 17:30 ` Jose Diaz de Grenu de Pedro
0 siblings, 0 replies; 4+ messages in thread
From: Jose Diaz de Grenu de Pedro @ 2015-11-30 17:30 UTC (permalink / raw)
To: linux-gpio
Cc: linux-kernel, linus.walleij, gnurou, jose.diazdegrenudepedro,
hector.palacios
Commit 79a9becda894 moved the awareness of active low state
into the gpiod_get_value*() functions, but it only inverts the
GPIO's raw value when it is active low. If the GPIO is active
high, the gpiod_get_value*() functions return the raw value of
the register, which can be any positive value.
This patch does a double inversion when the GPIO is active high
to make sure either 0 or 1 is returned by these functions.
Signed-off-by: Jose Diaz de Grenu de Pedro <Jose.DiazdeGrenudePedro@digi.com>
Signed-off-by: Hector Palacios <hector.palacios@digi.com>
---
change in v2:
- add missing semicolon
---
drivers/gpio/gpiolib.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 50c4922fe53a..bd96f0457ba8 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1981,9 +1981,9 @@ int gpiod_get_value(const struct gpio_desc *desc)
value = _gpiod_get_raw_value(desc);
if (test_bit(FLAG_ACTIVE_LOW, &desc->flags))
- value = !value;
-
- return value;
+ return !value;
+ else
+ return !!value;
}
EXPORT_SYMBOL_GPL(gpiod_get_value);
@@ -2224,9 +2224,9 @@ int gpiod_get_value_cansleep(const struct gpio_desc *desc)
value = _gpiod_get_raw_value(desc);
if (test_bit(FLAG_ACTIVE_LOW, &desc->flags))
- value = !value;
-
- return value;
+ return !value;
+ else
+ return !!value;
}
EXPORT_SYMBOL_GPL(gpiod_get_value_cansleep);
--
2.6.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] gpiolib: return 0 or 1 in gpiod_get_value*() functions
2015-11-30 17:30 ` Jose Diaz de Grenu de Pedro
(?)
@ 2015-11-30 20:05 ` Bjorn Andersson
-1 siblings, 0 replies; 4+ messages in thread
From: Bjorn Andersson @ 2015-11-30 20:05 UTC (permalink / raw)
To: Jose Diaz de Grenu de Pedro
Cc: linux-gpio, linux-kernel, Linus Walleij, Alexandre Courbot,
hector.palacios
On Mon, Nov 30, 2015 at 9:30 AM, Jose Diaz de Grenu de Pedro
<Jose.DiazdeGrenudePedro@digi.com> wrote:
> Commit 79a9becda894 moved the awareness of active low state
> into the gpiod_get_value*() functions, but it only inverts the
> GPIO's raw value when it is active low. If the GPIO is active
> high, the gpiod_get_value*() functions return the raw value of
> the register, which can be any positive value.
>
> This patch does a double inversion when the GPIO is active high
> to make sure either 0 or 1 is returned by these functions.
>
> Signed-off-by: Jose Diaz de Grenu de Pedro <Jose.DiazdeGrenudePedro@digi.com>
> Signed-off-by: Hector Palacios <hector.palacios@digi.com>
> ---
> change in v2:
> - add missing semicolon
> ---
> drivers/gpio/gpiolib.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 50c4922fe53a..bd96f0457ba8 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -1981,9 +1981,9 @@ int gpiod_get_value(const struct gpio_desc *desc)
>
> value = _gpiod_get_raw_value(desc);
> if (test_bit(FLAG_ACTIVE_LOW, &desc->flags))
> - value = !value;
> -
> - return value;
> + return !value;
> + else
> + return !!value;
> }
> EXPORT_SYMBOL_GPL(gpiod_get_value);
On linux-next (at least) _gpiod_get_raw_value() returns the following value:
value = value < 0 ? value : !!value;
So this should already be negative errno, 0 or 1.
Regards,
Bjorn
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] gpiolib: return 0 or 1 in gpiod_get_value*() functions
2015-11-30 17:30 ` Jose Diaz de Grenu de Pedro
(?)
(?)
@ 2015-12-10 16:54 ` Linus Walleij
-1 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2015-12-10 16:54 UTC (permalink / raw)
To: Jose Diaz de Grenu de Pedro
Cc: linux-gpio, linux-kernel, Alexandre Courbot, Hector Palacios
On Mon, Nov 30, 2015 at 6:30 PM, Jose Diaz de Grenu de Pedro
<Jose.DiazdeGrenudePedro@digi.com> wrote:
> Commit 79a9becda894 moved the awareness of active low state
> into the gpiod_get_value*() functions, but it only inverts the
> GPIO's raw value when it is active low. If the GPIO is active
> high, the gpiod_get_value*() functions return the raw value of
> the register, which can be any positive value.
No, because:
static int _gpiod_get_raw_value(const struct gpio_desc *desc)
{
struct gpio_chip *chip;
int offset;
int value;
chip = desc->chip;
offset = gpio_chip_hwgpio(desc);
value = chip->get ? chip->get(chip, offset) : -EIO;
value = value < 0 ? value : !!value;
trace_gpio_value(desc_to_gpio(desc), 1, value);
return value;
}
This returns a negative error code or the value clamped to [0,1]
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-12-10 16:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-30 17:30 [PATCH v2] gpiolib: return 0 or 1 in gpiod_get_value*() functions Jose Diaz de Grenu de Pedro
2015-11-30 17:30 ` Jose Diaz de Grenu de Pedro
2015-11-30 20:05 ` Bjorn Andersson
2015-12-10 16:54 ` Linus Walleij
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.