Why I can't export a configured Gpio as output in the device tree ?

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

Why I can't export a configured Gpio as output in the device tree ?

Jump to solution
2,050 Views
LAAZIBI
Contributor II

I am using a iMX93 QS93, In the device tree I configured the gpio as an output line as you can see below

 

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

		power_button_pshold {
			label = "PSHOLD";
			gpios = <&gpio1 9 GPIO_ACTIVE_HIGH>;
			default-state = "off";
		};
	};

 

 And here the Pin Multiplexing configuration: 

 

	pinctrl_gpiopshold: gpiopsholdgrp {
		fsl,pins = <
			MX93_PAD_PDM_BIT_STREAM0__GPIO1_IO09		0x120
		>;
	};

 

The gpio1 9 is not used somewhere else. 

I am building my image using yocto and after the successful build, I run the image in the target and tried to export the gpio by running `echo 9 > /sys/class/gpio/export`. The export fails with the error : 

 

-bash: echo: write error: Device or resource busy

 


The `gpioinfo` shows this line under `gpiochip3 - 32lines:` 

 

        line   9:       unnamed                 output consumer=PSHOLD

 

 The output of `cat /sys/kernel/debug/gpio` shows :

 

gpiochip3: GPIOs 0-31, parent: platform/47400080.gpio, 47400080.gpio:
 gpio-0   (                    |scl                 ) out lo
 gpio-1   (                    |sda                 ) in  lo
 gpio-2   (                    |scl                 ) out lo
 gpio-3   (                    |sda                 ) in  lo
 gpio-9   (                    |PSHOLD              ) out lo

gpiochip0: GPIOs 32-63, parent: platform/43810080.gpio, 43810080.gpio:
 gpio-50  (                    |nPBOUT              ) in  hi IRQ ACTIVE LOW
 gpio-60  (                    |sda                 ) in  lo
 gpio-61  (                    |scl                 ) out lo

gpiochip1: GPIOs 64-95, parent: platform/43820080.gpio, 43820080.gpio:

gpiochip2: GPIOs 96-127, parent: platform/43830080.gpio, 43830080.gpio:

 

I am struggling find what prevent the export of that gpio and being able to set its value, could anyone help me with this issue? 

Labels (2)
Tags (2)
0 Kudos
Reply
1 Solution
2,019 Views
Chavira
NXP TechSupport
NXP TechSupport

Hi @LAAZIBI!

Thank you for contacting NXP Support!

 

To use a gpios under Linux you have to use the gpioset command or configure the gpios under the driver gpio-leds in Linux.

 

To add the gpio-leds driver in Linux you can look the device tree file of the iMX8MP EVK board as a example.

 

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

 

To control the LED in terminal using the gpio-leds driver you should use the next commands:

#Output at HIGH state
echo 1 >> /sys/class/leds/<GPIO LABEL>/brightness

#Output at LOW state
echo 0 >> /sys/class/leds/<GPIO LABEL>/brightness

 

Best Regards!

Chavira

View solution in original post

0 Kudos
Reply
1 Reply
2,020 Views
Chavira
NXP TechSupport
NXP TechSupport

Hi @LAAZIBI!

Thank you for contacting NXP Support!

 

To use a gpios under Linux you have to use the gpioset command or configure the gpios under the driver gpio-leds in Linux.

 

To add the gpio-leds driver in Linux you can look the device tree file of the iMX8MP EVK board as a example.

 

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

 

To control the LED in terminal using the gpio-leds driver you should use the next commands:

#Output at HIGH state
echo 1 >> /sys/class/leds/<GPIO LABEL>/brightness

#Output at LOW state
echo 0 >> /sys/class/leds/<GPIO LABEL>/brightness

 

Best Regards!

