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 configuration as output

Part Number: PROCESSOR-SDK-AM65X
Other Parts Discussed in Thread: PCA9554, PCA9555, TLV320AIC3106

Hi Forum,

I am trying to configure GPIO pins as inputs or outputs, and then write to or read from them using simple command-line utilities in Linux.  I am using the Processor SDK for Linux, 06.00.00.07.

Following are my chages added for the configuration done in k3-am654-base-board.dts:

1.main_gpio1_pins_default: main-gpio1-pins-default {

pinctrl-single,pins = <
AM65X_WKUP_IOPAD(0x0048, PIN_OUTPUT, 7) /* (P5) WKUP_GPIO0_30 */
>;
};

2.Under the section

gpio-keys {

................

GPIO2 {

label = "TEST_GPIO2";
linux,code =<0>;
gpios = <&wkup_gpio0 30 GPIO_ACTIVE_HIGH>;
};

Result: I'm Able to see the configured GPIO in the shell as Input even though configured as Output in .dts and that GPIO is not configured for any other pins.

Not able to Toggle the GPIO and is configured always shows Input.

Can any one help how to toggle it in the SHELL?

 

 

  • Hi Varun,

    What value you have for WKUP_PADCONFIG_18/0x4301c048 register at user space? You can check the value with devmem2 command.

    The default value is 0x00010004, which correspond to MCU_UART0_TXD (mux mode 4). This muxmode is setup in u-boot k3-am654-r5-base-board.dts file

    mcu_uart0_pins_default: mcu_uart0_pins_default {

             pinctrl-single,pins = <

                      AM65X_WKUP_IOPAD(0x0048, PIN_OUTPUT, 4)    /* (P5) MCU_OSPI1_D2.MCU_UART0_TXD */

    If you need to change that mux mode from 4 to 7 in linux kernel, you can do this in below linux file:

    linux-kernel/arch/arm64/boot/dts/ti/k3-am654-base-board.dts

    &wkup_pmx0 {

       push_button_pins_default: push_button__pins_default {
            pinctrl-single,pins = <
                AM65X_WKUP_IOPAD(0x0030, PIN_INPUT, 7) /* (R5) WKUP_GPIO0_24 */
                AM65X_WKUP_IOPAD(0x003c, PIN_INPUT, 7) /* (P2) WKUP_GPIO0_27 */
                + AM65X_WKUP_IOPAD(0x0048, PIN_OUTPUT, 7) /* (P5) WKUP_GPIO0_30 */
            >;
        };



    gpio-keys {
            compatible = "gpio-keys";
            autorepeat;
            pinctrl-names = "default";
            pinctrl-0 = <&push_button_pins_default>;

            sw5 {
                label = "GPIO Key USER1";
                linux,code = <BTN_0>;
                gpios = <&wkup_gpio0 24 GPIO_ACTIVE_LOW>;
            };

            sw6 {
                label = "GPIO Key USER2";
                linux,code = <BTN_1>;
                gpios = <&wkup_gpio0 27 GPIO_ACTIVE_LOW>;
            };

            sw7 {
                label = "GPIO Key USER3";
                linux,code = <BTN_2>;
                gpios = <&wkup_gpio0 30 GPIO_ACTIVE_LOW>;
            };
        };

     


    Regards,
    Pavel

  • HI  ,

     Thanks for the reply. With your suggestions i tried, i'm able to onserve gpio 30 exported in shell. 

    1.Pin is always in INPUT direction and Value in LOW state always.

    2. When i try to modiy the value from LOW to HIGH its not happening

    3.Says no directory present, when i try to go inside /sys/class/gpio/gpio30/

    Can you brief how Devmem2 command can toggle the pin?

    If so can Application user guy can toggle it in application.

  • Varun,

    My idea is to use devmem2 to check if you made pinmux correct. Please execute below command and provide me the result.

    root@am65xx-evm:~# devmem2 0x4301c048

    Regards,
    Pavel

  • HI Porvel,

    Please check the result:

    root@am65xx-evm:~# devmem2 0x4301c048
    /dev/mem opened.
    Memory mapped at address 0xffff80c10000.
    Read at address 0x4301C048 (0xffff80c1c048): 0x00010007

  • Varun,

    varun jeevangoudar said:
    root@am65xx-evm:~# devmem2 0x4301c048
    /dev/mem opened.
    Memory mapped at address 0xffff80c10000.
    Read at address 0x4301C048 (0xffff80c1c048): 0x00010007

    Seems your pinmux for wkup_gpio0_30 is correct now.

    To control this gpio pin from user space with sysfs signal, first remove below DTS update we made before:

    gpio-keys {

       - sw7 {
         -       label = "GPIO Key USER3";
          -      linux,code = <BTN_2>;
           -     gpios = <&wkup_gpio0 30 GPIO_ACTIVE_LOW>;
           - };

     

    Then execute below command in linux shell to understand GPIO default mapping.

    root@am65xx-evm:~# cat /sys/kernel/debug/gpio


    Then to toggle wkup_gpio0_30 output pin, execute below commands:

    root@am65xx-evm:~# echo 30 > /sys/class/gpio/export
    root@am65xx-evm:~# echo "out" > /sys/class/gpio/gpio30/direction
    root@am65xx-evm:~# echo 1 > /sys/class/gpio/gpio30/value
    root@am65xx-evm:~# echo 0 > /sys/class/gpio/gpio30/value


    This is what I have on AM65x EVM when export pin 30:

    root@am65xx-evm:~# echo 30 > /sys/class/gpio/export
    root@am65xx-evm:~# cat /sys/class/gpio/
    export       gpio30/      gpiochip0/   gpiochip152/ gpiochip488/ gpiochip496/ gpiochip56/  unexport 
    root@am65xx-evm:~# cat /sys/class/gpio/gpio30/
    active_low  device/     direction   edge        power/      subsystem/  uevent      value       
    root@am65xx-evm:~# cat /sys/class/gpio/gpio30/direction
    in
    root@am65xx-evm:~# echo "out" > /sys/class/gpio/gpio30/direction
    root@am65xx-evm:~# cat /sys/class/gpio/gpio30/direction
    out
    root@am65xx-evm:~# cat /sys/class/gpio/gpio30/value
    0
    root@am65xx-evm:~# cat /sys/kernel/debug/gpio                             
    gpiochip1: GPIOs 0-55, parent: platform/42110000.wkup_gpio0, davinci_gpio.0:
     gpio-24  (                    |GPIO Key USER1      ) in  hi    
     gpio-27  (                    |GPIO Key USER2      ) in  hi    
     gpio-30  (                    |sysfs               ) out lo    

    gpiochip2: GPIOs 56-151, parent: platform/600000.main_gpio0, davinci_gpio.1:

    gpiochip3: GPIOs 152-241, parent: platform/601000.main_gpio1, davinci_gpio.2:

    gpiochip4: GPIOs 488-495, parent: i2c/0-0039, pca9554, can sleep:

    gpiochip0: GPIOs 496-511, parent: i2c/2-0021, pca9555, can sleep:
    root@am65xx-evm:~#


    Regards,
    Pavel

  • Hi Pavel,

    Our Intention was to not export in shell finally, It has to be exported in the kernel .dtsi file. 

    So once it's its exported from the .dtsi, respective /sys/class/gpio/gpio30 should be created automatically for the final Application guy to toggle it from application. 

  • HI pavel,

    I'm facing one issue, when i exported gpio in the shell.

    i.e When i toggle the Gpio its always in the low state, not toggling to high .

    root@am65xx-evm:/sys/class/gpio/gpio30# echo 1 > value
    root@am65xx-evm:/sys/class/gpio/gpio30# cat value
    0
    root@am65xx-evm:/sys/class/gpio/gpio30#

    Can you please help me out.

  • varun jeevangoudar said:

    I'm facing one issue, when i exported gpio in the shell.

    i.e When i toggle the Gpio its always in the low state, not toggling to high .

    root@am65xx-evm:/sys/class/gpio/gpio30# echo 1 > value
    root@am65xx-evm:/sys/class/gpio/gpio30# cat value
    0
    root@am65xx-evm:/sys/class/gpio/gpio30#

    Can you please help me out.

    You need to make the pinmux value from output only (0x00010007) to input/output (0x00050007)

    In DTS file:  AM65X_WKUP_IOPAD(0x0048, PIN_INPUT, 7) /* (P5) WKUP_GPIO0_30 */


    Or in user space:

    root@am65xx-evm:~# devmem2 0x4301c048 w 0x00050007

    Check below post for details:

    https://e2e.ti.com/support/processors/f/791/p/839063/3109068#3109068

    Regards,
    Pavel

  • varun jeevangoudar said:

    Our Intention was to not export in shell finally, It has to be exported in the kernel .dtsi file. 

    So once it's its exported from the .dtsi, respective /sys/class/gpio/gpio30 should be created automatically for the final Application guy to toggle it from application. 

    For using gpio pin in kernel driver level, you can explore how wkup_gpio0_24 pin is used as push button in below DTS and driver:

    linux-4.19.59/arch/arm64/boot/dts/ti/k3-am654-base-board.dts

    linux-4.19.59/drivers/input/keyboard/gpio_keys.c

    linux-4.19.59/Documentation/devicetree/bindings/input/gpio-keys.txt


    You can also explore how WKUP_GPIO0_25 pin is used for PCA554 chip.

    linux-4.19.59/arch/arm64/boot/dts/ti/k3-am654-base-board.dts

    linux-4.19.59/drivers/gpio/gpio-pca953x.c

    linux-4.19.59/Documentation/devicetree/bindings/gpio/gpio-pca953x.txt


    You can also explore how main_gpio0_71 is used for audio codec tlv320aic3106.

    Regards,
    Pavel

  • Hi Povel,

    I would like to Thank you for Good Suggestions.

    As per your previous mail, Referreing to driver file linux-4.19.59/drivers/input/keyboard/gpio_keys.c i created the new GPIO by adding extra key node similar like this:

    sw6 {
    label = "GPIO Key USER2";
    linux,code = <BTN_1>;
    gpios = <&wkup_gpio0 27 GPIO_ACTIVE_LOW>;
    };

    1.But still i'm not able to see the /sys/class/gpio/gpio30 created for my GPIO.

    2./sys fs entry is created only when i export manually in the shell. i.e echo 30 > /sys/class/gpio

    3.For my Requirement when i add pin muxing in .dtsi file, i need to see /sys fs entry is created Automatically. For that can you tell me which driver file i can modify?

     

  • HI Povel,

     in user space, When i tried writing 0x00050007 to any other GPIO , i'm able to set the value HI/Lo. 

    root@am65xx-evm:~# devmem2 0x4301c048 w 0x00050007

    Can you brief me how the value 0x00050007 sets what values in the register 0x4301c048. Actually what it does internally?

  • varun jeevangoudar said:

    root@am65xx-evm:~# devmem2 0x4301c048 w 0x00050007

    Can you brief me how the value 0x00050007 sets what values in the register 0x4301c048. Actually what it does internally?

    To understand what 0x00050007 value means, refer to below AM65x TRM section:

    5.1.1.4.108 CTRLMMR_WKUP_PADCONFIG18 Register

    Regards,
    Pavel

  • Hi Povel,

    Thanks for your suggestions.

    We do not have this conecern in writing this value 0x00050007 for particular Register memory in the shell. For work around we can write in the shell and Toggle it but for the End user application side we need to write parmenantly in the kernel.or Any where in side source code is fine.

    Do you have any suggestions for that?

  • varun jeevangoudar said:

    We do not have this conecern in writing this value 0x00050007 for particular Register memory in the shell. For work around we can write in the shell and Toggle it but for the End user application side we need to write parmenantly in the kernel.or Any where in side source code is fine.

    Do you have any suggestions for that?

    linux-kernel/arch/arm64/boot/dts/ti/k3-am654-base-board.dts

    &wkup_pmx0 {

       push_button_pins_default: push_button__pins_default {
            pinctrl-single,pins = <
                AM65X_WKUP_IOPAD(0x0030, PIN_INPUT, 7) /* (R5) WKUP_GPIO0_24 */
                AM65X_WKUP_IOPAD(0x003c, PIN_INPUT, 7) /* (P2) WKUP_GPIO0_27 */
                + AM65X_WKUP_IOPAD(0x0048, PIN_INPUT, 7) /* (P5) WKUP_GPIO0_30 */
            >;
        };

  • Hi Povel,

    Yes we added already in that dtsi file.But still when we write that value into address in shell only we are able to toggle the GPIO.

    please have a look:

  • varun jeevangoudar said:


    Yes we added already in that dtsi file.But still when we write that value into address in shell only we are able to toggle the GPIO.

    please have a look:



    Should be input/output, not output only.

    - AM65X_WKUP_IOPAD(0x0048, PIN_OUTPUT, 7) /* (P5) WKUP_GPIO0_30 */

    + AM65X_WKUP_IOPAD(0x0048, PIN_INPUT, 7) /* (P5) WKUP_GPIO0_30 */



    Please refer to my post from Nov-29:

    e2e.ti.com/.../3186162




  • But we need some gpio's as output only.

  • Varun,

    When you execute the below user space command, you are also making this pin I/O:

    root@am65xx-evm:~# devmem2 0x4301c048 w 0x00050007


    Regards,
    Pavel

  • HI,

    True, but we need in to set the value HI/LO without devmem2 0x4301c048 w 0x00050007 in the shell. How we can do that?

  • Varun,

    You need to configure wkup_gpio0_30 pin as I/O in:

    1. kernel DTS file

    2. OR kernel C file with direct register writes, using  __raw_writel() or writel_relaxed()

    linux-4.19.59/arch/arm64/include/asm/io.h


    For example, you can refer to below kernel files:

    linux-4.19.59/sound/soc/ti/davinci-mcasp.c

    linux-4.19.59/drivers/dma/ti/k3-udma.c

    You can also configure wkup_gpio0_30 pin in u-boot, refer to below e2e thread for details:

    https://e2e.ti.com/support/processors/f/791/t/856910

    Once you have configured wkup_gpio0_30 pin properly in kernel (or uboot), you can toggle this pin through sysfs. Sysfs is writing to WKUP_GPIO0 module registers, in example GPIO_DIRx, GPIO_SET_DATAx, etc


    Regards,
    Pavel

  • Hi povel,

    AS per your reference link https://e2e.ti.com/support/processors/f/791/p/856910/3198517#3198517

    #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

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

  • Hi Varun,

    The idea in my previous post was to configure in kernel or uboot only pinmux register 0x4301c048, while GPIO module registers (GPIO_DIRx, GPIO_SET_DATAx, etc) to be configured in user space through sysfs.

    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