一、工作流程
mmc驱动主要文件包括
drivers/mmc/card/block.c
drivers/mmc/card/queue.c
drivers/mmc/core/core.c
drivers/mmc/core/host.c
drivers/mmc/core/
内核启动时,首先执行core/core.c的mmc_init,注册mmc、sd总线,以及一个host class设备。接着执行card/block.c中,申请一个块设备。
二、数据结构:
这里涉及三种总线
- 1. platform bus //MMC host controller 作为一种 platform device, 它是需要注册到 platform bus上 的
- driver/base/platform.c
- struct bus_type platform_bus_type = {
- .name = "platform",
- .dev_attrs = platform_dev_attrs,
- .match = platform_match,
- .uevent = platform_uevent,
- .pm = &platform_dev_pm_ops,
- };
- 2. mmc bus type //在mmc_init()中被创建的.通过调用 mmc_register_bus() 来注册 MMC 总线
- drivers\mmc\core\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,
- .shutdown = mmc_bus_shutdown,
- .pm = &mmc_bus_pm_ops,
- };
- 3. sdio bus type //在mmc_init()中被创建的.通过调用sdio_register_bus() 来注册 SDIO 总线
- drivers\mmc\core\sdio_bus.c
- static struct bus_type sdio_bus_type = {
- .name = "sdio",
- .dev_attrs = sdio_dev_attrs,
- .match = sdio_bus_match,
- .uevent = sdio_bus_uevent,
- .probe = sdio_bus_probe,
- .remove = sdio_bus_remove,
- .pm = SDIO_PM_OPS_PTR,
- };
- //总线操作结构
- struct mmc_bus_ops {
- void (*remove)(struct mmc_host *);
- void (*detect)(struct mmc_host *);
- int (*sysfs_add)(struct mmc_host *, struct mmc_card *card);
- void (*sysfs_remove)(struct mmc_host *, struct mmc_card *card);
- void (*suspend)(struct mmc_host *);
- void (*resume)(struct mmc_host *);
- };
- // mmc卡的总线操作 core/mmc.c
- static const struct mmc_bus_ops mmc_ops = {
- .remove = mmc_remove,
- .detect = mmc_detect,
- .sysfs_add = mmc_sysfs_add,
- .sysfs_remove = mmc_sysfs_remove,
- .suspend = mmc_suspend,
- .resume = mmc_resume,
- };
- // sd卡的总线操作 core/sd.c
- static const struct mmc_bus_ops mmc_sd_ops = {
- .remove = mmc_sd_remove,
- .detect = mmc_sd_detect,
- .sysfs_add = mmc_sd_sysfs_add,
- .sysfs_remove = mmc_sd_sysfs_remove,
- .suspend = mmc_sd_suspend,
- .resume = mmc_sd_resume,
- };
- // sdio的总线操作 core/sdio.c
- static const struct mmc_bus_ops mmc_sdio_ops = {
- .remove = mmc_sdio_remove,
- .detect = mmc_sdio_detect,
- };
关于总线操作的函数:
.detect,驱动程序经常需要调用此函数去检测mmc卡的状态,具体实现是发送CMD13命令,并读回响应,如果响应错误,则依次调用.remove、detach_bus来移除卡及释放总线。
三、总体架构
1、kernel启动时,先后执行mmc_init()及mmc_blk_init(),以对mmc设备及mmc块模块进行初始