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.

Linux/AM4378: GPIO pin number

Part Number: AM4378
Other Parts Discussed in Thread: AM4372

Tool/software: Linux

Dear,

Our board is broadly based on AM437X-gp-evm and SDK is 4.02.  I am using General purpose pin for my isolated input and output.

I am using some of the pins from  GPIO0, GPIO1, GPIO2, GPIO4 and GPIO5

 I tried with GPIO0_24 as given below from calculation (0x32+24 = 24).

root@x-gp-evm:/sys/class/gpio# echo 24 > export

root@x-gp-evm:/sys/class/gpio/gpio24# echo "out" > direction

root@x-gp-evm:/sys/class/gpio/gpio24# echo 1 > value

It works good.

But  GPIO5_4 in the user space, i have calculated like (5x32)+4=  164 and entered as given below in my console.

root@x-gp-evm:/sys/class/gpio# echo 164 > export

But it says below error

" [ 44.513931] export_store: invalid GPIO 164

-sh echo: write error: Invalid argument".

 

If i execute, "root@x-gp-evm:/sys/class/gpio# ls ", i got  below message.

export   gpio16 gpiogpio0 gpiochip32 gpiochip64 unexport.

 

GPIO5 related dts entries as given below

&gpio5 {
pinctrl-names = "default";
pinctrl-0 = <&gpio5_pins_default>;
status = "okay";

p28 {
gpio-hog;
gpios = <28 GPIO_ACTIVE_LOW>;
output-high;
lines-name = "rs232-2-TX-Enable";
};
p29 {
gpio-hog;
gpios = <29 GPIO_ACTIVE_LOW>;
output-high;
lines-name = "rs232-1-TX-Enable";
};
};

gpio5_pins_default: gpio5_pins_default {
pinctrl-single,pins = <
0x250 ( PIN_OUTPUT_PULLUP | MUX_MODE7 ) /* (P25) spi4_sclk.gpio5[4] */
0x254 ( PIN_OUTPUT_PULLUP | MUX_MODE7 ) /* (R24) spi4_d0.gpio5[5] */
0x258 ( PIN_OUTPUT_PULLUP | MUX_MODE7 ) /* (P24) spi4_d1.gpio5[6] */
0x25c ( PIN_OUTPUT_PULLUP | MUX_MODE7 ) /* (N25) spi4_cs0.gpio5[7] */
0x238 ( PIN_OUTPUT_PULLUP | MUX_MODE7 ) /* (D25) gpio5_8.gpio5[8] */
0x23c ( PIN_OUTPUT_PULLUP | MUX_MODE7 ) /* (F24) gpio5_9.gpio5[9] */
0x244 ( PIN_OUTPUT_PULLUP | MUX_MODE7 ) /* (F23) gpio5_11.gpio5[11] */
/*extra 3 digital input entry for adding 8 gpi */
0x24c ( PIN_INPUT_PULLUP | MUX_MODE7 ) /* (E24) gpio5_13.gpio5[13] */
0x208 ( PIN_INPUT_PULLUP | MUX_MODE7 ) /* (AE18) cam0_data0.gpio5[19] */
0x20c ( PIN_INPUT_PULLUP | MUX_MODE7 ) /* (AB18) cam0_data1.gpio5[20] */
/* 4 output pin for rs485 direction control */
0x270 ( PIN_OUTPUT_PULLUP | MUX_MODE9 ) /* (D24) xdma_event_intr0.gpio5[28] */
0x274 ( PIN_OUTPUT_PULLUP | MUX_MODE9 ) /* (C24) xdma_event_intr1.gpio5[29] */
0x230 ( PIN_OUTPUT_PULLUP | MUX_MODE7 ) /* (H22) uart3_ctsn.gpio5[0] */
0x234 ( PIN_OUTPUT_PULLUP | MUX_MODE7 ) /* (K24) uart3_rtsn.gpio5[1] */
>;
};

How do i calculate GPIO pin(GPIO0 to GPIO5) and set in the user space?

 Regards,

Winiston.P

  • Hi Winiston,

    You are trying to export gpio5_4 (164) pin in sysfs, but you have not described that pin in DTS file.

    Can you try to export gpio5_28 (188) and gpio5_29 (189) in sysfs, do you have the same result?

    Regards,
    Pavel
  • Dear Pavel,

    First line is for gpio5_4(164) in my dts file. Entry for gpio5_4 as given below in my dts file.

    0x250 ( PIN_OUTPUT_PULLUP | MUX_MODE7 ) /* (P25) spi4_sclk.gpio5[4] */

    I tried gpio5_28(188) and gpio5_29(189). But i got the same result.

    I tried gpio4_24 (152). It works fine.  Is there any mistake in my GPIO5 declaration in my dts file ?

    Regards,

    Winiston.P

  • Winiston,

    I have tried to export GPIO5 pin on AM437x TI EVM and observe the same issue as you. Seems like we have different scheme for GPIO5 pins.

    For example, on AM437x TI EVM, gpio5_8 pin is used to select between LCD and HDMI display, we have this description in DTS file:
    linux-kernel/arch/arm/boot/dts/am437x-gp-evm.dts

    &gpio5 {
    pinctrl-names = "default";
    pinctrl-0 = <&display_mux_pins>;
    status = "okay";
    ti,no-reset-on-init;

    p8 {
    /*
    * SelLCDorHDMI selects between display and audio paths:
    * Low: HDMI display with audio via HDMI
    * High: LCD display with analog audio via aic3111 codec
    */
    gpio-hog;
    gpios = <8 GPIO_ACTIVE_HIGH>;
    output-high;
    line-name = "SelLCDorHDMI";
    };
    };

    display_mux_pins: display_mux_pins {
    pinctrl-single,pins = <
    /* GPIO 5_8 to select LCD / HDMI */
    AM4372_IOPAD(0xa38, PIN_OUTPUT_PULLUP | MUX_MODE7)
    >;
    };


    Then, in user space we have:

    root@am437x-evm:/sys/class/gpio# ls
    export gpio16 gpiochip0 gpiochip128 gpiochip32 gpiochip510 gpiochip64 gpiochip96 unexport
    root@am437x-evm:/sys/class/gpio# cat /sys/kernel/debug/gpio
    gpiochip4: GPIOs 128-159, parent: platform/48322000.gpio, gpio:
    gpio-136 ( |SelLCDorHDMI ) out hi

    The kernel map GPIO5 to gpiochip4, and pin gpio5_8 to gpio-136.

    Check how this apply to your custom board. See also below e2e thread:

    e2e.ti.com/.../1794050

    Regards,
    Pavel
  • Winiston,

    If you have no more questions related to the subject, please close/verify/resolve this thread.

    Regards,
    Pavel
  • Dear Pavel,

    GPIO pin number works as you said. It solved my problem. As you said, GPIO5 to gpiochip4. So gpio5_8 to gpio-136. Similarly GPIO4 to gpiochip3, GPIO3 to gpiochip2.

    Then how does GPIO0 always remain gpiochip0? 

    Regards,

    Winiston.P

  • Winiston,

    Check below pointers for more info how gpio pin is calculated:

    e2e.ti.com/.../701154
    www.emcraft.com/.../controlling-gpio-from-linux-user-space

    Regards,
    Pavel
  • Thanks Pavel !! this helps