https://blog.csdn.net/harvey2008/article/details/21228975
https://blog.csdn.net/harvey2008/article/details/21229041
https://blog.csdn.net/harvey2008/article/details/21229111
https://blog.csdn.net/dingzj2000/article/details/90905095
- 枚举流程
• 连接了设备的 HUB 在 HOST 查询其状态改变端点 时返回对应的 bitmap,告知HOST 某个PORT状态发生了改变。
• 主机向 HUB 查询该PORT的状态,得知有设备连接,并知道了该设备的基本特性。
• 主机等待(至少 100mS)设备上电稳定,然后向 HUB 发送请求,复位并使能该PORT。
• HUB执行PORT复位操作,复位完成后该PORT就使能了。现在设备进入到defalut状态,可以从Vbus获取不超过 100mA 的电流。主机可以通过 0地址与其通讯。
• 主机通过0地址向该设备发送get_device_descriptor标准请求,获取设备的描述符。
• 主机再次向 HUB 发送请求,复位该PORT。
• 主机通过标准请求 set_address给设备分配地址。
• 主机通过新地址向设备发送 get_device_descriptor标准请求,获取设备的描述符。
• 主机通过新地址向设备发送其他 get_configuration请求,获取设备的配置描述符。
• 根据配置信息,主机选择合适配置,通过 set_configuration请求对设备而进行配置。这时设备方可正常使用。
主机通过解析描述符后对设备有了足够的了解,会选择一个最合适的驱动给设备。
然后tell the world(announce_device)说明设备已经找到了,最后调用设备模型提供的接口device_add将设备添加到 usb 总线的设备列表里,
然后 usb总线会遍历驱动列表里的每个驱动,调用自己的 match(usb_device_match) 函数看它们和你的设备或接口是否匹配,
匹配的话调用device_bind_driver函数,现在就将控制权交到设备驱动了
[test:~] $ echo “2-1.3” | tee /sys/bus/usb/drivers/usb/unbind
1-1.4
[test:~] $ lsusb -t
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/1p, 5000M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 5000M
|__ Port 2: Dev 4, If 0, Class=Vendor Specific Class, Driver=r8152, 5000M
|__ Port 3: Dev 118, If 1, Class=Video, Driver=uvcvideo, 5000M
|__ Port 3: Dev 118, If 4, Class=Audio, Driver=snd-usb-audio, 5000M
|__ Port 3: Dev 118, If 2, Class=Video, Driver=uvcvideo, 5000M
|__ Port 3: Dev 118, If 0, Class=Video, Driver=uvcvideo, 5000M
|__ Port 3: Dev 118, If 5, Class=Human Interface Device, Driver=usbhid, 5000M
|__ Port 3: Dev 118, If 3, Class=Audio, Driver=snd-usb-audio, 5000M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/1p, 480M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/5p, 480M
|__ Port 5: Dev 4, If 0, Class=Vendor Specific Class, Driver=, 480M
[test:~] $ echo “2-1.3” | tee /sys/bus/usb/drivers/usb/bind
1-1.4
[test:~] $ lsusb -t
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/1p, 5000M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 5000M
|__ Port 2: Dev 4, If 0, Class=Vendor Specific Class, Driver=r8152, 5000M
|__ Port 3: Dev 118, If 1, Class=Video, Driver=uvcvideo, 5000M
|__ Port 3: Dev 118, If 4, Class=Audio, Driver=snd-usb-audio, 5000M
|__ Port 3: Dev 118, If 2, Class=Video, Driver=uvcvideo, 5000M
|__ Port 3: Dev 118, If 0, Class=Video, Driver=uvcvideo, 5000M
|__ Port 3: Dev 118, If 5, Class=Human Interface Device, Driver=usbhid, 5000M
|__ Port 3: Dev 118, If 3, Class=Audio, Driver=snd-usb-audio, 5000M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/1p, 480M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/5p, 480M
|__ Port 4: Dev 104, If 1, Class=Audio, Driver=snd-usb-audio, 12M
|__ Port 4: Dev 104, If 2, Class=Audio, Driver=snd-usb-audio, 12M
|__ Port 4: Dev 104, If 0, Class=Audio, Driver=snd-usb-audio, 12M
|__ Port 4: Dev 104, If 3, Class=Human Interface Device, Driver=usbhid, 12M
|__ Port 5: Dev 4, If 0, Class=Vendor Specific Class, Driver=, 480M