可
见,这里也会调用mmc_detect_change。。。我们跟着前面的分析来到mmc_setup这里,此时mmc_setup调用
mmc_discover_cards。Create a mmc_card entry for each discovered card,add
new card to
list.同时还会调用mmc_read_switch_caps或者mmc_process_ext_csds来实现对大容量卡的支持(>4G)
跟着程序的流程我们来到
if (!mmc_card_present(card) && !mmc_card_dead(card)) {
if (mmc_register_card(card))
来看
int
mmc_register_card(struct
mmc_card *
card) { int
ret;
/*
* Set the read-only status based on the supported commands
* and the write protect switch.
*/
md->
read_only =
mmc_blk_readonly(
card);//写保护
/*
* Both SD and MMC specifications state (although a bit
* unclearly in the MMC case) that a block size of 512
* bytes must always be supported by the card.
*/
md->
block_bits =
9;//块大小
md->
disk =
alloc_disk(
1 <<
MMC_SHIFT); //分配struct gendist,驱动程序不能自己动态分配该结构,而是必须调用
//alloc_disk,其参数为次设备号数目,注意了,是次设备号数目,不是次设备号
if(
md->
disk ==NULL){
ret =-
ENOMEM; goto
err_kfree; }
spin_lock_init(&
md->
lock);
md->
usage =
1;
ret =
mmc_init_queue(&
md->queue,
card,&
md->
lock);//
/*
* As discussed on lkml, GENHD_FL_REMOVABLE should:
*
* - be set for removable media with permanent block devices
* - be unset for removable block devices with permanent media
*
* Since MMC block devices clearly fall under the second
* case, we do not set GENHD_FL_REMOVABLE. Userspace
* should use the block device creation/destruction hotplug
* messages to tell when the card is present.
*/
/*
* The CSD capacity field is in units of read_blkbits.
* set_capacity takes units of 512 bytes.
*/
set_capacity(
md->
disk,
card->
csd.
capacity <<(
card->
csd.
read_blkbits -
9)); return
md;