MMC/SD Memory/SDIO卡mmc子系统驱动架构工作报告
2014-3-11深圳
目标:
分析整理(MMC/SD Memory/SDIO卡)mmc子系统驱动架构;
本文要点:
1、mmc子系统后端初始化相关的数据结构;
2、mmc子系统初始化驱动架构;
3、mmc请求处理;
4、基本的sd协议规范;
SDIO/SD Memory/MMC卡的区别:
●SDIO card is to provide high-speed data I/O with low power consumption for mobile
electronic devices.
●The SDIO (Secure Digital I/O) card is based on and compatible with the SD memory card. This
compatibility includes mechanical, electrical, power, signaling and software.
●SD Memory Card is a memory card that is specifically designed to meet the security,
capacity, performance, and environment requirements inherent in newly emerging audio and video consumer electronic devices.
The SD Memory Card will include a content protection mechanism.The SD Memory Card security system uses mutual authentication and a "new cipher algorithm" to protect against illegal usage of the card content.
A Non-secure access to the user's own content is also available.
●The MMC/eMMC is an universal low cost data storage and communication media. It is
designed to cover a wide area of applications as smart phones, cameras, organizers, PDAs, digital rec
orders, MP3 players, pagers, electronic toys, etc. Targeted features are high mobility and high performance at a low cost price.
These features include low power consumption and high data throughput at the memory card interface.
●SD Memory卡是从MMC卡发展过来的,它更注重内容保护,SD Memory卡在外形上同
MMC卡保持一致,且兼容MMC卡兼容规范.
所以就发展轨道来看,是MMC卡==>SD Memory卡==>SDIO卡,依次兼容,保持一致
硬件图:(以SD 总线为例)
linux版本命令注意:在默认速度下,SD 总线支持单master(application)与多slaves(cards)连接;而在高速和UHS-I(极高速)下,SD 总线只支持单master 与单slave 连接;(经分析:当前linux 版本代码针对的是单master 与单slave 连接模式)
D0-D3, CMD
VSS
VDD CLK
D0-D3, CMD
CLK VDD VSS
CLK VDD VSS D0-D3(A) CMD(A)
D0-D3(B) CMD(B)
SD Memory
Card(B)
SD Memory Card(A)
Host
数据结构
1.初始化:
mmc_card {} .dev ... ... .cid .csd *host ... ...
mmc_host {} *card
.class_dev *ops .disable .detect ... ... .ios *bus_ops
mmc_csd{} .max_dtr .cmdclass .capacity ... ...
mmc_cid{} .manfid ... ...
mmc_host_ops{} *request *set_ios *get_ro ... ...
sdhci_host {} *mmc ... ...
(前端)
gendisk {} *driverfs_dev .major .first_minor ... ...
mmc_bus_type {} *match *probe ... ...
device{} *bus ... ...
mmc_bus_match
mmc_bus_probe device_driver{} *bus ... ...
mmc_driver {} .drv .probe
... ...
mmc_blk_data {} .queue *disk ... ... mmc_queue{}
*card ... ...
(前端)
mmc_ios{} clock vdd bus_mode ... ...
delayed_work{} ... ...
mmc_sd_ops{} mmc_ops{} mmc_sdio_ops{}
其中:*ops :表示对控制器的操作,由前端控制器驱动中设定;
*bus_ops :表示对总线上卡的操作,不同类型总线对应的卡有不同的操作,其中mmc_sd_ops{}, 在mmc_sd_attach_bus_ops()
函数中设置; mmc_sdio_ops{} 在mmc_attach_bus()函数中设置; mmc_ops{} 在mmc_attach_bus_ops 函数中设置;
2.请求处理:
mmc_command {} *data *mrq opcode arg resp[4] flags retries ... ...
mmc_blk_data {}
queue ... ...
mmc_queue {} *data
*queue *thread *issue_fn *sg *req
mmc_data {} *mrq *stop *sg blksz blocks flags ... ...
request_queue {} queue_head *queuedata request {}
queuelist
mmc_blk_request {} mrq data cmd stop
mmc_request {} *cmd *data *stop *done ... ...
task_struct{} ... ...
scatterlist{} ... ...
(块层构建的请求)
request {} queuelist 注1
(当前取出的请求)
(mmc 构建的请求)
(mmc 构建的命令)
注1:不论是块层下发的读写请求,还是源自mmc 核心层要发出的命令,都使用mmc_request {}进行发
送 (原因:保存了所需资源的指针); 注2:有两种命令来源,一种是mmc 核心需要发的命令,一种是块层下发的请求也需要由mmc 为其生成命令。两个都是在mmc 子系统中构建;
注3:mmc 核心需要发的命令,以初始化为目的,不传输数据;由块层下发的请求所生成的命令,以数据读写为目的,要用到mmc_data {};
注2 注3 mmc_request()
数据结构成员:
struct mmc_card {
struct mmc_host *host; /* 隶属的MMC控制器*/
struct device dev; /* 当前设备*/
unsigned int rca; /* 卡地址*/
unsigned int type; /* 卡的类型: 0=MMC 1=SD 2=SDIO*/
unsigned int state; /* 卡状态*/
u32 raw_cid[4]; /* 卡cid,未解码*/
u32 raw_csd[4]; /* 卡csd,未解码*/
u32 raw_scr[2]; /* 卡scr,未解码*/
... ...;
struct mmc_cid cid; /* 卡身份,已解码*/
struct mmc_csd csd; /* 卡的特殊数据,已解码*/
struct sd_scr scr; /* 额外的SD数据,已解码*/
... ...;
};
mmc_card{}代表了一张MMC卡
struct mmc_cid {
unsigned int manfid; /* 制造商id*/
char prod_name[8]; /* 产品名*/
unsigned int serial; /* 产品序列号*/
unsigned short oemid; /* 产品OID*/
... ...
};
struct mmc_csd {
unsigned char mmca_vsn; /*卡版本号*/
unsigned short cmdclass; /* card支持的命令子集*/
unsigned short tacc_clks; /*用于计算读命令的末位和所读数据的首位间的最大时值Nac*/
unsigned int tacc_ns; /*用于计算读命令的末位和所读数据的首位间的最大时值Nac*/
unsigned int max_dtr; /*最大传输速率*/
unsigned int read_blkbits; /*最大的读数据块长度*/
unsigned int write_blkbits; /*最大的写数据块长度*/
unsigned int capacity; /*卡的存储容量*/
unsigned int read_partial:1, /*读小块尺寸数据(最小1byte)是否允许,SD卡恒为1*/
... ...
};
mmc_cid{},mmc_csd{}是MMC卡的CID寄存器与CSD寄存器相关的结构
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论