iMX8X Setting default GPIO value in Device Tree

Greetings,

My team and I have been working on a program which manipulates GPIO pins from userspace. We realize that there may be a more efficient way to take care of the initial values and directions assumed by GPIO pins instead of setting the GPIO pin value and direction every time the program begins to run, and that is, by configuring these pins in the device tree. We came across the Linux kernel documentation describing GPIO device tree bindings, and noticed that a way to do this would be to declare a gpio-hog node under the GPIO controller, e.g.

qe_pio_a: gpio-controller@1400 {
		compatible = "fsl,qe-pario-bank-a", "fsl,qe-pario-bank";
		reg = <0x1400 0x18>;
		gpio-controller;
		#gpio-cells = <2>;

		line_b {
			gpio-hog;
			gpios = <6 0>;
			output-low;
			line-name = "foo-bar-gpio";
		};
	};

We managed to alter the device tree according to the provided example, and indeed, the default GPIO pin value and direction was changed successfully. However, we noticed that the altered pin was marked as ‘used’ when running gpioinfo, resulting in us unable to request said pin from userspace. As delineated in this thread, We quickly began to realize that gpio-hog may not be what we were looking for.

Based on our use case, is there a different way which allows us to customize the default value and direction of GPIO pins in the device tree, and still allow us to interface with the pins from userspace? With consideration to implementation effort, is it simply a better idea to just set the value and direction of these GPIO pins when our program is executed?

Hi @marcel.tx ,
I have same question too, do you have idea how to handle this ?
Or you have any colleague good in device tree ?

Hi @gustavo.tx,
I am similar question at above also, do you have any idea ? Thank you.

By default GPIO pins configured as in input and you need to interact with a GPIO driver to set pin as an output and assign state. It can’t be done by Device Tee except this gpio-hog trick. From other hand you can select a pin pull-up or pull-down at Device Tree pin muxing section. Could it be enough for you case? Then when Linux boots you can set proper pin state by your app. You can also set pin state at U_boot level.

Hi @alex.tx

Thank you, set pin state at U_boot level seems like a good idea

Do you know how to set “active-high” / “active-low” for GPIO in U-Boot ?
The example seems doesn’t provide such command.

Just use gpio set to set pin HIGH and gpio clear to set it LOW

Hi @alex.tx ,

Just tested with these command for UBOOT, and these are the result

gpio set [gpio-number] = set pin to output direction with default value 1 (HIGH)

gpio clear [gpio-number]  = set pin to output direction with default value 0 (LOW)

gpio input [gpio-number] = set pin to input direction

None of them allow to set ACTIVE-HIGH or ACTIVE-LOW,

am I miss anything ? Thank you.

A GPIO line can be set HIGH or LOW. An ACTIVE-HIGH or ACTIVE-LOW are driver property. So when you mark it as ACTIVE-HIGH ‘set’ command make it HIGH. If it’s an ACTIVE-LOW same ‘set’ command will set it LOW. But all of that are done on Linux GPIO driver level.

At U_Boot level you can just set initial state to LOW or HIGH. An “Active-x” property neither exist nor required here.

Hi all,

One of the links provided as suggested solutions doesn’t work.

Can you please provide up-to-date info? I have the same intention and I have IMX8QM. By looking at this page, I wasn’t able to find where do I even use gpio set and gpio clear commands.

Thank you
Samir

Thank you

Hi hajili, the commands you listed are described here. They are to be executed inside u-boot.

1 Like

Hi @HatsyRei ,
Thank you for the info.

I managed to change the values when I am in UBoot, but after rebooting the default values are overwritten. How can I make sure that I change the default values and they remain how I set them?

Best,
Samir

Yes, because they just a commands. YOU should execute it each time after boot. To do this you can create a dedicated U_Boot environment variable with all commands you need and then add run you_variable_name to the boot_cmd . Don’t forget to do saveenv after editing.