I have a number of USB/TTL adapters, based on CP2102N, which have four GPIO lines.

I can open one of the serial devices by /dev/ttyUSB0, and the related GPIO lines are controlled by libgpiod: /dev/gpiochip1.

I need to make sure I am always modifying the right device and I need a way to figure out the relation either by querying /dev/ttyUSB0 resulting in -> /dev/gpiochip1, or by querying /dev/gpiochip1 resulting in -> /dev/ttyUSB0.

How do I do that? I don't see anything in libgpiod that does this.

  • Assuming linux, in the kernel source there is a directory tools/gpio. Building them and running lsgpio may give you a bit more info.
    – Bib
    Jan 30, 2022 at 15:38

1 Answer 1


You could try readlink /sys/class/gpio/gpiochip1 and/or readlink /sys/class/tty/ttyUSB0, and seeing if the two paths have the same controller and USB device components.

For example, if you get something like:

# readlink /sys/class/gpio/gpiochip1
# readlink /sys/class/tty/ttyUSB0
The same PCI USB controller and USB device path!

then you'd know that ttyUSB0 == gpiochip1.

  • Thanks, worked good. Feb 13, 2022 at 9:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .