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:
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.
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.
已解决! 转到解答。
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
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
Thank you @Chavira for your response.
I made changes as you recommended and the dtc compiler throws errors.
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.
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?
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
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.