How do you set your GPIO Pins at bootup?

I am exploring ways to set my GPIO pins on boot. I have made a local.rc script setting my pins to their desired state.
Researching the problem I looked at NetBSD and I like their solution.

I could also use u-boot pinmux to set the state. More complicated I could change the dts files.

What is your method?
 
The reason I ask is my options are limited on APU2 GPIO.
Because it is x86 I have no u-boot or dtsi to modify.
My options are a startup script or modify the nctgpio driver.

Here is my boring BananaPi-M1 script rc.local
Code:
#!/bin/sh
echo "Configuring GPIO Pins"
gpioctl -c 38 OUT
gpioctl -c 39 OUT
gpioctl -c 125 OUT
gpioctl -c 126 OUT
gpioctl -c 127 OUT
gpioctl -c 145 OUT
gpioctl -c 146 OUT
gpioctl -c 156 OUT
gpioctl -c 163 OUT
gpioctl -c 164 OUT
gpioctl -c 165 OUT
gpioctl -c 166 OUT
gpioctl -c 167 OUT
gpioctl -c 169 OUT
gpioctl -c 170 OUT
gpioctl -c 171 OUT
gpioctl -c 172 OUT
###
gpioctl 38 1
gpioctl 39 1
gpioctl 125 1
gpioctl 126 1
gpioctl 127 1
gpioctl 145 1
gpioctl 146 1
gpioctl 156 1
gpioctl 163 1
gpioctl 164 1
gpioctl 165 1
gpioctl 166 1
gpioctl 167 1
gpioctl 169 1
gpioctl 170 1
gpioctl 171 1
gpioctl 172 1
 
I think that at the very least it would useful for gpioctl to have an equivalent to sysctl's -f option, maybe -F, to load pin configuration and values from a file.
Also, gpio(4) mentions some hints specific to ar71xx_gpio driver, but some of them could be generalized to all drivers (the bus) and they probably could be extended.
 
Ideally the pin state would be handled in the BIOS on x86.
I feel this way because it seems to me you don't want to expose your sensors to the wrong direction on bootup and OS changed on startup.

Minnowboard uses Intel UEFI Tiano BIOS. It has pin state and even pin muxing settings.

APU1/2/3 uses Coreboot/SeaBIOS and I would think that would be the place to set them.
It is very bare and offers no such settings.There is a place to change GPIO pins to Serial Port 3 and 4.

Setting them in the OS seems like the last resort to me.
I haven't tried to use U-Boot pinmux function yet. I need to investigate it.
It seems a good way to override the boards DTB pin states..
 
I could also use u-boot pinmux to set the state. More complicated I could change the dts files.
Using u-boot sounds reasonable, should be straight forward. I don't set pins, but I do read pins in u-boot to determine which variant of hardware it's running on. The possibility of using device tree depends on hardware. As far as I know it's not possible to set a specific value in e.g. BBB, but you can enable pull-up or pull-down, which can be a work-around in some cases.
 
Back
Top