The GPIO sysfs interface allows users to manipulate any GPIO from userspace (also known as programmable flags). Since it uses gpiolib, it is able to dynamically utilize all GPIOs on the system, even ones on expander cards (like the ADP5520).
Userspace utilizes a sysfs control interface to dynamically request and release individual GPIOs. Once a GPIO has been requested, writing to the newly created path allows you to control the direction and the data while reading from it returns the GPIO data (which usually corresponds to a 0 or 1 which represents the signal level).
GPIOs are referred to by their numeric value. You can refer to the GPIO pin table to quickly figure out what number is used for a specific pin on a specific port in the Blackfin processor.
With recent kernels (2.6.33+) it is now possible to poll() on a GPIO simply set “rising”, “falling” or “both” to /sys/class/gpio/gpioX/edge then poll for POLLPRI on the relevant open+read fd.
Since the pins are tied to a GPIO controller, there are no platform resources you need to declare. Simply enable the driver in your kernel configuration menu:
Device Drivers ---> [*] GPIO Support ---> [*] /sys/class/gpio/... (sysfs interface)
All the GPIO interfaces are based in
You first have to request a GPIO. So if we wanted to request GPIO 23, we would do:
root:/> echo 23 > /sys/class/gpio/export
If this process was successful, you would end up with a
Then when we were done with it, we would release it by doing:
root:/> echo 23 > /sys/class/gpio/unexport
In the specific GPIO directory, there will be two files:
value. Reading from them returns the current state (direction / value) as you might expect. Writing to them sets the current state.
Possible commands for
|high||Set GPIO to an output with a starting value of 1|
|low||Set GPIO to an output with a starting value of 0|
|out|| Same as
|in||Set GPIO to an input|
value field simply uses numeric values, so
To set GPIO 23 to an input:
root:/> echo in > /sys/class/gpio/gpio23/direction
To set GPIO 23 to a high output:
root:/> echo high > /sys/class/gpio/gpio23/direction
To set GPIO 23's value to 0:
root:/> echo 0 > /sys/class/gpio/gpio23/value
To read GPIO 23's current value:
root:/> cat /sys/class/gpio/gpio23/value 0
The GPIO framework and GPIO sysfs interface are both documented in this file: