#define MMCSD_INIT_DELAY 64
-cyg_uint32 Card_rca = 0x1; /* Relative Card Address */
-card_ident Card_identification; /* Card Identification Data */
-card_type Card_type; /* Card Type */
-cyg_uint32 MMC_Spec_vers = 0x1; /* Spec vers used for MMC */
-card_specific_data csd; /* Global variable for Card Specific Data */
-cyg_uint32 Card_capacity_size = 0; /*Card capacity size */
-cyg_uint32 CCC = 0; /* Card Command Class */
+cyg_uint32 Card_rca = 0x1; /* Relative Card Address */
+card_ident Card_identification; /* Card Identification Data */
+card_type Card_type; /* Card Type */
+cyg_uint32 MMC_Spec_vers = 0x1; /* Spec vers used for MMC */
+card_specific_data csd; /* Global variable for Card Specific Data */
+cyg_uint32 Card_capacity_size = 0; /* Card capacity size */
+cyg_uint32 CCC = 0; /* Card Command Class */
int Card_Mode = 2;
int HighCapacityCard = 0;
==============================================================================*/
cyg_uint32 card_get_csd(void)
{
+ command_t cmd;
+ command_response_t response;
+ cyg_uint32 status = FAIL;
+ cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
+
+ /* Configure CMD9 for MMC/SD card */
+ /* 16bit card address is expected as Argument */
+ mxcmci_cmd_config(&cmd, CMD9, card_address, READ, RESPONSE_136,
+ DATA_PRESENT_NONE, ENABLE, DISABLE);
+
+ /* Issue Command CMD9 to Extrace CSD register contents */
+
+ if (host_send_cmd(&cmd) != FAIL) {
+ /* Read Command response */
+ response.format = RESPONSE_136;
+ host_read_response(&response);
+
+ /* Assign Response to CSD Strcuture */
+ csd.csd0 = response.cmd_rsp0;
+ csd.csd1 = response.cmd_rsp1;
+ csd.csd2 = response.cmd_rsp2;
+ csd.csd3 = response.cmd_rsp3;
+
+ flash_dprintf(FLASH_DEBUG_MAX, "CSD:%x:%x:%x:%x\n", csd.csd0,
+ csd.csd1, csd.csd2, csd.csd3);
+ status = SUCCESS;
+ } else {
+ diag_printf("Get CSD Failed.\n");
+ }
- command_t cmd;
- command_response_t response;
- cyg_uint32 status = FAIL;
- cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
-
- /* Configure CMD9 for MMC/SD card */
- /* 16bit card address is expected as Argument */
- mxcmci_cmd_config(&cmd, CMD9, card_address, READ, RESPONSE_136,
- DATA_PRESENT_NONE, ENABLE, DISABLE);
-
- /* Issue Command CMD9 to Extrace CSD register contents */
-
- if (host_send_cmd(&cmd) != FAIL) {
- /* Read Command response */
- response.format = RESPONSE_136;
- host_read_response(&response);
-
- /* Assign Response to CSD Strcuture */
- csd.csd0 = response.cmd_rsp0;
- csd.csd1 = response.cmd_rsp1;
- csd.csd2 = response.cmd_rsp2;
- csd.csd3 = response.cmd_rsp3;
-
- flash_dprintf(FLASH_DEBUG_MAX, "CSD:%x:%x:%x:%x\n", csd.csd0,
- csd.csd1, csd.csd2, csd.csd3);
- status = SUCCESS;
- } else {
- diag_printf("Get CSD Failed.\n");
- }
-
- return status;
-
+ return status;
}
static cyg_uint32 csd_get_value(void *csd, cyg_uint32 start_bit,
__FUNCTION__, value, *pcsd, *(pcsd + 1), *(pcsd + 2),
*(pcsd + 3));
return value;
-
}
cyg_uint32 card_get_capacity_size(void)
{
- cyg_uint32 capacity = 0;
- cyg_uint32 c_size, c_size_mult, blk_len;
-
- if (!csd.csd0 && !csd.csd1 && !csd.csd2 && !csd.csd3)
- flash_dprintf(FLASH_DEBUG_MAX,
- "WARNINGS:mxcmci_init should be done first!\n");
-
- switch (Card_type) {
- case SD_CSD_1_0:
- case MMC_CSD_1_0:
- case MMC_CSD_1_1:
- case MMC_CSD_1_2:
+ cyg_uint32 capacity = 0;
+ cyg_uint32 c_size, c_size_mult, blk_len;
+
+ if (!csd.csd0 && !csd.csd1 && !csd.csd2 && !csd.csd3)
+ flash_dprintf(FLASH_DEBUG_MAX,
+ "WARNINGS:mxcmci_init should be done first!\n");
+
+ switch (Card_type) {
+ case SD_CSD_1_0:
+ case MMC_CSD_1_0:
+ case MMC_CSD_1_1:
+ case MMC_CSD_1_2:
c_size = csd_get_value((void*)&csd, 62, 73);
- c_size_mult = csd_get_value(&csd, 47, 49);
- blk_len = csd_get_value(&csd, 80, 83);
- capacity = (c_size + 1) << (c_size_mult + 2 + blk_len - 10);
- break;
- case SD_CSD_2_0:
- //blk_len = csd_get_value(&csd, 80, 83);
- c_size = csd_get_value(&csd, 48, 69);
- capacity = (c_size + 1) * 512; /* block length is fixed to 512B */
- break;
- default:
- capacity = 1;
- break;
- }
-
- /* check whether the card is high capacity card */
- if(capacity>2*1024*1024)
- HighCapacityCard = 1;
- else
- HighCapacityCard = 0;
-
- return capacity;
+ c_size_mult = csd_get_value(&csd, 47, 49);
+ blk_len = csd_get_value(&csd, 80, 83);
+ capacity = (c_size + 1) << (c_size_mult + 2 + blk_len - 10);
+ break;
+ case SD_CSD_2_0:
+ //blk_len = csd_get_value(&csd, 80, 83);
+ c_size = csd_get_value(&csd, 48, 69);
+ capacity = (c_size + 1) * 512; /* block length is fixed to 512B */
+ break;
+ default:
+ capacity = 1;
+ break;
+ }
+ /* check whether the card is high capacity card */
+ if(capacity>2*1024*1024)
+ HighCapacityCard = 1;
+ else
+ HighCapacityCard = 0;
+
+ return capacity;
}
-cyg_uint32 mxcmci_data_read(cyg_uint32 * dest_ptr, cyg_uint32 len,
- cyg_uint32 offset)
+cyg_uint32 mxcmci_data_read(cyg_uint32 *dest_ptr, cyg_uint32 len,
+ cyg_uint32 offset)
{
- cyg_uint32 read_status = FAIL;
-
- read_status = mmc_data_read(dest_ptr, len, offset);
+ cyg_uint32 read_status = FAIL;
- if (read_status) {
- len = 0;
- }
- return len;
+ read_status = mmc_data_read(dest_ptr, len, offset);
+ if (read_status) {
+ len = 0;
+ }
+ return len;
}
cyg_uint32 mxcmci_software_reset(void)
{
- command_t cmd;
- cyg_uint32 response = FAIL;
-
- /*Configure CMD0 for MMC/SD card */
- /*CMD0 doesnt expect any response */
- mxcmci_cmd_config(&cmd, CMD0, NO_ARG, READ, RESPONSE_NONE,
- DATA_PRESENT_NONE, DISABLE, DISABLE);
-
- /*Issue CMD0 to MMC/SD card to put in active state */
- if (host_send_cmd(&cmd) != FAIL) {
- response = SUCCESS;
- } else {
- diag_printf("Card SW Reset Failed.\n");
- }
-
- return response;
+ command_t cmd;
+ cyg_uint32 response = FAIL;
+
+ /*Configure CMD0 for MMC/SD card */
+ /*CMD0 doesnt expect any response */
+ mxcmci_cmd_config(&cmd, CMD0, NO_ARG, READ, RESPONSE_NONE,
+ DATA_PRESENT_NONE, DISABLE, DISABLE);
+
+ /*Issue CMD0 to MMC/SD card to put in active state */
+ if (host_send_cmd(&cmd) != FAIL) {
+ response = SUCCESS;
+ } else {
+ diag_printf("Card SW Reset Failed.\n");
+ }
+
+ return response;
}
cyg_uint32 mxcmci_get_cid(void)
{
- command_t cmd;
- cyg_uint32 cid_request = FAIL;
- command_response_t response;
-
- /* Configure CMD2 for card */
- /* No Argument is expected for CMD2 */
- mxcmci_cmd_config(&cmd, CMD2, NO_ARG, READ, RESPONSE_136,
- DATA_PRESENT_NONE, ENABLE, DISABLE);
-
- /* Issue CMD2 to card to determine CID contents */
- if (host_send_cmd(&cmd) == FAIL) {
- cid_request = FAIL;
- diag_printf("Send CMD2 Failed.\n");
- } else {
- /* Read Command response */
- response.format = RESPONSE_136;
- host_read_response(&response);
-
- /* Assign CID values to mmc_cid structures */
- Card_identification.cid0 = response.cmd_rsp0;
- Card_identification.cid1 = response.cmd_rsp1;
- Card_identification.cid2 = response.cmd_rsp2;
- Card_identification.cid3 = response.cmd_rsp3;
-
- /* Assign cid_request as SUCCESS */
- cid_request = SUCCESS;
- }
-
- flash_dprintf(FLASH_DEBUG_MAX, "%s:CID=%X:%X:%X:%X\n", __FUNCTION__,
- Card_identification.cid0, Card_identification.cid1,
- Card_identification.cid2, Card_identification.cid3);
- return cid_request;
+ command_t cmd;
+ cyg_uint32 cid_request = FAIL;
+ command_response_t response;
+
+ /* Configure CMD2 for card */
+ /* No Argument is expected for CMD2 */
+ mxcmci_cmd_config(&cmd, CMD2, NO_ARG, READ, RESPONSE_136,
+ DATA_PRESENT_NONE, ENABLE, DISABLE);
+
+ /* Issue CMD2 to card to determine CID contents */
+ if (host_send_cmd(&cmd) == FAIL) {
+ cid_request = FAIL;
+ diag_printf("Send CMD2 Failed.\n");
+ } else {
+ /* Read Command response */
+ response.format = RESPONSE_136;
+ host_read_response(&response);
+
+ /* Assign CID values to mmc_cid structures */
+ Card_identification.cid0 = response.cmd_rsp0;
+ Card_identification.cid1 = response.cmd_rsp1;
+ Card_identification.cid2 = response.cmd_rsp2;
+ Card_identification.cid3 = response.cmd_rsp3;
+
+ /* Assign cid_request as SUCCESS */
+ cid_request = SUCCESS;
+ }
+
+ flash_dprintf(FLASH_DEBUG_MAX, "%s:CID=%X:%X:%X:%X\n", __FUNCTION__,
+ Card_identification.cid0, Card_identification.cid1,
+ Card_identification.cid2, Card_identification.cid3);
+ return cid_request;
}
cyg_uint32 mxcmci_trans_prepare(void)
{
- command_t cmd;
- cyg_uint32 card_state = 0;
- cyg_uint32 transfer_status = 0;
- command_response_t response;
- cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
-
- /* Configure CMD7 for MMC card */
- /* 16bit card address is expected as Argument */
- mxcmci_cmd_config(&cmd, CMD7, card_address, READ, RESPONSE_48,
- DATA_PRESENT_NONE, ENABLE, ENABLE);
-
- /* Sending the card from stand-by to transfer state */
- if (host_send_cmd(&cmd) == FAIL) {
- transfer_status = FAIL;
- diag_printf("Send CMD7 Failed.\n");
- } else {
-
- /* Configure CMD13 to read status of the card becuase CMD7 has R1b response */
- mxcmci_cmd_config(&cmd, CMD13, card_address, READ, RESPONSE_48,
- DATA_PRESENT_NONE, ENABLE, ENABLE);
-
- if (host_send_cmd(&cmd) == FAIL) {
- transfer_status = FAIL;
- diag_printf("Send CMD13 Failed.\n");
- } else {
- /* Read Command response */
- response.format = RESPONSE_48;
- host_read_response(&response);
-
- card_state = CURR_CARD_STATE(response.cmd_rsp0);
-
- if (card_state == TRAN) {
- transfer_status = SUCCESS;
-
- } else {
- diag_printf("card_state: 0x%x\n", card_state);
- transfer_status = FAIL;
- }
- }
-
- }
-
- return transfer_status;
+ command_t cmd;
+ cyg_uint32 card_state = 0;
+ cyg_uint32 transfer_status = 0;
+ command_response_t response;
+ cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
+
+ /* Configure CMD7 for MMC card */
+ /* 16bit card address is expected as Argument */
+ mxcmci_cmd_config(&cmd, CMD7, card_address, READ, RESPONSE_48,
+ DATA_PRESENT_NONE, ENABLE, ENABLE);
+
+ /* Sending the card from stand-by to transfer state */
+ if (host_send_cmd(&cmd) == FAIL) {
+ transfer_status = FAIL;
+ diag_printf("Send CMD7 Failed.\n");
+ } else {
+
+ /* Configure CMD13 to read status of the card becuase CMD7 has R1b response */
+ mxcmci_cmd_config(&cmd, CMD13, card_address, READ, RESPONSE_48,
+ DATA_PRESENT_NONE, ENABLE, ENABLE);
+
+ if (host_send_cmd(&cmd) == FAIL) {
+ transfer_status = FAIL;
+ diag_printf("Send CMD13 Failed.\n");
+ } else {
+ /* Read Command response */
+ response.format = RESPONSE_48;
+ host_read_response(&response);
+
+ card_state = CURR_CARD_STATE(response.cmd_rsp0);
+
+ if (card_state == TRAN) {
+ transfer_status = SUCCESS;
+
+ } else {
+ diag_printf("card_state: 0x%x\n", card_state);
+ transfer_status = FAIL;
+ }
+ }
+
+ }
+ return transfer_status;
}
cyg_uint32 mxcmci_trans_status(void)
{
- command_t cmd;
- cyg_uint32 card_state = 0;
- cyg_uint32 transfer_status = 0;
- command_response_t response;
- cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
-
- /* Configure CMD13 to read status of the card becuase CMD7 has R1b response */
- mxcmci_cmd_config(&cmd, CMD13, card_address, READ, RESPONSE_48,
- DATA_PRESENT_NONE, ENABLE, ENABLE);
-
- if (host_send_cmd(&cmd) == FAIL) {
- diag_printf("Fail, CMD13\n");
- transfer_status = FAIL;
- }
-
- else {
- /* Read Command response */
- response.format = RESPONSE_48;
- host_read_response(&response);
-
- card_state = CURR_CARD_STATE(response.cmd_rsp0);
-
- if (card_state == TRAN) {
- transfer_status = SUCCESS;
- //diag_printf("card_state: 0x%x\n", card_state);
- }
-
- else {
- //diag_printf("card_state: 0x%x\n", card_state);
- transfer_status = FAIL;
- }
- }
- return transfer_status;
+ command_t cmd;
+ cyg_uint32 card_state = 0;
+ cyg_uint32 transfer_status = 0;
+ command_response_t response;
+ cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
+
+ /* Configure CMD13 to read status of the card becuase CMD7 has R1b response */
+ mxcmci_cmd_config(&cmd, CMD13, card_address, READ, RESPONSE_48,
+ DATA_PRESENT_NONE, ENABLE, ENABLE);
+
+ if (host_send_cmd(&cmd) == FAIL) {
+ diag_printf("Fail, CMD13\n");
+ transfer_status = FAIL;
+ }
+
+ else {
+ /* Read Command response */
+ response.format = RESPONSE_48;
+ host_read_response(&response);
+
+ card_state = CURR_CARD_STATE(response.cmd_rsp0);
+
+ if (card_state == TRAN) {
+ transfer_status = SUCCESS;
+ //diag_printf("card_state: 0x%x\n", card_state);
+ }
+ else {
+ //diag_printf("card_state: 0x%x\n", card_state);
+ transfer_status = FAIL;
+ }
+ }
+ return transfer_status;
}
-void mxcmci_cmd_config(command_t * cmd_config, cyg_uint32 index,
- cyg_uint32 argument, xfer_type_t transfer,
- response_format_t format, data_present_select data,
- crc_check_enable crc, cmdindex_check_enable cmdindex)
+void mxcmci_cmd_config(command_t *cmd_config, cyg_uint32 index,
+ cyg_uint32 argument, xfer_type_t transfer,
+ response_format_t format, data_present_select data,
+ crc_check_enable crc, cmdindex_check_enable cmdindex)
{
+ command_t *cmd;
- command_t *cmd;
-
- /* Assign cmd to cmd_config */
- cmd = cmd_config;
+ /* Assign cmd to cmd_config */
+ cmd = cmd_config;
- /* Configure Command index */
- cmd->command = index;
+ /* Configure Command index */
+ cmd->command = index;
- /* Configure Command Argument */
- cmd->arg = argument;
+ /* Configure Command Argument */
+ cmd->arg = argument;
- /* Configure Data transfer type */
- cmd->data_transfer = transfer;
+ /* Configure Data transfer type */
+ cmd->data_transfer = transfer;
- /* Configure Response Format */
- cmd->response_format = format;
+ /* Configure Response Format */
+ cmd->response_format = format;
- /* Configure Data Present Select */
- cmd->data_present = data;
+ /* Configure Data Present Select */
+ cmd->data_present = data;
- /* Configiure CRC check Enable */
- cmd->crc_check = crc;
+ /* Configiure CRC check Enable */
+ cmd->crc_check = crc;
- /*Configure Command index check enable */
- cmd->cmdindex_check = cmdindex;
+ /* Configure Command index check enable */
+ cmd->cmdindex_check = cmdindex;
- /* if multi-block is used */
- if (CMD18 == index || CMD25 == index) {
- /*Configure Block count enable */
- cmd->block_count_enable_check = ENABLE;
- /*Configure Multi single block select */
- cmd->multi_single_block = MULTIPLE;
- } else {
- /*Configure Block count enable */
- cmd->block_count_enable_check = DISABLE;
+ /* if multi-block is used */
+ if (CMD18 == index || CMD25 == index) {
+ /* Configure Block count enable */
+ cmd->block_count_enable_check = ENABLE;
+ /* Configure Multi single block select */
+ cmd->multi_single_block = MULTIPLE;
+ } else {
+ /* Configure Block count enable */
+ cmd->block_count_enable_check = DISABLE;
- /*Configure Multi single block select */
- cmd->multi_single_block = SINGLE;
- }
+ /* Configure Multi single block select */
+ cmd->multi_single_block = SINGLE;
+ }
}