Using GPIO via sysfs?

Started by thom_nic, April 12, 2017, 12:45:35 AM

Previous topic - Next topic

thom_nic

I'm trying to use a GPIO (pin 121, P3_7/EMU0) as digital input.  I've tried a few different pins without success.


# cd /sys/class/gpio
# echo 121 >> export
# cd gpio121
# cat value
0
# cat direction
in
# cat active_low
0


I tried shorting GPIO_EXT pin 31 to pin 3 (3v3) and then to digital ground and cat value each time but it always reads 0.

I also tried using a pinmux in the DTS to define the pin as an INPUT_PULLUP as described here: https://e2e.ti.com/support/arm/sitara_arm/f/791/p/432614/1555809#1555809 but it did not seem to work.  Here's relevant DTS:


&am33xx_pinmux {


gpio3_pins: gpio3_pins_default {
pinctrl-single,pins = <
0x1e4 (PIN_INPUT_PULLUP | MUX_MODE7) /* (C14) emu0.gpio3_7 */
0x1e8 (PIN_INPUT_PULLUP | MUX_MODE7) /* (B14) emu1.gpio3_8 */
>;
  };
};

&gpio3 {
pinctrl-names = "default";
pinctrl-0 = <&gpio3_pins>;
status = "okay";
};


And I see the following in kernel debug sysfs:

# cat /sys/kernel/debug/pinctrl/44e10800.pinmux/pins|grep 121
pin 121 (44e109e4.0) 0000002f pinctrl-single

# cat /sys/kernel/debug/pinctrl/44e10800.pinmux/pingroups
registered pin groups:

...
group: gpio3_pins_default
pin 121 (44e109e4.0)
pin 122 (44e109e8.0)

# cat /sys/kernel/debug/pinctrl/44e10800.pinmux/pinmux-pins
Pinmux settings per pin
Format: pin (name): mux_owner gpio_owner hog?
...
pin 121 (44e109e4.0): 481ae000.gpio (GPIO UNCLAIMED) function gpio3_pins_default group gpio3_pins_default
pin 122 (44e109e8.0): 481ae000.gpio (GPIO UNCLAIMED) function gpio3_pins_default group gpio3_pins_default

# cat /sys/kernel/debug/pinctrl/44e10800.pinmux/pinmux-functions
...
function: gpio3_pins_default, groups = [ gpio3_pins_default ]

As far as I can tell nothing else is using that pin.

I also tried to set the pin as a digital output (echo out >> direction) then echo 1 >> value and probed the voltage vs digital ground with a multimeter but that also didn't change between writing a 1 or 0 but if I read the value file back it displayed the correct value (1 or 0.)

Is there something I'm missing to use GPIO pins from the SOM?

thom_nic

To answer my own question, it seems I was confusing pinctrl pin mapping and gpio pin mapping which are (apparently) completely unrelated.

Although the AM335x reference manual specifies 0x9e4 for conf_emu0 which shows up as "pin 121" in the various pinmux/ pinctrl listings under /sys/kernel/debug/pinctrl, this apparently is *not* the same as the pin number under /sys/class/gpio/.  GPIO pins are numbered incrementally such that gpio3_7 would be 3*32+7 = pin 103.  Which in fact works!  Problem solved.

thang

Hi I did the same as you above but still not working. Is there anything else to configure? Thank you