mmcsd卡驱动程序设计通信10123赵翔(编辑修改稿)内容摘要:

C/SD 卡模块注册初始化 : static int __devinit mmc_pxa_module_init( void ) { int ret = ENODEV。 ifdef CONFIG_ARCH_RAMSES RAMSES_MMC_ON()。 udelay(1000)。 endif host = mmc_register( MMC_REG_TYPE_HOST, amp。 pxa_mmc_controller_tmpl_rec, sizeof( pxa_mmc_hostdata_rec_t ) )。 //register the SD device if ( !host ) { MMC_DEBUG( MMC_DEBUG_LEVEL0, failed to register with MMC core\n )。 goto error。 } ret = 0。 error: return ret。 } 设备文件操作接口定义 static mmc_controller_tmpl_rec_t pxa_mmc_controller_tmpl_rec = { owner: THIS_MODULE, name: PXA250, block_size_max: PXA_MMC_BLKSZ_MAX, nob_max: PXA_MMC_NOB_MAX, probe: pxa_mmc_probe, init: pxa_mmc_init, remove: __devexit_p( pxa_mmc_remove ), update_acq: pxa_mmc_update_acq, init_card_stack: pxa_mmc_init_card_stack, check_card_stack: pxa_mmc_check_card_stack, setup_card: pxa_mmc_setup_card, stream_read: pxa_mmc_stream_read, read_block: pxa_mmc_read_block, read_mblock: pxa_mmc_read_mblock, stream_write: pxa_mmc_stream_write, write_block: pxa_mmc_write_block, write_mblock: pxa_mmc_write_mblock }。 16 MMC 接口初始化 static int pxa_mmc_init( mmc_controller_t ctrlr ) { int ret = ENODEV。 pxa_mmc_hostdata_t hostdata = (pxa_mmc_hostdata_t)ctrlrhost_data。 /* 1. allocate buffer */ hostdata = kmalloc( PXA_MMC_IODATA_SIZE, GFP_ATOMIC )。 //2K if ( !hostdata ) { ret = ENOMEM。 goto error。 } /* 2. initialize iobuf */ hostdata = PXA_MMC_BLKSZ_MAX。 /* current block size in bytes 1024* / hostdata = PXA_MMC_IODATA_SIZE。 /* buffer size for each transfer */ hostdata = PXA_MMC_BLOCKS_PER_BUFFER。 /* number of blocks */ /* 3 request irq */ if ( request_irq( IRQ_MMC, pxa_mmc_irq, 0, MMC, ctrlr ) ) { MMC_ERROR( failed to request IRQ_MMC\n )。 goto error。 } /* 4 init GPIO about MMC/SD/SDIO*/ init_gpio( )。 CKEN |= CKEN12_MMC。 /* enable MMC unit clock */ ret = 0。 goto out。 error: kfree( hostdata )。 out: return ret。 } GPIO 初始化函数 static void init_gpio(void) { GPCR1 |= 0x1。 //clear pin32 GPDR1 = GPDR1 | (10)。 //config pin32 as output GAFR1_L = (GAFR1_Lamp。 0xfffffffc) | (20)。 //) pin32 is used for function 2MMCLK //MMDAT0 PIN92 GPSR2 |= 0x10000000。 //pin92 configured as an output, set pin level high (one). 17 GPDR2 |= 0x10000000。 //pin92 as output // GPDR2 = GPDR2 amp。 ~(128)。 GAFR2_U = (GAFR2_U amp。 0xfcffffff) | (124)。 //pin32 is used for function 1MMDAT0 //MMDAT1 PIN109 GPSR3 |= (113)。 GPDR3 |= (113)。 GAFR3_L = (GAFR3_L amp。 0xf3ffffff) | (126)。 //MMDAT2 PIN110 GPSR3 |= (114)。 GPDR3 |= (114)。 GAFR3_L = (GAFR3_L amp。 0xcfffffff) | (128)。 //MMDAT3 PIN111 GPSR3 |= (115)。 GPDR3 |= (115)。 GAFR3_L = (GAFR3_L amp。 0x3fffffff) | (130)。 //MMCMD PIN112 GPSR3 |= 0x00010000。 GPDR3 |= 0x00010000。 //GPDR3 = GPDR3 amp。 ~(116)。 GAFR3_U = (GAFR3_U amp。 0xfffffffc) | (10)。 //function1 GPSR3 |= 0x0000e000。 //PIN111PIN109 GPDR3 |= 0x0000e000。 GAFR3_L = (GAFR3_L amp。 0x03ffffff) | 0x54000000。 }。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。