linux 設備驅動文件在與 dts 中的設備板級硬件信息匹配的關鍵字是 compatible 屬性。即比較驅動文件中 of_device_id 結構體元素的 .compatible 成員變量和 dts 文件中 node 中 compatible 屬性兩個字符串。
Rationale:
linux 啟動從 lk jump 到 kernel 之后
函數調用的深度比較深所以圖比較長,其中細節部分省略,可以打開具體源碼去看。
可以看到最后調用的函數
static inline int of_driver_match_device(struct device *dev,const struct device_driver *drv) --->of_match_device(drv->of_match_table, dev) != NULL; --->of_match_node(matches, dev->of_node) --->__of_match_node(matches, node) --->static const struct of_device_id *__of_match_node(const struct of_device_id *matches, const struct device_node *node) { const struct of_device_id *best_match = NULL; int score, best_score = 0; if (!matches) return NULL; for (; matches->name[0] || matches->type[0] || matches->compatible[0]; matches++) { //此函數將driver的of_match_table->compatible和node中的compatible比較 score = __of_device_is_compatible(node, matches->compatible, matches->type, matches->name); if (score > best_score) { best_match = matches; best_score = score; } } return best_match; }
傳遞到最后__of_device_is_compatible函數將driver的of_match_table->compatible和node中的compatible比較,這個比較不是單純的比較,是一種加分制。
匹配成功之后會進行probe,如果driver 的 probe 執行不成功(比如硬件問題,或者沒有掛載設備),會調用sys系列函數進行驅動卸載。
原文鏈接:https://blog.csdn.net/sinat_30545941/article/details/85943787
