//linux在注册平台drivers时,platform driver是如何与platform device配对的呢?
platform_driver_register(struct platform_driver *drv)
{
drv->driver.bus = &platform_bus_type;//注释1
driver_register(struct device_driver * drv)
{
bus_add_driver(struct device_driver *drv)
{
driver_attach(struct device_driver * drv)
{
return bus_for_each_dev(drv->bus, NULL, drv, __driver_attach);
}
}
}
}
bus_for_each_dev内部会调用__driver_attach
static int __driver_attach(struct device * dev, void * data)
{
struct device_driver * drv = data;
if (!dev->driver)
driver_probe_device(drv, dev)
{
if (drv->bus->match && !drv->bus->match(dev, drv))
}
}
由上面的调用可知,在注册platform driver时,最终调用drv->bus->match函数确定driver与device是否可以配对。而drv->bus->match是哪个函数呢?由注释1可知,drv->bus = &platform_bus_type,
所以drv->bus->match即platform_bus_type.match,即
static int platform_match(struct device * dev, struct device_driver * drv)//在platform.c中
{
struct platform_device *pdev = container_of(dev, struct platform_device, dev);
return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0);
}
是否配对,是通过比较platform_device.name与platform_driver.driver.name。
阅读(3344) | 评论(0) | 转发(0) |