bbb 的 emmc驱动在drivers\mmc\card\block.c,其mmc_dirver结构体如下,
根据以往平台总线驱动模型的经验来看的话,内核里应该有mmc_devices结构体,并且
其name也为"mmcblk",这样其probe函数将被调用,但是搜索整个内核文件并没有发现mmc_devices。
现在我们分析一下mmc_blk_probe什么时候被调用。
static struct mmc_driver mmc_driver = {
.drv= {.name = "mmcblk",
},
.probe = mmc_blk_probe,
.remove = mmc_blk_remove,
.suspend = mmc_blk_suspend,
.resume = mmc_blk_resume,
};
static int __init mmc_blk_init(void) //drivers\mmc\card\block.c
{
res = mmc_register_driver(&mmc_driver); //注册mmc_driver
}
int mmc_register_driver(struct mmc_driver *drv) //drivers\mmc\core\bus.c
{
drv->drv.bus = &mmc_bus_type; //mmc设备是挂载在mmc总线上的
return driver_register(&drv->drv); //注册mmc驱动
}
int driver_register(struct device_driver *drv) //drivers\base\driver.c
{
other = driver_find(drv->name, drv->bus); //在总线上查找是否已经注册过此驱动
if (other) {
put_driver(other);
printk(KERN_ERR "Error: Driver '%s' is already registered, "
"aborting...\n", drv->name);
return -EBUSY;
}
ret = bus_add_driver(drv); //如果没有注册过,则注册此驱动
}
int bus_add_driver(struct device_driver *drv) //drivers\base\bus.c
{
error = driver_attach(drv);
error = driver_create_file(drv, &driver_attr_uevent);
}
//try to bind driver to devices
int driver_attach(struct device_driver *drv) //drivers/base/dd.c
{
return bus_for_each_dev(drv->bus, NULL, drv, __driver_attach);
//__driver_attach的里面device的查找还没搞清楚
}
static int __driver_attach(struct device *dev, void *data) //drivers/base/dd.c
{
if (!driver_match_device(drv, dev))
return 0;
driver_probe_device(drv, dev);
}
static inline int driver_match_device(struct device_driver *drv, //drivers/base/base.h
struct device *dev)
{
//这里调用了mmc总线的match函数
return drv->bus->match ? drv->bus->match(dev, drv) : 1;
}
static int mmc_bus_match(struct device *dev, struct device_driver *drv) //drivers\mmc\core\bus.c
{
//mmc总线的match直接返回了1
return 1;
}
int driver_probe_device(struct device_driver *drv, struct device *dev) //drivers/base/dd.c
{
really_probe(dev, drv);
}
static int really_probe(struct device *dev, struct device_driver *drv) //drivers/base/dd.c
{
dev->bus->probe(dev); //这里调用总线的probe函数
}
static int mmc_bus_probe(struct device *dev) //drivers\mmc\core\bus.c
{
return drv->probe(card); //最终mmc总线的probe函数调用mmc_driver的probe函数
}