Skip to main content
Version: 5.0

GPIO (Linux)

Introduction​

Please note that pin configuration/muxing is a non-trivial part of the overall system design. It is easily possible to do illegal configurations when it comes to multiplexed pins (e.g. one pin driving low and the other one driving high). Even more though on SoCs where certain settings in this respect cannot be done per pin but rather only per pin group.

Torizon​

Torizon is preferred for using libgpiod, due to ease-of-use and a smoother application development experience. Visit the article below for instructions on how to use it:

Toradex BSP Layers and Reference Images for Yocto Project​

libgpiod is supported and can be used on Toradex BSP Layers and Reference Images for Yocto Project from the release 3.0b3 onwards. The userspace tools and libraries are included in our evaluation image. In this article, you will be able to learn how to use the command-line tools and the C API as well.

GPIO - Libgpiod​

Pin Standartization​

Since the long famous sysfs GPIO interface (/sys/class/gpio) has been deprecated, the GPIO Char Device API, also known as libgpiod has been adopted by the Linux kernel community as the replacement. The sysfs interface is still supported by Toradex BSPs but you are discouraged to use it.

GPIO pins should be named using the edge connector name (SODIMM on Colibri/Verdin and MXM3 on Apalis). That way, the user can easily identify and use GPIO pins by their names, instead of bank and number.

The access could be done via libgpiod command-line tools:

# gpioinfo
gpiochip0 - 32 lines:
line 0: "SODIMM_43" "cd" input active-low [used]
line 1: "SODIMM_45" "Wake-Up" input active-high [used]
line 2: "SODIMM_135" unused input active-high
line 3: "SODIMM_22" unused input active-high
...

# gpiofind SODIMM_135
gpiochip0 2

Or using the libgpiod library in a C/C++ program, as provided in the gpio-event.c and gpio-toggle.c examples.

If more meaningful names are required, the user can overwrite the GPIO names via device tree overlay. This feature should be implemented in the Linux BSP via the device tree.

Command Line Tools​

Here we present how to use the command-line tools.

gpiodetect​

Search for the GPIO banks, /dev/gpiochiop0 ... /dev/gpiochipX, and how many GPIO lines they have:

# gpiodetect
gpiochip0 [5d080000.gpio] (32 lines)

gpioinfo​

Read and displays the information contained in the GPIO bank lines. All usable pins exposed on the edge connector - either SODIMM or MXM3 depending on the SoM family - are labelled as SODIMM_x or MXM3_x.

danger

Pins labelled as unnamed are not available for use on the SODIMM/MXM3 connector.

See the example below:

# gpioinfo
gpiochip0 - 32 lines:
line 0: "SODIMM_216" unused input active-high
line 1: "SODIMM_19" unused input active-high
line 2: unnamed unused input active-high
line 3: unnamed "interrupt" input active-high [used]
line 4: unnamed unused input active-high
line 5: unnamed "spi_imx" input active-high [used]
line 6: unnamed unused input active-high
line 7: unnamed unused input active-high
line 8: "SODIMM_220" unused input active-high
line 9: "SODIMM_222" unused input active-high
line 10: unnamed "interrupt" input active-high [used]
line 11: "SODIMM_218" unused input active-high
line 12: "SODIMM_155" "regulator-usb-otg1" output active-high [used]
line 13: "SODIMM_157" unused input active-high
line 14: "SODIMM_185" "regulator-usb-otg2" output active-high [used]
line 15: "SODIMM_187" unused input active-high
line 16: unnamed unused input active-high
line 17: unnamed unused input active-high
line 18: unnamed unused input active-high
line 19: unnamed unused input active-high
line 20: unnamed unused input active-high
line 21: unnamed unused input active-high
line 22: unnamed unused input active-high
line 23: unnamed unused input active-high
line 24: unnamed unused input active-high
line 25: unnamed unused input active-high
line 26: unnamed unused input active-high
line 27: unnamed unused input active-high
line 28: unnamed unused input active-high
line 29: unnamed unused input active-high
line 30: unnamed unused input active-high
line 31: unnamed unused input active-high

To see only available pins, you can filter the command output with grep:

# gpioinfo | grep -e "SODIMM" -e "MXM3"

This command is useful to check which rows are being used, with their respective use descriptions, for a GPIO bank.

gpioset​

Writes the output value of a certain line in a gpiochip passed by argument. The example set the GPIO bank 0 line 12 to output low:

# gpioset /dev/gpiochip0 12=0

You can also use only the GPIO bank index as a parameter:

# gpioset 0 12=0

Now the example to set the GPIO bank 0 line 12 to output high:

# gpioset 0 12=1

gpioget​

Reads the value of input from a certain line in a gpiochip passed by argument:

# gpioget 0 13
1

The return of this command can be 1 if the input is high and 0 if the input is low.

# gpioget 0 13
0

gpiomon​

Wait for events on GPIO rows passed by argument:

# gpiomon 0 13
event: FALLING EDGE offset: 13 timestamp: [1570281706.661390750]
event: FALLING EDGE offset: 13 timestamp: [1570281706.661435750]
event: RISING EDGE offset: 13 timestamp: [1570281706.661604000]
event: RISING EDGE offset: 13 timestamp: [1570281706.916220125]
event: FALLING EDGE offset: 13 timestamp: [1570281706.918247625]

This command is useful for polling the lines to expect incoming input events.

How to Replace sysfs Commands​

The most important commands are gpioget and gpioset, though you could possibly use gpiomon as well. Check out our example that writes and reads from GPIO pins. The sysfs commands are commented in the script:

C Language Examples​

Some examples are provided in this chapter, illustrating how to use the C API from libgpiod.

How to Toggle a GPIO​

The example below uses the libgpiod API to access a GPIO bank and line that are the arguments to the program:

Here are some relevant highlights.

Include libgpiod library:

#include <gpiod.h>

Define GPIO chip and line structs:

   struct gpiod_chip *output_chip;
struct gpiod_line *output_line;

Configure a GPIO as output:

   /* open the GPIO bank */
output_chip = gpiod_chip_open_by_number(bank);

/* open the GPIO line */
output_line = gpiod_chip_get_line(output_chip, line);
/* config as output and set a description */
gpiod_line_request_output(output_line, "gpio-test",
GPIOD_LINE_ACTIVE_STATE_HIGH);

Toggle a GPIO:

   /* Clear */
int line_value = 0;
gpiod_line_set_value(output_line, line_value);

/* Set */
line_value = 1;
gpiod_line_set_value(output_line, line_value);

To run this example you can build the application using SDK and deploy it to the module as described in Linux SDKs or create an application recipe as described in Custom meta layers, recipes and images in Yocto Project (hello-world examples) .

Read GPIO Using Events (Interrupt Driven)​

This example uses the libgpiod API to register for an event (interrupt-driven) on a rising edge. For this example make sure to add 4 arguments, the first two specifying the bank and line number of the input GPIO and the next two for the bank and line number of the output GPIO:

Here are some relevant highlights. What has been discussed in the previous section is omitted.

Request rising events notification:

   ret = gpiod_line_request_rising_edge_events(input_line, "gpio-test");

Wait for an event to happen, read which event it was and validate that it's a rising event:

   while (1) {
gpiod_line_event_wait(input_line, NULL);
if (gpiod_line_event_read(input_line, &event) != 0)
continue;
/* this should always be a rising event in our example */
if (event.event_type != GPIOD_LINE_EVENT_RISING_EDGE)
continue;
}

To run this example you can build the application using SDK and deploy it to the module as described in Linux SDKs or create an application recipe as described in Custom meta layers, recipes and images in Yocto Project (hello-world examples) .

.NET Examples​

The article .NET Core Development and Debugging on Torizon Using Visual Studio Code explains how to use libgpiod with .NET.

Python Examples​

Our samples repository on GitHub provides an example: Python libgpiod example The following articles can help you with enough context for running and extending the sample:

GPIO Sysfs​

caution

The GPIO sysfs is deprecated and has been discontinued. Its use for BSP 3.0 is discouraged and will be removed. For Torizon use the new char device API and LIBGPIOD libraries and tools. See the GPIO Char Device API - libgpiod article for reference.

