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.

PROCESSOR-SDK-AM65X: GPIO APIs in U-boot

Part Number: PROCESSOR-SDK-AM65X

Hi,

I am trying to call some  gpio APIs from U-boot file as below.

/* Modification is done in U-boot file "am6_init.c" */

gpio_request();

gpio_direction_output(240, 1); // here 240 is gpio1_88


But i am not getting any expected result.



Regards,
Shadab




  • Hi Shadab,

    I would suggest you to explore how GPIO pins are handled in below AM65x u-boot files and reuse the same approach:

    u-boot-2019.01/board/ti/am65x/evm.c

    u-boot-2019.01/arch/arm/dts/k3-am654-base-board.dts

    u-boot-2019.01/arch/arm/dts/k3-am654-base-board-u-boot.dtsi


    Regarding gpio_request() and gpio_direction_output() example, I can provide you below files:

    u-boot-2019.01/board/ti/am57xx/board.c

    u-boot-2019.01/board/ti/am335x/board.c


    Regards,
    Pavel

  • Hi Pavel,

    I tried to call APIs from the file  u-boot-2019.01/board/ti/am65x/evm.c

    But i am not able to see any result.

    The source code which i added in the file is below:

    static void request_and_set_gpio(int gpio, char *name, int val)
    {
    int ret;

    ret = gpio_request(gpio, name);
    if (ret < 0) {
    printf("%s: Unable to request %s\n", __func__, name);
    return;
    }

    ret = gpio_direction_output(gpio, 0);
    if (ret < 0) {
    printf("%s: Unable to set %s  as output\n", __func__, name);
    goto err_free_gpio;
    }

    gpio_set_value(gpio, val);

    return;

    err_free_gpio:
    gpio_free(gpio);
    }
    #define REQUEST_AND_SET_GPIO(N) request_and_set_gpio(N, #N, 1);
    #define REQUEST_AND_CLR_GPIO(N) request_and_set_gpio(N, #N, 0);

     

    After that i am calling these function  as below :

    void spl_board_init(void)
    {

     probe_daughtercards();

    request_and_set_gpio(88, "gpio1", 1);
       
    }

  • Shadab,

    In u-boot-2019.01/board/ti/am57xx/board.c we have:

    #define GPIO_DDR_VTT_EN 203 //gpio7_11

    gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
    gpio_direction_output(GPIO_DDR_VTT_EN, 1);

    For AM65x gpio1_88, you need to use

    gpio_request(184,"custom_gpio");

    gpio_direction_output(184, 1);

    Regards,
    Pavel

  • Hi Pavel,

    I tried what you have suggested me in your reply  as below :

    void spl_board_init(void)
    {
        probe_daughtercards();
     

    gpio_request(184,"custom_gpio");

    gpio_direction_output(184, 1);

       
    }

     But i didn't get any expected result .Kindly suggest me if i am making any mistake.

    Regards,

    Shadab

  • Shadab,

    Md Shadab said:

    I tried what you have suggested me in your reply  as below :

    void spl_board_init(void)
    {
        probe_daughtercards();
     

    gpio_request(184,"custom_gpio");

    gpio_direction_output(184, 1);

       
    }

     But i didn't get any expected result .Kindly suggest me if i am making any mistake.

    I would suggest you to explore the result returned from these GPIO functions.

    ret = gpio_request(184,"custom_gpio");

    if (ret < 0) {
            printf("%s: gpio %d request failed %d\n", __func__,
                                184, ret);
            return;
        }

    ret = gpio_direction_output(184, 1);
        if (ret < 0) {
            printf("%s: Unable to set %s  as output\n", __func__, 184);
            goto err_free_gpio;
        }

    gpio_set_value(184, 1);

    Then I would suggest you to print and explore GPIO1 module registers, check if these has the correct and expected values.

    Regards,
    Pavel

  • Thank you Pavel for the reply .

    I tried to debug the response of GPIO functions in U-boot  but getting failure response.

    spl_board_init : gpio : 184  request failed -2

    Regards,

    Shadab

  • Shadab,

    Seems that gpio_request() is NOT working fine for AM65x u-boot. I would suggest you to try with other similar functions:

    1. dm_gpio_request()

    2. gpio_request_by_name()

    Regards,
    Pavel

  • Thank you for the reply Pavel.

    I am not able to understand how to call these APIs that you have mentioned in the last post

    1. dm_gpio_request()

    2. gpio_request_by_name()

    Can you provide me  some examples ?

     

    Regards,

    Shadab

  • Shadab,

    Using GPIO API in AM65x u-boot is a bit challenging.

    You can use direct approach instead. You can directly write in the GPIO registers to toggle pin gpio1_88. You need to use use below registers:

    #define DIR_REG *((unsigned int *) 0x00601060)    //GPIO1.GPIO_DIR45
     
    #define MUX_REG *((unsigned int *) 0x0011C300) //SOC_PADCONFIG_192
     
    #define SET_REG *((unsigned int *) 0x00601068)  //GPIO1.GPIO_SET_DATA45
     
    #define CLEAR_REG *((unsigned int *) 0x0060106C)  //GPIO1.GPIO_CLR_DATA45

    Then you can write below values:

    CLEAR_REG |= 0x01000000;

    MUX_REG = 0x08050007;
     
    DIR_REG &= ~0x01000000;

            SET_REG |= 0x01000000;
     
            sdelay(2);
     
            CLEAR_REG |= 0x01000000;
     
            sdelay(1);

  • Hi povel,

    We have to write these values in  board/ti/am65x/evm.c ? or any other file?

  • Varun,

    If you need to configure GPIO module registers in uboot, then you can do this in

    1. u-boot/board/ti/am65x/evm.c

    or

    2. u-boot/arch/arm/mach-k3/am6_init.c

    Regards,
    Pavel