Find GPIO Chips and Lines With gpiodetect and gpioinfo
List GPIO chips with gpiodetect and read every line's name, direction and consumer with gpioinfo from libgpiod 2.1 on Linux 6.12, then pick the line you want.

Before you can toggle a pin, you have to know which chip it belongs to and what number it has on that chip. A modern Linux board often has several GPIO chips: the SoC's own controllers, an I2C expander on a carrier board, perhaps a USB adapter. Each chip has its own set of lines, and the kernel names them from the device tree. Two small command-line tools from libgpiod answer both questions. gpiodetect lists the chips, and gpioinfo lists the lines of each chip with their names, directions and who is using them. This post shows how to read their output on libgpiod 2.1 with Linux 6.12, how to find a particular pin by its name and what the columns mean. The tools are described in the libgpiod documentation.
What a chip and a line are
The kernel's GPIO subsystem organizes pins into chips. A chip is one GPIO controller registered by a driver, and it appears as a device node /dev/gpiochipN where N counts up from zero in the order the chips were probed. A line is one pin on a chip, identified by its offset, a number from zero up to the chip's line count minus one. So a pin is addressed as "chip and offset", for example gpiochip0 and line 17.
Two properties are not stable. The chip number can change between boots if drivers probe in a different order, though it is usually stable on a fixed board. The offset is a property of the controller hardware and does not change. Names are the friendlier handle: the device tree can label lines, such as GPIO17 or status-led, and the tools can look a line up by that name regardless of chip.
Install and check the version
The tools come with libgpiod. Version 2 changed the command-line interface from version 1, so identify what you have first, because the options differ:
gpiodetect --versiongpiodetect (libgpiod) v2.1.3
Copyright (C) 2017-2023 Bartosz Golaszewski
License: GPL-2.0-or-later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.The version number on your system will depend on the distribution or the Yocto recipe. If it prints a 1.x version, the output formats and options below differ in details, which are noted where they matter.
List the chips with gpiodetect
Run gpiodetect with no arguments. It prints one line per chip:
gpiodetectgpiochip0 [pinctrl-bcm2835] (54 lines)
gpiochip1 [raspberrypi-exp-gpio] (8 lines)Each line has three parts. The first is the device node name, which you pass to other tools, here gpiochip0. The second, in square brackets, is the label the driver gave the chip, which identifies its type: this example is a Raspberry Pi with the SoC's pin controller and an expander controlled by the firmware. The third is how many lines the chip has. A label is more reliable than a chip number for identifying the hardware in scripts, since the number depends on probe order. Other tools accept the label in place of the chip name.
List the lines with gpioinfo
gpioinfo with no arguments prints every line of every chip, which is long. Name one chip to limit it, with --chip in version 2 or as a positional argument in version 1:
gpioinfo --chip gpiochip0 | head -12gpiochip0 - 54 lines:
line 0: "ID_SDA" input
line 1: "ID_SCL" input
line 2: "GPIO2" input
line 3: "GPIO3" input
line 4: "GPIO4" input
line 5: "GPIO5" input
line 6: "GPIO6" input
line 7: "GPIO7" input
line 8: "GPIO8" input
line 9: "GPIO9" input
line 10: "GPIO10" inputThe names and count depend on your board and its device tree. Each row has the line offset, the quoted name, and its current configuration. A line with no name from the device tree shows as unnamed. The right column starts with the direction, input or output, and then lists attributes when they apply.
Read the extra attributes
A line that is in use carries more information. The consumer is the label that the program holding the line gave when it requested it, and it appears as consumer="...". Other tokens show bias (pull-up, pull-down, bias-disabled), the drive mode (open-drain, open-source), whether the line is active low and which edges are being watched. A line used by the kernel, for example by a driver for an LED or a chip-select, shows its consumer as the kernel's label and the keyword used:
gpioinfo --chip gpiochip0 | grep -E 'used|consumer' line 16: "GPIO16" output consumer="led-activity"
line 22: "GPIO22" input consumer="cs-display" [used]The lines and consumers are examples. The consequence matters in practice: a line marked in use cannot be requested by your program until the holder releases it, and a request fails with "Device or resource busy". gpioinfo is the first thing to run when that error appears, to see who has the line.
Find a line by name
Rather than hunting through the list, search for the name that your schematic or device tree uses. The gpioinfo output goes through grep, but libgpiod 2 can also locate a line directly:
gpioinfo | grep -i 'status-led' line 21: "status-led" outputChip context is lost when you grep, so ask for the line by name. Version 1 had a separate gpiofind tool for this, which version 2 removed; in version 2 you pass the line name to gpioinfo itself:
gpioinfo status-ledgpiochip0 21 "status-led" outputThe result names the chip and the offset, which you then give to gpioget or gpioset. Version 2 can also use the name directly in those tools, so for most uses you do not need the offset at all, which is why good device tree names are worth writing.
Names, duplicates and the device tree
Line names come from the gpio-line-names property of the chip's node in the device tree. A board vendor that fills it in makes your life easy; one that does not leaves every line as unnamed, and you need the schematic or the SoC pin mapping to know that physical pin 11 on the header is a given offset. The kernel does not require names to be unique across chips. If two chips name a line RESET, a tool that searches by name finds the first and warns, so prefer chip and offset when names might collide.
What to do when the numbers do not match your expectation
The offset on the chip is not the pin number printed on the header, and it is not the SoC datasheet's pin number either. It is the index within the controller's bank. On an SoC with several banks, each bank is often a chip of its own, for example gpiochip0 to gpiochip4 with 32 lines each, and the pin named GPIO3_A4 in the datasheet is bank 3 and a computed offset, here 4 within group A, so offset 4. Read the vendor's mapping, and confirm by name where possible.
When not to rely on this
gpioinfo shows the state at the moment you run it. A line that a program requests and releases quickly will not show up, and the output does not tell you the line's electrical level; use gpioget for that. On a system where an application holds all lines through its own daemon, the consumer label is the only clue as to who has what, so set a meaningful consumer name in your own code.


