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.
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?
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.
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,
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.
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.
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?
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.