📄 mmc_drv.c
字号:
if ( ret ) { device->card_state = MMCSD_NOTREADY; } else { device->card_state = MMCSD_STANDBY; } return( ret );}/****************************************************************************** * Function Name: _MMCSD_SetCSD * * Input: None. * * Value Returned: * * Description: * * Get CSD Info * * Modification History: * 30 DEC,2001, Initial version. Yiwei Zhao *****************************************************************************/void _MMCSD_SetCSD(MMCSD_Dev *device,u8 * Csd_buff){ u32 size,t1,t2; u32 read_bl_len; /* read data block length */ u32 c_size; /* device size */ u32 mult,blocknr,block_len; u32 c_size_mult; u8 write_blk_len; u8 erase_sector_size; /* erase sector size */ u8 wp_grp_size; read_bl_len=( Csd_buff[5] & 0x0F ); //TRACE("Read Block Length [5] 0x%x",read_bl_len); device->ccc = (Csd_buff[5]&0xF0)>>4; device->ccc |= Csd_buff[4]<<4; c_size=0; t1=Csd_buff[6]&0x3; t1=t1<<10; t2=Csd_buff[7]; t2=t2<<2; t2=t1|t2; c_size=(t2|((Csd_buff[8]&0xC0)>>6)); //erase_sector_size=( ( Csd_buff[10] & 0x7C ) >> 2 ); erase_sector_size=0; erase_sector_size=((Csd_buff[10]&0x3F)<<1); erase_sector_size= erase_sector_size|((Csd_buff[11]&0x80)>>7); erase_sector_size++; wp_grp_size = 0; wp_grp_size = (Csd_buff[11]&0x3F)+1; write_blk_len = 0; write_blk_len = (Csd_buff[12]&0x03)<<2; write_blk_len = write_blk_len|((Csd_buff[13]&0xc0)>>6); c_size_mult=( ( ( Csd_buff[9] & 0x03 ) << 1 )| ( ( Csd_buff[10] & 0x80 ) >> 7 ) ); mult=1<<(c_size_mult+2); blocknr=(c_size+1)*mult; block_len=1<<read_bl_len; size=blocknr*block_len; device->dev_size=size; device->sect_num=size/MMCSD_MINIMUM_BLK_SIZE; device->blksize = MMCSD_MINIMUM_BLK_SIZE; device->blksize_bit = 9; device->phy_blksize = 1<<write_blk_len; device->phy_sectorsize = (device->phy_blksize)*erase_sector_size; device->wp_grp_size = (device->phy_sectorsize)*wp_grp_size; INFO("write block size is %d",device->phy_blksize); INFO("Erase sector size is %ld",(long int)(device->phy_sectorsize)); INFO("Card Size is %ld bytes, sect_num (for FAT file system) is %ld\n", (long int)size,size/MMCSD_MINIMUM_BLK_SIZE); INFO("Supported Card Command Class is 0x%0X\n",device->ccc); //INFO("Wirte Protected group size [11] = 0x%x",wp_grp_size); }/****************************************************************************** * Function Name: _MMCSD_SetCID * * Input: None. * * Value Returned: * * Description: * * Set CID * * Modification History: * 30 DEC,2001, Initial version. Yiwei Zhao *****************************************************************************/void _MMCSD_SetCID(MMCSD_Dev *device,u8* Cid_buff){ int j; for(j=0;j<16;j++) device->CID[j]=Cid_buff[j];}/****************************************************************************** * Function Name: _MMCSD_CSDCheck * * Input: None. * * Value Returned: * * MMCSD_STATUS * * Description: * * Check CSD register * * Modification History: * 30 DEC,2001, Initial version. Yiwei Zhao *****************************************************************************//****************************************************************************CSD Register -----------------------------------------------------------------------------Name | Width| CSD_Slice| pCsdbuff (BYTE) -----------------------------------------------------------------------------CSD struction 2 127:126 System spec. version 4 125:122 0reserved 2 121:120 -----------------------------------------------------------------------------data read access time 1 8 119:112 1-----------------------------------------------------------------------------data read access time 2 8 111:104 2-----------------------------------------------------------------------------Max data transfer rate 8 103:96 3-----------------------------------------------------------------------------card command classes 12 95:84 4max read data block length 4 83:80 5------------------------------------------------------------------------------partial blocks for read length 1 79:79 wirte block misalignment 1 78:78 read block misalignment 1 77:77DSR implemented 1 76:76reserved 2 75:74device size 12 73:62 6-7max read current 3 61:69max read current 3 58-56 8------------------------------------------------------------------------------max write current 3 55-53max write current 3 52-50device size multiplier 3 49-47 9erase sector size 5 46-42 erase group size 5 41-37 10write protect group size 5 36-32 11------------------------------------------------------------------------------write protect group enable 1 31:31manufactuter default ECC 2 30:29write speed factor 3 28:26max. write data block length 4 25:22 12partial blocks for write allowed 1 21:21reserved 5 20:16 13------------------------------------------------------------------------------File format group 1 15:15 copy flag 1 14:14permanent write protection 1 13:13 temporary write protection 1 12:12file format 2 11:10ECC code 2 9:8 14--------------------------------------------------------------------------------CRC 7 7:1Not used always '1' 1 0:0 15-------------------------------------------------------------------------------*********************************************************************************/ MMCSD_STATUS _MMCSD_CSDCheck(u8 *csdbuff ){ u8 temp; temp = 0; /*----------------------------------------------------------------------*/ /* CHECK FROM THE BEGINNING */ /*----------------------------------------------------------------------*/ /*---------------------- CSD_STRUCTURE ---------------------------------*/ temp = ( ( csdbuff[0] & 0xC0 ) >> 6 ); if ( ( temp != 0 )&&( temp != 1 ) ) {#ifdef KAREN_DEBUG// printk("CSD_STRUCTURE = %x \n",temp);#endif //Karen //return( MMCSD_CSD_MISS );//Karen modified//end Karen } /*------------------------- MMC_PORT -----------------------------------*/ temp = ( ( csdbuff[0] & 0x3C ) >> 2 ); if ( ( temp != 0 )&&( temp != 1 )&&( temp != 2 ) ) {#ifdef KAREN_DEBUG// printk("MMC_PORT = %x \n",temp);#endif //Karen// return( MMCSD_CSD_MISS );//end Karen } /*------------------------- TACC ---------------------------------------*/ temp = ( csdbuff[1] & 0x80 ); if ( temp != 0 ) {#ifdef KAREN_DEBUG printk("TACC = %x \n",temp);#endif //Karen// return( MMCSD_CSD_MISS );//end Karen } /*------------------------- NSAC ---------------------------------------*/ /*---------------------- TRAN_SPEED ------------------------------------*/ temp = ( csdbuff[3] & 0x80 ); if ( temp != 0 ) {#ifdef KAREN_DEBUG printk("TRAN_SPEED = %x \n",temp);#endif //Karen// return( MMCSD_CSD_MISS );//end Karen } /*-------------------------- CCC ---------------------------------------*/ // TRACE("CCC: ----- 0x%0X",device->ccc); /*---------------------- READ_BL_LEN -----------------------------------*/ temp = ( csdbuff[5] & 0x0F ); if ( temp > 0x0B ) {#ifdef KAREN_DEBUG printk("READ_BL_LEN = %x \n",temp);#endif //Karen// return( MMCSD_CSD_MISS );// end Karen } /*-------------------- READ_BL_PARTIAL ---------------------------------*/ /*------------------ WRITE_BLK_MISALIGN --------------------------------*/ /*------------------- READ_BLK_MISALIGN --------------------------------*/ /*-------------------------- DSR_IMP -----------------------------------*/ /*--------------------------- C_SIZE -----------------------------------*/ /*------------------- VDD_R_CURR_MIN,VDD_W_CURR_MIN --------------------*/ /*------------------- VDD_R_CURR_MAX,VDD_W_CURR_MAX --------------------*/ /*------------------------- C_SIZE_MULT --------------------------------*/ /*------------------------- SECTOR_SIZE --------------------------------*/ /*------------------------- ERASE_GRP_SIZE -----------------------------*/ /*-------------------------- WP_GRP_SIZE -------------------------------*/ /*------------------------ WP_GRP_ENABLE -------------------------------*/ /*------------------------- DEFAULT_ECC --------------------------------*/ /*-------------------------- R2W_FACTOR --------------------------------*/ temp = (( csdbuff[12] & 0x1C ) >> 2 ); if ( temp > 5 ) {#ifdef KAREN_DEBUG printk("R2W_FACTOR = %x \n",temp);#endif //Karen // return( MMCSD_CSD_MISS );//end Karen } /*------------------------- WRITE_BL_LEN -------------------------------*/ /*------------------------ WRITE_BL_PARTIAL ----------------------------*/ /*---------------------------- COPY ------------------------------------*/ /*----------------------- PERM_WRITE_PROTECT ---------------------------*/ /*------------------------ TMP_WRITE_PROTECT ---------------------------*/ /*----------------------------- ECC ------------------------------------*/ temp = ( csdbuff[14] & 0x03 ); if ( temp > 1 ) {#ifdef KAREN_DEBUG printk("ECC = %x \n",temp);#endif //Karen// return( MMCSD_CSD_MISS );//end Karen } /*----------------------------- CRC ------------------------------------*/ temp = ( csdbuff[15] & 0x01 ); if ( temp != 1 ) {// PLAM return((MMCSD_STATUS)0); //return( MMCSD_CSD_MISS );// end PLAM } else{/* IF NO ERROR BEFORE HERE, DO A NORMAL RETURN */ return( (MMCSD_STATUS)0 ); }}/****************************************************************************** * Function Name: _MMCSD_CIDCheck * * Input: None. * * Value Returned: * * MMCSD_STATUS * * Description: * * Check CID register * * Modification History: * 30 DEC,2001, Initial version. Yiwei Zhao *****************************************************************************//***************************************************************************** CID Register:(Bit) 127 119 111 103 95 87 79 71 63 55 47 39 31 15 7 0------------------------------------------------------------------------------------------CID Register |MID | OID | PNM | PSN |MDT| CRC|------------------------------------------------------------------------------------------pCidBuff :(BYTE) | 0 | 1 | 2 | 4 | 5 | 7 | 8 | 9 | 10| 11| 12|13| 14 | 15 | 16| ******************************************************************************/MMCSD_STATUS _MMCSD_CIDCheck( u8 *cidbuff ){ /*----------------------------------------------------------------------*/ /* TOTAL CHECK FROM THE BEGINNING */ /*----------------------------------------------------------------------*/ /*-------------------------- Manufacturer ID ---------------------------*/ if (( cidbuff[0] == 0 )&&( cidbuff[1] == 0 )&&( cidbuff[2] == 0 )) { return( MMCSD_CID_MISS ); } /*----------------------- Card individual number -----------------------*/ if (( cidbuff[3] == 0 )&&( cidbuff[4] == 0 )&&( cidbuff[5] == 0 )&& ( cidbuff[6] == 0 )&&( cidbuff[7] == 0 )&&( cidbuff[8] == 0 )&& ( cidbuff[9] == 0 )&&( cidbuff[10] == 0 )&&( cidbuff[11] == 0 )&& ( cidbuff[12] == 0 )&&( cidbuff[13] == 0 )&&( cidbuff[14] == 0 )) { return( MMCSD_CID_MISS ); } /*----------------- CRC7 checksum + not used,always'1' -----------------*/ if ( ( cidbuff[15] & 0x01 ) != 0x01 ) {// PLAM return 0;// return( MMCSD_CID_MISS );// end PLAM } return( 0 );}/*MMCSD_STATUS _MMCSD_SCRCheck(MMCSD_Dev *device){ MMCSD_Responses rp; MMCSD_scr scr; int ret; ret = _MMCSD_SendSCR(device->card_rca,&scr,device->port); if(ret) { FAILED("SendSCR failed"); return MMCSD_ERROR; } if(scr.sd_bus_width&0x05) { INFO("can support both 1-bit & 4-bit \n"); device->bit_width = 0; return MMCSD_OK; } else if(scr.sd_bus_width&0x01) { INFO("can support only 1-bit \n"); device->bit_width = 0; return MMCSD_OK; } else if(scr.sd_bus_width&0x04) { INFO("can support only 4-bit \n"); device->bit_width = 1; return MMCSD_OK; } else { return MMCSD_ERROR; } return MMCSD_OK;}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -