平台裝置驅動框架一

2021-08-18 14:40:52 字數 1466 閱讀 2888

//platform_driver.c

#include #include module_license("gpl");

int hello_probe(struct platform_device *dev)

int hello_remove(struct platform_device *dev)

struct platform_driver hello_driver = ,

};int hello_init(void)

void hello_exit(void)

module_init(hello_init);

module_exit(hello_exit);

//platform_device.c

#include #include module_license("gpl");

void hello_release(struct device *dev)

struct platform_device hello_device = ,

};int hello_init(void)

void hello_exit(void)

module_init(hello_init);

module_exit(hello_exit);

除了靠上面的.name匹配,驅動和裝置還可以通過.compatible匹配(另外裝置也可以通過裝置樹去配置,而不需要像上面一樣寫乙個platform_device.c。裝置樹去配置裝置是很方便的,不像platform_device.c那樣光寫個框架就需要很多diamagnetic,所以以後盡量使用裝置樹),比如按鍵驅動kernel\drivers\input\keyboard\gpio_keys.c下按鍵驅動的定義:

static struct of_device_id gpio_keys_of_match = ,

{},

}; static struct platform_driver gpio_keys_device_driver = ,

}; static int __init gpio_keys_init(void)

late_initcall(gpio_keys_init);

這裡按驅動name為gpio-keys,裝置樹按鍵這個裝置節點名字也要是一樣的

&soc ; 

}; };

裝置樹中的每乙個代表了乙個裝置的節點都要有乙個compatible屬性。compatible是系統用來決定繫結到裝置的裝置驅動的關鍵。compatible屬性是用來查詢節點的方法之一,另外還可以通過節點名或節點路徑查詢指定節點。

系統初始化時會初始化platform匯流排上的裝置(按鍵驅動表現為platform驅動),根據裝置節點"compatible"屬性和驅動中of_match_table對應的值,匹配了就載入對應的驅動

平台裝置驅動框架

框架入口原始檔 led drv.c led dev.c 可根據入口原始檔,再按著框架到核心走一遍 核心版本 linux 2.6.22.6 硬體平台 jz2440 以下是驅動框架 以下是驅動 led dev.c include include include include include inclu...

Linux misc裝置(一)misc驅動框架

copy from 文章目錄 linux misc裝置 一 misc驅動框架 一 misc簡介 二 misc驅動框架 三 misc原始碼剖析 四 misc裝置例項驅動編寫模板 一 misc簡介 linux的驅動設計是趨向於分層的,大多數裝置都有自己歸屬的型別,例如按鍵 觸控螢幕屬於輸入裝置,linu...

platform裝置驅動框架

這裡簡單總結下platform匯流排的裝置驅動 的框架。1 建立資料夾platform 2 在資料夾下編寫裝置檔案device.c include include include include include include module author wjb module license dua...