Linux kernel 開發基礎 (三)- 新增platform device

首頁 >> google協作平臺 >> Linux kernel 開發基礎 (三)- 新增platform device

新增platform device

並不複雜,

只需要更改三個地方

1. makefile

根據kconfig的設定,

定義要build的檔案

例如範例中的

obj-$(CONFIG_HELLO_DRIVER) += hello.o

這裡定義了:

CONFIG_HELLO_DRIVER為y

就將hello這個檔案build進kernel

2. kconfig

定義了driver 簡易描述以及預設值,

與makefile一起,

為kernel建立tree管理之用,

在make menuconfig時,

可將該driver相關訊息顯示在視窗界面

config HELLO_DRIVER
    default y
    tristate “Hello Driver”
help
 Say Y here if you want to enable hello driver.

這裡定義了一個新的driver HELLO_DRIVER,,

預設值為y

3. driver本身

static struct platform_driver hello_driver = {
.probe = hello_probe,
.remove = __devexit_p(hello_remove),
.driver = {
.name = “hello”,
.owner = THIS_MODULE,
},
.suspend = hello_suspend,
.resume = hello_resume,
};

driver定義著platform device的功能,

如果還是不是很了解,

可以下載範例程式去build 看看



================================
分享與讚美,是我們繼續打拼的原動力.
若文章對您有幫助,望請不吝按讚或分享.
或者對影片有興趣可以訂閱頻道接收通知
================================
YouTube 頻道
FB 粉絲專頁
================================

guangyaw

重點主題: 程式設計: Python , Django,Android 工具與軟體: Open edX,Linux工具,Blender教學 分享各地美景與產品使用心得,遊戲實況,甚至影視戲劇等, 您的訂閱就是頻道成長的原動力。 YouTube 頻道: https://youtube.com/xyawli

You may also like...

1 Response

  1. 2021-02-06

    […] 新增platform device 範例 是直接向platform bus註冊一個裝置 其他較常見的裝置要註冊也是大同小異, makefile 與 kconfig 寫法是相同的,差異在於在哪個Bus下註冊裝置 […]

發表迴響