linux v4l2驱动,Android设备驱动之——V4L2

V4l2相关结构体

1.V4l2_device

struct V4l2_device{

/* DEV-> driver_data指向这个结构。 注:DEV可能是空的,如果没有父设备是如同ISA设备。 */

struct device *dev;

/* 用于跟踪注册的subdevs */

struct list_head subdevs;

/*锁定此结构体;可以使用的驱动程序以及如果这个结构嵌入到一个更大的结构。 */

spinlock_t lock;

/* 独特的设备名称,默认情况下,驱动程序姓名+总线ID */

char name[V4L2_DEVICE_NAME_SIZE];

/*报告由一些子设备调用的回调函数。 */

void (*notify)(struct v4l2_subdev *sd,

unsigned int notification, void *arg);

};

v4l2_device注册和注销

v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev);

第一个参数‘dev’通常是一个pci_dev的struct device的指针,但它是ISA设备或一个设备创建多个PCI设备时这是罕见的DEV为NULL,因此makingit不可能联想到一个特定的父母v4l2_dev。 您也可以提供一个notify()回调子设备,可以通过调用通知你的事件。取决于你是否需要设置子设备。一个子设备支持的任何通知必须在头文件中定义 .

注册时将初始化 v4l2_device 结构体. 如果 dev->driver_data字段是空, 它将连接到 v4l2_dev.

v4l2_device_unregister(struct v4l2_device *v4l2_dev);

注销也将自动注销设备所有子设备。

2.video_device

在/dev目录下的设备节点使用的 struct video_device(v4l2_dev.h)创建。

struct video_device

{

/*设备操作函数 */

const struct v4l2_file_operations *fops;

/* 虚拟文件系统 */

struct device dev;        /* v4l 设备 */

struct cdev *cdev;        /* 字符设备 */

struct device *parent;        /*父设备 */

struct v4l2_device *v4l2_dev;    /* v4l2_device parent */

/* 设备信息 */

char name[32];

int vfl_type;

/* 'minor' is set to -1 if the registration failed */

int minor;

u16 num;

/* use bitops to set/clear/test flags */

unsigned long flags;

/*属性来区分一个物理设备上的多个索引 */

int index;

/* V4L2 文件句柄 */

spinlock_t        fh_lock; /*锁定所有的 v4l2_fhs */

struct list_head    fh_list; /* List of struct v4l2_fh */

int debug;            /* Activates debug level*/

/* Video standard vars */

v4l2_std_id tvnorms;        /* Supported tv norms */

v4l2_std_id current_norm;    /* Current tvnorm */

/* 释放的回调函数 */

void (*release)(struct video_device *vdev);

/* 控制的回调函数 */

const struct v4l2_ioctl_ops *ioctl_ops;

}

动态分配:

struct video_device *vdev = video_device_alloc();

结构体配置:

fops:设置这个v4l2_file_operations结构,file_operations的一个子集。v4l2_dev: 设置这个v4l2_device父设备

name:

ioctl_ops:使用v4l2_ioctl_ops简化的IOCTL,然后设置v4l2_ioctl_ops结构。

lock:如果你想要做的全部驱动程序锁定就保留为NULL。否则你给它一个指针指向一个mutex_lock结构体和任何v4l2_file_operations被调用之前核心应该释放释放锁。

parent:一个硬件设备有多个PCI设备,都共享相同v4l2_device核心时,设置注册使用NULL v4l2_device作为父设备结构。

flags:可选的。设置到V4L2_FL_USE_FH_PRIO如你想让框架处理VIDIOC_G/ S_PRIORITY的ioctl。这就需要您使用结构v4l2_fh。这个标志最终会消失,一旦所有的驱动程序使用的核心优先处理。但现在它必须明确设定。

如果使用v4l2_ioctl_ops,那么你应该设置。unlocked_ioctlvideo_ioctl2在v4l2_file_operations结构。

注册/注销 video_device:

video_register_device(struct video_device *vdev, int type, int nr);

__video_register_device(struct video_device *vdev, int type, int nr,int warn_if_nr_in_use)

参数:

vdev:我们要注册的视频设备结构。

type:设备类型注册

nr:设备号(0==/dev/video0,1??== /dev/video1,...-1==释放第一个)

warn_if_nr_in_use:如果所需的设备节点号码已经在使用另一个号码代替选择。

注册程式分配次设备号和设备节点的数字根据请求的类型和注册到内核新设备节点。如果无法找到空闲次设备号或设备节点编号,或者如果设备节点注册失败,就返回一个错误。

           video_unregister_device(struct video_device *vdev);0b1331709591d260c1c78e86d0c51c18.png

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值