To find out which GPIO number to use in the Linux sysfs interface, you have to know the correspondence between available pins in the carrier board, number of the correspondent pins on the SODIMM connector of the Colibri computer on module and number of the pins on Linux.

Download or open in a web browser the Colibri Evaluation Board and the Colibri iMX6 datasheets from the respective products pages of the developer website:

For this introduction guide, some pins configured by default as GPIO in the Toradex BSP were chosen. The choice of pins was made based on their availability on all the carrier boards covered by the getting-started guide. This module will not go through the configuration of other pins as GPIO, although it is possible.

First of all, you need to find the correspondence between the SODIMM and the connectors exposed for the developer on the Colibri Evaluation Board V3.2. Consult the Colibri Evaluation Board datasheet and fill the table below based in the example provided:

Note: The notation CONNECTOR.PIN will be employed in this lesson, e.g. X12.5 means pin 5 of the X12 connector.

Have a look at the table available in the "List Functions" chapter of the Colibri iMX6 datasheet. It provides a list of most of the iMX6 pins available on the SODIMM connector.

The SODIMM pins we are interested at are connected to the iMX6 SoC and have names defined by the iMX6 Ball Name function. Each pin is multiplexed to have a specific function - among them GPIO, therefore the ALT5 function is the column that we are interested at.

Having a look at the GPIO Alphanumeric to GPIO Numeric Assignment article, the correspondence between ALT5 and the Linux numeric representation of the GPIO pins is provided as a table. To find it from the ALT5 it is possible to use the formula below:

PORTx[y]

Linux numeric representation = [(x-1)*32]+y

Either by consulting the table from the article pointed above or calculating it, the previous table with the correspondence between Iris Carrier Board pins and SODIMM pins can be extended to have the iMX6 pin name (ALT5), formed by GPIO controller, as example GPI07, plus pin at SoC level, as example IO09, and the Linux numeric representation. Fill the table below based in the example provided:

The Toradex Linux pre-built image comes with a tool named Toradex GPIO tool meant for debugging pins configuration. It can also be used to determine the correspondences found in the previous step. We will use it to test the hardware connections.

Note: You need a display and a mouse connected to the system in order to use the GPIO tool. Please go to the beginning of the getting-started guide for more information about assembling the peripherals.

There is a debug interface provided by the kernel debugfs for GPIO, which holds information about GPIO pins already reserved for drivers, as well as pin configuration and state. See the example below for the Colibri iMX6, and try it yourself:

root@colibri-imx6:~# cat /sys/kernel/debug/gpio

GPIOs 0-31, platform/209c000.gpio, 209c000.gpio:

gpio-15 (sysfs ) in hi

GPIOs 32-63, platform/20a0000.gpio, 20a0000.gpio:

gpio-37 (cd ) in lo

gpio-50 (sysfs ) out lo

gpio-54 (Wake-Up ) in lo

GPIOs 64-95, platform/20a4000.gpio, 20a4000.gpio:

gpio-90 (enable ) out lo

gpio-95 (usb_host_vbus ) out lo

GPIOs 96-127, platform/20a8000.gpio, 20a8000.gpio:

gpio-108 (scl ) in hi

gpio-109 (sda ) in hi

GPIOs 128-159, platform/20ac000.gpio, 20ac000.gpio:

gpio-130 (spi_imx ) out lo

GPIOs 160-191, platform/20b0000.gpio, 20b0000.gpio:

GPIOs 192-223, platform/20b4000.gpio, 20b4000.gpio:

gpio-204 (id ) in lo

See that the pins 15 and 50, configured as input and output in the previous steps, are the only ones taken by sysfs and are correctly configured as in and out respectively.

Export, unexport, configure and toggle the GPIO pins as you read the debugfs information to see the changes.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Toradex nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL Toradex BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The GPIO sysfs interface enables the use of interrupts from user space, as long as it is supported by the underlying hardware. Read the sysfs GPIO documentation, have a look at the poll system call and try to implement an application that handles the interrupt. Have a look at the source code below for reference:

You have to browse the computer on module datasheet and/or device-tree in order to verify that the pin can be configured as GPIO. After that, you must customize the system device-tree in order to change the pin configuration.

If there isn't a kernel driver that suits your needs, you can access GPIO from kernel space rather than user space, and use the gpio.h kernel library.

There are other ways to access GPIO registers directly either from user space (using mmap) or kernel space (using ioremap). Those are problematic since they bypass the kernel handling of the GPIO controllers and might lead to unexpected behavior.