Reputation: 2637
I have a USB VID and PID for an attached device on GNU / Linux. 045e:0084
, for example. I want the binding so I grep the output of lsusb
for the VID:PID
and massage it into a format acceptable for udevadm
lookup. Finally, I take the basename of the resultant path. Something like:
bus_dev=$(lsusb|grep VID:PID...) # Grep / Sed magic to extract bus and device from VID and PID.
path=$(udevadm info -q path -n /dev/bus/usb/$bus_dev) # e.g., -n /dev/bus/usb/003/018
basename $path # e.g., /devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2.3/3-2.3.1
# e.g., yields 3-2.3.1
I can then use it like so:
echo 3-2.3.1|sudo tee /sys/bus/usb/drivers/usb/unbind
What's the preferred way to get the binding from a USB vendor and product ID?
Upvotes: 3
Views: 3710
Reputation: 3699
You mean something like this?
vidpid="1d6b:0002"
bus_dev=`lsusb | grep "ID\s$vidpid" | sed 's/^.*Bus\s\([0-9]\+\)\sDevice\s\([0-9]\+\).*$/\1\/\2/g' | tail -n 1`
path=$(udevadm info -q path -n /dev/bus/usb/$bus_dev)
basename $path
Upvotes: 1