This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

GPIO quarries on OMAPL138 and Linux-2.6.33

Other Parts Discussed in Thread: OMAPL138, DA8XX

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,

    1.) Please provide the user usage information of GPIO driver, on  Linux-2.6.33.

    Go through kernel documentation "Documentation/gpio.txt" for more details

    2.) How to access GPIO pin on user side like gpio_request();  gpio_request_input(); etc

    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 > export
    cd gpio11
    echo out > direction
    echo 0 > value
    echo 1 > value
    echo 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.

  • Hi,

    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", ??);

  • Hi,

    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.

    Regards

    AnilKumar

    Please mark this Forum post as answered via the Verify Answer button below if it helps answer your question.  Thanks!

  • Hi,  

    cd /sys/class/gpio/
    echo 11 > export
    cd gpio11
    echo out > direction
    echo 0 > value
    echo 1 > value
    echo 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!

    what's the meaning of  write(fd, "11", 3); // Include null!

    Regards

    He

  • Hi,

    what's the meaning of  write(fd, "11", 3); // Include null!

    This means writing 11 into export file.

    Regards

    AnilKumar

    Please mark this Forum post as answered via the Verify Answer button below if it helps answer your question.  Thanks!

  • 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?

    Regards

    He

  • 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

    Regards

    AnilKumar

    Please mark this Forum post as answered via the Verify Answer button below if it helps answer your question.  Thanks!

  • 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?

    Regards

    He

  • 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 Norman
    I 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 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?

    Regards
    He

  • Hi He,

    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

    Regards

    AnilKumar

    Please mark this Forum post as answered via the Verify Answer button below if it helps answer your question.  Thanks!

  • Hi Anil

    I do it like this:

    # echo 18 > /sys/class/gpio/export
    ~# ls  /sys/class/gpio/gpio18
    active_low  edge        subsystem   value
    direction   power       uevent
    :~# echo out > /sys/class/gpio/gpio18/direction
    ~# echo 0 > /sys/class/gpio/gpio18/value
    ~# cat /sys/class/gpio/gpio18/value
    1
    ~# echo 1 > /sys/class/gpio/gpio18/value
    ~# cat /sys/class/gpio/gpio18/value
    1

    ~# echo 0 > /sys/class/gpio/gpio18/value
    ~# cat /sys/class/gpio/gpio18/value
    1

    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

  • Hi He,

    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

    Regards

    AnilKumar

    Please mark this Forum post as answered via the Verify Answer button below if it helps answer your question.  Thanks!

  • Your pinmux changes look okay. As As yaliu_2000 pointed out, you need to add a call to one of the pinmux config functions to actually write to the pinmux registers.

    ---arch/arm/mach-davinci/da850.c---

    static const struct mux_config da850_pins[] = {
    #ifdef CONFIG_DAVINCI_MUX
        /* UART0 function */
    ...
        MUX_CFG(DA850, ECAP2_APWM2,    1,    0,    15,    4,    false)

        /* More GPIO function */                      /* Add */
        MUX_CFG(DA850, GPIO1_1, 4, 24, 15, 8, false)  /* Add */
    #endif
    };

    ---arch/arm/mach-davinci/include/mach/mux.h---

    enum davinci_da850_index {
        /* UART0 function */
        DA850_NUART0_CTS,
    ...
        DA850_ECAP2_APWM2,

        /* More GPIO function */ /* Add at end of list */
        DA850_GPIO1_1,           /* Add at end of list */
    };


    ---arch/arm/mach-davinci/board-da850-evm.c---
    ...
    static const short da850_evm_my_gpio_pins[] = { /* Add */
        DA850_GPIO1_1,                              /* Add */
        -1                                          /* Add */
    };                                              /* Add */
    ...
    static __init void da850_evm_init(void)
    {
    ...
        ret = davinci_cfg_reg_list(da850_evm_my_gpio_pins);                     /* Add */
        if (ret)                                                                /* Add */
            pr_warning("da850_evm_init: my gpio pins setup failed: %d\n", ret); /* Add */
    ...
    }

    Make sure you have the right pin. As yaliu_2000 and Anil have pointed out

    GP1[1] is the HW GPIO Signal Name
    18 is the Reference Manual GPIO number
    17 is the Linux GPIO number. USE THIS NUMBER for sysfs calls.

    Note that the pinmux config for GPIO1_1 is also used by UART1_RXD in da850.c:
        MUX_CFG(DA850, UART1_RXD,    4,    24,    15,    2,    false)

    Depending on which version of board-da850-evm.c that you have. You may have to comment out the pinmux config of UART1:

    ...
    static __init void da850_evm_init(void)
    {
    ...
    //    /* Support for UART 1 */                                        /* Comment out */
    //    ret = davinci_cfg_reg_list(da850_uart1_pins);                   /* Comment out */
    //    if (ret)                                                        /* Comment out */
    //        pr_warning("da850_evm_init: UART 1 mux setup failed:"   /* Comment out */
    //                        " %d\n", ret);          /* Comment out */
    ...
    }

    Some versions of this file use the kernel config CONFIG_DAVINCI_UART1_AFE for conditional pinmux of UART1.

    Just a side note. You should start a new thread instead of tacking onto someone elses thread. Besides making the thread difficult to track, you cannot verify a helpful reply. Some people do care about the points gained from a verified reply You might get more replys.

  • Hi Norman 

    I have solved my problem. 

    Thank you very much!

    In this modify:

     static __init void da850_evm_init(void)
    {
    ...
        ret = davinci_cfg_reg_list(da850_evm_my_gpio_pins);                     /* Add */
        if (ret)                                                                /* Add */
            pr_warning("da850_evm_init: my gpio pins setup failed: %d\n", ret); /* Add */
    ...
    }

    When I use davinci_cfg_reg_list,it occur a error.  So I use da8xx_pinmux_setup replace it.

    Thank you again.

    Regards

    He