The NXP i.MX6 CPU has seven general purpose input/output (GPIO) ports. Each port can generate and control 32 signals.

The Dialog PMIC DA9063 has 16 configurable GPIO pins.

On the ConnectCore 6:

  • Many of the i.MX6 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).

  • Eight PMIC GPIO pins are available (labeled PMIC_GPIOx where x is the GPIO pin).

See Hardware reference manuals for information about GPIO pins and their multiplexed functionality.

On the ConnectCore 6 SBC, GPIOs are used for many purposes, such as:

  • Power enable line for transceivers

  • Reset line for controllers

  • LCD backlight control

  • Interrupt line

  • User LEDs

An expansion connector allows direct access to eight digital i.MX6 GPIOs.

See Hardware reference manuals for information about using GPIO pins on the SBC board.

Kernel configuration

You can manage the GPIO driver support through the kernel configuration options:

  • /sys/class/gpio/…​ (sysfs interface) (CONFIG_GPIO_SYSFS)

  • Dialog Semiconductor DA9063 GPIO (CONFIG_GPIO_DA9063)

These options are enabled as built-in on the ConnectCore 6 SBC kernel configuration file.

Support for i.MX6 GPIOs is automatically provided through the non-visible option CONFIG_GPIO_MXC.

Kernel driver

The i.MX6 GPIO driver is located at drivers/gpio/gpio-mxc.c.

The Dialog DA9063 GPIO driver is located at drivers/gpio/gpio-da9063.c.

Device tree bindings and customization

The i.MX6 GPIO device tree binding is documented at Documentation/devicetree/bindings/gpio/fsl-imx-gpio.txt.

One GPIO controller is defined for each i.MX6 GPIO port in the common i.MX6 device tree file:

i.MX6 device tree
            gpio1: gpio@0209c000 {
                compatible = "fsl,imx6q-gpio", "fsl,imx35-gpio";
                reg = <0x0209c000 0x4000>;
                interrupts = <0 66 IRQ_TYPE_LEVEL_HIGH>,
                         <0 67 IRQ_TYPE_LEVEL_HIGH>;
                gpio-controller;
                #gpio-cells = <2>;
                interrupt-controller;
                #interrupt-cells = <2>;
            };

[...]

            gpio7: gpio@020b4000 {
                compatible = "fsl,imx6q-gpio", "fsl,imx35-gpio";
                reg = <0x020b4000 0x4000>;
                interrupts = <0 78 IRQ_TYPE_LEVEL_HIGH>,
                         <0 79 IRQ_TYPE_LEVEL_HIGH>;
                gpio-controller;
                #gpio-cells = <2>;
                interrupt-controller;
                #interrupt-cells = <2>;
            };

The Dialog DA9063 GPIO device tree binding is documented at Documentation/devicetree/bindings/gpio/gpio-da9063.txt.

The DA9063 PMIC GPIO controller is defined in the ConnectCore 6 device tree file:

ConnectCore 6 device tree
&i2c2 {
    clock-frequency = <100000>;
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_i2c2>;
    status = "okay";
    pmic_dialog: dialog@58 {
        compatible = "dlg,da9063";

        [...]

        gpio_extender: gpio {
            compatible = "dlg,da9063-gpio";
            gpio-controller;
            #gpio-cells = <2>;
        };

        [...]
    };
};

Both i.MX6 and DA9063 PMIC GPIOs are used in the ConnectCore 6 and ConnectCore 6 SBC device tree files.

GPIOs on the ConnectCore 6

Example: Bluetooth

ConnectCore 6 device tree
bluetooth {
    digi,pwrdown-gpios = <&gpio_extender 4 0>;
    /* U-Boot will fill in the MAC address here */
};

This example shows the power down line of the Bluetooth chip is connected on the ConnectCore 6 to the PMIC’s GPIO 4.

ConnectCore 6 SBC device tree
bluetooth {
    digi,disable-gpios = <&gpio1 9 GPIO_ACTIVE_LOW>;
    /* U-Boot will fill in the MAC address here */
};

This example shows the disable line of the Bluetooth chip is connected on the ConnectCore 6 SBC to the i.MX6 GPIO port 1 pin 9.

GPIOs on the ConnectCore 6 SBC

Example: Ethernet PHY

ConnectCore 6 SBC device tree
/* 10/100/1000 KSZ9031 PHY */
&fec {
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_enet>;
    phy-mode = "rgmii";
    phy-reset-gpios = <&gpio1 25 GPIO_ACTIVE_HIGH>;
    phy-reset-duration = <10>;
    phy-reset-wait = <1>;
    phy-supply = <&ldo4>;
    status = "okay";
};

This example shows the ConnectCore 6 SBC’s Ethernet PHY reset line connected to i.MX6 GPIO port 1 pin 25.

Example: external 5V regulator

