Attempting to answer my own question...

Phil Endecott wrote:
Greg KH wrote:
On Mon, Dec 03, 2007 at 06:19:53PM +0000, Phil Endecott wrote:
Dear Experts,

Can anyone suggest the best way to determine the speed (low/full/high) at which a device is operating from user-space?

usbdevice_fs has 'connectinfo', which seems to return a flag for low-speed operation. But it doesn't seem to distinguish between full and high-speed. A usbdevicefs method would be ideal as I'm already using that, but maybe there is something in /sys?

Yes, there's a "speed" file there, try it out, I think it's exactly what
you are looking for :)

Thanks Greg. I should have spotted that; I must have been lost in /sys's maze of twisty symlinks.

Now I just need to work out how to convert from e.g. /proc/bus/usb/001/010 to e.g. /sys/devices/pci0000:00/0000:00:10.3/usb1/1-4/1-4.6/1-4.6.3. Any ideas?

(Sometimes I already have the /sys path; my app listens for uevents on a netlink socket, and these include both pathnames. But when it starts it looks for already-attached devices by iterating through /proc/bus/usb, and in this case it doesn't have the /sys path conveniently available. Maybe I should instead do this initial search in some other way, e.g. through /sys/bus/usb/devices?)


I think I need to iterate through /sys/bus/usb/devices, skipping the "usb*" and "*:*" files; in each case I can get the bus number from the first bit of the directory name, and the device number from the devnum file in that directory. Example:

for i in /sys/bus/usb/devices/*
do
  case `basename $i` in
  usb*) ;;
  *:*) ;;
  *) bus=`basename $i | sed 's/-.*$//g'`
     device=`cat $i/devnum`
     speed=`cat $i/speed`
     echo "/proc/bus/usb/${bus}/${device} ${speed}"
  esac
done

Output:

/proc/bus/usb/1/2 480
/proc/bus/usb/1/4 1.5
/proc/bus/usb/1/3 12

This looks sane to me apart from the obvious lack of leading zeros.


Phil.




-
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to