一、注冊平臺設備
platform_device_register(&usr_mci_device);
二、填寫平臺設備結(jié)構(gòu)體
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,
};
三、填寫資源結(jié)構(gòu)體(物理地址查芯片手冊)
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,
},
};
四、注冊平臺驅(qū)動
platform_driver_register(&usr_mci_driver);
五、填寫平臺驅(qū)動結(jié)構(gòu)體
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函數(shù)
static int __devinit usr_mci_probe(struct platform_device *pdev)
七、創(chuàng)建一個自己的設備結(jié)構(gòu)體
struct usr_host {
struct mmc_host *mmc;
spinlock_t lock;
struct mmc_request *mrq;
struct mmc_command *cmd;
struct mmc_data *data;
void __iomem *base;
unsigned int card_status;
struct scatterlist *dma_sg;
unsigned int dma_sg_num;
unsigned int dma_alloc_size;
unsigned int dma_dir;
dma_addr_t dma_paddr;
unsigned int *dma_vaddr;
struct timer_list timer;
unsigned int irq;
unsigned int irq_status;
unsigned int is_tuning;
wait_queue_head_t intr_wait;
unsigned long pending_events;
unsigned int id;
};
struct usr_host?*host;
八、分配一個包含了mmc_host的自定義結(jié)構(gòu)體(core需要)
struct?mmc_host *mmc;
mmc = mmc_alloc_host(sizeof(struct usr_host), &pdev->dev);
九、初始化mmc_host結(jié)構(gòu)體
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重上電
十四、設置時鐘相位
十五、設置閾值
十六、設置中斷狀態(tài)
十七、設置中斷屏蔽
十八、設置DMA搬移數(shù)據(jù)
十九、設置全局中斷使能
二十、設置FIFO突發(fā)長度與FIFO大小
二十一、卡檢測
二十二、初始化定時器,定時處理函數(shù)為卡檢測
二十三、獲取資源結(jié)構(gòu)體的軟中斷號
二十四、初始化等待隊列
init_waitqueue_head(&host->intr_wait);
二十五、request_irq注冊中斷
二十六、寫中斷函數(shù)(喚醒等待隊列)
static irqreturn_t usr_irq(int irq, void *dev_id)
{
wake_up(&host->intr_wait);
}
?
評論
查看更多