Configure pin as simple GPIO

Hello,
I am using Solidrun Pulse with iMX8M Plus on it. I have built OS based on instructions from this repository. But I can not get any of the GPIO pins working as simple GPIO pin.

As additional explanation - below as attachment you can find two of many patches which I applied just for the testing purposes but they simply not working. After the building I can find that file imx8mp-solidrun.dts in the build directory have been affected by the patches, so there is no doubt that patching gone well but I am still unable toggle the pin, nor to get logical 0 or 1 from it by following these instructions.

So can I get just simple example of the patch which makes any of the mikroBUS pins (preferably UART ones) functional as GPIO input pin?

Thanks.

0011-gpio-example1.patch

diff --git a/arch/arm/dts/imx8mp-solidrun.dts b/arch/arm/dts/imx8mp-solidrun.dts
index 1725cae6..921dabd2 100644
--- a/arch/arm/dts/imx8mp-solidrun.dts
+++ b/arch/arm/dts/imx8mp-solidrun.dts
@@ -586,4 +586,10 @@
 			MX8MP_IOMUXC_GPIO1_IO02__WDOG1_WDOG_B	0xc6
 		>;
 	};
+
+    pinctrl_button: buttongrp {
+            fsl,pins =
+                <MX8MP_IOMUXC_UART3_RXD__GPIO5_IO26	0x00>,
+                <MX8MP_IOMUXC_UART3_RXD__GPIO5_IO26	0x00>;
+    };
 };

0011-gpio-example2.patch

diff --git a/arch/arm/dts/imx8mp-solidrun.dts b/arch/arm/dts/imx8mp-solidrun.dts
index 1725cae6..c1a7aa9d 100644
--- a/arch/arm/dts/imx8mp-solidrun.dts
+++ b/arch/arm/dts/imx8mp-solidrun.dts
@@ -409,6 +409,8 @@
 			MX8MP_IOMUXC_SAI2_RXD0__GPIO4_IO23	0x19
 			MX8MP_IOMUXC_SAI2_TXFS__GPIO4_IO24	0x19
 			MX8MP_IOMUXC_UART4_RXD__GPIO5_IO28	0x19
+            MX8MP_IOMUXC_UART3_RXD__GPIO5_IO26 0x146
+            MX8MP_IOMUXC_UART3_TXD__GPIO5_IO27 0x106
 		>;
 	};

The issue is that you have defined those pins in 2 locations. The pin mux driver will then only assign them to one function. If the group that the pins are assigned to is then owned by another driver the kernel will not allow userspace to control them as they are allocated to a driver.

Hi jnettlet,
thanks for fast response. I haven’t applied both patches in the same time, but beside that - can you send me an example of proper patch how to set MX8MP_IOMUXC_UART3_RXD__GPIO5_IO26 as GPIO controllable from user space.

Thanks.

It would be something like this.

diff --git a/arch/arm64/boot/dts/freescale/imx8mp-hummingboard-pulse.dts b/arch/arm64/boot/dts/freescale/imx8mp-hummingboard-pulse.dts
index 32e43400de96..a928e50c9fc2 100644
--- a/arch/arm64/boot/dts/freescale/imx8mp-hummingboard-pulse.dts
+++ b/arch/arm64/boot/dts/freescale/imx8mp-hummingboard-pulse.dts 
@@ -514,6 +550,7 @@ MX8MP_IOMUXC_HDMI_DDC_SCL__HDMIMIX_HDMI_SCL 0x400001c3
                        MX8MP_IOMUXC_HDMI_DDC_SDA__HDMIMIX_HDMI_SDA     0x400001c3
                        MX8MP_IOMUXC_HDMI_HPD__HDMIMIX_HDMI_HPD         0x40000019
                        MX8MP_IOMUXC_HDMI_CEC__HDMIMIX_HDMI_CEC         0x40000019
+                       MX8MP_IOMUXC_UART3_RXD__GPIO5_IO26              0x19
                >;
        };
 
diff --git a/arch/arm64/boot/dts/freescale/imx8mp-sr-som.dtsi b/arch/arm64/boot/dts/freescale/imx8mp-sr-som.dtsi
index 02aa6e6c3101..882d6ccee931 100644
--- a/arch/arm64/boot/dts/freescale/imx8mp-sr-som.dtsi
+++ b/arch/arm64/boot/dts/freescale/imx8mp-sr-som.dtsi
@@ -516,7 +516,6 @@ pinctrl_uart1: uart1grp {
                fsl,pins = <
                        MX8MP_IOMUXC_UART1_RXD__UART1_DCE_RX    0x140
                        MX8MP_IOMUXC_UART1_TXD__UART1_DCE_TX    0x140
-                       MX8MP_IOMUXC_UART3_RXD__UART1_DCE_CTS   0x140
                        MX8MP_IOMUXC_UART3_TXD__UART1_DCE_RTS   0x140
                >;
        };

And then to expose the pin to sysfs you need to export it with echo 154 > /sys/class/gpio/export as per the instructions on developer.solid-run.com. The gpio can then be controlled in /sys/class/gpio/gpio154

Hmmm, both files are not existing at all.

RROR: u-boot-imx-2021.04-r0 do_patch: Applying '0011-proposal.patch' failed:
stdout: can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/arch/arm64/boot/dts/freescale/imx8mp-hummingboard-pulse.dts b/arch/arm64/boot/dts/freescale/imx8mp-hummingboard-pulse.dts
|index 32e43400de96..a928e50c9fc2 100644
|--- a/arch/arm64/boot/dts/freescale/imx8mp-hummingboard-pulse.dts
|+++ b/arch/arm64/boot/dts/freescale/imx8mp-hummingboard-pulse.dts

I was patching totally different file imx8mp-solidrun.dts.- the one created here. Then later I patch that file.

I can not even find imx8mp-hummingboard-pulse.dts. So where that file coming from - I can not find it the linux-imx repository. Where I can find it ?

P.S.
The most similar one which I can see is linux-imx/arch/arm64/boot/dts/freescale/imx8mq-hummingboard-pulse.dts - but that is imx8mq

those patches are for the linux kernel. The patched kernel should be in your build/tmp/work directory, which should include the device-tree files for the iMX8MP som and hummingboard.

I don’t get where is the imx8mp-hummingboard-pulse.dts. In general - if I want to patch some file it must exist somewhere - in this particular case I want to patch imx8mp-hummingboard-pulse.dts but I can not find it - it is not in the build directory. Or can you tell me where I should put the patch which you proposed?

For example the file which I was patching imx8mp-solidrun.dts is in build/tmp/work/imx8mpsolidrun-poky-linux/u-boot-imx/2021.04-r0/git/arch/arm/dts.

Thanks.

The file does not exist in the meta repository for yocto. We provide a patch series for NXP’s BSP that adds our board support. The device-tree files are created when yocto does the bitbake build for the kernel package. Therefore your will only find the file in your yocto build directory.

I would recommend that you familiarize yourself with the Yocto kernel development process regarding adding your own customization patches. Yocto Project Linux Kernel Development Manual — The Yocto Project ® 4.0.999 documentation