1.uvc驱动模块入口
[cpp]
module_init(uvc_init); //1.模块入口
2.初始化函数
[cpp]
static int __init uvc_init(void) // 2.初始化函数
{
int result;
result = usb_register(&uvc_driver.driver); // 3.注册usb设备驱动(usb摄像头设备)
if (result == 0) //注册失败
printk(KERN_INFO DRIVER_DESC " (" DRIVER_VERSION ")\n");
return result;
}
3.注册usb设备驱动(usb摄像头设备)
3.1 usb摄像头驱动
[cpp]
struct uvc_driver uvc_driver = { // 3.1 usb摄像头设备
.driver = {
.name = "uvcvideo",
.probe = uvc_probe, // 4. probe方法
.disconnect = uvc_disconnect,
.suspend = uvc_suspend,
.resume = uvc_resume,
.reset_resume = uvc_reset_resume,
.id_table = uvc_ids, //3.2 支持的设备id列表
.supports_autosuspend = 1,
},
};
3.2 支持的设备id列表uvc_ids
[cpp]
static struct usb_device_id uvc_ids[] = {
/* Genius eFace 2025 */
{ .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO,
.idVendor = 0x0458,
.idProduct = 0x706e,
.bInte易做图ceClass = USB_CLASS_VIDEO, //uvc接口类 0x0e
.bInte易做图ceSubClass = 1,
.bInte易做图ceProtocol = 0,
.driver_info = UVC_QUIRK_PROBE_MINMAX },
...
...
...
/* SiGma Micro USB Web Camera */
{ .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO,
.idVendor = 0x1c4f,
.idProduct = 0x3000,
.bInte易做图ceClass = USB_CLASS_VIDEO,
.bInte易做图ceSubClass = 1,
.bInte易做图ceProtocol = 0,
.driver_info = UVC_QUIRK_PROBE_MINMAX | UVC_QUIRK_IGNORE_SELECTOR_UNIT },
/* Generic USB Video Class */ //通用usb视频类
{ USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, 0) }, //匹配方法:uvc类
{}
};
4.probe方法
[cpp]
static int uvc_probe(struct usb_inte易做图ce *intf,const struct usb_device_id *id)
{
struct usb_device *udev = inte易做图ce_to_usbdev(intf); //通过usb接口获取usb设备
struct uvc_device *dev; //声明uvc设备
int ret;
if (id->idVendor && id->idProduct) //有厂商id和商品id(知名设备)
uvc_trace(UVC_TRACE_PROBE, "Probing known UVC device %s (%04x:%04x)\n", udev->devpath, id->idVendor,id->idProduct);
else //通用uvc设备
uvc_trace(UVC_TRACE_PROBE, "Probing generic UVC device %s\n",udev->devpath);
/* Allocate memory for the device and initialize it. */
if ((dev = kzalloc(sizeof *dev, GFP_KERNEL)) == NULL) //分配uvc设备内存
return -ENOMEM;
INIT_LIST_HEAD(&dev->entities); //初始化entities(实体)链表 Terminal或Unit
INIT_LIST_HEAD(&dev->chains); //初始化chains(链)链表
INIT_LIST_HEAD(&dev->streams); //初始化streams(视频流)链表
atomic_set(&dev->nstreams, 0);
atomic_set(&dev->users, 0);
atomic_set(&dev->nmappings, 0);
dev->udev = usb_get_dev(udev); //易做图usb设备,并增加其引用计数
dev->intf = usb_get_intf(intf); //易做图usb接口,并增加其引用计数
dev->intfnum = intf->cur_altsetting->desc.bInte易做图ceNumber; //获取usb接口描述符接口数
dev->quirks = (uvc_quirks_param == -1) ? id->driver_info : uvc_quirks_param;
if (udev->product != NULL) //存在产品名
strlcpy(dev->name, udev->product, sizeof dev->name); //设置uvc设备名字为其产品名
else //通用的uvc设备名
snprintf(dev->name, sizeof dev->name,"UVC Camera (%04x:%04x)",le16_to_cpu(udev->descriptor.idVendor),le16_to_cpu(udev->descriptor.idProduct));
/* Parse the Video Class control descriptor. */
if (uvc_parse_control(dev) < 0) { //-->5 uvc解析usb视频类控制描述符
uvc_trace(UVC_TRACE_PROBE, "Unable to parse UVC descriptors.\n");
goto error;
}
uvc_printk(KERN_INFO, "Found UVC %u.%02x device %s (%04x:%04x)\n",dev->uvc_version >> 8, dev->uvc_version & 0xff,
udev->product ? udev->product : "<unnamed>",le16_to_cpu(udev->descriptor.idVendor),le16_to_cpu(udev->descriptor.idProduct));
if (dev->quirks != id->driver_info) {
uvc_printk(KERN_INFO, "Forcing device quirks to 0x%x by module parameter for testing purpose.\n", dev->quirks);
uvc_printk(KERN_INFO, "Please report required quirks to the linux-uvc-devel mailing list.\n");
}
/* Initialize controls. */
if (uvc_ctrl_init_device(dev) < 0) //8.uvc初始化控制
goto error;
/* Scan the device for video chains. */
if (uvc_scan_device(dev) < 0) //10.uvc扫描视频链
<