####关注一下device_add(&card->dev);会把卡作为一个设备注册,
####这个注册会触发到bus里的match操作,这部分不理解的可以回顾前面讲到的设备模型,
####这里的bus对应mmc,调用的match函数对应于bus.c中
static struct bus_type mmc_bus_type = {
.name = "mmc",
.dev_attrs = mmc_dev_attrs,
.match = mmc_bus_match,
.uevent = mmc_bus_uevent,
.probe = mmc_bus_probe,
.remove = mmc_bus_remove,
.suspend = mmc_bus_suspend,
.resume = mmc_bus_resume,
.pm = MMC_PM_OPS_PTR,
};
/*
* This currently matches any MMC driver to any MMC card - drivers
* themselves make the decision whether to drive this card in their
* probe method.
*/
static int mmc_bus_match(struct device *dev, struct device_driver *drv)
{
return 1;
}
####总为真,那么直接会触发bus的probe操作,
####
static int mmc_bus_probe(struct device *dev)
{
struct mmc_driver *drv = to_mmc_driver(dev->driver);
struct mmc_card *card = mmc_dev_to_card(dev);
return drv->probe(card);
}
####会调用mmc_driver 里的probe,
####这里的mmc_driver就指的是block.c中的mmc_driver,
####还是看一下,这个过程吧,
####drivers/mmc/card/block.c
static int __init mmc_blk_init(void)
{
int res;
if (perdev_minors != CONFIG_MMC_BLOCK_MINORS)
pr_info("mmcblk: using %d minors per device\n", perdev_minors);
max_devices = 256 / perdev_minors;
res = register_blkdev(MMC_BLOCK_MAJOR, "mmc"); //注册mmc块设备,这个后面来讲
if (res)
goto out;
res = mmc_register_driver(&mmc_driver); //重点是这个
if (res)
goto out2;
return 0;
out2:
unregister_blkdev(MMC_BLOCK_MAJOR, "mmc");
out:
return res;
}
#####
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,
};
####在bus.c中
/**
* mmc_register_driver - register a media driver
* @drv: MMC media driver
*/
int mmc_register_driver(struct mmc_driver *drv)
{
drv->drv.bus = &mmc_bus_type;
return driver_register(&drv->drv);
}
####bus类型被指定成了mmc,也就是挂到了mmc上,这样刚才的卡注册默认全部匹配,
####所以也就会直接触发block里的probe,mmc_blk_probe
####下面的东西块设备关联比较多,放到下一章来讲
总结:描述了卡的识别阶段,并没有深入到卡的具体探测,这部分结合前面的协议转换图就不难理解,这部分主要集中在sd到块设备部分的过度
Thanks