To use pins other than the already exported ones directly from userspace through sysfs they first have to be exported as GPIOs.

How to find the pin number​

Use the module datasheet to find what SoC pin(s) are routed to what module edge connector pin and the carrier board datasheet or schematic to find where those signals go to. The relationship between SOC GPIO names and the 'magic' numbers used here can be found on this page. The bank and line nomenclature can differ depending on the processor family.

For example, to verify the GPIO banks and lines for the Apalis i.MX8, check the Apalis i.MX8 datasheet on the section I/O Pins -> Functions List. For example, let's assume we need to access MXM3 X1 pin 5 (Apalis GPIO3) from an Apalis iMX8:

Apalis iMX8 I/O Pins -> Function List

From the datasheet we can see that Apalis MXM3 X1 Pin 5 has the GPIO function on ALT3 accessible at LSIO.GPIO0_IO12. This means we need to access GPIO bank 0 line 12.

info

Apalis iMX6 starts enumerating GPIO banks with 1, while GPIO banks in Linux always start at 0. That means that GPIO2_IO6 on Apalis iMX6 is GPIO bank 1 line 6 on Linux. Either way, it is important to make sure that the pin is actually muxed as a GPIO in the device-tree or platform data. Failing to do so will not give any error. The pin will simply report 0 if configured as an input and not react to any state change if configured as an output.

caution

The highlighted function in the datasheet indicates the default function of the given pin. If the GPIO function is not indicated as default, there is a high chance that you will need to define the pins you will be using as GPIO in a custom Device Tree Overlay (DTO). Find further documentation and examples on how to do so here: Device Tree Overlays

How to use GPIO Sysfs​

In the following example, we are going to use SODIMM pin 100 of a Colibri T20. This makes for the following relationship:

SODIMM Pin
Number
SODIMM Pin
Name
SoC Pin
Name
SoC GPIO
Function Name
Kernel GPIO
Number
Evaluation Board
Connector
100nPXCVRENSPI1_SCKX5189X9. 7

To export a particular pin as GPIO for user control proceed as follows:

$ echo 189 > /sys/class/gpio/export

To change that GPIO pins direction to in/out:

$ echo "in" > /sys/class/gpio/gpio189/direction

or

$ echo "out" > /sys/class/gpio/gpio189/direction

To check the value (in case its direction is input):

caution

On i.MX based modules one cannot read back the value which has been set to an output unless one did set the SION bit in the pin muxing.

$ cat /sys/class/gpio/gpio189/value

To change its value (in case its direction is output):

$ echo 1 > /sys/class/gpio/gpio189/value

or

$ echo 0 > /sys/class/gpio/gpio189/value

To directly force a GPIO to output and set its initial value (e.g. glitch-free operation):

$ echo high > /sys/class/gpio/gpio189/direction

or

$ echo low > /sys/class/gpio/gpio189/direction

To configure a GPIO as an interrupt source:

Note: If a GPIO is configured as an input, one can configure the GPIO as an interrupt source. Configure GPIO if the interrupt occurs when the GPIO signal has a rising edge, a falling edge, or interrupts on both rising and falling edges.

$ echo "rising" > /sys/class/gpio/gpio189/edge

Possible values:

  • rising: Trigger on rising edge
  • falling: Trigger on falling edge
  • both: Trigger on both edges
  • none: Disable interrupts on both edges

To un-export aka revert the exporting of a GPIO pin:

$ echo 189 > /sys/class/gpio/unexport
caution

GPIOs which are already used in the drivers can not be controlled from sysfs, unless a driver explicitly exported that particular pins GPIO.

More information concerning the Linux' GPIO subsystem can be found in the following kernel documentation file:

https://git.toradex.com/cgit/linux-toradex.git/tree/Documentation/gpio.txt

GPIO Power Management Keys​

Linux systems use key events to initiate a clean shutdown or suspend-to-memory sequence. On a typical PC, pressing the power button generates a key event which will lead to a shutdown of the system. For an embedded system, a GPIO with a key code assigned can be used to trigger key events. When the key is pressed (GPIO triggered), the system will initiate the sequence.

The systemd service systemd-logind is the user-space program listening to key events (if they are tagged with the string "power-switch", see below). Four key codes are supported:

  • KEY_POWER = initiate shutdown
  • KEY_POWER2 = initiate shutdown
  • KEY_SLEEP = suspend-to-ram, commonly known as "suspend"
  • KEY_SUSPEND = suspend-to-disk, commonly known as "hibernate"

There are two steps required:

  1. Declare a GPIO as an input device and assign a key code using the GPIO keyboard driver
  2. Use a udev rule to tag the GPIO input device

GPIO Keyboard Driver​

For device tree enabled kernels, a node as follows can be used in the carrier board device tree file:

gpio-keys {
compatible = "gpio-keys";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_gpiokeys>;
power {
label = "Power-Key";
gpios = <&gpio1 9 GPIO_ACTIVE_HIGH>;
linux,code = <KEY_POWER>;
debounce-interval = <10>;
};
};

For details on how to customise the device tree refer to the Device Tree Customization article.

For Apalis T30, the predefined macro POWER_GPIO in the board file can be enabled to enable the power key code (see this commit). For the Colibri T20/T30 boards a similar approach can be adopted.

For Colibri T30, the example below enables SODIMM Pin 162 as a suspend pin

