Why gpio value is giving non zero instead of 1 if it is high?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Why gpio value is giving non zero instead of 1 if it is high?

Jump to solution
1,267 Views
bandarulavanya
Contributor V

Hi All,

I am using kernel verson 3.14.28 with dts support. When i am doing cat /sys/class/gpio/gpio157

root@imx6_fs_wcam:/home# cat /sys/class/gpio/gpio157/value
0 (when low)
root@imx6_fs_wcam:/home# cat /sys/class/gpio/gpio157/value
536870912 (when high)

Why instead of 1 we are getting 536870912  this value here?

If any one knows can you explain me.

Thanks

Lavanya

1 Solution
1,112 Views
fabio_estevam
NXP Employee
NXP Employee

This issue has already been fixed in recent kernel versions. Please try 4.1 kernel instead.

View solution in original post

4 Replies
1,113 Views
fabio_estevam
NXP Employee
NXP Employee

This issue has already been fixed in recent kernel versions. Please try 4.1 kernel instead.

1,112 Views
fabio_estevam
NXP Employee
NXP Employee

Here is the upstream commit that fixes this issue:

commit 25b35da7f4cce82271859f1b6eabd9f3bd41a2bb
Author: Linus Walleij <linus.walleij@linaro.org>
Date: Wed Feb 5 14:08:02 2014 +0100

gpio: generic: clamp retured value to [0,1]

The generic GPIO would return 0 for low generic GPIO, and
something != 0 for high GPIO. Let's make this sane by clamping
the returned value to [0,1].

Reported-by: Evgeny Boger <boger@contactless.ru>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c
index 8c778af..d815dd2 100644
--- a/drivers/gpio/gpio-generic.c
+++ b/drivers/gpio/gpio-generic.c
@@ -139,7 +139,7 @@ static int bgpio_get(struct gpio_chip *gc, unsigned int gpio)
{
struct bgpio_chip *bgc = to_bgpio_chip(gc);

- return bgc->read_reg(bgc->reg_dat) & bgc->pin2mask(bgc, gpio);
+ return !!(bgc->read_reg(bgc->reg_dat) & bgc->pin2mask(bgc, gpio));
}

static void bgpio_set(struct gpio_chip *gc, unsigned int gpio, int val)

0 Kudos
Reply
1,112 Views
bandarulavanya
Contributor V

Hi Fabio Estevam,

Thankyou, i will follow this

0 Kudos
Reply
1,112 Views
BiyongSUN
NXP Employee
NXP Employee

Linux document can give you explaination

Documentation/gpio/sysfs.txt

 allow userspace to reconfigure this GPIO's direction.
 "value" ... reads as either 0 (low) or 1 (high). If the GPIO is configured as an output, this value may be written;
  any nonzero value is treated as high.
  If the pin can be configured as interrupt-generating interrupt
  and if it has been configured to generate interrupts (see the description of "edge"), you can poll(2) on that file and
  poll(2) will return whenever the interrupt was triggered. If
  you use poll(2), set the events POLLPRI and POLLERR. If you
  use select(2), set the file descriptor in exceptfds. After
  poll(2) returns, either lseek(2) to the beginning of the sysfs
  file and read the new value or close the file and re-open it
  to read the value.
 "edge" ... reads as either "none", "rising", "falling", or

0 Kudos
Reply