You are here: Digi Embedded Yocto > System development > Linux v3.14 Board Support Package > Devices and interfaces > General Purpose Input/Output (GPIO)

General Purpose Input/Output (GPIO)

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 system-on-module:

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:

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:

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

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

Platform driver mapping

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:

Common 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 system-on-module device tree file:

ConnectCore 6 system-on-module 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 system-on-module and ConnectCore 6 SBC device tree files.

GPIOs on the ConnectCore 6 system-on-module

Example: Bluetooth

ConnectCore 6 system-on-module 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 system-on-module 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 0>;
    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.

Note 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. Refer to 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:

GPIOs on the ConnectCore 6 system-on-module

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 system-on-module device tree, the i.MX6 CPU's seven GPIO ports are probed first:

The PMIC is probed second:

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:

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

Note If your platform's device tree defines additional GPIO controllers, the gpiochipN assigned to the i.MX6 and PMIC may be different, depending on the order in which Linux probes the various drivers.

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:
	root@ccimx6sbc:~# cd /sys/class/gpio/
	root@ccimx6sbc:/sys/class/gpio# echo 34 > export
  1. Configure the GPIO as output:
	root@ccimx6sbc:/sys/class/gpio# echo out > gpio34/direction
  1. Turn on the LED by setting the GPIO high:
	root@ccimx6sbc:/sys/class/gpio# echo 1 > gpio34/value
  1. Turn off the LED by setting the GPIO low:
	root@ccimx6sbc:/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 thorugh 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

root@ccimx6sbc:~# gpio_sysfs_test
Usage: gpio-sysfs-test <gpio_in> [gpio_out]
  
Where gpio_in is a pushbutton and gpio_out an optional LED

Note 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.

 

© 2017 Digi International Inc. All rights reserved.
General Purpose Input/Output (GPIO) updated on 24 April 2017 11:48:26 PM