USB Core 设备模型、枚举与匹配

USB Core 设备模型、枚举与匹配

1. 对象层次

1
2
3
4
5
6
usb_bus
└─ usb_device
└─ usb_host_config
└─ usb_interface
└─ usb_host_interface (altsetting)
└─ usb_host_endpoint

一个复合设备的不同interface可分别绑定UVC、UAC、HID、CDC等驱动。

2. Hub枚举

hub.c主路径:

1
2
3
4
5
6
7
8
9
10
11
port status change
-> hub_event
-> port debounce/reset
-> usb_alloc_dev
-> address device
-> read device descriptor
-> read configurations
-> usb_new_device
-> device_add
-> authorize/configure
-> interface probe

USB2先在地址0交互再SET_ADDRESS;SuperSpeed由xHCI/Hub协议配合slot/address。

3. 描述符

config.c解析device/config/interface/endpoint及class-specific extra descriptors,执行长度、数量和duplicate检查。驱动不能信任设备给出的长度。

4. 匹配

usb_device_match()支持:

  • vendor/product;
  • device class/subclass/protocol;
  • interface class/subclass/protocol;
  • bcdDevice range;
  • driver_info。

通常使用 MODULE_DEVICE_TABLE(usb, ids)自动加载模块。

5. Probe

usb_probe_interface()

-检查授权和condition;
-runtime PM get;
-选择默认altsetting;
-调用driver probe;
-建立端点/sysfs;
-允许autosuspend。

失败时执行unbind和PM回滚。

6. Configuration

usb_set_configuration()会disable旧interfaces/endpoints、发送SET_CONFIGURATION、创建新interface devices并重新匹配。切换不是对活动I/O透明操作。

7. Altsetting

usb_set_interface()用于音视频带宽/端点布局切换。旧URB必须先停止,避免向已disable endpoint提交。

8. Disconnect

Hub检测拔出后:

1
2
3
4
5
6
usb_disconnect
-> mark not attached
-> unbind interfaces
-> kill pending activity
-> remove sysfs
-> release address/device

Driver disconnect必须同步work/URB并允许设备已物理消失。

9. Generic driver

无interface driver时,USB generic device driver负责configuration和基础PM,不等于设备功能可用。

文章互动

阅读 --

留言

0 条留言

正在加载留言…