/sys/bus/usb/devices下的文件命名:
root@Four-Faith:/sys/bus/usb/devices# ls -l
lrwxrwxrwx 1 root root 0 Jan 1 1970 1-0:1.0 -> ../../../devices/platform/xhc_mtk/usb1/1-0:1.0
lrwxrwxrwx 1 root root 0 Jan 8 23:27 1-2 -> ../../../devices/platform/xhc_mtk/usb1/1-2
lrwxrwxrwx 1 root root 0 Jan 8 23:28 1-2:1.0 -> ../../../devices/platform/xhc_mtk/usb1/1-2/1-2:1.0
lrwxrwxrwx 1 root root 0 Jan 8 23:28 1-2:1.1 -> ../../../devices/platform/xhc_mtk/usb1/1-2/1-2:1.1
lrwxrwxrwx 1 root root 0 Jan 8 23:27 1-2:1.2 -> ../../../devices/platform/xhc_mtk/usb1/1-2/1-2:1.2
lrwxrwxrwx 1 root root 0 Jan 8 23:28 1-2:1.3 -> ../../../devices/platform/xhc_mtk/usb1/1-2/1-2:1.3
lrwxrwxrwx 1 root root 0 Jan 8 23:28 1-2:1.4 -> ../../../devices/platform/xhc_mtk/usb1/1-2/1-2:1.4
lrwxrwxrwx 1 root root 0 Jan 8 23:28 1-2:1.5 -> ../../../devices/platform/xhc_mtk/usb1/1-2/1-2:1.5
lrwxrwxrwx 1 root root 0 Jan 1 1970 2-0:1.0 -> ../../../devices/platform/xhc_mtk/usb2/2-0:1.0
lrwxrwxrwx 1 root root 0 Jan 1 1970 usb1 -> ../../../devices/platform/xhc_mtk/usb1
lrwxrwxrwx 1 root root 0 Jan 1 1970 usb2 -> ../../../devices/platform/xhc_mtk/usb2
如上可知:/sys/bus/usb/devices都是实际指向/sys/devices/platform/下的文件,文件的命名是根据USB命名的规则,比如:
/sys/bus/usb/devices/usb1,usb2表示表示两个usb hub,是root bug,usb1/内有属于usb bug device的一些属性,可以看一下:
root@Four-Faith:/sys/devices/platform/xhc_mtk/usb1# ls
1-0:1.0 bcdDevice maxchild
1-2 bmAttributes product
authorized busnum quirks
authorized_default configuration remove
avoid_reset_quirk descriptors serial
bConfigurationValue dev speed
bDeviceClass devnum subsystem
bDeviceProtocol devpath uevent
bDeviceSubClass driver urbnum
bMaxPacketSize0 ep_00 usb_device
bMaxPower idProduct version
bNumConfigurations idVendor
bNumInterfaces manufacturer
一个hub也是一个usb decice,因此一个usb device ,直接引用include/linux/usb/ch9.h中的定义是:(+表示在该目录下存在)
|
|
lzj@lzj-laptop:/sys/bus/usb/devices/usb1$ cat bDeviceClass 09 |
hub当然还是一个hub device,它具有普通usb device没有的一些性质, struct usb_hub_descriptor,但这些信息没有在sysfs中显示,可能是一个普通用户不需要知道hub的信息吧,所以内核开发者没有在sysfs中显示
**************以上是device(或者是USB hub)级别的信息,一个usb device有1个或多个interface.下面开始讲interface
1-0:1.0就是interface的目录,表示root hub1-port0上的configuration1的interface0,
命名规则是:roothub-port:configuration.interface.
看看1-0:1.0目录下的内容:
root@Four-Faith:/sys/devices/platform/xhc_mtk/usb1/1-0:1.0# ls
bAlternateSetting bInterfaceSubClass modalias
bInterfaceClass bNumEndpoints subsystem
bInterfaceNumber driver supports_autosuspend
bInterfaceProtocol ep_81 uevent
其实1-0:1.0是usb hub1自己占有的,在没有接入任何usb设备的时候,1-0:1.0都存在并且可以在usb1中找到,在用户接入USB设备之后并且该设备挂载在ubs hug1下,那么就会在usb1下多出1-2/目录,打开看:
drwxr-xr-x 5 root root 0 Jan 9 13:46 1-2:1.0
drwxr-xr-x 6 root root 0 Jan 9 13:46 1-2:1.1
drwxr-xr-x 6 root root 0 Jan 9 13:45 1-2:1.2
drwxr-xr-x 6 root root 0 Jan 9 13:46 1-2:1.3
drwxr-xr-x 6 root root 0 Jan 9 13:46 1-2:1.4
drwxr-xr-x 5 root root 0 Jan 9 13:46 1-2:1.5
-rw-r--r-- 1 root root 4096 Jan 9 13:46 authorized
-rw-r--r-- 1 root root 4096 Jan 9 13:46 avoid_reset_quirk
-rw-r--r-- 1 root root 4096 Jan 9 13:46 bConfigurationValue
-r--r--r-- 1 root root 4096 Jan 9 13:46 bDeviceClass
-r--r--r-- 1 root root 4096 Jan 9 13:46 bDeviceProtocol
-r--r--r-- 1 root root 4096 Jan 9 13:46 bDeviceSubClass
-r--r--r-- 1 root root 4096 Jan 9 13:46 bMaxPacketSize0
-r--r--r-- 1 root root 4096 Jan 9 13:46 bMaxPower
-r--r--r-- 1 root root 4096 Jan 9 13:46 bNumConfigurations
-r--r--r-- 1 root root 4096 Jan 9 13:46 bNumInterfaces
-r--r--r-- 1 root root 4096 Jan 9 13:46 bcdDevice
-r--r--r-- 1 root root 4096 Jan 9 13:46 bmAttributes
-r--r--r-- 1 root root 4096 Jan 9 13:46 busnum
-r--r--r-- 1 root root 4096 Jan 9 13:46 configuration
-r--r--r-- 1 root root 65553 Jan 9 13:46 descriptors
-r--r--r-- 1 root root 4096 Jan 9 13:46 dev
-r--r--r-- 1 root root 4096 Jan 9 13:46 devnum
-r--r--r-- 1 root root 4096 Jan 9 13:46 devpath
lrwxrwxrwx 1 root root 0 Jan 9 13:46 driver -> ../../../../../bus/usb/drivers/usb
drwxr-xr-x 2 root root 0 Jan 9 13:46 ep_00
-r--r--r-- 1 root root 4096 Jan 9 13:45 idProduct
-r--r--r-- 1 root root 4096 Jan 9 13:45 idVendor
-r--r--r-- 1 root root 4096 Jan 9 13:46 manufacturer
-r--r--r-- 1 root root 4096 Jan 9 13:46 maxchild
-r--r--r-- 1 root root 4096 Jan 9 13:46 product
-r--r--r-- 1 root root 4096 Jan 9 13:46 quirks
--w------- 1 root root 4096 Jan 9 13:46 remove
-r--r--r-- 1 root root 4096 Jan 9 13:46 serial
-r--r--r-- 1 root root 4096 Jan 9 13:46 speed
lrwxrwxrwx 1 root root 0 Jan 9 13:46 subsystem -> ../../../../../bus/usb
-rw-r--r-- 1 root root 4096 Jan 9 13:46 uevent
-r--r--r-- 1 root root 4096 Jan 9 13:46 urbnum
drwxr-xr-x 3 root root 0 Jan 9 13:46 usb_device
-r--r--r-- 1 root root 4096 Jan 9 13:46 version
会多出如下:
drwxr-xr-x 5 root root 0 Jan 9 13:46 1-2:1.0
drwxr-xr-x 6 root root 0 Jan 9 13:46 1-2:1.1
drwxr-xr-x 6 root root 0 Jan 9 13:45 1-2:1.2
drwxr-xr-x 6 root root 0 Jan 9 13:46 1-2:1.3
drwxr-xr-x 6 root root 0 Jan 9 13:46 1-2:1.4
drwxr-xr-x 5 root root 0 Jan 9 13:46 1-2:1.5
这些就是用户刚刚挂载在ubs1 这个bug下的设备,他们占用usb bub1中port1,configuration都为1,而interface0 - 6都被用户占用,在1-2:1.0可以找到ttyUSB0/,ttyUSB0就是/dev/ttyUSB0相关。我现在挂载在usb hub1上的设备是usb转串口的lte模块,所以名字是ttyUSB*