Chavira

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-1957617%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EWhy%20I%20can't%20export%20a%20configured%20Gpio%20as%20output%20in%20the%20device%20tree%20%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1957617%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20am%20using%20a%20%3CSTRONG%3EiMX93%20QS93%2C%26nbsp%3B%3C%2FSTRONG%3EIn%20the%20device%20tree%20I%20configured%20the%20gpio%20as%20an%20output%20line%20as%20you%20can%20see%20below%3C%2FP%3E%3CBR%20%2F%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%09gpio_pshold%20%7B%0A%09%09compatible%20%3D%20%22gpio-leds%22%3B%0A%09%09pinctrl-names%20%3D%20%22default%22%3B%0A%09%09pinctrl-0%20%3D%20%26lt%3B%26amp%3Bpinctrl_gpiopshold%26gt%3B%3B%0A%0A%09%09power_button_pshold%20%7B%0A%09%09%09label%20%3D%20%22PSHOLD%22%3B%0A%09%09%09gpios%20%3D%20%26lt%3B%26amp%3Bgpio1%209%20GPIO_ACTIVE_HIGH%26gt%3B%3B%0A%09%09%09default-state%20%3D%20%22off%22%3B%0A%09%09%7D%3B%0A%09%7D%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CBR%20%2F%3E%3CP%3E%26nbsp%3BAnd%20here%20the%20Pin%20Multiplexing%20configuration%3A%26nbsp%3B%3C%2FP%3E%3CBR%20%2F%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%09pinctrl_gpiopshold%3A%20gpiopsholdgrp%20%7B%0A%09%09fsl%2Cpins%20%3D%20%26lt%3B%0A%09%09%09MX93_PAD_PDM_BIT_STREAM0__GPIO1_IO09%09%090x120%0A%09%09%26gt%3B%3B%0A%09%7D%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CBR%20%2F%3E%3CP%3EThe%20gpio1%209%20is%20not%20used%20somewhere%20else.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3EI%20am%20building%20my%20image%20using%20yocto%20and%20after%20the%20successful%20build%2C%20I%20run%20the%20image%20in%20the%20target%20and%20tried%20to%20export%20the%20gpio%20by%20running%20%60echo%209%20%26gt%3B%20%2Fsys%2Fclass%2Fgpio%2Fexport%60.%20The%20export%20fails%20with%20the%20error%20%3A%26nbsp%3B%3C%2FP%3E%3CBR%20%2F%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E-bash%3A%20echo%3A%20write%20error%3A%20Device%20or%20resource%20busy%3C%2FCODE%3E%3C%2FPRE%3E%3CBR%20%2F%3E%3CP%3E%3CBR%20%2F%3EThe%20%60gpioinfo%60%20shows%20this%20line%20under%20%60gpiochip3%20-%2032lines%3A%60%26nbsp%3B%3C%2FP%3E%3CBR%20%2F%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%20%20%20%20%20%20%20%20line%20%20%209%3A%20%20%20%20%20%20%20unnamed%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20output%20consumer%3DPSHOLD%3C%2FCODE%3E%3C%2FPRE%3E%3CBR%20%2F%3E%3CP%3E%26nbsp%3BThe%20output%20of%20%60cat%20%2Fsys%2Fkernel%2Fdebug%2Fgpio%60%20shows%20%3A%3C%2FP%3E%3CBR%20%2F%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Egpiochip3%3A%20GPIOs%200-31%2C%20parent%3A%20platform%2F47400080.gpio%2C%2047400080.gpio%3A%0A%20gpio-0%20%20%20(%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7Cscl%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%20out%20lo%0A%20gpio-1%20%20%20(%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7Csda%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%20in%20%20lo%0A%20gpio-2%20%20%20(%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7Cscl%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%20out%20lo%0A%20gpio-3%20%20%20(%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7Csda%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%20in%20%20lo%0A%20gpio-9%20%20%20(%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7CPSHOLD%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%20out%20lo%0A%0Agpiochip0%3A%20GPIOs%2032-63%2C%20parent%3A%20platform%2F43810080.gpio%2C%2043810080.gpio%3A%0A%20gpio-50%20%20(%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7CnPBOUT%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%20in%20%20hi%20IRQ%20ACTIVE%20LOW%0A%20gpio-60%20%20(%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7Csda%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%20in%20%20lo%0A%20gpio-61%20%20(%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7Cscl%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%20out%20lo%0A%0Agpiochip1%3A%20GPIOs%2064-95%2C%20parent%3A%20platform%2F43820080.gpio%2C%2043820080.gpio%3A%0A%0Agpiochip2%3A%20GPIOs%2096-127%2C%20parent%3A%20platform%2F43830080.gpio%2C%2043830080.gpio%3A%3C%2FCODE%3E%3C%2FPRE%3E%3CBR%20%2F%3E%3CP%3EI%20am%20struggling%20find%20what%20prevent%20the%20export%20of%20that%20gpio%20and%20being%20able%20to%20set%20its%20value%2C%20could%20anyone%20help%20me%20with%20this%20issue%3F%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1957617%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3ELinux%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EYocto%20Project%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1957855%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Why%20I%20can't%20export%20a%20configured%20Gpio%20as%20output%20in%20the%20device%20tree%20%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1957855%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%20%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F240727%22%20target%3D%22_blank%22%3E%40LAAZIBI%3C%2FA%3E!%3C%2FP%3E%0A%3CP%3EThank%20you%20for%20contacting%20NXP%20Support!%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3ETo%20use%20a%20gpios%20under%20Linux%20you%20have%20to%20use%20the%20%3CSTRONG%3Egpioset%3C%2FSTRONG%3E%20command%20or%20configure%20the%20gpios%20under%20the%20driver%20%3CSTRONG%3Egpio-leds%20%3C%2FSTRONG%3Ein%20Linux.%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3ETo%20add%20the%20%3CSTRONG%3Egpio-leds%20driver%20%3C%2FSTRONG%3E%20in%20Linux%20you%20can%20look%20the%20device%20tree%20file%20of%20the%20iMX8MP%20EVK%20board%20as%20a%20example.%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fnxp-imx%2Flinux-imx%2Fblob%2Flf-6.1.y%2Farch%2Farm64%2Fboot%2Fdts%2Ffreescale%2Fimx8mp-evk.dts%23L20%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fnxp-imx%2Flinux-imx%2Fblob%2Flf-6.1.y%2Farch%2Farm64%2Fboot%2Fdts%2Ffreescale%2Fimx8mp-evk.dts%23L20%3C%2FA%3E%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3ETo%20control%20the%20LED%20in%20terminal%20using%20the%20%3CSTRONG%3Egpio-leds%20driver%20%3C%2FSTRONG%3Eyou%20should%20use%20the%20next%20commands%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%23Output%20at%20HIGH%20state%0Aecho%201%20%26gt%3B%26gt%3B%20%2Fsys%2Fclass%2Fleds%2F%3CGPIO%20label%3D%22%22%3E%2Fbrightness%0A%0A%23Output%20at%20LOW%20state%0Aecho%200%20%26gt%3B%26gt%3B%20%2Fsys%2Fclass%2Fleds%2F%3CGPIO%20label%3D%22%22%3E%2Fbrightness%3C%2FGPIO%3E%3C%2FGPIO%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CBR%20%2F%3E%0A%3CP%3EBest%20Regards!%3C%2FP%3E%0A%3CP%3EChavira%3C%2FP%3E%3C%2FLINGO-BODY%3E