介绍
日期 | 作者 | 说明 |
---|---|---|
2024/04/07 | Manfredxxc | 初版 |
内核版本:kernel-4.1.15
在v4l2框架里,若直接注册v4l2设备和子设备的话,需要保证v4l2设备在子设备之前注册。
v4l2_async_notifier
就是用来解耦这种先后依赖关系的
数据结构简要说明
首先介绍两个全局链表:
subdev_list
:全局子设备链表,代表待注册到v4l2设备上的子设备们notifier_list
:全局v4l2_async_notifier
链表
struct v4l2_async_subdev
表示一个异步子设备,支持四种匹配方式custom、devname、i2c、of
struct v4l2_async_subdev {
enum v4l2_async_match_type match_type;
union {
struct {/* ... */} of;
struct {/* ... */} device_name;
struct {/* ... */} i2c;
struct {/* ... */} custom;
} match;
/* v4l2-async core private: not to be used by drivers */
struct list_head list; // 链接到v4l2异步通知器的等待链表上
};
v4l2_async_notifier
表示一个v4l2异步通知器
struct v4l2_async_notifier {
unsigned int num_subdevs; // 子设备数量
struct v4l2_async_subdev **subdevs; // asd(异步子设备)数组
struct v4l2_device *v4l2_dev; // 绑定的v4l2设备
struct list_head waiting; // asd(异步子设备链表):等待驱动注册
struct list_head done; // sd(子设备)链表:子设备驱动已成功注册
struct list_head list; // 全局通知器的链表成员
// 子设备驱动成功探测一个子设备
int (*bound)(struct v4l2_async_notifier *notifier, struct v4l2_subdev *subdev, struct v4l2_async_subdev *asd);
// 所有子设备都成功探测
int (*complete)(struct v4l2_async_notifier *notifier);
// 一个子设备正在接触绑定
void (*unbind)(struct v4l2_async_notifier *notifier, struct v4l2_subdev *subdev, struct v4l2_async_subdev *asd);
};
API简要说明
v4l2_async_notifier_register
- 描述:为v4l2设备注册v4l2异步通知器,用于子设备异步注册
- 原型:
int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev, struct v4l2_async_notifier *notifier)
- 详情:
- 添加
@notifier->subdevs
中符合匹配类型的asd到@notifier->waiting
- 添加
@notifier
到全局v4l2异步通知器链表:notifier_list
- 匹配全局子设备链表:
subdev_list
和@notifier->waiting
,如果有asd和subdev匹配上,则注册相应的子设备到v4l2设备上
- 添加
v4l2_async_register_subdev
- 描述:在全局v4l2异步通知器链表上匹配asd,有则注册,无则将该子设备加入到全局子设备链表上留待后续匹配注册
- 原型:
int v4l2_async_register_subdev(struct v4l2_subdev *sd)