11

How to programatically determine the usb port speed in embedded devices running the Linux kernel?

caf
  • 233,326
  • 40
  • 323
  • 462
bluegenetic
  • 1,365
  • 4
  • 11
  • 15
  • 2
    This either belongs on Server fault or you need to specify what language want to use. – Ben Everard Dec 24 '09 at 09:49
  • 5
    Don't be silly: embedded devices don't have server admins (and neither are the people that run code on them "users", so it's not a superuser question either!). It's clearly a question about embedded **development**, asking about programming for OS specific features. – caf Dec 25 '09 at 23:23
  • 3
    All you need is lsusb -t – sMyles Jun 28 '14 at 02:32

2 Answers2

31

You can read /sys/bus/usb/devices/usb?/speed - it'll give you the bus speed of the root hub(s) in Mbps: either 1.5, 12, 480, 5000 or 10000. The first two indicate USB1 (low speed or full speed), the third USB2 and the fourth and fifth USB3.

caf
  • 233,326
  • 40
  • 323
  • 462
1

This rather depends on were the code that needs the information is running. If you want to modify a kernel USB device drivers behavior based on connection speed then the usb_device struct that passed to the driver by the USB subsystem contains a speed enumeration. If you want an application in user space to detect the devices connection speed then try walking the /sys/bus/usb tree you should be able to identify your USB device by checking the idProduct and idVendor entries. Once you have a match then the speed entry will give you what you need. If you have multiple devices connected then you might need to figure a way to match USB id to specific device. Generally USB to device mappings vary on any hot plug support present whether the device supplies a serial number and the sub system that abstracts the functionality provided by the USB device.

Andrew Roca
  • 285
  • 1
  • 2