Author:DriverMonkey
Mail:[email protected]
Phone:13410905075
QQ:196568501
This wiki page provides the usage information of GPIO Linux driver usage, both in user and kernel space.
Set pinmux configuration for GPIO pin usage, details of pinmux configuration are mentioned on PSP user guide. If the pinmux settings are not correct then the GPIO will not function as expected.
For example the AM335x has 4 banks of 32 GPIOs, for a total of 128 GPIO, i.e Bank-0[0..31], Bank-1[0..31], Bank-2[0..31], Bank-3[0..31].
In this case Bank-1[0..31] maps to Linux GPIO numbers 32..63, Bank-2[0..31] to Linux GPIO numbers 64..95 etc.
This section describes about the kernel configurations for GPIO driver
The default kernel configuration enables support for GPIO driver (built into the kernel).
To enable or disable GPIO driver from kernel build, follow these steps:
$ make CROSS_COMPILE=arm-none-linux-gnueabi- ARCH=arm menuconfig
Power management options ---> [*] Networking support ---> Device Drivers ---> File systems ---> ... ...
PPS support ---> PTP clock support ---> -*- GPIO Support ---> < > Dallas's 1-wire support ---> ... ...
GPIO can be access using SYSFS entries from User Space. For that Select /sys/class/gpio/... (sysfs interface) from the GPIO support.
[ ] Debug GPIO calls [*] /sys/class/gpio/... (sysfs interface) *** Memory mapped GPIO drivers: *** < > Basic memory-mapped GPIO controllers support ... ...
GPIO pin is also used as a interrupt source, these are the general usage of IRQ handling using GPIO lines.
irq_num = gpio_to_irq(30)
request_irq(irq_num, handler, 0, "gpio_test", NULL);
set_irq_type(irq_num, IRQ_TYPE_EDGE_RISING);
free_irq(irq_num, NULL); gpio_free(30);
gpio_request()
err = gpio_request(30, "sample_name");
Setting the GPIO pin 30 as input
gpio_direction_input(30);
Make pin 30 as output and set the value as high.
gpio_direction_output(30, 1);
Exporting that particular pin (30) to sysfs entry then use this API
gpio_export(30, true);
Get value from GPIO pin
gpio_get_value(30);
Device Drivers ---> GPIO Support ---> /sys/class/gpio/... (sysfs interface)
$ echo 30 > /sys/class/gpio/export
$ echo "out" > /sys/class/gpio/gpio30/direction
or
$ echo "in" > /sys/class/gpio/gpio30/direction
$ echo 1 > /sys/class/gpio/gpio30/value
or
$ echo 0 > /sys/class/gpio/gpio30/value
$ echo 30 > /sys/class/gpio/unexport
Note: GPIO's which are used already in the drivers can not be control from sysfs, unless until driver export that particular pin.
Run these commands for knowing what are the GPIO's already requested in the drivers.
$ mount -t debugfs debugfs /sys/kernel/debug
$ cat /sys/kernel/debug/gpio