一、注冊平臺設備
platform_device_register(&usr_mci_device);
二、填寫平臺設備結構體
static struct platform_device usr_mci_device= {
.name????????? = "xxx",
.id???????????? = 0,
.dev = {
.release???? = usr_mci_platdev_release,
.dma_mask? = &usr_mmc_dmamask,
.coherent_dma_mask = DMA_BIT_MASK(32),
},
.num_resources? ? = ARRAY_SIZE(usr_mci_resources),
.resource???? ???? = usr_mci_resources,
};
三、填寫資源結構體(物理地址查芯片手冊)
static struct resource usr_mci_resources[] = {
[0] = {
.start????????? = CONFIG_USR_IOBASE,
.end??????????? = CONFIG_USR_IOBASE + USR_MCI_IO_SIZE - 1,
.flags????????? = IORESOURCE_MEM,
},
[1] = {
.start????????? = CONFIG_USR_INTR,
.end??????????? = CONFIG_USR_INTR,
.flags????????? = IORESOURCE_IRQ,
},
};
四、注冊平臺驅動
platform_driver_register(&usr_mci_driver);
五、填寫平臺驅動結構體
static struct platform_driver usr_mci_driver= {
.probe = usr_mci_probe,
.remove = usr_mci_remove,
.suspend = usr_mci_suspend,
.resume = usr_mci_resume,
.driver = {
.name = DRIVER_NAME,
},
};
六、重寫probe函數
static int __devinit usr_mci_probe(struct platform_device *pdev)
七、創建一個自己的設備結構體
struct usr_host {
struct mmc_host*mmc;
spinlock_tlock;
struct mmc_request*mrq;
struct mmc_command*cmd;
struct mmc_data*data;
void __iomem*base;
unsigned intcard_status;
struct scatterlist*dma_sg;
unsigned intdma_sg_num;
unsigned intdma_alloc_size;
unsigned intdma_dir;
dma_addr_tdma_paddr;
unsigned int*dma_vaddr;
struct timer_listtimer;
unsigned intirq;
unsigned intirq_status;
unsigned intis_tuning;
wait_queue_head_tintr_wait;
unsigned longpending_events;
unsigned intid;
};
struct usr_host?*host;
八、分配一個包含了mmc_host的自定義結構體(core需要)
struct?mmc_host *mmc;
mmc = mmc_alloc_host(sizeof(struct usr_host), &pdev->dev);
九、初始化mmc_host結構體
mmc->ops
mmc->f_min
mmc->f_max
mmc->caps
mmc->max_blk_count
mmc->max_segs
mmc->max_seg_size
mmc->max_req_size
mmc->ocr_avail
mmc->ocr
十、初始化usr_host
host=mmc->private;
host->dma_vaddr =?dma_alloc_coherent(&pdev->dev, PAGE_SIZE,&host->dma_paddr, GFP_KERNEL);
host->mmc = mmc;
host->id
host->base
十一、初始化SDIO的時鐘、驅動能力
十二、SDIO復位
十三、SDIO重上電
十四、設置時鐘相位
十五、設置閾值
十六、設置中斷狀態
十七、設置中斷屏蔽
十八、設置DMA搬移數據
十九、設置全局中斷使能
二十、設置FIFO突發長度與FIFO大小
二十一、卡檢測
二十二、初始化定時器,定時處理函數為卡檢測
二十三、獲取資源結構體的軟中斷號
二十四、初始化等待隊列
init_waitqueue_head(&host->intr_wait);
二十五、request_irq注冊中斷
二十六、寫中斷函數(喚醒等待隊列)
static irqreturn_t usr_irq(int irq, void *dev_id)
{
wake_up(&host->intr_wait);
}