用于聚合驱动程序的组件助手¶
组件助手允许驱动程序收集一堆子设备,包括它们的绑定驱动程序,到一个聚合驱动程序中。各种子系统已经提供了获取这些组件的函数,例如 of_clk_get_by_name()。当没有这种子系统特定的方式来查找设备时,可以使用组件助手:组件助手填补了特定硬件的聚合驱动程序的空白,而进一步标准化到子系统中是不切实际的。常见的例子是当一个逻辑设备(例如 DRM 显示驱动程序)分布在 SoC 的各种组件(扫描引擎、混合块、各种输出的转码器等等)上时。
组件助手也不能解决运行时依赖关系,例如用于系统挂起和恢复操作。另请参见 设备链接。
组件使用 component_add()
注册,并使用 component_del()
注销,通常来自驱动程序的 probe 和 disconnect 函数。
聚合驱动程序首先使用 component_match_add()
组装它们需要的组件匹配列表。然后使用 component_master_add_with_match()
将其注册为聚合驱动程序,并使用 component_master_del()
注销。
API¶
-
struct component_ops¶
组件驱动程序的回调
定义:
struct component_ops {
int (*bind)(struct device *comp, struct device *master, void *master_data);
void (*unbind)(struct device *comp, struct device *master, void *master_data);
};
成员
bind
当聚合驱动程序准备好绑定整个驱动程序时,通过
component_bind_all()
调用。unbind
当聚合驱动程序准备好绑定整个驱动程序时,通过
component_unbind_all()
调用,或者当component_bind_all()
部分失败并且需要取消绑定一些已经绑定的组件时调用。
描述
组件使用 component_add()
注册,并使用 component_del()
注销。
-
struct component_master_ops¶
聚合驱动程序的回调
定义:
struct component_master_ops {
int (*bind)(struct device *master);
void (*unbind)(struct device *master);
};
成员
bind
当所有组件或聚合驱动程序(如传递给
component_master_add_with_match()
的匹配列表中指定的那样)准备就绪时调用。通常,绑定聚合驱动程序有 3 个步骤为聚合驱动程序分配一个结构。
通过调用
component_bind_all()
,将所有组件绑定到聚合驱动程序,并将聚合驱动程序结构作为不透明指针数据传递。向子系统注册聚合驱动程序以发布其接口。
请注意,聚合驱动程序的生命周期与任何底层
struct device
实例不一致。因此,不能使用 devm,并且在此回调中获取或分配的所有资源必须在 unbind 回调中显式释放。unbind
当聚合驱动程序(使用
component_master_del()
)或其组件之一(使用component_del()
)被注销时调用。
描述
聚合驱动程序使用 component_master_add_with_match()
注册,并使用 component_master_del()
注销。
-
void component_match_add(struct device *parent, struct component_match **matchptr, int (*compare)(struct device*, void*), void *compare_data)¶
添加组件匹配条目
参数
struct device *parent
具有聚合驱动程序的设备
struct component_match **matchptr
指向组件匹配列表的指针
int (*compare)(struct device *, void *)
用于匹配所有组件的比较函数
void *compare_data
传递给 compare 函数的不透明指针
描述
向 matchptr 中存储的列表添加一个新的组件匹配,parent 聚合驱动程序需要该匹配才能正常工作。在添加第一个匹配之前,指向 matchptr 的组件匹配列表必须初始化为 NULL。这仅与使用 component_add()
添加的组件匹配。
matchptr 中分配的匹配列表使用 devm 操作自动释放。
另请参见 component_match_add_release()
和 component_match_add_typed()
。
参数
struct device *dev
组件设备
void *data
来自
component_match_add_release()
的 compare_data
描述
当 compare_data 是设备 of_node 时的通用比较函数。例如 component_match_add_release(masterdev, match
, component_release_of, component_compare_of, component_dev_of_node)
参数
struct device *dev
组件设备
void *data
来自
component_match_add_release()
的 compare_data
描述
关于示例,请参见 component_compare_of()
。
参数
struct device *dev
组件设备
void *data
来自
component_match_add_release()
的 compare_data
描述
当 compare_data 是 struce device 时的通用比较函数。例如 component_match_add(masterdev, match
, component_compare_dev, component_dev)
参数
struct device *dev
组件设备
void *data
来自
component_match_add_release()
的 compare_data
描述
当 compare_data 是设备名称字符串时的通用比较函数。例如 component_match_add(masterdev, match
, component_compare_dev_name, “component_dev_name”)
-
void component_match_add_release(struct device *parent, struct component_match **matchptr, void (*release)(struct device*, void*), int (*compare)(struct device*, void*), void *compare_data)¶
添加具有释放回调的组件匹配条目
参数
struct device *parent
聚合驱动程序的父设备
struct component_match **matchptr
指向组件匹配列表的指针
void (*release)(struct device *, void *)
compare_data 的释放函数
int (*compare)(struct device *, void *)
用于匹配所有组件的比较函数
void *compare_data
传递给 compare 函数的不透明指针
描述
向 matchptr 中存储的列表添加一个新的组件匹配,聚合驱动程序需要该匹配才能正常工作。在添加第一个匹配之前,指向 matchptr 的组件匹配列表必须初始化为 NULL。这仅与使用 component_add()
添加的组件匹配。
matchptr 中分配的匹配列表使用 devm 操作自动释放,其中 release 将被调用以释放 compare_data 持有的任何引用,例如,当 compare_data 是一个 device_node
时,必须使用 of_node_put()
释放。
-
void component_match_add_typed(struct device *parent, struct component_match **matchptr, int (*compare_typed)(struct device*, int, void*), void *compare_data)¶
为类型化的组件添加组件匹配条目
参数
struct device *parent
聚合驱动程序的父设备
struct component_match **matchptr
指向组件匹配列表的指针
int (*compare_typed)(struct device *, int, void *)
用于匹配所有类型化组件的比较函数
void *compare_data
传递给 compare 函数的不透明指针
描述
向 matchptr 中存储的列表添加一个新的组件匹配,聚合驱动程序需要该匹配才能正常工作。在添加第一个匹配之前,指向 matchptr 的组件匹配列表必须初始化为 NULL。这仅与使用 component_add_typed()
添加的组件匹配。
matchptr 中分配的匹配列表使用 devm 操作自动释放。
另请参见 component_match_add_release()
和 component_match_add_typed()
。
-
int component_master_add_with_match(struct device *parent, const struct component_master_ops *ops, struct component_match *match)¶
注册聚合驱动程序
参数
struct device *parent
聚合驱动程序的父设备
const struct component_master_ops *ops
聚合驱动程序的回调
struct component_match *match
聚合驱动程序的组件匹配列表
描述
注册一个新的聚合驱动程序,该驱动程序由通过调用 component_match_add()
函数之一添加到 match 的组件组成。一旦 match 中的所有组件都可用,它将通过从 ops 调用 component_master_ops.bind
来组装。必须通过调用 component_master_del()
来注销。
-
void component_master_del(struct device *parent, const struct component_master_ops *ops)¶
取消注册一个聚合驱动程序
参数
struct device *parent
聚合驱动程序的父设备
const struct component_master_ops *ops
聚合驱动程序的回调
描述
取消注册一个通过 component_master_add_with_match()
注册的聚合驱动程序。如有必要,首先通过调用来自 ops 的 component_master_ops.unbind
来拆卸聚合驱动程序。
参数
struct device *parent
聚合驱动程序的父设备
void *data
不透明指针,传递给所有组件
描述
通过将 data 传递给它们的 component_ops.unbind
函数来解绑聚合设备的所有组件。应从 component_master_ops.unbind
调用。
参数
struct device *parent
聚合驱动程序的父设备
void *data
不透明指针,传递给所有组件
描述
通过将 data 传递给它们的 component_ops.bind
函数来绑定聚合设备 dev 的所有组件。应从 component_master_ops.bind
调用。
-
int component_add_typed(struct device *dev, const struct component_ops *ops, int subcomponent)¶
注册一个组件
参数
struct device *dev
组件设备
const struct component_ops *ops
组件回调
int subcomponent
子组件的非零标识符
描述
为 dev 注册一个新组件。当聚合驱动程序准备好通过调用 component_bind_all()
来绑定整个驱动程序时,将调用 ops 中的函数。另请参见 struct component_ops
。
subcomponent 必须是非零值,用于区分在同一设备 dev 上注册的多个组件。使用 component_match_add_typed()
匹配这些组件。
需要在驱动程序卸载/断开连接时通过调用 component_del()
来取消注册组件。
另请参见 component_add()
。
-
int component_add(struct device *dev, const struct component_ops *ops)¶
注册一个组件
参数
struct device *dev
组件设备
const struct component_ops *ops
组件回调
描述
为 dev 注册一个新组件。当聚合驱动程序准备好通过调用 component_bind_all()
来绑定整个驱动程序时,将调用 ops 中的函数。另请参见 struct component_ops
。
需要在驱动程序卸载/断开连接时通过调用 component_del()
来取消注册组件。
另请参见 component_add_typed()
,它允许在同一设备上存在多个不同的组件。
-
void component_del(struct device *dev, const struct component_ops *ops)¶
取消注册一个组件
参数
struct device *dev
组件设备
const struct component_ops *ops
组件回调
描述
取消注册一个通过 component_add()
添加的组件。如果该组件绑定到聚合驱动程序中,这将强制整个聚合驱动程序(包括其所有组件)被解绑。