先贴出调用拓扑图:
driver_init platform_driver_register if (drv->probe) drv->driver.probe = platform_drv_probe; driver_register bus_add_driver driver_attach bus_for_each_dev(drv->bus, NULL, drv, __driver_attach); // 扫面bus上每个设备,调用__driver_attach driver_probe_device if (drv->bus->match && !drv->bus->match(dev, drv)) // 调用bus->match , bus_type really_probe ret = dev->bus->probe(dev); // 实际上就是驱动程序实现的probe
再看match
platform_driver_register
drv->driver.bus = &platform_bus_type; // platform_bus_type 定义如下
struct bus_type platform_bus_type = { .name = "platform", .dev_attrs = platform_dev_attrs, .match = platform_match, .uevent = platform_uevent, .suspend = platform_suspend, .suspend_late = platform_suspend_late, .resume_early = platform_resume_early, .resume = platform_resume, };
可以看到bus->match 最终就是platform_match
platform_match return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0);
这里就明白了, 实际上, match是根据device 和 driver 的name字段。