Search by Tags

Device Tree Customization Examples

 
Applicable for

Article updated at 21 Jan 2020
Compare with Revision

Subscribe for this article updates

Introduction

This article is a collection of examples of Device Tree customization. Examples may get obsolete over time, please check the testing environment details.

General Purpose Input / Output (GPIO)

Changing pinmux of a default function to GPIO

Tested on Embedded Linux BSP 3.0b3 (toradex_4.14-2.0.x-imx) / Apalis iMX8QP / Apalis Evaluation Board

In this documentation, we will change a default unneeded function from its original definition to GPIO.

Basically, the steps are:

  1. Locate former function definition and disable or delete it.
  2. Define a new pinctrl with our GPIO pinmux definitions of the selected pins.
  3. Add the pinctrl to the iomux group.

In this particular example, we will be changing the SPI0 pins to a sysfs accessed GPIO.

diff --git a/arch/arm64/boot/dts/freescale/fsl-imx8qxp-apalis-eval.dtsi b/arch/arm64/boot/dts/freescale/fsl-imx8qxp-apalis-eval.dtsi
index c957472c3652..12652f69f5ff 100644
--- a/arch/arm64/boot/dts/freescale/fsl-imx8qxp-apalis-eval.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-imx8qxp-apalis-eval.dtsi
@@ -199,7 +199,7 @@

 /* Apalis SPI1 */
 &lpspi0 {
-   status = "okay";
+   status = "disabled";

    spidev0: spi@0 {
        compatible = "toradex,evalspi";
diff --git a/arch/arm64/boot/dts/freescale/fsl-imx8qxp-apalis.dtsi b/arch/arm64/boot/dts/freescale/fsl-imx8qxp-apalis.dtsi
index 56012aab1cf3..a0292e37af14 100644
--- a/arch/arm64/boot/dts/freescale/fsl-imx8qxp-apalis.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-imx8qxp-apalis.dtsi
@@ -317,7 +317,7 @@
            <&pinctrl_gpio8>, <&pinctrl_qspi0a_gpios>,
            <&pinctrl_sata1_act>, <&pinctrl_reset_moci>,
            <&pinctrl_mmc1_gpios>, <&pinctrl_dap1_gpios>,
-           <&pinctrl_parallel_csi>;
+           <&pinctrl_parallel_csi>, <&pinctrl_gpiospi0>;

    apalis-imx8qxp {
        /* Apalis AN1_ADC */
@@ -613,6 +613,17 @@
            >;
        };

+       /* Apalis SPI1 pins changed to GPIO*/
+       pinctrl_gpiospi0: lpspi0gpiogrp {
+           fsl,pins = <
+               SC_P_SPI0_CS0_LSIO_GPIO1_IO08           0x21    /* MXM3 227 */
+               SC_P_SPI0_SDI_LSIO_GPIO1_IO05           0x21    /* MXM3 223 */
+               SC_P_SPI0_SDO_LSIO_GPIO1_IO06           0x21    /* MXM3 225 */
+               SC_P_SPI0_SCK_LSIO_GPIO1_IO04           0x21    /* MXM3 221 */
+           >;
+       };
+
+
        /* Apalis SPI2 */
        pinctrl_lpspi2: lpspi2grp {
            fsl,pins = <

Note: Pinmux definition are under include/dt-bindings/pinctrl/pads-imx8qpx.h Note: Remember to check the following article to understand the equivalence between physical pins and Linux GPIO: GPIO Alphanumeric to GPIO Numeric Assignment

SION Bit - i.MX family

Tested on Embedded Linux BSP 2.8 / Colibri iMX7 / Colibri Evaluation Board

Remarks: you must check if the SION Bit is available for both the i.MX family you target (i.MX 6, i.MX7, etc,) as well as the specific pin you want to use (SoC pin exposed in the edge connector).

arch/arm/boot/dts/imx7-colibri.dtsi
diff --git a/arch/arm/boot/dts/imx7-colibri.dtsi b/arch/arm/boot/dts/imx7-colibri.dtsi
index 4a1ef3f83faf..d2449ec2cb22 100644
--- a/arch/arm/boot/dts/imx7-colibri.dtsi
+++ b/arch/arm/boot/dts/imx7-colibri.dtsi
@@ -365,7 +365,7 @@
 
        pinctrl_gpio1: gpio1-grp {
                fsl,pins = <
-                       MX7D_PAD_SAI1_RX_SYNC__GPIO6_IO16       0x14 /* SODIMM 77 */
+                       MX7D_PAD_SAI1_RX_SYNC__GPIO6_IO16       ((1 << 30) | 0x14) /* SODIMM 77 */
                        MX7D_PAD_EPDC_DATA09__GPIO2_IO9         0x14 /* SODIMM 89 */
                        MX7D_PAD_EPDC_DATA08__GPIO2_IO8         0x74 /* SODIMM 91 */
                        MX7D_PAD_LCD_RESET__GPIO3_IO4           0x14 /* SODIMM 93 */

Inertial Measurement Unit (IMU)

InvenSense MPU-6050

Tested on Embedded Linux BSP 2.8 / Colibri iMX6ULL / Iris Carrier Board

Remarks: address 68 cannot be used since it is also used by the Iris RTC. The pin AD0 of MPU-6050 has to be driven high.

arch/arm/boot/dts/imx6ull-colibri-eval-v3.dtsi
diff --git a/arch/arm/boot/dts/imx6ull-colibri-eval-v3.dtsi b/arch/arm/boot/dts/imx6ull-colibri-eval-v3.dtsi
index 5870638c3a6f..c2eb33edae6b 100644
--- a/arch/arm/boot/dts/imx6ull-colibri-eval-v3.dtsi
+++ b/arch/arm/boot/dts/imx6ull-colibri-eval-v3.dtsi
@@ -166,6 +166,12 @@
 		compatible = "st,m41t0";
 		reg = <0x68>;
 	};
+
+	mpu6050@69 {
+		compatible = "invensense,mpu6050";
+		reg = <0x69>;
+		status = "okay";
+	};
 };
 
 &lcdif {