ConnectCore 6 SBC device tree
5v_reg {
    compatible = "regulator-fixed";
    gpio = <&gpio_extender 7 0>;
    regulator-name = "gpio-ext-reg";
    regulator-boot-on;
    /* Leave enabled for MIPI camera suspend  to work */
    /* regulator-always-on; */
    enable-active-high;
    regulator-min-microvolt = <5000000>;
    regulator-max-microvolt = <5000000>;
};

This example shows the ConnectCore 6 SBC’s external 5V regulator controlled through the PMIC’s GPIO 7 pin.

Example: expansion GPIOs

ConnectCore 6 SBC device tree
hog {
    pinctrl_hog: hog {
        fsl,pins = <
            ...
            /* EXP_GPIO_0 */
            MX6QDL_PAD_NANDF_D5__GPIO2_IO05 0x80000000
            /* EXP_GPIO_1 */
            MX6QDL_PAD_NANDF_D6__GPIO2_IO06 0x80000000
            /* EXP_GPIO_2 */
            MX6QDL_PAD_NANDF_D7__GPIO2_IO07 0x80000000
            /* EXP_GPIO_3 */
            MX6QDL_PAD_EIM_CS1__GPIO2_IO24 0x80000000
            /* EXP_GPIO_4 */
            MX6QDL_PAD_EIM_EB0__GPIO2_IO28 0x80000000
            /* EXP_GPIO_5 */
            MX6QDL_PAD_EIM_EB1__GPIO2_IO29 0x80000000
            /* EXP_GPIO_6 */
            MX6QDL_PAD_GPIO_18__GPIO7_IO13 0x80000000
            /* EXP_GPIO_7 */
            MX6QDL_PAD_GPIO_19__GPIO4_IO05 0x80000000
        };
   };
};

This example shows the IOMUX selection (as GPIO function) of several i.MX6 GPIOs that on the ConnectCore 6 SBC GPIOs are routed to an expansion connector.

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). For example, to enable the SION bit for EXP_GPIO_0, use the following in the device tree (note that 0x80000000 | (1 << 30) = 0xC0000000 ):

ConnectCore 6 SBC device tree
hog {
    pinctrl_hog: hog {
        fsl,pins = <
            ...
            /* EXP_GPIO_0 */
            MX6QDL_PAD_NANDF_D5__GPIO2_IO05 0xC0000000
        };
   };
};

For more information, see the NXP Application Note AN5078.

GPIO usage from user space

The GPIOs can be accessed from the sysfs. See the Linux kernel documentation at Documentation/gpio/sysfs.txt.

Calculating 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 6

Every GPIO port of the i.MX6 CPU is a different GPIO controller and thus has its own /sys/class/gpio/gpiochipN entry on the sysfs. The Dialog DA9063 PMIC chip also contains a GPIO controller and has its own gpiochipN entry.

On the default ConnectCore 6 device tree, the i.MX6 CPU’s seven 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

  • PORT6: /sys/class/gpio/gpiochip160

  • PORT7: /sys/class/gpio/gpiochip192

The PMIC is probed second:

  • PMIC: /sys/class/gpio/gpiochip240

The Linux GPIO number for a certain GPIO pin can be determined by adding the GPIO pin index to the port base index. For instance:

  • i.MX6 GPIO2_4 (port 2, pin 4) is: 32 + 4 = 36

  • PMIC GPIO3 is: 240 + 3 = 243

Since the i.MX6 CPU has seven ports, all of which have 32 pins, the following formula also applies for i.MX6 CPU GPIOs (without requiring the user to know the GPIO base of each port):

LinuxGPIO_num = (<imx6_gpio_port> - 1) * 32 + <imx6_gpio_pin>

For example, i.MX6 GPIO2_4 (port 2, pin 4) translates to: (2 - 1) * 32 + 4 = 36

Example write from sysfs

The ConnectCore 6 SBC contains three LEDs (GPIOs 34, 35, 36). To turn the LED connected to GPIO 34 on and off:

  1. Request the GPIO:

    ~# cd /sys/class/gpio/
    ~# /sys/class/gpio# echo 34 > export
  1. Configure the GPIO as output:

  ~# /sys/class/gpio# echo out > gpio34/direction
  1. Turn on the LED by setting the GPIO high:

  ~# /sys/class/gpio# echo 1 > gpio34/value
  1. Turn off the LED by setting the GPIO low:

  ~# /sys/class/gpio# echo 0 > gpio34/value

Example application for sysfs access

Digi Embedded Yocto provides the example application gpio_sysfs_test for accessing the GPIOs via sysfs through the package dey-examples-gpio-sysfs.

The gpio_sysfs_test application configures an input pin (preferably a push button) and output pin (preferably an LED) and 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
The ConnectCore 6 SBC does not have a push button connected to a GPIO. To run this test application on the ConnectCore 6 SBC you can use any of the GPIOs available at the GPIO expansion connector as input, and any of the user LEDs on the board as output.