Colibri iMX6DL Devicetree GPIOs dont match with /sys/kernel/debug/gpio

Colibri EvalBoard
Colibri iMX6DL
Yocto Angstrom

I try to add a Rotary encoder knob to the device-tree (gpio 165 and 167). From the documentation of the iMX6 I found these
SIGNAL X1 Pin i.MX6 Ball iMX6 Function DeviceTree

knob encoder A GPIO_SODIMM_165 165 CSI0_DATA12 GPIO5_IO30 (ALT5) MX6QDL_PAD_CSI0_DAT12__GPIO5_IO30
knob encoder B GPIO_SODIMM_167 167 CSI0_DATA13 GPIO5_IO31 (ALT5) MX6QDL_PAD_CSI0_DAT13__GPIO5_IO31

In the local.conf I added a device-tree

KERNEL_DEVICETREE_append_colibri-imx6 = " my_dt.dtb "

that looks like this with added rotary and gpio muxing:

/dts-v1/;

#include <dt-bindings/input/input.h>
#include <dt-bindings/interrupt-controller/irq.h>
#include "imx6dl.dtsi"
#include "imx6qdl-colibri.dtsi"

/ {
        model = "Toradex Colibri iMX6DL/S Rev:A";
        compatible = "toradex,colibri_imx6dl-eval", "toradex,colibri_imx6dl", "fsl,imx6dl";

        rotary@0 {
                compatible = "rotary-encoder";
                pinctrl-0 = <&pinctrl_rotary>;
                gpios = <&gpio5 30 GPIO_ACTIVE_LOW>, <&gpio5 31 GPIO_ACTIVE_LOW>;
                linux,axis = <0>;
                rotary-encoder,steps = <20>;
                rotary-encoder,relative-axis;
                rotary-encoder,rollover;
        };
};

&iomuxc {
        pinctrl-names = "default";
        pinctrl-0 = <
                &pinctrl_rotary
                &pinctrl_additionalgpio
        >;

        gpio {
                pinctrl_rotary: rotary {
                        fsl,pins = <
                                MX6QDL_PAD_CSI0_DAT12__GPIO5_IO30       PAD_CTRL_HYS_PU
                                MX6QDL_PAD_CSI0_DAT13__GPIO5_IO31       PAD_CTRL_HYS_PU
                        >;
                };

compile and flash the the Colibri. But then on inspection of the gpios it does not match what was in the device tree. Instead of bank 5 they are on bank 4 and gpios 158 and 159 instead of 165 and 167.

root@colibri-imx6:~# cat /sys/kernel/debug/gpio
gpiochip0: GPIOs 0-31, parent: platform/209c000.gpio, 209c000.gpio:

gpiochip1: GPIOs 32-63, parent: platform/20a0000.gpio, 20a0000.gpio:
 gpio-37  (                    |cd                  ) in  hi IRQ
 gpio-54  (                    |Wake-Up             ) in  lo IRQ

gpiochip2: GPIOs 64-95, parent: platform/20a4000.gpio, 20a4000.gpio:
 gpio-90  (                    |enable              ) out hi    
 gpio-95  (                    |usb_host_vbus       ) out lo    

gpiochip3: GPIOs 96-127, parent: platform/20a8000.gpio, 20a8000.gpio:
 gpio-108 (                    |scl                 ) in  hi    
 gpio-109 (                    |sda                 ) in  hi    

gpiochip4: GPIOs 128-159, parent: platform/20ac000.gpio, 20ac000.gpio:
 gpio-158 (                    |rotary@0            ) in  hi IRQ
 gpio-159 (                    |rotary@0            ) in  hi IRQ

gpiochip5: GPIOs 160-191, parent: platform/20b0000.gpio, 20b0000.gpio:

gpiochip6: GPIOs 192-223, parent: platform/20b4000.gpio, 20b4000.gpio:
 gpio-204 (                    |id                  ) in  hi IRQ

The correct device-tree was loaded (seen in uboot) and the dtb also seemed to compile correctly (inspected with dtc).

The GPIO controllers’ enumeration starts from 1, while banks’ numbering starts from 0. That’s why GPIO5_IOxx belongs to Bank 4.
Please also note that there’s no direct relation between X1 connector pin number and GPIO number. For iMX6 SoC, GPIO numbers are calculated by the formula 32 x (controller - 1) + gpio. So, GPIO5_IO30 has the number 158, and GPIO5_IO31 has the number 159.
Please refer to this article for details.

I had the bank numbering in mind but when both gpio number and bank were off that confused me.
It seems like the DT is correct. I could not yet verify the working of the rotary knob but at least the GPIO are correct.