diff --git a/arch/arm/mach-tegra/board-colibri_t30.c b/arch/arm/mach-tegra/board-colibri_t30.c
index 7265d8d..2c4079e 100644
--- a/arch/arm/mach-tegra/board-colibri_t30.c
+++ b/arch/arm/mach-tegra/board-colibri_t30.c
@@ -394,7 +394,7 @@ static struct gpio colibri_t30_gpios[] = {
// {TEGRA_GPIO_PN3, GPIOF_IN, "SODIMM pin 180"},
// {TEGRA_GPIO_PN4, GPIOF_IN, "SODIMM pin 160"},
// {TEGRA_GPIO_PN5, GPIOF_IN, "SODIMM pin 158"},
- {TEGRA_GPIO_PN6, GPIOF_IN, "SODIMM pin 162"},
+// {TEGRA_GPIO_PN6, GPIOF_IN, "SODIMM pin 162"},
//conflicts with ADDRESS13
// {TEGRA_GPIO_PP4, GPIOF_IN, "SODIMM pin 120"},
//conflicts with ADDRESS14
@@ -668,6 +668,7 @@ static struct gpio_keys_button colibri_t30_keys[] = {
GPIO_KEY(KEY_POWER, PV1, 0, 1), /* SODIMM pin 45,
Iris X16-20 */
GPIO_KEY(KEY_MENU, PK6, 1, 0), /* SODIMM pin 135 */
+ GPIO_KEY(KEY_SLEEP, PN6, 0, 0), /* SODIMM pin 162 */
};

static struct gpio_keys_platform_data colibri_t30_keys_platform_data = {
--
2.6.3

Tag the GPIO Input Device​

Use a udev rule to add the power-switch tag to the GPIO key event source. Store the file in a udev rules directory, e.g. /etc/udev/rules.d/power-key.rules

ACTION=="remove", GOTO="power_switch_end"

SUBSYSTEM=="input", KERNEL=="event*", ENV{ID_PATH}=="platform-gpio-keys*", ATTRS{keys}=="*", TAG+="power-switch"

LABEL="power_switch_end"

With that, all keycodes get tagged as power-switch events, and systemd will interpret the relevant key codes. The exact behaviour can be fine-tuned through HandlePowerKey/HandleSuspendKey and HandleHibernateKey in /etc/systemd/logind.conf.

GPIO Power-Off​

To power off a system completely after shutdown, often a GPIO is needed to switch off the system. Newer Kernel provides a specific GPIO power-off driver to achieve this.

Our Colibri and Apalis Evaluation Boards have a push button power on/off controller (LTC2954) which has a GPIO input FORCE_OFF# (X4-5 on Colibri or X61-5 on Apalis). This signal makes sure that the DC-DC converter on the carrier board are switched-off completely as if the user pressed the on/off button. After connecting these signals to a GPIO, the GPIO power-off driver needs to be enabled. On device-tree based kernels (e.g. Colibri/Apalis iMX6 and Colibri VF50/VF61), the driver CONFIG_POWER_RESET_GPIO need to be enabled (up to v2.3Beta5 this is not the case by default). Furthermore, on Colibri VF50/VF61 using V2.7 and newer releases the default power off method needs to be disabled by reverting commit ARM: vf610: PM: register power_off function. Finally, a new node needs to be added which specifies the GPIO to switch power off. This example uses SO-DIMM 135 (EXT_IO_0) as power-off GPIO for Colibri VF50/VF61 modules:

gpio-poweroff {
compatible = "gpio-poweroff";
gpios = <&gpio2 25 GPIO_ACTIVE_LOW>;
};

The poweroff command needs to be used to power-off the system completely ("halt" does not work):

# poweroff

For Apalis T30, the predefined macro FORCE_OFF_GPIO in the board file can be enabled (see this commit). For the Colibri T20/T30 boards, a similar approach can be adopted.

For i.MX6 based modules CONFIG_POWER_RESET_GPIO must be set in the kernel configuration. Additionally, for the 3.10.17 kernel version, you will have to at least cherry-pick this commit or use the toradex_imx_3.10.17_1.0.0_ga-next branch.

info

To have gpio-poweroff driver working well on i.MX6 with new kernel versions >= toradex_4.14-2.0.x-imx, you should add the property force-mode to the gpio-poweroff node.

For i.MX8/8X based modules CONFIG_POWER_RESET_GPIO must be set in the kernel configuration. You also need to correctly mux the GPIO pin that you choose to use. Here is an example of device tree that uses SO-DIMM 104 as power-off GPIO for Colibri iMX8X:

arch/arm64/boot/dts/freescale/fsl-imx8qxp-colibri.dtsi
diff --git a/arch/arm64/boot/dts/freescale/fsl-imx8qxp-colibri-eval-v3.dtsi b/arch/arm64/boot/dts/freescale/fsl-imx8qxp-colibri-eval-v3.dtsi
index 6fa5b6207c70b..2d8acb0c2ac33 100644
--- a/arch/arm64/boot/dts/freescale/fsl-imx8qxp-colibri-eval-v3.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-imx8qxp-colibri-eval-v3.dtsi
@@ -41,7 +41,10 @@
gpio-key,wakeup;
};
};
-
+ gpio-poweroff {
+ compatible = "gpio-poweroff";
+ gpios = <&gpio3 23 GPIO_ACTIVE_LOW>;
+ };
panel {
compatible = "panel-dpi";
backlight = <&backlight>;
diff --git a/arch/arm64/boot/dts/freescale/fsl-imx8qxp-colibri.dtsi b/arch/arm64/boot/dts/freescale/fsl-imx8qxp-colibri.dtsi
index d6a46f06b6a05..effec9b844d4e 100644
--- a/arch/arm64/boot/dts/freescale/fsl-imx8qxp-colibri.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-imx8qxp-colibri.dtsi
@@ -413,7 +413,7 @@
SC_P_QSPI0B_DATA3_LSIO_GPIO3_IO21 0x20 /* SODIMM 98 */
SC_P_SAI1_RXFS_LSIO_GPIO0_IO31 0x20 /* SODIMM 100 */
SC_P_QSPI0B_DQS_LSIO_GPIO3_IO22 0x20 /* SODIMM 102 */
- SC_P_QSPI0B_SS0_B_LSIO_GPIO3_IO23 0x20 /* SODIMM 104 */
+ SC_P_QSPI0B_SS0_B_LSIO_GPIO3_IO23 0x21 /* SODIMM 104 */
SC_P_QSPI0B_SS1_B_LSIO_GPIO3_IO24 0x20 /* SODIMM 106 */
>;
};

GPIO LED​

The GPIO LED driver allows using a GPIO to control a LED. Using the Kernels LED driver framework has the advantage that triggers can be specified, which allow using an LED as a visual activity signal for various system activities.

leds {
compatible = "gpio-leds";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_gpio_leds>;

led0: user1 {
label = "user1";
gpios = <&gpio1 16 GPIO_ACTIVE_HIGH>; /* SODIMM 103 */
default-state = "off";
linux,default-trigger = "mmc0";
};
};
...
pinctrl_gpio_leds: gpioleds {
fsl,pins = <
VF610_PAD_PTC3__GPIO_48 0x2180
>;
};

You can also get a list of valid triggers (and configure the active trigger) through the sysfs file at /sys/class/leds/user1/trigger.

GPIO PPS​

The GPIO PPS is a feature present in the Linux Kernel that allows the usage of a GPIO with a given Pulse-Per-Second (PPS) signal.

Starting from BSP 5, it's enabled by default in the kernel config on Toradex Reference Images for Yocto Project and TorizonCore:

CONFIG_PPS_CLIENT_GPIO
CONFIG_PPS_CLIENT_LDISC

Here is one example of a device tree for Colibri iMX7D 1GB. In addition to the example, you must also make sure to check the pin muxing, i.e. make sure that no other driver muxes and claims the pin function GPIO1_IO02, and to mux the pin to gpio as part of the pps node.

Also note that since pps is a new node, it must be created somewhere in the tree under /.

  / {
model = "Toradex Colibri iMX7D 1GB on Colibri Evaluation Board V3 Testing for custom carrier";
compatible = "toradex,colibri_imx7d_emmc-eval", "toradex,colibri_imx7d_emmc", \
"fsl,imx7d";
pps {
compatible = "pps-gpio";
gpios = <&gpio1 2 0>;
assert-falling-edge;
};
};

Please refer to the Linux kernel documentation on device tree bindings for more details: Device-Tree Bindings for a PPS Signal on GPIO

GPIO U-Boot​

One can also access GPIOs from U-Boot. This allows one to implement functionality such as β€œPress button X and turn the device ON to upgrade firmware" using U-Boot scripts.

The GPIO driver can be used from within the U-Boot source code. Additionally, the GPIO driver has a corresponding gpio command-line interface that can be used to set and get GPIO values. Note that for the command-line interface to work the corresponding pin must be muxed to its GPIO functionality in the U-Boot code.

On a Colibri VF accesses from code allow to set a GPIO around 40ms, access from the command-line interface in 'bootcmd' 70ms after power-up.

info

The relationship between SOC GPIO names and the 'magic' numbers used here can be found on GPIO Alphanumeric to GPIO Numeric Assignment article.

Command Line Interface​

# gpio help
gpio - query and control gpio pins

Usage:
gpio <input|set|clear|toggle> <pin>
- input/set/clear/toggle the specified pin
gpio status [-a] [<bank> | <pin>] - show [all/claimed] GPIOs

To set the GPIO:

> gpio set [gpio-number]

To clear the GPIO

> gpio clear [gpio-number]

To toggle the GPIO

> gpio toggle [gpio-number]

To read the state of GPIO:

> gpio input [gpio-number]

Usually, all GPIO pins are muxed as input in U-Boot. You can confirm it, for instance, with the command below:

>  gpio status -a
Bank GPIO0_:
GPIO0_0: input: 0 [ ]
GPIO0_1: input: 0 [ ]
GPIO0_2: input: 0 [ ]
...
GPIO7_29: input: 0 [ ]
GPIO7_30: input: 0 [ ]
GPIO7_31: input: 0 [ ]

Example - Colibri iMX8X​

This example has been tested on Colibri iMX8QXP + Colibri Evaluation Board V3.2 using the mainline master branch of U-Boot.

To calculate the pin number in U-Boot, use the formula below:

caution

beware that this formula is different from the formula for the Linux user space provided in GPIO Alphanumeric to GPIO Numeric Assignment.

pin = 32 * GPIO_BANK + GPIO_LINE

For example, GPIO3_10:
pin = 32 * 3 + 10 = 106

Change the pinmux configuration in the U-Boot device tree, in the source code. The change below set the GPIO on SODIMM 45 as output:

arch/arm/dts/fsl-imx8qxp-colibri.dts
diff --git a/arch/arm/dts/fsl-imx8qxp-colibri.dts b/arch/arm/dts/fsl-imx8qxp-colibri.dts
index 0c20edf2cf..562effb366 100644
--- a/arch/arm/dts/fsl-imx8qxp-colibri.dts
+++ b/arch/arm/dts/fsl-imx8qxp-colibri.dts
@@ -89,7 +89,7 @@

