用於聚合驅動程式的元件助手¶
元件助手允許驅動程式收集一堆子裝置,包括它們的繫結驅動程式,到一個聚合驅動程式中。各種子系統已經提供了獲取這些元件的函式,例如 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() 新增的元件。如果該元件繫結到聚合驅動程式中,這將強制整個聚合驅動程式(包括其所有元件)被解綁。