@ -132,8 +132,10 @@ static int mmc_send_status(struct mmc *mmc, int timeout)
MMC_STATE_PRG )
MMC_STATE_PRG )
break ;
break ;
else if ( cmd . response [ 0 ] & MMC_STATUS_MASK ) {
else if ( cmd . response [ 0 ] & MMC_STATUS_MASK ) {
# if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
printf ( " Status Error: 0x%08X \n " ,
printf ( " Status Error: 0x%08X \n " ,
cmd . response [ 0 ] ) ;
cmd . response [ 0 ] ) ;
# endif
return COMM_ERR ;
return COMM_ERR ;
}
}
} else if ( - - retries < 0 )
} else if ( - - retries < 0 )
@ -148,7 +150,9 @@ static int mmc_send_status(struct mmc *mmc, int timeout)
printf ( " CURR STATE:%d \n " , status ) ;
printf ( " CURR STATE:%d \n " , status ) ;
# endif
# endif
if ( timeout < = 0 ) {
if ( timeout < = 0 ) {
# if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
printf ( " Timeout waiting card ready \n " ) ;
printf ( " Timeout waiting card ready \n " ) ;
# endif
return TIMEOUT ;
return TIMEOUT ;
}
}
@ -178,7 +182,9 @@ struct mmc *find_mmc_device(int dev_num)
return m ;
return m ;
}
}
# if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
printf ( " MMC Device %d not found \n " , dev_num ) ;
printf ( " MMC Device %d not found \n " , dev_num ) ;
# endif
return NULL ;
return NULL ;
}
}
@ -230,7 +236,9 @@ static ulong mmc_erase_t(struct mmc *mmc, ulong start, lbaint_t blkcnt)
return 0 ;
return 0 ;
err_out :
err_out :
# if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
puts ( " mmc erase failed \n " ) ;
puts ( " mmc erase failed \n " ) ;
# endif
return err ;
return err ;
}
}
@ -245,6 +253,7 @@ mmc_berase(int dev_num, lbaint_t start, lbaint_t blkcnt)
if ( ! mmc )
if ( ! mmc )
return - 1 ;
return - 1 ;
# if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
if ( ( start % mmc - > erase_grp_size ) | | ( blkcnt % mmc - > erase_grp_size ) )
if ( ( start % mmc - > erase_grp_size ) | | ( blkcnt % mmc - > erase_grp_size ) )
printf ( " \n \n Caution! Your devices Erase group is 0x%x \n "
printf ( " \n \n Caution! Your devices Erase group is 0x%x \n "
" The erase range would be change to "
" The erase range would be change to "
@ -252,6 +261,7 @@ mmc_berase(int dev_num, lbaint_t start, lbaint_t blkcnt)
mmc - > erase_grp_size , start & ~ ( mmc - > erase_grp_size - 1 ) ,
mmc - > erase_grp_size , start & ~ ( mmc - > erase_grp_size - 1 ) ,
( ( start + blkcnt + mmc - > erase_grp_size )
( ( start + blkcnt + mmc - > erase_grp_size )
& ~ ( mmc - > erase_grp_size - 1 ) ) - 1 ) ;
& ~ ( mmc - > erase_grp_size - 1 ) ) - 1 ) ;
# endif
while ( blk < blkcnt ) {
while ( blk < blkcnt ) {
blk_r = ( ( blkcnt - blk ) > mmc - > erase_grp_size ) ?
blk_r = ( ( blkcnt - blk ) > mmc - > erase_grp_size ) ?
@ -278,8 +288,10 @@ mmc_write_blocks(struct mmc *mmc, lbaint_t start, lbaint_t blkcnt, const void*sr
int timeout = 1000 ;
int timeout = 1000 ;
if ( ( start + blkcnt ) > mmc - > block_dev . lba ) {
if ( ( start + blkcnt ) > mmc - > block_dev . lba ) {
# if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
printf ( " MMC: block number 0x " LBAF " exceeds max(0x " LBAF " ) \n " ,
printf ( " MMC: block number 0x " LBAF " exceeds max(0x " LBAF " ) \n " ,
start + blkcnt , mmc - > block_dev . lba ) ;
start + blkcnt , mmc - > block_dev . lba ) ;
# endif
return 0 ;
return 0 ;
}
}
@ -303,7 +315,9 @@ mmc_write_blocks(struct mmc *mmc, lbaint_t start, lbaint_t blkcnt, const void*sr
data . flags = MMC_DATA_WRITE ;
data . flags = MMC_DATA_WRITE ;
if ( mmc_send_cmd ( mmc , & cmd , & data ) ) {
if ( mmc_send_cmd ( mmc , & cmd , & data ) ) {
# if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
printf ( " mmc write failed \n " ) ;
printf ( " mmc write failed \n " ) ;
# endif
return 0 ;
return 0 ;
}
}
@ -315,7 +329,9 @@ mmc_write_blocks(struct mmc *mmc, lbaint_t start, lbaint_t blkcnt, const void*sr
cmd . cmdarg = 0 ;
cmd . cmdarg = 0 ;
cmd . resp_type = MMC_RSP_R1b ;
cmd . resp_type = MMC_RSP_R1b ;
if ( mmc_send_cmd ( mmc , & cmd , NULL ) ) {
if ( mmc_send_cmd ( mmc , & cmd , NULL ) ) {
# if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
printf ( " mmc fail to send stop cmd \n " ) ;
printf ( " mmc fail to send stop cmd \n " ) ;
# endif
return 0 ;
return 0 ;
}
}
}
}
@ -382,7 +398,9 @@ static int mmc_read_blocks(struct mmc *mmc, void *dst, lbaint_t start,
cmd . cmdarg = 0 ;
cmd . cmdarg = 0 ;
cmd . resp_type = MMC_RSP_R1b ;
cmd . resp_type = MMC_RSP_R1b ;
if ( mmc_send_cmd ( mmc , & cmd , NULL ) ) {
if ( mmc_send_cmd ( mmc , & cmd , NULL ) ) {
# if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
printf ( " mmc fail to send stop cmd \n " ) ;
printf ( " mmc fail to send stop cmd \n " ) ;
# endif
return 0 ;
return 0 ;
}
}
}
}
@ -402,8 +420,10 @@ static ulong mmc_bread(int dev_num, lbaint_t start, lbaint_t blkcnt, void *dst)
return 0 ;
return 0 ;
if ( ( start + blkcnt ) > mmc - > block_dev . lba ) {
if ( ( start + blkcnt ) > mmc - > block_dev . lba ) {
# if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
printf ( " MMC: block number 0x " LBAF " exceeds max(0x " LBAF " ) \n " ,
printf ( " MMC: block number 0x " LBAF " exceeds max(0x " LBAF " ) \n " ,
start + blkcnt , mmc - > block_dev . lba ) ;
start + blkcnt , mmc - > block_dev . lba ) ;
# endif
return 0 ;
return 0 ;
}
}
@ -1265,6 +1285,7 @@ static int mmc_startup(struct mmc *mmc)
mmc - > block_dev . blksz = mmc - > read_bl_len ;
mmc - > block_dev . blksz = mmc - > read_bl_len ;
mmc - > block_dev . log2blksz = LOG2 ( mmc - > block_dev . blksz ) ;
mmc - > block_dev . log2blksz = LOG2 ( mmc - > block_dev . blksz ) ;
mmc - > block_dev . lba = lldiv ( mmc - > capacity , mmc - > read_bl_len ) ;
mmc - > block_dev . lba = lldiv ( mmc - > capacity , mmc - > read_bl_len ) ;
# if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
sprintf ( mmc - > block_dev . vendor , " Man %06x Snr %04x%04x " ,
sprintf ( mmc - > block_dev . vendor , " Man %06x Snr %04x%04x " ,
mmc - > cid [ 0 ] > > 24 , ( mmc - > cid [ 2 ] & 0xffff ) ,
mmc - > cid [ 0 ] > > 24 , ( mmc - > cid [ 2 ] & 0xffff ) ,
( mmc - > cid [ 3 ] > > 16 ) & 0xffff ) ;
( mmc - > cid [ 3 ] > > 16 ) & 0xffff ) ;
@ -1274,6 +1295,11 @@ static int mmc_startup(struct mmc *mmc)
( mmc - > cid [ 2 ] > > 24 ) & 0xff ) ;
( mmc - > cid [ 2 ] > > 24 ) & 0xff ) ;
sprintf ( mmc - > block_dev . revision , " %d.%d " , ( mmc - > cid [ 2 ] > > 20 ) & 0xf ,
sprintf ( mmc - > block_dev . revision , " %d.%d " , ( mmc - > cid [ 2 ] > > 20 ) & 0xf ,
( mmc - > cid [ 2 ] > > 16 ) & 0xf ) ;
( mmc - > cid [ 2 ] > > 16 ) & 0xf ) ;
# else
mmc - > block_dev . vendor [ 0 ] = 0 ;
mmc - > block_dev . product [ 0 ] = 0 ;
mmc - > block_dev . revision [ 0 ] = 0 ;
# endif
# if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBDISK_SUPPORT)
# if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBDISK_SUPPORT)
init_part ( & mmc - > block_dev ) ;
init_part ( & mmc - > block_dev ) ;
# endif
# endif
@ -1340,7 +1366,9 @@ int mmc_start_init(struct mmc *mmc)
if ( mmc_getcd ( mmc ) = = 0 ) {
if ( mmc_getcd ( mmc ) = = 0 ) {
mmc - > has_init = 0 ;
mmc - > has_init = 0 ;
# if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
printf ( " MMC: no card present \n " ) ;
printf ( " MMC: no card present \n " ) ;
# endif
return NO_CARD_ERR ;
return NO_CARD_ERR ;
}
}
@ -1375,7 +1403,9 @@ int mmc_start_init(struct mmc *mmc)
err = mmc_send_op_cond ( mmc ) ;
err = mmc_send_op_cond ( mmc ) ;
if ( err & & err ! = IN_PROGRESS ) {
if ( err & & err ! = IN_PROGRESS ) {
# if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
printf ( " Card did not respond to voltage select! \n " ) ;
printf ( " Card did not respond to voltage select! \n " ) ;
# endif
return UNUSABLE_ERR ;
return UNUSABLE_ERR ;
}
}
}
}
@ -1431,6 +1461,8 @@ static int __def_mmc_init(bd_t *bis)
int cpu_mmc_init ( bd_t * bis ) __attribute__ ( ( weak , alias ( " __def_mmc_init " ) ) ) ;
int cpu_mmc_init ( bd_t * bis ) __attribute__ ( ( weak , alias ( " __def_mmc_init " ) ) ) ;
int board_mmc_init ( bd_t * bis ) __attribute__ ( ( weak , alias ( " __def_mmc_init " ) ) ) ;
int board_mmc_init ( bd_t * bis ) __attribute__ ( ( weak , alias ( " __def_mmc_init " ) ) ) ;
# if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
void print_mmc_devices ( char separator )
void print_mmc_devices ( char separator )
{
{
struct mmc * m ;
struct mmc * m ;
@ -1448,6 +1480,10 @@ void print_mmc_devices(char separator)
printf ( " \n " ) ;
printf ( " \n " ) ;
}
}
# else
void print_mmc_devices ( char separator ) { }
# endif
int get_mmc_num ( void )
int get_mmc_num ( void )
{
{
return cur_dev_num ;
return cur_dev_num ;