本小节想重点说一下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.