Hi,
I have some quarries on GPIO for OMAPL138 LINUX-2.6.33.
1.) Please provide the user usage information of GPIO driver, on Linux-2.6.33.
2.) How to access GPIO pin on user side like gpio_request(); gpio_request_input(); etc
3.) what are the user API for accessing the gpio. for linx application.
4.) And i checked the /sys/class/gpio is present .
Thanks in adv
Ram
Hi Ram,
Go through kernel documentation "Documentation/gpio.txt" for more details
http://processors.wiki.ti.com/index.php/Sitara_GPIO_Driver_User_Guide#Driver_Usage
Regards
AnilKumar
Noticed in your other forum threads that you have some confustion between the kernel and user space interfaces to GPIOS. User space access to the sysfs GPIO driver is all through files. Here's an example to toggling GPIO 11 in a Linux console or terminal:
cd /sys/class/gpio/echo 11 > exportcd gpio11echo out > directionecho 0 > valueecho 1 > valueecho 0 > value
The equivalent code in C is:
#include <fcntl.h> /* For open() */#include <unistd.h> /* For read(), close() */int main(int argc, char *argv[]){ int fd; fd = open("/sys/class/gpio/export", O_WRONLY); write(fd, "11", 3); // Include null! close(fd); fd = open("/sys/class/gpio/gpio11/direction", O_WRONLY); write(fd, "out", 4); close(fd); fd = open("/sys/class/gpio/gpio11/value", O_WRONLY); write(fd, "0", 2); write(fd, "1", 2); write(fd, "0", 2); close(fd); return(0);}
Please take note that you must check that the GPIO line you want to use is pinmux'ed to an external pin. That involves looking at the kernel code and possibly modifiying the kernel.
Thanks for your above example to toggle gpio....
Hi, if I want set GP2[3] to out direction .And set it to 1 or 0, how can I use the function write and open?\
fd = open("/sys/class/gpio/export", O_WRONLY); write(fd, "??", ??); // Include null! close(fd);
fd = open("/sys/class/gpio/gpio11/direction", O_WRONLY); write(fd, "??", ??); close(fd);
fd = open("/sys/class/gpio/gpio11/value", O_WRONLY); write(fd, "0", ??);
write(fd, buf, len);
fd - file pointer
buf - contains characters ex: "1" or "0" or "in" or "out"
len - length of the buffer ex: 2 or 2 or 3 or 4.
Please mark this Forum post as answered via the Verify Answer button below if it helps answer your question. Thanks!
#include <fcntl.h> /* For open() */#include <unistd.h> /* For read(), close() */int main(int argc, char *argv[]){ int fd; fd = open("/sys/class/gpio/export", O_WRONLY); write(fd, "11", 3); // Include null!
what's the meaning of write(fd, "11", 3); // Include null!
He
This means writing 11 into export file.
Hi AnilKumar
I don't know what the "11" mean. if i want control GP1[1], in the OMAPL138 datasheet:
GPIO Register Bits and Banks Associated With GPIO Signals
GPIO Pin Number GPIO Signal Name Bank Number Control Registers Register Bit Register Field
1 GP0[0] 0 register_name01 Bit 0 GP0P0
2 GP0[1] 0 register_name01 Bit 1 GP0P1
…… …… ……
18 GP1[1] 1 register_name01 Bit 17 GP1P1
Can I use it like this write(fd,“18",3) ? right?
int fd; fd = open("/sys/class/gpio/export", O_WRONLY); write(fd, "18", 3); // Include null! close(fd);
fd = open("/sys/class/gpio/gpio18/direction", O_WRONLY); write(fd, "out", 4); close(fd);
fd = open("/sys/class/gpio/gpio18/value", O_WRONLY); while(1){ write(fd, "0", 2); sleep(3); write(fd, "1", 2); sleep(3); } close(fd);
When I detect the pin GP1[1], I can't get the value I set to it . Why?
Hi He,
The way you are using are correct,
Make sure that pinmux settings are proper, refer OMAPL138 GPIO user guide for more details
Below post will help you on GPIO functionality.
http://e2e.ti.com/support/dsp/davinci_digital_media_processors/f/716/p/182160/657204.aspx#657204
Hi,AnilKuma
Thank you for your quick reply. But I still have problem to find the pinmux setting fuction.
My PSP is: OMAP_L138_arm_1_00_00_08\DaVinci-PSP-SDK-03.20.00.08\
I tried to add below in /arch/arm/mach-davinci/include/mach/mux.h
/* GPIO function */
DA850_GPIO2_6, DA850_GPIO2_8,
DA850_GPIO1_1,//my add
and add in /arch/arm/mach-davinci/da850.c in static const struct mux_config da850_pins[] = {} fuction
/* GPIO function */ MUX_CFG(DA850, GPIO2_6, 6, 4, 15, 8, false) MUX_CFG(DA850, GPIO2_8, 5, 28, 15, 8, false)
MUX_CFG(DA850, GPIO1_1, 4, 24, 15, 8, false) //my add
after rebuilt the kernel When I detect the pin GP1[1], I still can't get the value I set to it . Is I wrong? Is there any other place I must modify?
Hi Ram
Do you solve you problem? I have the same problems with you ?
Are you success setting pinmux? How to do it.
Below is my problems.
Hi NormanI have some trobles in pinmux settings.My PSP is: OMAP_L138_arm_1_00_00_08\DaVinci-PSP-SDK-03.20.00.08\ I tried to add below in /arch/arm/mach-davinci/include/mach/mux.h/* GPIO function */DA850_GPIO2_6,DA850_GPIO2_8,DA850_GPIO1_1,//my add
and add in /arch/arm/mach-davinci/da850.c in static const struct mux_config da850_pins[] = {} fuction/* GPIO function */MUX_CFG(DA850, GPIO2_6, 6, 4, 15, 8, false)MUX_CFG(DA850, GPIO2_8, 5, 28, 15, 8, false)MUX_CFG(DA850, GPIO1_1, 4, 24, 15, 8, false) //my addafter rebuilt the kernel When I detect the pin GP1[1], I still can't get the value I set to it . Is I wrong? Is there any other place I must modify?
RegardsHe
Make sure that you have written the correct value to corresponding register
http://e2e.ti.com/support/embedded/linux/f/354/p/167148/609581.aspx#609581
Hi Anil
I do it like this:
# echo 18 > /sys/class/gpio/export~# ls /sys/class/gpio/gpio18active_low edge subsystem valuedirection power uevent:~# echo out > /sys/class/gpio/gpio18/direction~# echo 0 > /sys/class/gpio/gpio18/value~# cat /sys/class/gpio/gpio18/value1~# echo 1 > /sys/class/gpio/gpio18/value~# cat /sys/class/gpio/gpio18/value1
~# echo 0 > /sys/class/gpio/gpio18/value~# cat /sys/class/gpio/gpio18/value1
why the value can not be change? when I use "echo 29 > /sys/class/gpio/export " , the export29 value can changed as I set.
The file 'value' is R/W.
Did you call "davinci_cfg_reg(gpio_pin)" to set pinmux for gpio18 besides adding entries in mux.h and da850.c?
BTW, gpio1[1] is gpio17 instead of gpio18.
Regards,
Yan
Make sure that you are configuring the same GPIO pin.
You are trying to add pinmux for GPIO1_1 (18th gpio pin) means gpio 17 in your previous post.
Here you are changing the value of gpio 18 (19th pin), use the same GPIO at both the places
Can you check these
echo 17 > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio17/direction
echo 0 > /sys/class/gpio/gpio17/value
echo 1 > /sys/class/gpio/gpio17/value
Note: Can you check the status of pinmux register after kernel boots-up