pinctrl_hog1: hog1grp {
fsl,pins = <
- SC_P_QSPI0A_DATA1_LSIO_GPIO3_IO10 0x00000020 /* 45 */
+ SC_P_QSPI0A_DATA1_LSIO_GPIO3_IO10 0x02000020 /* 45 */
SC_P_ENET0_RGMII_TXD3_LSIO_GPIO5_IO02 0x06000020 /* 65 */
SC_P_CSI_D07_CI_PI_D09 0x00000061
SC_P_QSPI0A_DATA2_LSIO_GPIO3_IO11 0x00000020 /* 69 */

Re-compile and deploy U-Boot, then toggle this GPIO from the U-Boot command-line:

> gpio set 106  
gpio: pin 106 (gpio 106) value is 1
> gpio clear 106
gpio: pin 106 (gpio 106) value is 0

Example - Colibri VFxx​

To clear GPIO #22 (Backlight PWM configured as GPIO on a Colibri VF) do:

# gpio out 22

To read GPIO #10 (UART A, DTR on a Colibri VF) do:

Colibri VFxx # gpio input 10
gpio: pin 10 (gpio 10) value is 0

To read GPIO #10 (UART A, DTR on a Colibri VF) and react on the read value do:

Colibri VFxx # if gpio input 10 ; then echo "commands for 0" ; else echo "commands for 1" ; fi
gpio: pin 10 (gpio 10) value is 0
commands for 0

From Source Code​

To access a GPIO earlier than what would be possible from the U-Boot command line or to include it in an algorithm written in source code using the GPIO API. In most cases this code would live in the board file (e.g. board/toradex/colibri_vf/colibri_vf.c).

The GPIO's need to be configured only after the GPIO driver is loaded, if a GPIO gets configured before the driver has been loaded, the GPIO functions will have no effect. The 'board_init' function is called just after GPIO initialization and hence is an appropriate place to configure custom GPIO's.

e.g. To set GPIO_10 during boot from board file:

 diff --git i/board/toradex/colibri_vf/colibri_vf.c w/board/toradex/colibri_vf/colibri_vf.c
index 3272733..ca30af8 100644
--- i/board/toradex/colibri_vf/colibri_vf.c
+++ w/board/toradex/colibri_vf/colibri_vf.c
@@ -478,6 +483,11 @@ int board_init(void)
*/

setbits_le32(&scsc->sosc_ctr, SCSC_SOSC_CTR_SOSC_EN);
+#ifdef CONFIG_VYBRID_GPIO
+ gpio_request(10, "SODIMM_PIN_23");
+ gpio_direction_output(10, 1);
+#endif

GPIO Debugging​

All "free" Pins are configured as GPIOs by default and are already exported from within the board-specific platform configuration to be used from userspace through the sysfs interface.

To know what GPIOs are currently exported from the platform configuration resp. requested from drivers proceed as follows:

$ cat /sys/kernel/debug/gpio

Apalis iMX6​

root@apalis-imx6:~# cat /sys/kernel/debug/gpio
GPIOs 0-31, platform/209c000.gpio, 209c000.gpio:
gpio-0 (usb_host_vbus ) out lo
gpio-2 (PCIe reset ) out lo
gpio-4 (Wake-Up ) in hi
gpio-6 (sysfs ) in lo
gpio-25 (phy-reset ) out lo
gpio-28 (PCIe EP reset ) out lo

GPIOs 32-63, platform/20a0000.gpio, 20a0000.gpio:
gpio-36 (sysfs ) in lo
gpio-37 (sysfs ) in lo
gpio-38 (sysfs ) in lo
gpio-39 (sysfs ) in lo
gpio-58 (spi_imx ) out lo
gpio-62 (scl ) in hi

GPIOs 64-95, platform/20a4000.gpio, 20a4000.gpio:
gpio-80 (sda ) in hi
gpio-86 (usb_otg_vbus ) out lo
gpio-92 (usb_host_vbus_hub ) out lo

GPIOs 96-127, platform/20a8000.gpio, 20a8000.gpio:
gpio-116 (cd ) in hi

GPIOs 128-159, platform/20ac000.gpio, 20ac000.gpio:
gpio-153 (spi_imx ) out lo

GPIOs 160-191, platform/20b0000.gpio, 20b0000.gpio:
gpio-174 (cd ) in hi

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

Apalis iMX8​

apalis-imx8-06438744:/# cat /sys/kernel/debug/gpio
gpiochip7: GPIOs 256-287, parent: platform/5d0f0000.gpio, 5d0f0000.gpio:

gpiochip6: GPIOs 288-319, parent: platform/5d0e0000.gpio, 5d0e0000.gpio:

gpiochip5: GPIOs 320-351, parent: platform/5d0d0000.gpio, 5d0d0000.gpio:
gpio-320 ( |reset ) out hi

gpiochip4: GPIOs 352-383, parent: platform/5d0c0000.gpio, 5d0c0000.gpio:
gpio-356 ( |VCC_USBH(2A|2C|2D|3|) out hi
gpio-364 ( |cd ) in hi IRQ
gpio-379 ( |ref-clock ) out hi

gpiochip3: GPIOs 384-415, parent: platform/5d0b0000.gpio, 5d0b0000.gpio:
gpio-412 ( |GPIO fan control ) out hi

gpiochip2: GPIOs 416-447, parent: platform/5d0a0000.gpio, 5d0a0000.gpio:
gpio-425 ( |cd ) in hi IRQ
gpio-436 ( |Wake-Up ) in hi IRQ

gpiochip1: GPIOs 448-479, parent: platform/5d090000.gpio, 5d090000.gpio:
gpio-449 ( |usb3503 intn ) out lo
gpio-450 ( |usb3503 reset ) out hi
gpio-452 ( |enable ) out hi
gpio-459 ( |phy-reset ) out hi
gpio-478 ( |HDMI_CTRL ) out hi

gpiochip0: GPIOs 480-511, parent: platform/5d080000.gpio, 5d080000.gpio:
gpio-511 ( |usb3503 connect ) out hi

Apalis iMX8X​

info

Apalis iMX8X is phased out, and it is not available for purchase anymore. The latest supported BSP and TorizonCore version is 5.4.0.

root@apalis-imx8x-v11a:~# cat /sys/kernel/debug/gpio
gpiochip9: GPIOs 208-223, parent: i2c/17-0020, pcal6416, can sleep:
gpio-208 (HDMI1_CEC )
gpio-209 (SPDIF1_IN )
gpio-210 (SPDIF1_OUT )
gpio-211 (UART4_TXD )
gpio-212 (UART1_DCD )
gpio-213 (UART1_RI )
gpio-214 (UART1_DSR )
gpio-215 (UART1_DTR )
gpio-216 (PWM1 )
gpio-217 (Wi-Fi_WKUP_WLAN )
gpio-218 (Wi-Fi_W_DISABLE )
gpio-219 (Wi-Fi_WKUP_BT )
gpio-220 (Wi-Fi_PDn )
gpio-221 (Wi-Fi_WKUP_HOST )
gpio-222 (DSI_SW_SEL |LVDS_HDMI_MUX ) out hi
gpio-223 (HDMI1_HPD |hpd ) in hi IRQ

gpiochip8: GPIOs 224-255, parent: platform/58222000.gpio, 58222000.gpio:

gpiochip7: GPIOs 256-287, parent: platform/5d0f0000.gpio, 5d0f0000.gpio:

gpiochip6: GPIOs 288-319, parent: platform/5d0e0000.gpio, 5d0e0000.gpio:

gpiochip5: GPIOs 320-351, parent: platform/5d0d0000.gpio, 5d0d0000.gpio:
gpio-320 (MXM3_67 )
gpio-321 (MXM3_71 )
gpio-322 (MXM3_73 )
gpio-323 (MXM3_113 )
gpio-324 (MXM3_115 )
gpio-325 (MXM3_119 )
gpio-326 (MXM3_121 )
gpio-327 (MXM3_125 )
gpio-328 (MXM3_127 )
gpio-329 (MXM3_131 )
gpio-330 (MXM3_59 )
gpio-331 (MXM3_61 )

gpiochip4: GPIOs 352-383, parent: platform/5d0c0000.gpio, 5d0c0000.gpio:
gpio-352 ( )
gpio-353 ( )
gpio-354 ( )
gpio-355 (MXM3_211 )
gpio-356 (MXM3_84 |usb_host_vbus_hub ) out hi
gpio-357 (MXM3_262 )
gpio-358 (MXM3_209 )
gpio-359 ( )
gpio-360 ( )
gpio-361 ( )
gpio-362 ( )
gpio-363 ( )
gpio-364 ( )
gpio-365 ( )
gpio-366 ( )
gpio-367 ( )
gpio-368 ( )
gpio-369 ( )
gpio-370 ( )
gpio-371 (MXM3_152 )
gpio-372 (MXM3_148 )
gpio-373 (MXM3_156 )
gpio-374 (MXM3_164 |cd ) in hi IRQ
gpio-375 (MXM3_154 )
gpio-376 (MXM3_150 )
gpio-377 (MXM3_160 )
gpio-378 (MXM3_162 )
gpio-379 (MXM3_144 )
gpio-380 (MXM3_146 )
gpio-381 (MXM3_77 )
gpio-382 (MXM3_79 )
gpio-383 (MXM3_65 )

gpiochip3: GPIOs 384-415, parent: platform/5d0b0000.gpio, 5d0b0000.gpio:
gpio-384 (MXM3_191 )
gpio-385 (MXM3_193 )
gpio-386 (MXM3_203 )
gpio-387 (MXM3_201 )
gpio-388 ( |phy-reset ) out hi
gpio-389 ( )
gpio-390 ( )
gpio-391 ( )
gpio-392 ( )
gpio-393 (MXM3_96 )
gpio-394 (MXM3_110 )
gpio-395 (MXM3_114 )
gpio-396 (MXM3_116 )
gpio-397 (MXM3_286 |enable ) out hi
gpio-398 (MXM3_158 )
gpio-399 (MXM3_198 )
gpio-400 (MXM3_274 |usb_otg1_vbus ) out lo
gpio-401 (MXM3_11 )
gpio-402 (MXM3_13 )
gpio-403 (MXM3_15 |pcie_switch ) out hi
gpio-404 (MXM3_17 )
gpio-405 (MXM3_1 )
gpio-406 (MXM3_3 )
gpio-407 (MXM3_5 )
gpio-408 (MXM3_7 )

gpiochip2: GPIOs 416-447, parent: platform/5d0a0000.gpio, 5d0a0000.gpio:
gpio-416 (MXM3_8 )
gpio-417 ( )
gpio-418 ( )
gpio-419 (MXM3_140 )
gpiochip1: GPIOs 448-479, parent: platform/5d090000.gpio, 5d090000.gpio:
gpio-448 (MXM3_235 |fsl_lpspi ) in hi
gpio-449 (MXM3_233 )
gpio-450 (MXM3_231 )
gpi
o-451 (MXM3_229 )
gpio-452 (MXM3_221 )
gpio-453 (MXM3_223 )
gpio-454 (MXM3_225 )
gpio-455 (MXM3_316 )
gpio-456 (MXM3_227 |fsl_lpspi ) in lo
gpio-457 (MXM3_307 )
gpio-458 (MXM3_305 )
gpio-459 (MXM3_194 )
gpio-460 ( )
gpio-461 (MXM3_311 )
gpio-462 (MXM3_309 )
gpio-463 (MXM3_128 )
gpio-464 (MXM3_130 )
gpio-465 (MXM3_12 )
gpio-466 (MXM3_14 )
gpio-467 (MXM3_16 )
gpio-468 (MXM3_18 )
gpio-469 (MXM3_132 )
gpio-470 (MXM3_126 )
gpio-471 (MXM3_134 )
gpio-472 (MXM3_136 )
gpio-473 (MXM3_35 )
gpio-474 (MXM3_37 |Wake-Up ) in hi IRQ
gpio-475 (MXM3_4 )
gpio-476 (MXM3_6 )
gpio-477 (MXM3_207 )
gpio-478 (MXM3_205 )
gpio-479 (MXM3_239 )

gpiochip0: GPIOs 480-511, parent: platform/5d080000.gpio, 5d080000.gpio:
gpio-480 ( )
gpio-481 (MXM3_293 )
gpio-482 (MXM3_295 )
gpio-483 (MXM3_297 )
gpio-484 (MXM3_299 )
gpio-485 (MXM3_301 )
gpio-486 (MXM3_273 )
gpio-487 (MXM3_275 )
gpio-488 (MXM3_277 )
gpio-489 (MXM3_279 )
gpio-490 (MXM3_281 )
gpio-491 (MXM3_283 )
gpio-492 (MXM3_255 )
gpio-493 (MXM3_257 )
gpio-494 (MXM3_259 )
gpio-495 (MXM3_261 )
gpio-496 (MXM3_247 )
gpio-497 ( )
gpio-498 ( )
gpio-499 (MXM3_245 )
gpio-500 (MXM3_243 )
gpio-501 (MXM3_112 )
gpio-502 (MXM3_118 )
gpio-503 ( )
gpio-504 (MXM3_265 )
gpio-505 (MXM3_196 )
gpio-506 (MXM3_200 )
gpio-507 (MXM3_202 )
gpio-508 (MXM3_204 )
gpio-509 (MXM3_310 )
gpio-510 (MXM3_312 )
gpio-511 (MXM3_318 )

Apalis T30​

root@apalis-t30:~# cat /sys/kernel/debug/gpio 
GPIOs 0-255, tegra-gpio:
gpio-6 (Just for testing ) in lo
gpio-26 (THERMD_ALERT_N ) in hi
gpio-68 (RESET_MOCI_N ) out hi
gpio-111 (HDMI1_HPD ) in lo
gpio-128 (GPIO6 X1-11 ) in lo
gpio-129 (GPIO8 X1-15, FAN ) in lo
gpio-146 (GPIO1 X1-1 ) in lo
gpio-147 (GPIO2 X1-3 ) in lo
gpio-148 (GPIO3 X1-5 ) in lo
gpio-149 (GPIO4 X1-7 ) in lo
gpio-150 (GPIO5 X1-9 ) in lo
gpio-151 (PEX_PERST_N ) out hi
gpio-168 (TOUCH_PEN_INT ) in hi
gpio-169 (KEY_POWER ) in hi
gpio-170 (BKL1_ON ) out hi
gpio-171 (sdhci_cd ) in hi
gpio-216 (LVDS: Single/Dual Ch) out lo
gpio-219 (LVDS: 18/24 Bit Mode) out hi
gpio-220 (LVDS: Output Enable ) out hi
gpio-221 (LVDS: Power Down ) out hi
gpio-222 (LVDS: Clock Polarity) out hi
gpio-223 (LVDS: Colour Mapping) out hi
gpio-225 (LVDS: Swing Mode ) out hi
gpio-226 (LVDS: DDRclk Disable) out hi
gpio-229 (sdhci_cd ) in hi
gpio-232 (SATA1_ACT_N ) out hi
gpio-233 (usb_host_vbus ) out hi

GPIOs 256-264, i2c/4-002d, tps6591x, can sleep:
gpio-262 (fixed_reg_en_hdmi ) out hi

Apalis TK1​

root@apalis-tk1:~# cat /sys/kernel/debug/gpio 
GPIOs 0-255, platform/6000d000.gpio, tegra-gpio:
gpio-63 (+V1.05_AVDD_HDMI_PLL) out lo
gpio-70 (temp_alert ) in hi
gpio-108 (VCC_USBO1 ) out lo
gpio-109 (VCC_USBH(2A|2C|2D|3|) out hi
gpio-111 (hdmi_hpd ) in hi
gpio-146 (LAN_RESET_N ) out hi
gpio-164 (RESET_MOCI_N ) out hi
gpio-170 (sdhci_cd ) in hi
gpio-171 (sdhci_cd ) in hi
gpio-221 (BKL1_ON ) out hi
gpio-233 (PEX_PERST_N ) out hi
gpio-235 (WAKE1_MICO ) in hi

GPIOs 1016-1023, platform/as3722-pinctrl, as3722-gpio, can sleep:
gpio-1018 (+V3.3 ) out hi

Colibri iMX6​

root@colibri-imx6:~# cat /sys/kernel/debug/gpio 
gpiochip0: GPIOs 0-31, parent: platform/209c000.gpio, 209c000.gpio:

gpiochip1: GPIOs 32-63, parent: platform/20a0000.gpio, 20a0000.gpio:
gpio-37 ( |cd ) in hi IRQ
gpio-54 ( |Wake-Up ) in lo IRQ

gpiochip2: GPIOs 64-95, parent: platform/20a4000.gpio, 20a4000.gpio:
gpio-95 ( |usb_host_vbus ) out lo

gpiochip3: GPIOs 96-127, parent: platform/20a8000.gpio, 20a8000.gpio:
gpio-108 ( |scl ) in hi
gpio-109 ( |sda ) in hi

gpiochip4: GPIOs 128-159, parent: platform/20ac000.gpio, 20ac000.gpio:
gpio-130 ( |spi_imx ) out hi

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

gpiochip6: GPIOs 192-223, parent: platform/20b4000.gpio, 20b4000.gpio:
gpio-204 ( |id ) in hi IRQ

Colibri iMX6ULL​

root@colibri-imx6ull:~# cat /sys/kernel/debug/gpio
gpiochip0: GPIOs 0-31, parent: platform/209c000.gpio, 209c000.gpio:
gpio-2 ( |VCC_USB[1-4] ) out lo
gpio-11 ( |enable ) out hi
gpiochip1: GPIOs 32-63, parent: platform/20a0000.gpio, 20a0000.gpio:
gpiochip2: GPIOs 64-95, parent: platform/20a4000.gpio, 20a4000.gpio:
gpio-90 ( |spi_imx ) out hi
gpiochip3: GPIOs 96-127, parent: platform/20a8000.gpio, 20a8000.gpio:
gpio-118 ( |sysfs ) in lo
gpio-120 ( |sysfs ) out lo
gpiochip4: GPIOs 128-159, parent: platform/20ac000.gpio, 20ac000.gpio:
gpio-128 ( |cd ) in hi
gpio-129 ( |Wake-Up ) in lo
gpio-130 ( |id ) in lo
gpio-139 ( |WIFI_PDN ) out hi

Colibri iMX7​

root@colibri-imx7:~# cat /sys/kernel/debug/gpio 
GPIOs 0-31, platform/30200000.gpio, 30200000.gpio:
gpio-0 (cd ) in lo
gpio-1 (Wake-Up ) in lo

GPIOs 32-63, platform/30210000.gpio, 30210000.gpio:

GPIOs 64-95, platform/30220000.gpio, 30220000.gpio:

GPIOs 96-127, platform/30230000.gpio, 30230000.gpio:
gpio-103 (VCC_USB[1-4] ) out lo
gpio-107 (spi_imx ) out lo

GPIOs 128-159, platform/30240000.gpio, 30240000.gpio:
gpio-129 (enable ) out lo

GPIOs 160-191, platform/30250000.gpio, 30250000.gpio:

GPIOs 192-223, platform/30260000.gpio, 30260000.gpio:
gpio-206 (id ) in lo

Colibri iMX8X​

root@colibri-imx8x:~# cat /sys/kernel/debug/gpio
gpiochip9: GPIOs 216-223, parent: i2c/16-0043, fxl6408, can sleep:
gpio-218 ( |power-on ) out lo
gpio-219 ( |clkreq ) out hi
gpio-220 ( |usb3503 reset ) out hi
gpio-221 ( |usb3503 bypass ) out hi
gpio-222 ( |disable ) out hi

gpiochip8: GPIOs 224-255, parent: platform/58222000.gpio, 58222000.gpio:

gpiochip7: GPIOs 256-287, parent: platform/5d0f0000.gpio, 5d0f0000.gpio:

gpiochip6: GPIOs 288-319, parent: platform/5d0e0000.gpio, 5d0e0000.gpio:

gpiochip5: GPIOs 320-351, parent: platform/5d0d0000.gpio, 5d0d0000.gpio:
gpio-329 ( |id ) in lo IRQ

gpiochip4: GPIOs 352-383, parent: platform/5d0c0000.gpio, 5d0c0000.gpio:
gpio-352 ( |reset ) out hi
gpio-355 ( |usbh_vbus ) out lo
gpio-371 ( |enable ) out hi

gpiochip3: GPIOs 384-415, parent: platform/5d0b0000.gpio, 5d0b0000.gpio:
gpio-388 ( |usb3503 intn ) out hi
gpio-393 ( |cd ) in hi IRQ
gpio-394 ( |Wake-Up ) in lo IRQ
gpio-396 ( |enable ) out hi

gpiochip2: GPIOs 416-447, parent: platform/5d0a0000.gpio, 5d0a0000.gpio:

gpiochip1: GPIOs 448-479, parent: platform/5d090000.gpio, 5d090000.gpio:
gpio-448 ( |fsl_lpspi ) out hi

gpiochip0: GPIOs 480-511, parent: platform/5d080000.gpio, 5d080000.gpio:

Colibri T20​

root@colibri_t20:~# cat /sys/kernel/debug/gpio
GPIOs 0-223, tegra-gpio:
gpio-0 (SODIMM pin 73 ) in hi
gpio-2 (SODIMM pin 186 ) in lo
gpio-3 (SODIMM pin 184 ) in lo
gpio-10 (SODIMM pin 154 ) out hi
gpio-13 (sysfs ) out hi
gpio-14 (SODIMM pin 55 ) in hi
gpio-15 (SODIMM pin 63 ) in hi
gpio-22 (sysfs ) out hi
gpio-23 (sdhci4_cd ) in hi irq-215 edge-both
gpio-29 (SODI-98, Iris X16-13) in lo
gpio-67 (SODIMM pin 130 ) in hi
gpio-68 (SODIMM pin 87 ) in hi
gpio-70 (SODIMM pin 132 ) in hi
gpio-80 (SODIMM pin 150 ) in lo
gpio-81 (SODIMM pin 152 ) in lo
gpio-84 (SODIMM pin 106 ) in lo
gpio-88 (SOD-101, Iris X16-16) in lo
gpio-89 (SOD-103, Iris X16-15) in lo
gpio-90 (SODI-79, Iris X16-19) in lo
gpio-91 (SODI-97, Iris X16-17) in lo
gpio-94 (SODI-85, Iris X16-18) in lo
gpio-104 (SODIMM pin 174 ) in lo
gpio-105 (SODIMM pin 176 ) in lo
gpio-106 (SODIMM pin 178 ) in lo
gpio-107 (SODIMM pin 180 ) in lo
gpio-108 (SODIMM pin 160 ) in lo
gpio-109 (SODIMM pin 158 ) in lo
gpio-110 (SODIMM pin 162 ) in lo
gpio-111 (sysfs ) in hi irq-303 edge-both
gpio-124 (SODIMM pin 120 ) in lo
gpio-125 (SODIMM pin 122 ) in lo
gpio-126 (SODIMM pin 124 ) in lo
gpio-127 (SODIMM pin 188 ) in lo
gpio-144 (nand_wp ) out hi
gpio-154 (SODIMM pin 69 ) in lo
gpio-155 (SODIMM pin 77 ) in lo
gpio-156 (BL_ON ) out hi
gpio-166 (SODIMM pin 118 ) in lo
gpio-168 (WOLFSON_RESET ) out hi
gpio-169 (ulpi_phy_reset_b ) out hi
gpio-171 (SODI-45, Iris X16-20) in lo
gpio-172 (ethernet_reset ) out hi
gpio-176 (sysfs ) out hi
gpio-178 (VBUS_BUS ) out lo
gpio-184 (SODIMM pin 142 ) in lo
gpio-185 (SODIMM pin 140 ) in lo
gpio-186 (SODIMM pin 138 ) in lo
gpio-187 (SODIMM pin 136 ) in lo
gpio-188 (SODIMM pin 134 ) in lo
gpio-190 (102, I X13 ForceOFF#) in hi
gpio-191 (104, I X14 ForceOFF#) in hi
gpio-202 (SODIMM pin 156 ) in lo
gpio-204 (SODIMM pin 164 ) in lo
gpio-212 (SODIMM pin 166 ) in lo
gpio-213 (SODIMM pin 168 ) in lo
gpio-214 (SODIMM pin 170 ) in lo
gpio-215 (SODIMM pin 172 ) in lo
gpio-217 (ethernet_vbus ) out hi
gpio-218 (SOD-133, Iris X16-14) in lo
gpio-219 (SODIMM pin 127 ) in lo
gpio-220 (SODIMM pin 22 ) in lo

GPIOs 224-227, i2c/4-0034, tps6586x, can sleep:

Colibri T30​

root@colibri-t30:~# cat /sys/kernel/debug/gpio
GPIOs 0-255, tegra-gpio:
gpio-10 (SODIMM pin 154 ) in lo
gpio-17 (SODIMM pin 81 ) in lo
gpio-23 (sdhci_cd ) in hi
gpio-26 (THERMD_ALERT ) in hi
gpio-67 (SODIMM pin 130 ) in lo
gpio-70 (SODIMM pin 132 ) in lo
gpio-85 (USBC_DET ) in hi
gpio-86 (KEY_MENU ) in lo
gpio-110 (SODIMM pin 162 ) in lo
gpio-111 (hdmi_hpd ) in lo
gpio-144 (SODIMM pin 73 ) in hi
gpio-153 (EN_MIC_GND ) out hi
gpio-157 (KEY_BACK ) in hi
gpio-158 (KEY_HOME ) in hi
gpio-168 (TOUCH_PEN_INT ) in hi
gpio-169 (KEY_POWER ) in lo
gpio-170 (BL_ON ) out hi
gpio-171 (SODI-85, Iris X16-18) in hi
gpio-178 (usb_host_vbus ) out lo
gpio-181 (SODIMM pin 75 ) in lo
gpio-188 (SODIMM pin 134 ) in lo
gpio-190 (102, I X13 ForceOFF#) in lo
gpio-191 (104, I X14 ForceOFF#) in lo
gpio-220 (SODIMM pin 166 ) in lo
gpio-221 (SODIMM pin 168 ) in lo
gpio-222 (SODIMM pin 170 ) in lo
gpio-223 (SODIMM pin 172 ) in lo
gpio-226 (KEY_FIND ) in hi
gpio-230 (KEY_VOLUMEDOWN ) in hi
gpio-231 (SODIMM pin 94 ) in hi
gpio-232 (LAN_RESET ) out hi
gpio-234 (LAN_V_BUS ) out hi
gpio-237 (SODIMM pin 69 ) in hi
gpio-238 (SODIMM pin 65 ) in hi
gpio-239 (KEY_VOLUMEUP ) in hi

GPIOs 256-264, i2c/4-002d, tps6591x, can sleep:
gpio-262 (fixed_reg_en_hdmi ) out lo

Colibri VF50​

root@colibri-vf:~# cat /sys/kernel/debug/gpio 
GPIOs 0-31, platform/40049000.gpio, vf610-gpio:
gpio-4 (ym ) out hi
gpio-8 (pen-detect ) in hi IRQ
gpio-12 (yp ) out hi
gpio-13 (xp ) out hi

GPIOs 32-63, platform/4004a000.gpio, vf610-gpio:
gpio-41 (Wake-Up ) in hi IRQ
gpio-42 (cd ) in lo
gpio-45 (backlight ) out hi

GPIOs 64-95, platform/4004b000.gpio, vf610-gpio:
gpio-83 (usbh_vbus ) out lo
gpio-93 (xm ) out lo

GPIOs 96-127, platform/4004c000.gpio, vf610-gpio:
gpio-102 (id ) in hi IRQ

GPIOs 128-159, platform/4004d000.gpio, vf610-gpio:

Colibri VF61​

root@colibri-vf:~# cat /sys/kernel/debug/gpio 
GPIOs 0-31, platform/40049000.gpio, vf610-gpio:
gpio-8 (AC97 link sdata ) out lo
gpio-9 (AC97 link sync ) out lo
gpio-13 (AC97 link reset ) out hi

GPIOs 32-63, platform/4004a000.gpio, vf610-gpio:
gpio-41 (Wake-Up ) in hi IRQ
gpio-42 (cd ) in lo
gpio-45 (backlight ) out hi

GPIOs 64-95, platform/4004b000.gpio, vf610-gpio:
gpio-83 (usbh_vbus ) out lo

GPIOs 96-127, platform/4004c000.gpio, vf610-gpio:
gpio-102 (id ) in hi IRQ

GPIOs 128-159, platform/4004d000.gpio, vf610-gpio:

Verdin iMX8M Mini​

root@verdin-imx8mm:~# cat /sys/kernel/debug/gpio 
gpiochip0: GPIOs 0-31, parent: platform/30200000.gpio, 30200000.gpio:
gpio-0 (SODIMM_216 )
gpio-1 (SODIMM_19 )
gpio-2 ( )
gpio-3 ( )
gpio-4 ( )
gpio-5 ( |spi_imx ) in hi
gpio-6 ( )
gpio-7 ( )
gpio-8 (SODIMM_220 )
gpio-9 (SODIMM_222 )
gpio-10 ( )
gpio-11 (SODIMM_218 )
gpio-12 (SODIMM_155 |usb_otg1_vbus ) out hi
gpio-13 (SODIMM_157 )
gpio-14 (SODIMM_185 |usb_otg2_vbus ) out hi
gpio-15 (SODIMM_187 )

gpiochip1: GPIOs 32-63, parent: platform/30210000.gpio, 30210000.gpio:
gpio-32 ( )
gpio-33 ( )
gpio-34 ( )
gpio-35 ( )
gpio-36 ( )
gpio-37 ( )
gpio-38 ( )
gpio-39 ( )
gpio-40 ( )
gpio-41 ( )
gpio-42 ( )
gpio-43 ( )
gpio-44 (SODIMM_84 |cd ) in hi IRQ
gpio-45 (SODIMM_78 )
gpio-46 (SODIMM_74 )
gpio-47 (SODIMM_80 )
gpio-48 (SODIMM_82 )
gpio-49 (SODIMM_70 )
gpio-50 (SODIMM_72 )
gpio-52 ( |V3.3_ETH ) out hi

gpiochip2: GPIOs 64-95, parent: platform/30220000.gpio, 30220000.gpio:
gpio-64 (SODIMM_52 )
gpio-65 (SODIMM_54 )
gpio-66 (SODIMM_64 )
gpio-67 (SODIMM_21 |enable ) out hi
gpio-68 (SODIMM_206 )
gpio-69 (SODIMM_76 |V3.3_SD ) out lo
gpio-70 (SODIMM_56 )
gpio-71 (SODIMM_58 )
gpio-72 (SODIMM_60 )
gpio-73 (SODIMM_62 )
gpio-74 ( )
gpio-75 ( )
gpio-76 ( )
gpio-77 ( )
gpio-78 (SODIMM_66 )
gpio-79 (SODIMM_17 |hpd ) in lo IRQ
gpio-80 ( )
gpio-81 ( )
gpio-82 ( )
gpio-83 (SODIMM_244 )
gpio-84 (SODIMM_250 )
gpio-85 (SODIMM_48 )
gpio-86 (SODIMM_44 )
gpio-87 (SODIMM_42 )
gpio-88 (SODIMM_46 )
gpio-89 ( |V3.3_WI-FI ) out hi

gpiochip3: GPIOs 96-127, parent: platform/30230000.gpio, 30230000.gpio:
gpio-96 (SODIMM_102 )
gpio-97 (SODIMM_90 )
gpio-98 (SODIMM_92 )
gpio-99 (SODIMM_94 )
gpio-100 (SODIMM_96 )
gpio-101 (SODIMM_100 )
gpio-102 ( )
gpio-103 ( )
gpio-104 ( )
gpio-105 (SODIMM_174 )
gpio-106 (SODIMM_120 )
gpio-107 (SODIMM_104 )
gpio-108 (SODIMM_106 )
gpio-109 (SODIMM_108 )
gpio-110 (SODIMM_112 )
gpio-111 (SODIMM_114 )
gpio-112 (SODIMM_116 )
gpio-113 ( )
gpio-114 (SODIMM_118 )
gpio-115 ( |SE050_ENABLE ) out hi
gpio-116 (SODIMM_88 )
gpio-117 (SODIMM_149 )
gpio-118 (SODIMM_147 )
gpio-119 (SODIMM_36 )
gpio-120 (SODIMM_32 )
gpio-121 (SODIMM_30 )
gpio-122 (SODIMM_34 )
gpio-123 (SODIMM_38 )
gpio-124 (SODIMM_252 |Wake-Up ) in hi IRQ
gpio-125 (SODIMM_133 )
gpio-126 (SODIMM_135 )
gpio-127 (SODIMM_129 )
gpiochip4: GPIOs 128-159, parent: platform/30240000.gpio, 30240000.gpio:
gpio-128 (SODIMM_131 )
gpio-129 ( |CTRL_SLEEP_MOCI# ) out hi
gpio-130 (SODIMM_91 )
gpio-131 (SODIMM_16 )
gpio-132 (SODIMM_15 )
gpio-133 (SODIMM_208 |reset ) in hi
gpio-134 (SODIMM_137 )
gpio-135 (SODIMM_139 )
gpio-136 (SODIMM_141 )
gpio-137 (SODIMM_143 )
gpio-138 (SODIMM_196 )
gpio-139 (SODIMM_200 )
gpio-140 (SODIMM_198 )
gpio-141 (SODIMM_202 |spi_imx ) out hi
gpio-142 ( )
gpio-143 ( )
gpio-144 (SODIMM_55 )
gpio-145 (SODIMM_53 )
gpio-146 (SODIMM_95 )
gpio-147 (SODIMM_93 )
gpio-148 (SODIMM_14 )
gpio-149 (SODIMM_12 )
gpio-150 ( )
gpio-151 ( )
gpio-152 ( )
gpio-153 ( |spi_imx ) out hi
gpio-154 (SODIMM_210 )
gpio-155 (SODIMM_212 )
gpio-156 (SODIMM_151 )
gpio-157 (SODIMM_153 )
gpiochip6: GPIOs 494-495, parent: spi/spi2.0, spi2.0, can sleep:

gpiochip5: GPIOs 496-511, parent: i2c/3-0021, pcal6416, can sleep:

Verdin iMX8M Plus​

root@verdin-imx8mp-06817296:~# cat /sys/kernel/debug/gpio 
gpiochip0: GPIOs 0-31, parent: platform/30200000.gpio, 30200000.gpio:
gpio-0 ( )

gpiochip1: GPIOs 32-63, parent: platform/30210000.gpio, 30210000.gpio:
gpio-32 ( )
gpio-43 ( |regulator-wifi-en ) out hi
gpio-44 ( |cd ) in hi IRQ ACTIVE LOW
gpio-52 ( |regulator-module-eth) out hi
gpio-61 ( |CTRL_SLEEP_MOCI# ) out hi

gpiochip2: GPIOs 64-95, parent: platform/30220000.gpio, 30220000.gpio:
gpio-64 ( )
gpio-84 ( |hpd ) in lo IRQ

gpiochip3: GPIOs 96-127, parent: platform/30230000.gpio, 30230000.gpio:
gpio-96 ( |Wake-Up ) in hi IRQ ACTIVE LOW
gpio-118 ( |regulator-usdhc2 ) out lo
gpio-124 ( |reset ) in hi ACTIVE LOW

gpiochip4: GPIOs 128-159, parent: platform/30240000.gpio, 30240000.gpio:
gpio-128 ( )
gpio-137 ( |spi_imx ) out hi
gpio-142 ( |scl ) out lo
gpio-143 ( |sda ) in lo
gpio-146 ( |scl ) out lo
gpio-147 ( |sda ) in lo
gpio-148 ( |scl ) out lo
gpio-149 ( |sda ) in lo

gpiochip5: GPIOs 496-511, parent: i2c/3-0021, 3-0021, can sleep:
gpio-500 ( |regulator-eth2phy ) out hi

GPIO Tool​

caution

GPIO Tool is deprecated on Toradex BSPs, it was only available until BSP 2.8, so this section is kept only for reference. Its use for BSP 3.0 is discouraged and will be removed.

The Toradex GPIO tool can be used to read the current pin configuration or to temporally change the pin configuration and GPIO state. It can either be started from the launcher on the desktop or through the command line as follows:

root@colibri_t20:~$ GPIOConfig
Toradex GPIOConfig utility

The GPIO Tool does not support i.MX 8/8X modules. Pin muxing on i.MX8/8X SoC is exclusively handled by the system control unit firmware aka SCFW, only the Linux kernel pin control subsystem can change the pin muxing by parsing the device tree. The GPIO Tool, as a userspace application, is not allowed to do pin muxing, thus it is not possible to update it to support i.MX8/X SoCs.

GPIO Libsoc​

caution

Libsoc is deprecated on Toradex BSPs - this section is kept only for reference. Its use for BSP 3.0 is discouraged and will be removed. For Torizon use the new char device API and LIBGPIOD libraries and tools. See the GPIO Char Device API - libgpiod article for reference.

Libsoc is a C library to interface with common peripherals found in System on Chips (SoC) through generic Linux Kernel interfaces. Libsoc is integrated with Embedded Linux BSP starting from release 2.8b3. The Sysfs GPIO access is file-based and Libsoc userspace library uses the sysfs gpio interface. Please refer to https://github.com/jackmitch/libsoc for more information.

info

When using Libsoc instead of Sysfs GPIO directly the mapping from SoC GPIO representation to Linux GPIO number is abstracted, therefore inside a Toradex Computer on Module family (e.g Apalis, Colibri or Verdin) the GPIO number corresponds to the CoM edge connector (i.e. MXM3 or SODIMM) pin number, making the application more easily portable between modules (e.g. Apalis iMX6 and Apalis T30).

Cross-Compiling Libsoc Examples​

Build and install the OE-core aka Yocto SDK in your host machine. For instructions related to building and installing the SDK, have a look at the Linux SDKs knowledge-base article.

Examples are provided below. To cross-compile:

cd ~/
git clone https://github.com/bhuvanchandra/libsoc-examples.git
cd libsoc-examples
cd io-ctrl
MACHINE=colibri-vf make

For available machines, have a look in Makefile, e.g.:

cat Makefile | grep MACHINE

Copy the binary to the target via ssh and run the example. E.g.:

scp ~/libsoc-examples/io-ctrl/io root@<target-board-ip-address>:/home/root/

Cross-Compiling Libsoc​

If you are using an Embedded Linux BSP aka Linux image prior to 2.8b3 then you have to build Libsoc and deploy to the device.

Please refer to /libsoc/contrib/board-files/ path to get conf file name. E.g.:

cd ~/
git clone https://github.com/jackmitch/libsoc.git
ls libsoc/contrib/board_files/ | grep -i -e apalis -e colibri

For instance, for Apalis iMX6 the board in Libsoc is apalis-imx6. For Colibri iMX7 512MB it is colibri-imx7-512mb and so on.

The example below is provided for Colibri VF61:

$ cd libsoc
$ . /usr/local/oecore-x86_64/environment-setup-armv7at2hf-neon-angstrom-linux-gnueabi
$ echo $CC
arm-angstrom-linux-gnueabi-gcc -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard --sysroot=/usr/local/oecore-x86_64/sysroots/armv7at2hf-neon-angstrom-linux-gnueabi
$ autoreconf -i
$ ./configure --host=arm-angstrom-linux-gnueabi --prefix=/usr/local/oecore-x86_64/sysroots/armv7at2hf-neon-angstrom-linux-gnueabi/ --enable-board=colibri-vf61 --with-board-configs
$ MACHINE=colibri-vf make -j3
$ sudo make install
info

If you are building for Colibri iMX7 then modify MACHINE=colibri-imx7 make -j3.

Deploy the library and conf file to the target via ssh and run the example:

scp /usr/local/oecore-x86_64/sysroots/armv7at2hf-neon-angstrom-linux-gnueabi/usr/lib/libsoc.so.2 root@<target-board-ip-address>:/home/root/usr/libs
scp ./contrib/board_files/colibri-vf.conf root@<target-board-ip-address>:/home/root/etc/libsoc.conf
Send Feedback!