淺析Linux下sdio介面對sd卡硬體檢測流程
static struct pxamci_platform_data luther_mci_platform_data = {
.detect_delay = 20,//檢測到sd裝置插入之後,延時detect_delay個tick之後,執行函數
.ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
.init = luther_mci_init,
.setpower = luther_mci_setpower,
.exit = luther_mci_exit,
};
在luther_init()->
//luther_mmc_slot[0].gpio_cd = mfp_to_gpio(MFP_CFG_PIN(GPIO8_GPIO_MMC_DETECT));
所以設定GPIO8作為sd卡插入的中斷檢測IO
//pxamci_probe()->該函數是和platform的裝置匹配上之後,會立即調用的probe
//host->pdata->init(&pdev->dev, pxamci_detect_irq, mmc); 將mmc作為devid的傳遞參數
//就是調用裝置函數luther_mci_platform_data->luther_mci_init()
//request_irq(cd_irq, luther_detect_int,IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,"MMC card detect", data);
//這樣將中斷註冊到了物理硬體系統
當GPIO8檢測到電平變化,將觸發pxamci_detect_irq()中斷處理函數,
該函數會繼續調用mmc_detect_change()->mmc_schedule_delayed_work(&host->detect, delay);調度該host的自動檢測函數
對於host->detect的初始化是這樣完成的:
pxamci_probe()->mmc_alloc_host()申請平台SD單元對應的mmc_host結構體->
INIT_DELAYED_WORK(&host->detect, mmc_rescan)建立該平台SD單元對應的sdio裝置插入
檢測核心work_queue工作隊列函數mmc_rescan->mmc_rescan()這是一個共用函數,如果有4個SD卡控制器在你的arm平台上,
那麼4個SD控制器將分別對應4個mmc_host結構體,分別對應4個sdio裝置插入檢測核心work_queue工作隊列,
但工作隊列都將調用mmc_rescan()這1個函數,所以linux核心的物件導向的類共用機製做得很好->
使用mmc_alloc_host()函數申請的平台mmc_host結構體,沒有對其分配bus匯流排指標,僅分配了它所屬的parent,即這個
mmc不屬於某個bus,所以這個mmc_host對應的dev也不會從任何bus匯流排上分配到任何driver驅動,這也是應該的.
mmc_attach_sdio()->mmc_attach_bus(host, &mmc_sdio_ops);
mmc_sdio_init_card()->sdio_init_func()->sdio_alloc_func()->這樣當detect到sdio裝置之後,
將分配dev對應的sdio_func結構題,
調用sdio_read_func_cis()的cistpl_manfid()來填充sd卡的vendor,這樣當wlan驅動probe的時候,
就會和wlan驅動的id表中的vendor嘗試匹配,如果成功,那麼wlan驅動將接管該檢測到的sd卡[gliethttp_20080626].