VAR-SOM-AM33 GPIO
GPIO state
The current state of the systems' GPIOs can be obtained in user-mode, as shown in the following example:
$ cat /sys/kernel/debug/gpio
The above command on Variscite's VAR-DVK-MX6 will show the following:
root@var-som-mx6:~# cat /sys/kernel/debug/gpio GPIOs 0-31, platform/209c000.gpio, 209c000.gpio: gpio-25 (phy-reset ) out lo GPIOs 32-63, platform/20a0000.gpio, 20a0000.gpio: GPIOs 64-95, platform/20a4000.gpio, 20a4000.gpio: gpio-77 (ov5640_mipi_pwdn ) out lo gpio-86 (usb_otg_vbus ) out lo GPIOs 96-127, platform/20a8000.gpio, 20a8000.gpio: gpio-101 (tlv320aic3x reset ) out lo gpio-106 (ov5640_mipi_reset ) out lo gpio-110 (2194000.usdhc cd ) in hi gpio-111 (2194000.usdhc ro ) in hi gpio-120 (spi_imx ) out lo gpio-121 (ads7846_pendown ) in hi GPIOs 128-159, platform/20ac000.gpio, 20ac000.gpio: gpio-141 (PCIe reset ) out lo GPIOs 160-191, platform/20b0000.gpio, 20b0000.gpio: gpio-178 (sysfs ) out lo GPIOs 192-223, platform/20b4000.gpio, 20b4000.gpio: gpio-200 (wlan-en-regulator ) out lo
Each GPIO is defined as in or out and the state is shown as lo or hi.
For example pin 110 is the SD-Card card-detect.
When SD-Card is removed the state will be:
gpio-110 (2194000.usdhc cd ) in hi
When the SD-Card is plugged the state will be:
gpio-110 (2194000.usdhc cd ) in lo
Manipulating a single GPIO via /sys/class/gpio
GPIOs in i.MX6 are grouped in groups of 32 pins.
For example GPIO1_3 belong to the first group pin 3. Its absolute number will be 3.
GPIO7_4 will be (7-1)*32+4=196.
Lets assume that you defined this GPIO in the device tree. We will show in the following sections how to define it.
To configure as output:
$ echo 196 > /sys/class/gpio/export $ echo out > /sys/class/gpio/gpio196/direction
Set GPIO high:
$ echo 1 > /sys/class/gpio/gpio196/value
Set GPIO low:
$ echo 0 > /sys/class/gpio/gpio196/value
To configure as input:
$ echo 196 > /sys/class/gpio/export $ echo in > /sys/class/gpio/gpio196/direction
$ cat /sys/class/gpio/gpio196/value
Will read the current value.