Set GPIO direction in Device Tree

Hi, I configured the device tree to use the UART_A_DCD pin as GPIO. Now I can export it, set the direction and use it. I would like to set the direction as OUTPUT and initial value to HIGH, directly in the device tree. I cannot wait to start Linux to bring the signal HIGH.

How can I do?

Regards Davide

You can modify a Uboot to do it before Linux boots. However it still takes a couple hundred milliseconds to set it high after power on. By default most of GPIO lines are set as input after reset, so you can use an external pull up resister to keep it HIGH until software takes care about pin state.

Would you modify the file “colibri_vf.c” board_init()? I am trying the same but setting the output doesn’t seem to work. I am able to put in a printf and see that come out very early - right after “Reset cause:”. Which routine do you recommend?

Yes I’d do it at the end of board_late_init() (colibri_vf.c). You need to setup iomux and GPIO direction/state.

Ok, thank you. External resistance is a good solution, but at boot I see the UART_A_DCD signal go high and low (It’s boot debug port…). The DTB settings are activated when starting the boot or starting the Linux?

The main/kernel device tree (DTB) are applied by Linux, so during Linux kernel start.

Ok, thanks.
Regards Davide

Ok - this works in ‘board_init’;

/* this reports to the PWM1 - back light */
/*
	22 is the numeric representation
	59 is the actual pin number on the SOM
*/
gpio_request(22, "SODIMM_PIN_59");
gpio_direction_output(22, 1);
gpio_set_value(22, 0);

But this doesn’t;

/* set the RS485 direction bit */
/*
	81 is the numeric representation
	34 is the actual pin number on the SOM
*/
gpio_request(81, "SODIMM_PIN_34");
gpio_direction_output(81, 1);
gpio_set_value(81, 0);

Changed this to enum in iomux-vf610.h:

VF610_PAD_PTD2__GPIO_81			= IOMUX_PAD(0x0144, 0x0144, 2, __NA_, 0, VF610_GPIO_PAD_CTRL),

Took it out of uart_pads structure, added it to gpio_pads in the colibri_vf.c
Example:

static const iomux_v3_cfg_t gpio_pads[] = {
	VF610_PAD_PTA17__GPIO_7,
	VF610_PAD_PTA20__GPIO_10,
	VF610_PAD_PTA21__GPIO_11,
	VF610_PAD_PTA30__GPIO_20,
	VF610_PAD_PTA31__GPIO_21,
	VF610_PAD_PTB0__GPIO_22,
	VF610_PAD_PTB1__GPIO_23,
	VF610_PAD_PTB8__GPIO_30,
	VF610_PAD_PTB9__GPIO_31,
	VF610_PAD_PTC0__GPIO_45,
	VF610_PAD_PTD2__GPIO_81,
};

Still not working. Did ‘cat /sys/class/gpio’ -

export
gpio103
gpio39
gpio43
gpio48
gpio5
gpio63
gpio65
gpio66
gpio67
gpio69
gpio70
gpio91
gpio96
gpio98
gpiochip0
gpiochip128
gpiochip32
gpiochip64
gpiochip96
unexport

And same in u-boot:
GPIOs 0-31, platform/40049000.gpio, vf610-gpio:
gpio-5 (sysfs ) out lo

GPIOs 32-63, platform/4004a000.gpio, vf610-gpio:
gpio-39 (sysfs ) out lo
gpio-41 (Wake-Up ) in lo IRQ
gpio-42 (cd ) in hi IRQ
gpio-43 (ft5x06_ts ) out hi
gpio-45 (backlight ) out hi
gpio-48 (sysfs ) out lo
gpio-63 (sysfs ) out hi

GPIOs 64-95, platform/4004b000.gpio, vf610-gpio:
gpio-65 (sysfs ) out hi
gpio-66 (sysfs ) out lo
gpio-67 (sysfs ) out lo
gpio-69 (sysfs ) out hi
gpio-70 (sysfs ) out hi
gpio-89 (id ) in lo IRQ
gpio-91 (ft5x06_ts ) in hi IRQ

GPIOs 96-127, platform/4004c000.gpio, vf610-gpio:
gpio-96 (sysfs ) out lo
gpio-98 (sysfs ) out hi
gpio-103 (sysfs ) out hi

GPIOs 128-159, platform/4004d000.gpio, vf610-gpio:

Where did I go wrong?
Thanks!!

Hi

Whatever you do in U-Boot is only configured until the kernel changes it.

The answer to your initial question, how to early output a high on a GPIO , is to set it in U-Boot. So you would need to test if your change to U-Boot did really set the pin to GPIO/Output/High. E.g. stop booting in U-Boot and measure the pin.

Then, when the kernel boots the kernel will apply a pin mux given in the device tree (if there is one) but it will not change direction or value of a pin due to the muxing.

Especially the kernel will not export the pin to user space. So if you later want to control the pin from user space you have to export it first. I’m unsure if you need to set direction or if that gets read back from the registers.

echo XX > /sys/class/gpio/export
echo high > /sys/class/gpio/gpioXX/direction

Max

Hi,

I have made one gpio of ioexpander by default high by adding following line in the device tree…

pinctrl-assert-gpios = <&max7310_c 3 GPIO_ACTIVE_HIGH>; /* For Rotary2 */

So in your case you can just replace &max7310 with &gpioX, where X = 0,1,2,3…etc it depends on your gpio bank, then specify the corresponding gpio pin, example <&gpio1 1 GPIO_ACTIVE_HIGH>;

It should work for your case…

Regards,
Vimal Babu

Thank you.