生活随笔
收集整理的這篇文章主要介紹了
SD卡驱动分析(二)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
三.下面分析一下高通的android2.3的代碼中SD卡驅(qū)動(dòng)的流程。
? ? ? ? ??在kernel中,SD卡是作為平臺(tái)設(shè)備加入到內(nèi)核中去的,在/kernel/arch/arm/mach-msm/devices-msm7627a.c中:
[cpp]?view plaincopy
static?void?__init?msm7x2x_init(void)?? ??->?static?void?__init?msm7x27a_init_mmc(void)?? ???????->?msm_add_sdcc(1,?&sdc1_plat_data);??? ????????????->?pdev?=?msm_sdcc_devices[controller-1];?? ???????????pdev->dev.platform_data?=?plat;?? ???????????return?platform_device_register(pdev);????
? ??
? ? ? ? ??同時(shí)KERNEL啟動(dòng)的過程中在kernel/drivers/mmc/core/core.c文件內(nèi)會(huì)調(diào)用static int __init mmc_init(void)函數(shù):
[cpp]?view plaincopy
static?int?__init?mmc_init(void)?? ??->?ret?=?mmc_register_bus();?? ?????ret?=?mmc_register_host_class();?? ?????ret?=?sdio_register_bus();??
? ??
? ??在/kernel/drivers/mmc/card/block.c中調(diào)用:
[cpp]?view plaincopy
static?int?__init?mmc_blk_init(void)?? ??->res=register_blkdev(MMC_BLOCK_MAJOR,"mmc");????? ????res?=?mmc_register_driver(&mmc_driver);???
? ? 在kernel/drivers/mmc/host/msm_sdcc.c文件中調(diào)用static int__init msmsdcc_init(void),向內(nèi)核中注冊(cè)struct platform_driver msmsdcc_driver,這個(gè)platform_driver,與之前注冊(cè)的platform_devices相匹配后調(diào)用probe函數(shù):
[cpp]?view plaincopy
static?int?msmsdcc_probe(struct?platform_device?*pdev)?? ??->?struct?mmc_platform_data?*plat?=?pdev->dev.platform_data?? ?????for?(i?=?0;?i?<?pdev->num_resources;?i++)??? ?????mmc=mmc_alloc_host(sizeof(struct?msmsdcc_host),?&pdev->dev);??? ?????host?=?mmc_priv(mmc);?? ?????host->mmc?=?mmc;????
? ? 然后我們來分析剛才提到的mmc_alloc_host函數(shù):
[cpp]?view plaincopy
<p>struct?mmc_host?*mmc_alloc_host(int?extra,?structdevice?*dev)</p><p>?->?struct?mmc_host*host;</p><p>????host?=kzalloc(sizeof(struct?mmc_host)?+?extra,?GFP_KERNEL);??
? ?
? ?還記得之前在msm_sdcc.c中的msmsdcc_probe函數(shù)快結(jié)束的時(shí)候有mmc_add_host(mmc)這樣一個(gè)函數(shù)嗎?下面我們就來分析這個(gè)函數(shù):
[cpp]?view plaincopy
int?mmc_add_host(struct?mmc_host?*host)?? ?->?err?=?device_add(&host->class_dev);?? ?????->?dev_set_name(dev,?"%s",?dev->init_name);?? ????????error?=?device_create_file(dev,?&uevent_attr);?? ????????error?=?bus_add_device(dev);?? ?????????? ????mmc_start_host(host);?? ?????->?mmc_power_off(host);?? ?????????->?mmc_set_ios(host);?? ?????????????->?host->ops->set_ios(host,?ios);?? ????mmc_detect_change(host,?0);?? ??????->?mmc_schedule_delayed_work(&host->detect,?delay);???
? ? 好了,剛才說了很多的mmc_rescan函數(shù)也等不及了,快來一睹它的真容吧:
[cpp]?view plaincopy
void?mmc_rescan(struct?work_struct?*work)?? ??->?struct?mmc_host?*host?=?container_of(work,?struct?mmc_host,?detect.work);?? ?????if?(host->bus_ops?&&?host->bus_ops->detect?&&?!host->bus_dead?&&?!(host->caps?&?MMC_CAP_NONREMOVABLE))??? ?????mmc_rescan_try_freq(host,?host->f_min)?? ??????->?mmc_power_up(host);?? ?????????sdio_reset(host)?? ?????????mmc_go_idle(host)?? ??????????->?cmd.opcode?=?MMC_GO_IDLE_STATE?? ?????????mmc_send_if_cond(host,?host->ocr_avail)?? ??????????->?cmd.opcode?=?SD_SEND_IF_COND?? ?????????if?(!mmc_attach_sdio(host))?? ?????????if?(!mmc_attach_sd(host))?? ?????????if?(!mmc_attach_mmc(host))???
? ? 下面以mmc_attach_sd為例來分析:
[cpp]?view plaincopy
int?mmc_attach_sd(struct?mmc_host?*host)?? ??->?err?=?mmc_send_app_op_cond(host,?0,?&ocr)???? ?????mmc_sd_attach_bus_ops(host)??? ??????->?bus_ops?=?&mmc_sd_ops??? ?????mmc_sd_init_card(host,?host->ocr,?NULL)?? ???????->?err?=?mmc_sd_get_cid(host,?ocr,?cid,?&rocr)?? ???????????->?err?=?mmc_all_send_cid(host,?cid)??? ??????????card?=?mmc_alloc_card(host,?&sd_type)??? ??????????mmc_send_relative_addr(host,?&card->rca)?? ??????????err?=?mmc_sd_get_csd(host,?card)??? ??????????err?=?mmc_select_card(card)??? ??????????err?=?mmc_sd_setup_card(host,?card,?oldcard?!=?NULL)??? ???????????->?err?=?mmc_app_send_scr(card,?card->raw_scr)?? ??????????????if?(host->ops->get_ro)??? ??????????err?=?mmc_app_set_bus_width(card,?MMC_BUS_WIDTH_4)???
? ? 到此為止,就完成了整個(gè)SD卡起動(dòng)初始化的過程,在啟動(dòng)初始化完成之后,以后系統(tǒng)要調(diào)用SD卡的相動(dòng),都會(huì)通過之前注冊(cè)的塊設(shè)備來一步步的向下調(diào)用。
總結(jié)
以上是生活随笔為你收集整理的SD卡驱动分析(二)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。