V4L2 设备分析
目录
v4l2_device 结构体
struct v4l2_device
结构体是v4l2 设备驱动的主要结构体。v4l2_device结构体如下:
//linux/include/media/v4l2-device.h
struct v4l2_device {
struct device *dev; //pointer to struct device.
#if defined(CONFIG_MEDIA_CONTROLLER)
struct media_device *mdev;
#endif
struct list_head subdevs; //used to keep track of the registered subdevs
spinlock_t lock;
char name[V4L2_DEVICE_NAME_SIZE]; //unique device name, by default the driver name + bus ID
void (*notify)(struct v4l2_subdev *sd,
unsigned int notification, void *arg); //notify callback called by some sub-devices
struct v4l2_ctrl_handler *ctrl_handler; //The control handler. May be %NULL.
struct v4l2_prio_state prio;
struct kref ref; //Keep track of the references to this struct.
void (*release)(struct v4l2_device *v4l2_dev);//Release function that is called when the ref count goes to 0.
};
每一个v4l2 设备都需要对用有一个struct v4l2_device
。 这里需要注意的是成员subdevs
,它用于管理已经注册的各个subdevice。在驱动程序中还经常需要用的是,dev->driver_data 指向了这个结构体。方便通过device 结构体找到此结构体。
enum v4l2_priority {
V4L2_PRIORITY_UNSET = 0, /* not initialized */
V4L2_PRIORITY_BACKGROUND = 1,
V4L2_PRIORITY_INTERACTIVE = 2,
V4L2_PRIORITY_RECORD = 3,
V4L2_PRIORITY_DEFAULT = V4L2_PRIORITY_INTERACTIVE,
};
struct v4l2_prio_state {
atomic_t prios[4];
};
struct v4l2_ctrl_handler {
struct mutex _lock;
struct mutex *lock;
struct list_head ctrls;
struct list_head ctrl_refs;
struct v4l2_ctrl_ref *cached;
struct v4l2_ctrl_ref **buckets;
v4l2_ctrl_notify_fnc notify;
void *notify_priv;
u16 nr_of_buckets;
int error;
};
V4L2设备注册
v4l2_device_register
函数完成对