[#5627] fail to control gpio used by led and button through /sys/class/gpio/
Submitted By: Mingquan Pan
Open Date
2009-10-19 06:16:18 Close Date
2009-10-20 05:49:57
Priority:
Medium Assignee:
Michael Hennerich
Status:
Closed Fixed In Release:
N/A
Found In Release:
2010R1 Release:
Category:
N/A Board:
N/A
Processor:
BF537 Silicon Revision:
Is this bug repeatable?:
Yes Resolution:
Not reproducible
Uboot version or rev.:
Toolchain version or rev.:
09r1-rc9
App binary format:
N/A
Summary: fail to control gpio used by led and button through /sys/class/gpio/
Details:
After enabling in the kernel:
CONFIG_ARCH_WANT_OPTIONAL_GPIOLIB=y
CONFIG_GPIOLIB=y
# CONFIG_DEBUG_GPIO is not set
CONFIG_GPIO_SYSFS=y
I try to use /sys/class/gpio/ to control led and button on bf537 stamp.
based on the table:
" BF537-STAMP:\n"
"\tLED1 => GPIO6\tPB1 => GPIO2\n"
"\tLED2 => GPIO7\tPB2 => GPIO3\n"
"\tLED3 => GPIO8\tPB3 => GPIO4\n"
"\tLED4 => GPIO9\tPB4 => GPIO5\n"
"\tLED5 => GPIO10\n"
"\tLED6 => GPIO11\n"
I export gpio2 and 6, and changed the LED1 direction to out and set its value from 0 to 1, but the led is always on and nothing happened. As to the button, whatever I push the button, the value is also not changed.
root:/> cd /sys/class/gpio/
root:/> echo 2 > export
root:/> echo 6 > export
root:/sys/class/gpio> ls
export gpio2 gpio6 gpiochip0 unexport
...
...
root:/sys/class/gpio> cat gpio2/direction
in
root:/sys/class/gpio> cat gpio2/value
0
root:/sys/class/gpio> cat gpio6/direction
out
root:/sys/class/gpio> cat gpio6/value
1
So is there anything else I need to do to manipulate the gpio sys interface?
Follow-ups
--- Michael Hennerich 2009-10-19 06:49:45
http://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:gpio-sysfs&s[]=gpiolib
PF6 aka GPIO_6 = LED1:
root:/sys/devices/virtual/gpio/gpio4> cd /sys/class/gpio/
root:/sys/class/gpio> echo 6 > export
root:/sys/class/gpio> echo low > gpio6/direction
root:/sys/class/gpio> echo high > gpio6/direction
root:/sys/class/gpio> echo low > gpio6/direction
root:/sys/class/gpio>
Works
PF8 aka GPIO_8 = LED3:
root:/sys/class/gpio> echo 8 > export
root:/sys/class/gpio> cd gpio8/
root:/sys/devices/virtual/gpio/gpio8> ls
direction power subsystem uevent value
root:/sys/devices/virtual/gpio/gpio8> echo high > direction
root:/sys/devices/virtual/gpio/gpio8> echo low > direction
root:/sys/devices/virtual/gpio/gpio8>
Works for me…
PF4 aka GPIO_4 = PB3:
root:/sys/class/gpio> echo 4 > export
root:/sys/class/gpio> cd gpio4/
root:/sys/devices/virtual/gpio/gpio4> ls
direction power subsystem uevent value
root:/sys/devices/virtual/gpio/gpio4> echo in > direction
root:/sys/devices/virtual/gpio/gpio4> cat value
0
root:/sys/devices/virtual/gpio/gpio4> cat value
1
root:/sys/devices/virtual/gpio/gpio4> cat value
0
root:/sys/devices/virtual/gpio/gpio4> cat value
1
root:/sys/devices/virtual/gpio/gpio4>
Works for me, too.
Did you connect SW5?
--- Mingquan Pan 2009-10-19 23:07:48
Yeah, following your steps, it is working on my side too.
But there is still some issue for the button accepting the pushing action.
If I don't run the command : echo in > direction at the first, since the
default direction for the button is in, then cat value won't notice the pushing
action and get the changing result, remaining 0, like:
PF5 aka GPIO_5 = PB4:
root:/sys/class/gpio> echo 5 > export
root:/sys/class/gpio> cd gpio5/
root:/sys/devices/virtual/gpio/gpio5> ls
direction power subsystem uevent value
root:/sys/devices/virtual/gpio/gpio5> cat direction
in
root:/sys/devices/virtual/gpio/gpio5> cat value
0
root:/sys/devices/virtual/gpio/gpio5> cat value
0
root:/sys/devices/virtual/gpio/gpio5> cat value
0
--- Michael Hennerich 2009-10-20 04:00:53
The default direction of a GPIO which direction is not written - is not
defined.
The default DIR is 'in' - but upon reset the INEN Input Enables are
disabled - so you won't be able to read whatever happens on the pin
Level.
- Refused -
You need to write 'direction' prior in using the gpio anyhow -
-Michael
--- Mingquan Pan 2009-10-20 05:49:57
All right. So echo the value to the direction before operatating on the gpios.
Close it.
Files
Changes
Commits
Dependencies
Duplicates
Associations
Tags
File Name File Type File Size Posted By
No Files Were Found