iMX8X Setting default GPIO value in Device Tree


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-cells = <2>;

		line_b {
			gpios = <6 0>;
			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.