What is point of GPIO/pinmux configuration in Device Tree?

I’m new to BBB, Linux, Yocto, etc… I just modified the am335x-bone-common.dtsi device tree file as an experiment. I’m learning. I started out easy. I configured a pin as an output as shown below. I then added the gpiod library to my project to test my new configuration.

But… as far as I can tell. The gpioset function of the gpiod library can set the direction of the pin. Likewise, so can the older sysfs gpio driver. So suddenly I’m unclear of the point of setting the pinmux if the userspace drivers simply set the direction anyways.

&am33xx_pinmux {
pinctrl-names = “default”;
pinctrl-0 = <&clkout2_pin &testpins>;

    testpins: testpins {
            pinctrl-single,pins = <
                    AM33XX_PADCONF(AM335X_PIN_GPMC_A5, PIN_OUTPUT_PULLDOWN, MUX_MODE7)      /* gpmc_a5.gpio1_21 */
            >;
    };

Sometimes you just want to gain control of the logic your pins are connected to
as early as possible in the boot process, and a way to do that is trough the device-tree.

Some pins are reserved and should not be touched by software; device-tree supports
this trough hogging.

… but you’re right. If none of those scenarios apply to you, don’t concern yourself
with those intricacies, and just use whatever works for you.

1 Like

The pinmux configures the routing of the pin to the peripheral and only that.

So if you want to use a GPIO port, you first must make sure that the signal is routed from the peripheral to the pin.

Configuring the GPIO port as an input or an output does not change the pinmuxing, but you still need to do it for the GPIO peripheral to work correctly.

1 Like

Argh, Pinmuxing! Yes, there’s that, haha!

1 Like

so pinmuxing and input/output selection are separate? They appear to be the same register within the AM335x. if I’m understanding this correctly, the various GPIO drivers (sysfs and gpiod) can impact bits 5 through 3 of the conf__ register but not bits 2 through 0?

this makes sense to me. yes the initial pull-up/pull-down settings may need to be configured before any linux driver can possibly do it

Not looked at the gpiod source code, but it could be that it is actually setting the bits in the GPIO_OE register and not touching the pin muxing registers.

1 Like

ok. I’ll leave it at that. Thanks so much @benedict.hewson @lranders for your help.