How can I control a iMX8MPEVK's gpio pin?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How can I control a iMX8MPEVK's gpio pin?

Jump to solution
1,178 Views
bgaurav1718
Contributor III

I am trying to control pin 40 of J21 header in the board. I went through schematics and reference manual and found its connection to GPIO3_20 pin in the processor. So, I proceeded to add following entries to the gpio-leds section in device tree: 

        rgb {
            label = "rgb:status";
            gpios = <0x97 0x14 0x00>;
            default-state = "on";
        };

 My dts file looks like this:

bgaurav1718_0-1722329218972.png

Why gpios = <0x97 0x14 0x00> ?

0x97 is the phandle to gpio controller I am trying to access. GPIO3 is located in 30220000 as per the reference manual. 

bgaurav1718_1-1722329702231.png

0x14 (hex) = 20 (dec).

0x00 = Active high. 

I compiled  this dts file to dtb, uploaded it into boot partition and booted the device. I can see the entry /sys/class/leds/rgb:status . At this moment, the voltage at pin 40 reads 0.2V. Even after echo 1 > brightness or echo 0 > brightness, the voltage level at pin 40 does not seem to change. 
What am I doing wrong exactly? I am really confused at this point and any guide would be of great help.

Tags (1)
0 Kudos
Reply
1 Solution
1,079 Views
Chavira
NXP TechSupport
NXP TechSupport

Hi @bgaurav1718!

 

Sorry for my mistake!

Cheking detailed the problem was that pin is used in the node micfil.

To use as a gpio the pin 40 you have to disable the micfil functions in the line 860.

 

https://github.com/nxp-imx/linux-imx/blob/lf-6.1.y/arch/arm64/boot/dts/freescale/imx8mp-evk.dts#L860

change the line:

status = "okay";

 

to :

status = "disabled";

 

and then you should able to use the gpio pin.

 

Best Regards!

Chavira

View solution in original post

7 Replies
1,142 Views
bgaurav1718
Contributor III

Original dts file

0 Kudos
Reply
1,156 Views
Chavira
NXP TechSupport
NXP TechSupport

Hi @bgaurav1718!

Thank you for contacting NXP Support!

 

To add the pin 40 as a GPIO you should declare as the next:

 

 

gpio-leds {
		compatible = "gpio-leds";
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_gpio_led>;

		status {
			label = "yellow:status";
			gpios = <&gpio3 16 GPIO_ACTIVE_HIGH>;
			default-state = "on";
		};
                
                rgb {
                        label = "rgb:status"
                        gpios =  <&gpio3 20 GPIO_ACTIVE_HIGH>;
                        default-state = "on";
                }
	};

 

 

and under pinctrl_gpio_led node you have to add the proper configuration for the pin.

 

	pinctrl_gpio_led: gpioledgrp {
		fsl,pins = <
			MX8MP_IOMUXC_NAND_READY_B__GPIO3_IO16	0x140
                        MX8MP_IOMUXC_SAI5_RXC__GPIO3_IO20       0x140
		>;
	};

 

 

Best Regards!

Chavira

1,145 Views
bgaurav1718
Contributor III

Thank you @Chavira  for your response.

I made changes as you recommended and the dtc compiler throws errors.

gpios = <&gpio3 16 GPIO_ACTIVE_HIGH>;
    Error: syntax error
    FATAL ERROR: Unable to parse input tree
gpios =  <&gpio3 20 GPIO_ACTIVE_HIGH>;
    Error: syntax error
    FATAL ERROR: Unable to parse input tree
 
With regard to pin configuration,  I didn't find the node pinctrl_gpio_led. 
It is defined as
pinctrl_gpio_led = "/soc@0/bus@30000000/pinctrl@30330000/gpioledgrp";
inside __symbols__ {}
 
However, I can find the gpioledgrp node, so I guessed this to be the node you were referring to in order to add pin configuration. In original dts file, it is defined as 
                gpioledgrp {
                    fsl,pins = <0x120 0x380 0x00 0x05 0x00 0x140>;
                    phandle = <0x96>;
                };

I added the pin configuration and now looks like this:

                gpioledgrp {
                    fsl,pins = <MX8MP_IOMUXC_NAND_READY_B__GPIO3_IO16 0x140                                                          MX8MP_IOMUXC_SAI5_RXC__GPIO3_IO20 0x140>;
                    phandle = <0x96>;
                };

Error: syntax error
FATAL ERROR: Unable to parse input tree

I have added the dts file, which is decompiled from original dtb file (Command: dtc -I dtb -O dts -f imx8mp-evk.dtb -o imx8mp-evk.dts), in my original post.

I suspect something to be wrong with my dts file. I am not sure though. 

0 Kudos
Reply
1,116 Views
Chavira
NXP TechSupport
NXP TechSupport

Hi @bgaurav1718!

 

I compiled the dtb by my side without errors.

 

I attached the patch.

 

Best Regards!

Chavira

1,091 Views
bgaurav1718
Contributor III

Thank you @Chavira for the patch. 

I figured out the values for erroneous macros from kernel source and I got the control in user space for the specified pin. 

Adding the pin configuration details in pinctrl_gpio_led node did the trick. 

 

However,  when I remove sub-nodes from inside gpio-leds node,  I can turn on/off the yellow:status led from libgpiod cli tool. But, doing same doesn't make any difference in case of header pin 40. I still have configuration details in pinctrl_gpio_led node.  Any suggestion where I need to look for errors?

0 Kudos
Reply
1,080 Views
Chavira
NXP TechSupport
NXP TechSupport

Hi @bgaurav1718!

 

Sorry for my mistake!

Cheking detailed the problem was that pin is used in the node micfil.

To use as a gpio the pin 40 you have to disable the micfil functions in the line 860.

 

https://github.com/nxp-imx/linux-imx/blob/lf-6.1.y/arch/arm64/boot/dts/freescale/imx8mp-evk.dts#L860

change the line:

status = "okay";

 

to :

status = "disabled";

 

and then you should able to use the gpio pin.

 

Best Regards!

Chavira

1,056 Views
bgaurav1718
Contributor III

This works perfectly. Once again thank you so much @Chavira 

Can you please tell me how you figured out the pin was being used in the micfil node? I am sure there are other pins that have similar configuration. I would like to be able to figure it out myself rather than asking for help every time.  

0 Kudos
Reply