DESK-MX8M-L/Peripherals/GPIOs

From DAVE Developer's Wiki
Jump to: navigation, search
History
Issue Date Notes

2022/01/14

First DESK-MX8M-L release

2023/02/24

DESK-MX8M-L-2.0.0 release
2023/08/22 DESK-MX8M-L-4.0.0 release


Peripheral GPIOs[edit | edit source]

i.MX8 can handle external pins in many different ways and most of them can be configured as GPIOs. When a pin is set as a GPIO, it is possible to read its value, change its direction or change output value directly from the shell.

Device tree configuration[edit | edit source]

ORCA SOM[edit | edit source]

Here below a simple example of device tree configuration for using a GPIO on DAVE's kit for the ORCA SOM with gpio-leds sysfs interface:

From imx8mp-mito8mplus-cb1001.dts:

	leds {
		compatible = "gpio-leds";

		ptn36043_gpio {
			/* this gpio set the USB-C crossbar switch direction.
			 * As the connected peripheral would always be the power source of
			 * the system, hotplug is not possible.
			 * It's status is configured by the bootloader according to the CC
			 * direction and has only to be preserved during the execution.
			 * see usb_dwc3_0 for more details */
			gpios = <&gpio1 12 GPIO_ACTIVE_HIGH>;
			default-state = "keep";
		};
	};
...
...
&iomuxc {
...
...
	pinctrl_gpio_led: gpioledgrp {
		fsl,pins = <
			MX8MP_IOMUXC_NAND_READY_B__GPIO3_IO16	0x19
		>;
	};
...
...
};

Accessing the peripheral in ORCA SOM[edit | edit source]

Linux messages at boot time[edit | edit source]

With the previous leds configuration for the GPIOs, it is possible to find them on sysfs under /sys/class/leds sub-directory:

root@desk-mx8mp:~# ls -la /sys/class/leds/
total 0
drwxr-xr-x  2 root root 0 Jul 26 05:52 .
drwxr-xr-x 87 root root 0 Jul 26 05:52 ..
lrwxrwxrwx  1 root root 0 Jul 26 05:52 mmc0:: -> ../../devices/platform/soc@0/30800000.bus/30b40000.mmc/leds/mmc0::
lrwxrwxrwx  1 root root 0 Jul 26 05:52 mmc1:: -> ../../devices/platform/soc@0/30800000.bus/30b50000.mmc/leds/mmc1::
lrwxrwxrwx  1 root root 0 Jul 26 05:52 mmc2:: -> ../../devices/platform/soc@0/30800000.bus/30b60000.mmc/leds/mmc2::
lrwxrwxrwx  1 root root 0 Jul 26 05:52 ptn36043_gpio -> ../../devices/platform/leds/leds/ptn36043_gpio
root@desk-mx8mp:~#

Usage as led function[edit | edit source]

Setting the brightness node, it is possible to change the GPIO status:

  • read actual led/GPIO status
root@desk-mx8mp:~# cat /sys/class/leds/ptn36043_gpio/brightness 
1
root@desk-mx8mp:~#
  • change led/GPIO status to Low (0)
root@desk-mx8mp:~# echo 0 > /sys/class/leds/ptn36043_gpio/brightness                                                                                                                                                                          
root@desk-mx8mp:~# [ 7970.890896] usb 2-1: USB disconnect, device number 2
  • change led/GPIO status to High (1)
root@desk-mx8mp:~# echo 1 > /sys/class/leds/ptn36043_gpio/brightness                                                                                                                                                                          
root@desk-mx8mp:~# [ 7978.902356] usb 2-1: new SuperSpeed USB device number 5 using xhci-hcd
[ 7979.060143] hub 2-1:1.0: USB hub found
[ 7979.064524] hub 2-1:1.0: 4 ports detected
root@desk-mx8mp:~#

Usage with sysfs[edit | edit source]

It is possible to configure the GPIO pin directly at Linux userspace using sysfs even if it is discouraged: see below .

See here below, an example of configuring a GPIO pin using J8 connector:

  • set J8.11 SAI2_RXD0 (MX8MP_IOMUXC_SAI2_RXD0__GPIO4_IO23) as output GPIO
    • GPIO4_IO23 => (n-1)*32 + IO = (4-1)*32+23 = 119
  • export the GPIO
root@desk-mx8mp:~# echo 119 > /sys/class/gpio/export

Using the GPIO as output

root@desk-mx8mp:~# echo out > /sys/class/gpio/gpio119/direction
  • set the GPIO level
root@desk-mx8mp:~# echo 1 > /sys/class/gpio/gpio119/value
root@desk-mx8mp:~# cat /sys/class/gpio/gpio119/value                                                                                                                                                                                          
1
root@desk-mx8mp:~# echo 0 > /sys/class/gpio/gpio119/value                                                                                                                                                                                     
root@desk-mx8mp:~# cat /sys/class/gpio/gpio119/value 
0
root@desk-mx8mp:~#

For using the GPIO as input:

root@desk-mx8mp:~# echo in > /sys/class/gpio/gpio119/direction
  • read the GPIO level
root@desk-mx8mp:~# cat /sys/class/gpio/gpio119/value
0
root@desk-mx8mp:~#

Note that on i.MX SoC the GPIO value can be read back only if the SION bit is set the pin muxing.

Additional information[edit | edit source]

Information about GPIOs usage under sysfs directory https://www.kernel.org/doc/Documentation/gpio/sysfs.txt

GPIO sysfs deprecated[edit | edit source]

Warning-icon.png sysfs GPIO ABI has been deprecated. See more information here about it. A character device access has to be used, more information here Warning-icon.png

Information about GPIOs library libgpiod - C library and tools - can be found on git.kernel.org