The NXP i.MX6UL CPU has five GPIO ports. Each port can generate and control 32 signals.
The MCA also features a number of GPIO pins (multiplexed with Analog-to-Digital Converter (ADC) functionality). See MCA General Purpose Input/Output (GPIO) for additional information on MCA GPIOs.
GPIOs on the ConnectCore 6UL platforms
-
On the ConnectCore 6UL system-on-module:
-
Many of the i.MX6UL GPIOs are available at the system-on-module, multiplexed with other functions (labeled GPIOxIOy where _x is the port and y is the GPIO pin). See Hardware reference manuals for information about GPIO pins and their multiplexed functionality.
-
Eight MCA GPIO pins are available (labeled MCA_IOx where x is the GPIO pin).
-
-
On the ConnectCore 6UL SBC Express, the expansion connector allows direct access to several i.MX6UL GPIOs and MCA GPIOs.
-
On the ConnectCore 6UL SBC Pro board, an I/O Expander chip features up to 39 GPIO pins (multiplexed with Analog-to-Digital Converter (ADC) functionality). See I/O Expander GPIO for additional information on I/O Expander GPIOs. The GPIO connector allows direct access to several i.MX6UL GPIOs, MCA GPIOs, and I/O Expander GPIOs.
GPIOs on the SOM and carrier board are used for many purposes, such as:
-
Power enable line for transceivers
-
Reset line for controllers
-
LCD backlight control
-
Interrupt line
-
User LED
-
User button
Kernel configuration
You can manage the user space interface with GPIOs through the kernel configuration option:
-
/sys/class/gpio/… (sysfs interface) (CONFIG_GPIO_SYSFS)
This option is enabled as built-in on the default ConnectCore 6UL kernel configuration file.
Support for i.MX6UL GPIOs is automatically provided through the non-visible option CONFIG_GPIO_MXC.
Kernel driver
The driver for the i.MX6UL GPIO is located at:
File | Description |
---|---|
i.MX6UL GPIO driver |
Device tree bindings and customization
The i.MX6UL GPIO device tree binding is documented at Documentation/devicetree/bindings/gpio/fsl-imx-gpio.txt.
One GPIO controller is defined for each i.MX6UL GPIO port in the common i.MX6UL device tree file:
gpio1: gpio@0209c000 {
compatible = "fsl,imx6ul-gpio", "fsl,imx35-gpio";
reg = <0x0209c000 0x4000>;
interrupts = <GIC_SPI 66 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 67 IRQ_TYPE_LEVEL_HIGH>;
gpio-controller;
#gpio-cells = <2>;
interrupt-controller;
#interrupt-cells = <2>;
gpio-ranges = <&iomuxc 0 23 10>, <&iomuxc 10 17 6>,
<&iomuxc 16 33 16>;
};
[...]
gpio5: gpio@020ac000 {
compatible = "fsl,imx6ul-gpio", "fsl,imx35-gpio";
reg = <0x020ac000 0x4000>;
interrupts = <GIC_SPI 74 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 75 IRQ_TYPE_LEVEL_HIGH>;
gpio-controller;
#gpio-cells = <2>;
interrupt-controller;
#interrupt-cells = <2>;
gpio-ranges = <&iomuxc 0 7 10>, <&iomuxc 10 5 2>;
};
The ConnectCore 6UL device tree include file and the carrier board device tree files use the i.MX6UL GPIOs.
For example, on the ConnectCore 6UL, GPIO5_IO04 is used as interrupt line from the MCA, and GPIO4_IO14 is used to activate internal circuitry during the MCA firmware update:
mca_cc6ul: mca@7e {
compatible = "digi,mca_cc6ul_dt_ids";
reg = <0x7e>;
interrupt-parent = <&gpio5>;
interrupts = <4 IRQ_TYPE_EDGE_FALLING>;
interrupt-controller;
#interrupt-cells = <2>;
fw-update-gpio = <&gpio4 14 GPIO_ACTIVE_LOW>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_mca_cc6ul>;
[...]
};
On the ConnectCore 6UL SBC Pro, GPIO5_IO06 is used to reset the PHY of ENET2 Ethernet interface:
&fec2 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_enet2 &pinctrl_enet2_mdio>;
phy-mode = "rmii";
phy-handle = <ðphy1>;
phy-reset-gpios = <&gpio5 6 GPIO_ACTIVE_LOW>;
phy-reset-duration = <26>;
digi,phy-reset-in-suspend;
[...]
};
IOMUX configuration
Pads that are to be used as GPIOs must be configured as such. See Pin multiplexing (IOMUX).
When GPIOs are managed by other drivers, pinctrl-0 configures a set of pads to work according to the specified interface functionalities. In the example below, pinctrl_usdhc2 sets the first six pins for CMD, CLK, and DATA0-DATA3, and also configures GPIO5_IO01 as a GPIO to toggle the hardware multiplexer that selects between the eMMC and microSD card:
pinctrl_usdhc2: usdhc2grp {
fsl,pins = <
MX6UL_PAD_CSI_HSYNC__USDHC2_CMD 0x17059
MX6UL_PAD_CSI_VSYNC__USDHC2_CLK 0x10039
MX6UL_PAD_CSI_DATA00__USDHC2_DATA0 0x17059
MX6UL_PAD_CSI_DATA01__USDHC2_DATA1 0x17059
MX6UL_PAD_CSI_DATA02__USDHC2_DATA2 0x17059
MX6UL_PAD_CSI_DATA03__USDHC2_DATA3 0x17059
/* Mux selector between eMMC/SD# */
MX6UL_PAD_SNVS_TAMPER1__GPIO5_IO01 0x79
>;
};
For GPIOs that are not associated with any interface or that can’t be handled by a driver, you can define the IOMUX in the pinctrl_hog node of the device tree IOMUX section. For example, GPIO3_IO04 is available at the expansion connector of the ConnectCore 6UL SBC Express:
&iomuxc {
pinctrl-names = "default";
imx6ul-ccimx6ul {
[...]
pinctrl_hog: hoggrp {
fsl,pins = <
/* GPIO3_IO04 on Expansion connector */
MX6UL_PAD_LCD_RESET__GPIO3_IO04 0xf030
>;
};
};
};
SION bit
It is not possible to read the real signal level of a GPIO pin that is configured as an output. You can use the software input on (SION) bit to read the value of an output GPIO.
SION bit mode increases the power consumption of the module, so it is disabled by default. |
To enable the SION bit, set the bit 30 (special value). In other words, do an OR mask of your previous value with 0x40000000:
&iomuxc {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_hog>;
pinctrl_hog: hoggrp {
fsl,pins = <
/* GPIO3_IO04 on Expansion connector (SION enabled)*/
MX6UL_PAD_LCD_RESET__GPIO3_IO04 0x4000f030
>;
};
[...]
};
For more information, see the NXP Application Note AN5078.
GPIO usage from user space
You can access the GPIOs from the sysfs. See the Linux kernel documentation at Documentation/gpio/sysfs.txt.
Calculate the Linux GPIO number of a GPIO pin
For each GPIO controller entry on the device tree, Linux creates an entry /sys/class/gpio/gpiochipN, where N is an integer number starting at 0, with the following read-only attributes:
-
base: same as N, the first GPIO managed by this chip
-
label: provided for diagnostics (not always unique)
-
ngpio: the number of GPIOs this controller manages (from N to N + ngpio - 1)
GPIOs on the ConnectCore 6UL system-on-module
Every GPIO port of the i.MX6UL CPU is a different GPIO controller and thus has its own /sys/class/gpio/gpiochipN entry on the sysfs.
On the default ConnectCore 6UL system-on-module device tree, the i.MX6UL CPU’s GPIO ports are probed first:
-
PORT1: /sys/class/gpio/gpiochip0
-
PORT2: /sys/class/gpio/gpiochip32
-
PORT3: /sys/class/gpio/gpiochip64
-
PORT4: /sys/class/gpio/gpiochip96
-
PORT5: /sys/class/gpio/gpiochip128
Calculate the Linux GPIO number for a certain GPIO pin by adding the GPIO pin index to the port base index. For instance:
i.MX6UL GPIO2_IO4 (port 2, pin 4) is: 32 + 4 = 36
Since the i.MX6UL CPU has five ports, all of which have 32 pins, the following formula also applies to i.MX6UL CPU GPIOs (without requiring the user to know the GPIO base of each port):
LinuxGPIO_num = (<imx6ul_gpio_port> - 1) * 32 + <imx6ul_gpio_pin>
For example, i.MX6UL GPIO2_IO4 (port 2, pin 4) translates to: (2 - 1) * 32 + 4 = 36
Example: write from sysfs
The ConnectCore 6UL SBC Express has GPIO3_IO04 on the expansion connector. To drive this as an ouput:
-
Calculate the Linux GPIO number:
GPIO3_IO04: (3 -1) * 32 + 4 = 68
-
Request the GPIO:
~# echo 68 > /sys/class/gpio/export
-
Configure the GPIO as output:
~# echo out > /sys/class/gpio/gpio68/direction
-
Drive the GPIO high:
~# echo 1 > /sys/class/gpio/gpio68/value
-
Drive the GPIO low:
~# echo 0 > /sys/class/gpio/gpio68/value
-
When you are done using the GPIO, free it with:
~# echo 68 > /sys/class/gpio/unexport
Example application for sysfs access
Digi Embedded Yocto provides the example application gpio_sysfs_test through the package dey-examples-gpio-sysfs.
The gpio_sysfs_test application shows accessing the GPIOs via sysfs:
-
Configures an input pin (preferably a push button).
-
Configures an output pin (preferably an LED).
-
Toggles the output on each press of the push button.
-
It also configures the input as interrupt to toggle the output on interrupt events.
Syntax
~# gpio_sysfs_test Usage: gpio-sysfs-test <gpio_in> [gpio_out] Where gpio_in is a pushbutton and gpio_out an optional LED
On the ConnectCore 6UL SBC Express:
-
User button is GPIO3_IO03
-
User LED is GPIO3_IO11
On the ConnectCore 6UL SBC Pro:
-
There is no user button connected to a GPIO. You can use any of the GPIOs available at the expansion connector as input and drive it low/high manually.
-
User LED is I/O Expander IO23. See I/O Expander for additional information on I/O Expander GPIOs.