/** * 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. Return whether they match * or not. */ static int platform_match( struct device *dev, struct device_driver *drv) {
struct platform_device *pdev = to_platform_device(dev); struct platform_driver *pdrv = to_platform_driver(drv); /* When driver_override is set, only bind to the matching driver */ /* 针对特殊情况,dev中的driver_override被设置,则只匹配和driver_override名字相同的驱动程序 */ if (pdev->driver_override) return !strcmp(pdev->driver_override, drv->name); /* Attempt an OF style match first,设备树方式匹配 */ if (of_driver_match_device(dev, drv)) return 1; /* Then try ACPI style match */ /* 高级配置和电源管理之类的匹配,这里不是我们这次的重点 */ if (acpi_driver_match_device(dev, drv)) return 1; /* Then try to match against the id table */ /* 有驱动中有id_table,则dev中的名字和任何一个id_table里面的值匹配就认为匹配 */ if (pdrv->id_table) return platform_match_id(pdrv->id_table, pdev) != NULL; /* fall-back to driver name match */ /* 驱动和设备的名字匹配 */ return (strcmp(pdev->name, drv->name) == 0); } |