痛苦之旅二:linux总线设备驱动模型之匹配函数

本文深入探讨了Linux中platform device和platform driver的匹配过程,主要关注设备树方式的匹配。介绍了`platform_match`函数及其在设备注册时的角色,以及匹配的四种方式,特别是基于设备树的匹配方法,强调了`of_driver_match_device`函数在匹配过程中的作用和`compatible`属性的比较。
摘要由CSDN通过智能技术生成

本小节想重点说一下platform device和platform driver是如何匹配上的

一. platform_match

函数位置:drivers/base/platform.c

函数描述:platform device平台设备ID按照如下格式:<name><instance>,其中name代表该平台设备类型的简述,例如pci等等;instance为该平台设备的编号,例如0 1 2等等;platform driver平台驱动的ID都是按照name来编排的,所以按照platform的name和driver的name来进行驱动与设备的匹配

函数返回值:返回1表示match上了,0表示没有match上

函数如何被调用:系统为platform bus定义了一个实例叫做platform_bus_type

在系统每次注册一个platform device时,该函数被调用寻找匹配的platform driver;

在系统每次注册一个platform driver时,该函数被调用寻找匹配的platform device

/* @match:	Called, perhaps multiple times, whenever a new device or driver
 *		    is added for this bus. It should return a positive value if the
 *		    given device can be handled by the given driver and zero
 *		    otherwise. It may also return error code if determining that
 *		    the driver supports the device is not possible. In case of
 *		    -EPROBE_DEFER it will queue the device for deferred probing.
 */
struct bus_type platform_bus_type = {
	.name		= "platform", /* The name of the bus */
	.dev_groups	= platform_dev_groups,
	.match		= platform_match, 
	.uevent		= platform_uevent,
	.pm		= &platform_dev_pm_ops,
};
/**
 * platform_match - bind platform device to platform driver.
 * @dev: device.
 * @drv: driver.
 *
 * Platform device IDs are assumed to be encoded like this:
 * "<name><instance>", where <name> is a short description of the type of
 * device, like "pci" or "floppy", and <instance> is the enumerated
 * instance of the device, like '0' or '42'.  Driver IDs are simply
 * "<name>".  So, extract the <name> from the platform_device structure,
 * and compare it against the name of the driver. 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值