Properly using gpio_request and pinmux for GPIO

Oliver Westermann owestermann at gmail.com
Thu Nov 12 14:24:27 CET 2020


Hey,

I'm wondering if there is documentation or a good example on how to
configure pin muxing in combination with the gpio_request functions. Our
current implementation is incomplete as it doesn't handle the muxing, but
before randomly copying code I would like to know what the "upstream" way
of doing things like this is, so maybe someone can advise.

The goal is to define N pins as "revision pins" (basically pull up/down
resistors for board revisions) in the dts and based upon this definition
read the pins and calculate a value. Our current implementation just has a
pin list like this:

board-rev-gpios = <
      &gpio0 1 GPIO_ACTIVE_HIGH
      &gpio0 2 GPIO_ACTIVE_HIGH
      &gpio0 3 GPIO_ACTIVE_HIGH
>;

and uses gpio_request_list_by_name() to access those by name, this works as
long as no muxing is required.

My current understanding of the full solution would be to define not only
the gpios, but also a pinctrl, sth like this:

DTS:
    board_rev {
        pinctrl-names = "gpio";
        pinctrl-0 = <&pinctrl_board_rev>;
        gpios = <
          &gpio0 1 GPIO_ACTIVE_HIGH
          &gpio0 2 GPIO_ACTIVE_HIGH
          &gpio0 3 GPIO_ACTIVE_HIGH
        >;
    };

    pinctrl_board_rev: i2c1grp {
        fsl,pins = <
            MX8MM_IOMUXC_GPIO1_IO00_GPIO1_IO0           0x400001c3
            MX8MM_IOMUXC_GPIO1_IO00_GPIO1_IO2           0x400001c3
            MX8MM_IOMUXC_GPIO1_IO00_GPIO1_IO3           0x400001c3
        >;
    };

Code:
    /* get board_rev node as board_rev, prepare arrays, ... */
    gpio_request_list_by_name(board_rev, "gpios", gpios, ARRAY_SIZE(gpios),
GPIOD_IS_IN);
    pinctrl_select_state(board_rev, "gpio");

Would this be the correct way to use the muxing functionality?

Best regards, Olli


More information about the U-Boot mailing list