V4L2 简单分析 内核自带的 uvc 驱动 1

 发布日期:2019-03-22 06:42:31  阅读次数:阅读数:40  来源:

文件:drivers\media\usb\uvc\uvc_driver.c

static int __init uvc_init(void)
ret = usb_register(&uvc_driver.driver);

struct uvc_driver uvc_driver = {
	.driver = {
		.name		= "uvcvideo",
		.probe		= uvc_probe,
		.disconnect	= uvc_disconnect,
		.suspend	= uvc_suspend,
		.resume		= uvc_resume,
		.reset_resume	= uvc_reset_resume,
		.id_table	= uvc_ids,
		.supports_autosuspend = 1,
	},
};

我们可以通过这个 查看这个 uvc_ids 可以看到 uvc 支持的USB摄像头设备驱动有哪些

 

一旦匹配,就会调用:uvc_probe 函数

static int uvc_probe(struct usb_interface *intf,
		     const struct usb_device_id *id)
{
	struct usb_device *udev = interface_to_usbdev(intf);
     //注册设备
    if (v4l2_device_register(&intf->dev, &dev->vdev) < 0)
    /* Register video device nodes. */
    //这里是注册 video 设备
	if (uvc_register_chains(dev) < 0)

我们可以跟踪 uvc_register_chains 函数

uvc_register_chains(dev)
    uvc_register_terms(dev, chain);
        uvc_register_video(dev, stream);
            /* Register the device with V4L. */
    	vdev = video_device_alloc();
            vdev->v4l2_dev = &dev->vdev;
    	vdev->fops = &uvc_fops;
    	vdev->release = uvc_release;
    	strlcpy(vdev->name, dev->name, sizeof vdev->name);
             //终于在这里注册了
            video_register_device(vdev, VFL_TYPE_GRABBER, -1)

 

我们看下 uvc_fops 里面的函数

const struct v4l2_file_operations uvc_fops = {
	.owner		= THIS_MODULE,
	.open		= uvc_v4l2_open,
	.release	= uvc_v4l2_release,
	.unlocked_ioctl	= uvc_v4l2_ioctl,
#ifdef CONFIG_COMPAT
	.compat_ioctl32	= uvc_v4l2_compat_ioctl32,
#endif
	.read		= uvc_v4l2_read,
	.mmap		= uvc_v4l2_mmap,
	.poll		= uvc_v4l2_poll,
#ifndef CONFIG_MMU
	.get_unmapped_area = uvc_v4l2_get_unmapped_area,
#endif
};

 

我们看下 uvc_v4l2_ioctl

uvc_v4l2_ioctl
    video_usercopy(file, cmd, arg, uvc_v4l2_do_ioctl);
        uvc_v4l2_do_ioctl
            switch (cmd) {
                    //这里对应了所有的 io ctrl 功能
                }

 

如果您有好的新闻与建议,欢迎点击文章投稿

    发表评论

    电子邮件地址不会被公开。

  • 内容

  • 网名