GPIO number assignment

Hello,

I’ve been reading many previous posts about GPIO port mapping in Linux. All of them describe how to map from Tegra GPIO names (i.e.: GPIO_PU0) to Linux GPIO port numbers (i.e.: 160) using “arch/arm/mach-tegra/gpio-names.h”, but I can’t find a straightforward explanation on how to map actual pin names (like CAM_I2C_SCL) into GPIO_P… names. Also, the more I look at Table 29 “Tegra K1 GPIO Register Summary”, the less sense it makes.

Please help.

Thanks in advance,
E.

This is a really vague answer, but you probably need to look at the general PINMUX concept from the TRM. Whether or not a GPIO is bound to something like a camera function depends on this…there are more functions the TK1 can support than there are pins. Related to this is early assignment during boot of PINMUX…the assignment of pins to a given function based on initial register setup. Within the kernel source are many device tree source files (.dts and .dtsi) which are compiled into a device tree binary (the .dtb file named in “/boot/extlinux/extlinux.conf” FDT key/value).

If you are interested in this, you can reverse compile the dtb (binary device tree blob) and see what is in it. The original dts/dtsi (source) files have comments and information which are lost during a reverse compile, but it’s easy to find dts files corresponding to the dtb reverse compile section you are interested in. The device tree compiler is “dtc”. This is available as an installable developer tool on almost any Linux distribution, plus you can build this directly in the kernel source…the tool is available in a scripts subdirectory with every kernel if you want that exact dtc/compiler version. An example reverse compile of a dtb file is:

dtc -I dtb -O dts -o /tmp/extracted.dts /boot/the_firmware_in_extlinux.dtb

Hello linuxdev,

thanks for your reply, but you seem to be addressing a completely different question. I understand the pinmux concept, I know each pin can be configured to serve different purposes and that this is generally defined in the kernel device tree for modern devices.

What I, and looks like many more developers in this forum ask, is how particular uP pins are mapped to Linux sysfs GPIO numbers. Please address this question.

Thanks in advance,
Emilio.

PS: I looked into the decompiled device tree, and no found reference at all to pin<->GPIO mappings.

I’m not quite sure what you’re looking for as far as the explanation goes. However, there is a large set of defines that map the pins to the GPIO in the kernel source:

drivers/pinctrl/pinctrl-tegra124.c

These defines appear to map the pins to the GPIO offset.

Thanks Kangalow, those defines are exactly what I was looking for!