VAR-SOM-MX6 GPIO: Difference between revisions
Line 11: | Line 11: | ||
<br/> root@var-som-mx6:~# cat /sys/kernel/debug/gpio | <br/> root@var-som-mx6:~# cat /sys/kernel/debug/gpio | ||
<br/>GPIOs 0-31, platform/209c000.gpio, 209c000.gpio: | <br/>GPIOs 0-31, platform/209c000.gpio, 209c000.gpio: | ||
<br/> gpio-25 (phy- | <br/> gpio-25 (phy-reset ) out lo | ||
<br/>GPIOs 32-63, platform/20a0000.gpio, 20a0000.gpio: | <br/>GPIOs 32-63, platform/20a0000.gpio, 20a0000.gpio: | ||
<br/>GPIOs 64-95, platform/20a4000.gpio, 20a4000.gpio: | <br/>GPIOs 64-95, platform/20a4000.gpio, 20a4000.gpio: |
Revision as of 13:13, 9 December 2015
GPIO
Introduction
GPIO on the i.MX6 are complex to understand. We will cover all aspects of GPIO manipulation. Startling with Linux command line debug and manipulation up to deep dive into the device tree settings.
GPIO state
The state of the GPIO can be checked by:
$ cat /sys/kernel/debug/gpio
For example:
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
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 lo
gpio-111 (2194000.usdhc ro ) in lo
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 SDCARD card detect.
For SDCARD removed the state will be:
gpio-110 (2194000.usdhc cd ) in hi
For SDCARD inserted the state will be:
gpio-110 (2194000.usdhc cd ) in lo
Manipulating single GPIO via /sys/class/gpio
GPIO's in i.MX6 are grouped in groups of 32 pins.
For example GPIO1_3 belong to the first group pin 3. His 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.
For output definition:
$ echo 196 > /sys/class/gpio/export $ echo out > /sys/class/gpio/gpio196/direction
$ echo 1 > /sys/class/gpio/gpio196/value $ echo 0 > /sys/class/gpio/gpio196/value Will write into it 1/0 respectively.
For input definition:
$ echo 196 > /sys/class/gpio/export $ echo in> /sys/class/gpio/gpio196/direction
$ cat /sys/class/gpio/gpio196/value Will read the value.
Device Tree GPIO manipulation
Device Tree GPIO include files
Device Tree GPIO definition
First you need to modify the relevnt device tree and make sure your gpio is defined.
For Example:
Edit arch/arm/boot/dts/imx6qdl-var-som.dtsi and in the section below:
hog {
pinctrl_hog_1: hoggrp-1 {
fsl,pins = <
/* CTW6120 IRQ */
MX6QDL_PAD_EIM_DA7__GPIO3_IO07 0x80000000
/* Touch */
/* for Bluetooth/wifi enable */
/* SDMMC2 CD/WP */
MX6QDL_PAD_KEY_COL4__GPIO4_IO14 0x80000000
MX6QDL_PAD_KEY_ROW4__GPIO4_IO15 0x80000000
/* USBOTG ID pin */
/* PMIC INT */
MX6QDL_PAD_GPIO_17__GPIO7_IO12 0x80000000
/* Wifi Slow Clock */
MX6QDL_PAD_ENET_RXD0__OSC32K_32K_OUT 0x000b0 /* WIFI Slow clock */
/* Audio Clock */
MX6QDL_PAD_GPIO_0__CCM_CLKO1 0x130b0 /* Audio Codec Clock */
/* Camera Clock */
MX6QDL_PAD_GPIO_3__CCM_CLKO2 0x130b0 /* Camera MCLK */
>;
};
Add the relevant GPIO to the above section in the device tree.