在linux核心中,自帶的驅動都以platform
模型的形式設計的。
一般情況下,所有的platform device
在一起定義,並且在一起註冊。
driver
是設計成了不同的原始檔。
因為device
放在一起定義,比較好找,我們可以現在找到device
,再找driver
。
找到針對乙個硬體平台的主初始化原始檔(arch/arm/mach-***x/mach-***x.c
)
如:rkpx3
平台/arch/arm/mach-rkpx3/board-rkpx3-sdk.c
2. 找主初始化原始檔中的機器巨集
3. 找到主初始化函式(kernel
啟動過程中,會呼叫的乙個函式,做嵌入式平台的初始化)
static void __init machine_rk30_board_init(void)
分析platform_add_devices()
int platform_add_devices(struct platform_device **devs, int num)
} return ret;
}
4. 找到platform device
的總表–>devices
static struct platform_device *devices __initdata =
---->條件編譯選項,條件編譯選項在kconfig
中定義,通過make menuconfig
給其賦值,賦值後儲存在.config
中,由makefile
來使用該值,以確定如何編譯驅動程式。
.config
---->在make
過程中,會生成乙個標頭檔案/include/generated/autoconf.h
—>makefile
使用autoconf.h
5. 在總表中,找到platform device
—>
6. 根據platform device
找到platform driver
依據:二者是同名的
static struct platform_driver radio_tea6851a_pdriver = ,
.probe = radio_si4713_pdriver_probe,
.remove = __exit_p(radio_tea6851a_pdriver_remove),
};
分析probe
函式
/* platform driver inte***ce */
/* radio_tea6851a_pdriver_probe - probe for the device */
static int radio_tea6851a_pdriver_probe(struct platform_device *pdev)
rsdev = kzalloc(sizeof *rsdev, gfp_kernel);
if (!rsdev)
printk("v4l2_device_register\n");
rval = v4l2_device_register(&pdev->dev, &rsdev->v4l2_dev);
if (rval)
printk("i2c_get_adapter\n");
adapter = i2c_get_adapter(pdata->i2c_bus);
if (!adapter)
printk("v4l2_i2c_new_subdev_board\n");
sd = v4l2_i2c_new_subdev_board(&rsdev->v4l2_dev, adapter,
pdata->subdev_board_info, null);
if (!sd)
printk("video_device_alloc\n");
rsdev->radio_dev = video_device_alloc();
if (!rsdev->radio_dev)
memcpy(rsdev->radio_dev, &radio_tea6851a_vdev_template,
sizeof(radio_tea6851a_vdev_template));
video_set_drvdata(rsdev->radio_dev, rsdev);
printk("video_register_device\n");
if (video_register_device(rsdev->radio_dev, vfl_type_radio, radio_nr))
dev_info(&pdev->dev, "new device successfully probed\n");
goto exit;
free_vdev:
video_device_release(rsdev->radio_dev);
put_adapter:
i2c_put_adapter(adapter);
unregister_v4l2_dev:
v4l2_device_unregister(&rsdev->v4l2_dev);
free_rsdev:
kfree(rsdev);
exit:
return rval;
}
prob
分析待續。 linux 核心 驅動
首先 1.建立裝置 分配cdev結構體 if globalmem major 手動分配 ret register chrdev region devno,1,globalmem else globalmem 提供給上層使用 2 建立核心裝置 struct globalmem dev globalme...
新增linux核心驅動
1.將核心驅動.ko放入 lib modules 3.2.0 23 generic kernel drivers 目錄下 2.執行depmod a來解決依賴 掃瞄driver下的驅動依賴關係 命令執行完成後,會自動生成modules.dep 和modules.alias。dep為依賴關係。3.更新當...
linux核心驅動 poll waitqueue
在操作io裝置時,讀取裝置狀態或者資料時,如果採用輪詢方式,會占用大量的cpu資源,這種方式肯定是不可取,所以需要在核心驅動支援非同步通知方式,等到裝置準備好,再通知應用程式,其他時間應用程式應當處於休眠狀態,讓出cpu。本篇介紹poll的使用方法。1 首先定義乙個wait queue head t...