* ioctl callbacks */
const struct v4l2_ioctl_ops *ioctl_ops;
DECLARE_BITMAP(valid_ioctls, BASE_VIDIOC_PRIVATE);
/* serialization lock */
DECLARE_BITMAP(disable_locking, BASE_VIDIOC_PRIVATE);
struct mutex *lock;
};
3. V4L2_device结构体:
这个结构体中包含了一个非常重要的结构体v4l2_device
:
struct v4l2_device {
/* dev->driver_data points to this struct.
Note: dev might be NULL if there is no parent device
as is the case with e.g. ISA devices. */
struct device *dev;
#if defined(CONFIG_MEDIA_CONTROLLER)
struct media_device *mdev;
#endif
/* used to keep track of the registered subdevs */
struct list_head subdevs;
/* lock this struct; can be used by the driver as well if this
struct is embedded into a larger struct. */
spinlock_t lock;
/* unique device name, by default the driver name + bus ID */
char name[V4L2_DEVICE_NAME_SIZE];
/* notify callback called by some sub-devices. */
void (*notify)(struct v4l2_subdev *sd,
unsigned int notification, void *arg);
/* The control handler. May be NULL. */
struct v4l2_ctrl_handler *ctrl_handler;
/* Device's priority state */
struct v4l2_prio_state prio;
/* BKL replacement mutex. Temporary solution only. */
struct mutex ioctl_lock;
/* Keep track of the references to this struct. */
struct kref ref;
/* Release function that is called when the ref count goes to 0. */
void (*release)(struct v4l2_device *v4l2_dev);
};
3.1 v4l2_device的注册和注销:
int v4l2_device_register(struct device*dev, struct v4l2_device *v4l2_dev)
static void v4l2_device_release(struct kref *ref)
4. v4l2_subdev结构体
V4l2_subdev代表子设备,包含了子设备的相关属性和操作。先来看下结构体原型:
struct v4l2_subdev {
struct v4l2_device *v4l2_dev; //指向父设备
//提供一些控制v4l2设备的接口
const struct v4l2_subdev_ops *ops;
//向V4L2框架提供的接口函数
const struct v4l2_subdev_internal_ops *internal_ops;
//subdev控制接口
struct v4l2_ctrl_handler *ctrl_handler;
/* name must be unique */
charname[V4L2_SUBDEV_NAME_SIZE];
/*subdev device node */
struct video_device *devnode;
};
其中 list 域作为链表节点链接至 v4l2_dev 指向的 v4l2_device 结构中,这个结构中最重要的成员就是 struct v4l2_subdev_ops *ops,该域包含了 v4l2 设备支持的所有操作,定义如下:
struct v4l2_subdev_ops {
const struct v4l2_subdev_core_ops *core; /* 通用操作合集 */
const struct v4l2_subdev_tuner_ops *tuner; /* 调谐器操作合集 */
const struct v4l2_subdev_audio_ops *audio; /* 音频操作合集 */
const struct v4l2_subdev_video_ops *video; /* 视频操作合集 */
};
v4l2_subdev_core_ops 包含的操作合集是各种类型设备通用的:
struct v4l2_subdev_core_ops {
int (*g_chip_ident)(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip); /* 获取设备id */
int (*log_status)(struct v4l2_subdev *sd); /* 状态消息 */
int (*s_config)(struct v4l2_subdev *sd, int irq, void *platform_data); /* 设置配置信息 */
int (*init)(struct v4l2_subdev *sd, u32 val); /* 初始化设备 */
int (*load_fw)(struct v4l2_subdev *sd); /* 加载firmware */
int (*reset)(struct v4l2_subdev *sd, u32 val); /* 重置设备 */
int (*s_gpio)(struct v4l2_subdev *sd, u32 val); /* 设置gpio */
int (*queryctrl)(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc); /* 查询设备支持的操作 */
int (*g_ctrl)(struct v4l2_subdev *sd, struct v4l2_control *ctrl); /* 获取当前命令值 */
int (*s_ctrl)(struct v4l2_subdev *sd, struct v4l2_control *ctrl); /* 设置当前命令值 */
int (*g_ext_ctrls)(struct v4l2_subdev *sd, struct v4l2_ext_controls *ctrls); /* 获取外置命令值 */
int (*s_ext_ctrls)(struct v4l2_subdev *sd, struct v4l2_ext_controls *ctrls); /* 设置外置命令值 */
int (*try_ext_ctrls)(struct v4l2_subdev *sd, struct v4l2_ext_controls *ctrls);
int (*q