【韦东山驱动代码移植高通平台之十九】平台设备通过device tree实现

本文介绍如何使用设备树配置文件来自动创建平台设备,并详细解释了platform_driver中probe函数的作用及其实现方式。通过示例代码展示了compatible属性如何用于匹配设备。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

平台设备通过device tree实现

在设备树的soc节点下添加node

testplat {

compatible = "testfac,plat";

};

机器会根据设备树的节点来自动创建平台设备,platform_driver的driver成员里的of_match_table的compatible成员与设备树里的compatible属性匹配时,就会执行platform_driver里设置的probe函数。

 

参考代码

#include <linux/init.h>
#include <linux/module.h>
#include <linux/major.h>
#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/types.h>
#include <linux/fs.h>
#include <linux/platform_device.h>

#define TAG "testplat"

static int test_plat_probe(struct platform_device *dev)
{
	printk(TAG" FUNC:%s LINE:%d\n", __func__, __LINE__);

	return 0;
}

static const struct of_device_id test_plat_of_match[] = {
	{ .compatible = "testfac,plat", },
	{},
};

static struct platform_driver test_plat_drv = {
	.probe		= test_plat_probe,
	.driver		= {
		.name	= "testplat",
		.owner	= THIS_MODULE,
		.of_match_table = test_plat_of_match,
	},
};

static int test_plat_init(void)
{
	int ret;

	printk(TAG" FUNC:%s LINE:%d\n", __func__, __LINE__);
	ret = platform_driver_register(&test_plat_drv);

	return ret;
}
static void test_plat_exit(void)
{
	printk(TAG" FUNC:%s LINE:%d\n", __func__, __LINE__);

	platform_driver_unregister(&test_plat_drv);
}
module_init(test_plat_init);
module_exit(test_plat_exit);
MODULE_LICENSE("GPL");

执行platform_driver_register时,会优先根据of_match_table里的compatible来匹配平台设备,匹配到的话,执行probe函数。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值