From: Jose Diaz de Grenu de Pedro <Jose.DiazdeGrenudePedro@digi.com> To: linux-gpio@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linus.walleij@linaro.org, gnurou@gmail.com, jose.diazdegrenudepedro@digi.com, hector.palacios@digi.com Subject: [PATCH v2] gpiolib: return 0 or 1 in gpiod_get_value*() functions Date: Mon, 30 Nov 2015 18:30:31 +0100 [thread overview] Message-ID: <1448904631-30230-1-git-send-email-Jose.DiazdeGrenudePedro@digi.com> (raw) 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
WARNING: multiple messages have this Message-ID (diff)
From: Jose Diaz de Grenu de Pedro <Jose.DiazdeGrenudePedro@digi.com> To: <linux-gpio@vger.kernel.org> Cc: <linux-kernel@vger.kernel.org>, <linus.walleij@linaro.org>, <gnurou@gmail.com>, <jose.diazdegrenudepedro@digi.com>, <hector.palacios@digi.com> Subject: [PATCH v2] gpiolib: return 0 or 1 in gpiod_get_value*() functions Date: Mon, 30 Nov 2015 18:30:31 +0100 [thread overview] Message-ID: <1448904631-30230-1-git-send-email-Jose.DiazdeGrenudePedro@digi.com> (raw) 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
next reply other threads:[~2015-11-30 17:30 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-11-30 17:30 Jose Diaz de Grenu de Pedro [this message] 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 20:05 ` Bjorn Andersson 2015-12-10 16:54 ` Linus Walleij
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1448904631-30230-1-git-send-email-Jose.DiazdeGrenudePedro@digi.com \ --to=jose.diazdegrenudepedro@digi.com \ --cc=gnurou@gmail.com \ --cc=hector.palacios@digi.com \ --cc=linus.walleij@linaro.org \ --cc=linux-gpio@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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.