linux uvc深入理解(三)

上一篇讲到usb_register将uvc_driver.driver注册进去,今天我们来梳理下uvc_driver.driver中最重要的函数probe(即uvc_probe)。
uvc_probe会传入2组参数,分别是struct usb_interface *intf和const struct usb_device_id *id。
通过intf我们可以获取usb最重要的结构体struct usb_device,通过id我们可以得到挂载uvc驱动的usb设备的PID和VID。
在uvc_probe中主要是构建了struct uvc_device

struct uvc_device {
struct usb_device *udev;
struct usb_interface *intf;
unsigned long warnings;
__u32 quirks;
int intfnum;
char name[32];

enum uvc_device_state state;
struct list_head list;
atomic_t users;

/* Video control interface */
__u16 uvc_version;
__u32 clock_frequency;

struct list_head entities;
struct list_head chains;

/* Video Streaming interfaces */
struct list_head streams;
atomic_t nstreams;

/* Status Interrupt Endpoint */
struct usb_host_endpoint *int_ep;
struct urb *int_urb;
__u8 *status;
struct input_dev *input;
char input_phys[64];
};

下面我们介绍下几个在probe函数中比较重要的函数

uvc_parse_control

主要作用是解析uvc设备的usb描述符

uvc_ctrl_init_device

将之前uvc_drive中controls队列中的uvc控制参数添加到struct uvc_device的entities队列里,最后

list_add_tail(&dev->list, &uvc_driver.devices);

将uvc_device挂接到uvc_drive中,实现设备和驱动的挂载过程

uvc_scan_device&uvc_register_terms

将video设备注册到uvc链中,最后通过uvc_register_video将所有video设备都注册成支持v4l2接口的uvc设备
让我们看下v4l2的ops结构体内容

const struct v4l2_file_operations uvc_fops = {
.owner = THIS_MODULE,
.open = uvc_v4l2_open,
.release = uvc_v4l2_release,
.ioctl = uvc_v4l2_ioctl,
.read = uvc_v4l2_read,
.mmap = uvc_v4l2_mmap,
.poll = uvc_v4l2_poll,
};

通过这种方式我们的uvc设备就能提供给上层v4l2的接口了

uvc_status_init

如果你的uvc设备还支持input的话,就需要单独为它注册input device节点(input_register_device),除此之外该函数还初始化中了中断urb,当你进行中断传输完成时会待用uvc_status_complete返回urb的提交状态,我们一般看到Non-zero status (-71) in status completion handler这种错误就是在这个函数返回的。

 

转载于:https://my.oschina.net/u/2007478/blog/968475

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值