- //wait max timeout (unit: ms)
- cyg_uint32 timeout = 15000;
-
- command_t cmd;
- command_response_t response;
- cyg_uint32 voltage_validation_command = 0;
- cyg_uint32 default_rca = 0;
-
- cyg_uint32 ocr_value = SD_OCR_VALUE_HV_LC; /* nirp_oct07: <- split OCR to 3.3v and 1.8v cases */
- cyg_uint32 voltage_validation = FAIL;
- cyg_uint32 interface_value = 0;
- cyg_uint32 card_usable = SUCCESS;
-
- /* Configure Command CMD8 to check for High capacity support */
- /* try 3.3V first */
- mxcmci_cmd_config(&cmd, CMD8, SD_IF_HV_COND_ARG, READ, RESPONSE_48,
- DATA_PRESENT_NONE, ENABLE, ENABLE);
-
- /* Issue Command CMD8 to SD Memory card */
- if (host_send_cmd(&cmd) == SUCCESS) { /* nirp_oct07: <- changed order of detection */
- //diag_printf("%s:CMD8 OK!\n", __FUNCTION__);
- response.format = RESPONSE_48;
- host_read_response(&response);
-
- /* Obtain Interface value from the response buffer */
- interface_value = response.cmd_rsp0;
-
- /* Check if volatge lies in range or not */
- if ((interface_value & SD_IF_HV_COND_ARG) == SD_IF_HV_COND_ARG) {
- ocr_value = ((cyg_uint32) (SD_OCR_VALUE_HV_HC) & 0xFFFFFFFF); /* nirp_oct07: <- split OCR to 3.3v and 1.8v cases */
- }
-
- /* start timer for a delay of 1.5sec, for ACMD41 */
- hal_delay_us(1500);
-
- while ((voltage_validation_command < 20)
- && (voltage_validation != SUCCESS)
- && (card_usable == SUCCESS)) {
- /* Configure CMD55 for SD card */
- /* This command expects defualt RCA 0x0000 as argument. */
- mxcmci_cmd_config(&cmd, CMD55, default_rca, READ,
- RESPONSE_48, DATA_PRESENT_NONE,
- ENABLE, ENABLE);
-
- /* Issue CMD55 to SD Memory card */
- if (host_send_cmd(&cmd) == FAIL) {
- voltage_validation = FAIL;
- //diag_printf("Send CMD55 Failed.\n");
- break;
- } else {
- /* Configure ACMD41 for SD card */
- /* This command expects operating voltage range as argument. */
- /* CODE REVIEW START: Need to check why BUSY was expected */
- /* INTERNAL CODE REVIEW: Accepted - to fix original code if needed */
- /* nirp: changed RESPONSE_48_CHECK_BUSY to RESPONSE_48 */
- /* nirp_oct03: why with busy again? ACMD41 doesn't hold busy line */
- mxcmci_cmd_config(&cmd, ACMD41, ocr_value, READ,
- RESPONSE_48, DATA_PRESENT_NONE, DISABLE,
- DISABLE);
-
- /* Issue ACMD41 to SD Memory card to determine OCR value */
- if (host_send_cmd(&cmd) == FAIL) {
- voltage_validation = FAIL;
- diag_printf("Send CMD41 Failed.\n");
- break;
- } else {
- /* Read Response from CMDRSP0 Register */
- response.format = RESPONSE_48;
- host_read_response(&response);
-
- /* Obtain OCR Values from the response */
- /* Obtain OCR value from the response buffer */
- ocr_value = response.cmd_rsp0;
-
- /* Check if card busy bit is cleared or not */
- if (!(response.cmd_rsp0 & CARD_BUSY_BIT)) {
- /* Iterate One more time */
- voltage_validation_command++;
- } else {
-
- /*CODE REVIEW START: Update code and check only bit 30, HC or LC card type. All voltage bits needs to be masked. */
- /* INTERNAL CODE REVIEW: Accepted - need fix the code accordingly */
- /* nirp: It may be better to check the actual power supply voltage - requiring the entire range (0xff8000) may fail the sequence even if the device can be supported */
- /*CODE REVIEW END: */
-
- if ((response.cmd_rsp0 & SD_OCR_HC_RES) == SD_OCR_HC_RES) {
- address_mode = SECT_MODE;
- voltage_validation = SUCCESS;
- }
- /* CODE REVIEW 3: (same as above) Check is logically correct, but seems redundent.
- Anything that fails the HC check, is assumed Low Capacity */
- /* nirp_oct03: this can be just an "else". the LC macro is 0 anyway,
- and anything not HC is LC by default */
- /* removed else if */
- else {
- address_mode = BYTE_MODE;
- voltage_validation = SUCCESS;
- }
- }
- }
- }
-
- hal_delay_us(1000);
- }
-
- if (voltage_validation == FAIL) {
- card_usable = FAIL;
- }
-
- } else {
- /*3.3v test failed, try to test 1.8v mode! */
- mxcmci_cmd_config(&cmd, CMD8, SD_IF_LV_COND_ARG, READ,
- RESPONSE_48, DATA_PRESENT_NONE, ENABLE,
- ENABLE);
-
- /* Issue Command CMD8 to SD Memory card */
- if (host_send_cmd(&cmd) == FAIL) {
- //diag_printf("%s:CMD8 for 1.8v failed!\n", __FUNCTION__);
- /* nirp_oct07: CMD8 failed both in 3.3 and in 1.8v, try SD 1.x case - no CMD8, LC, 3.3v only */
- ocr_value = ((cyg_uint32) (SD_OCR_VALUE_HV_LC) & 0xFFFFFFFF); /* nirp_oct07: <- changed order of detection */
- } else {
- //diag_printf("%s:CMD8 for 1.8v OK!\n", __FUNCTION__);
- response.format = RESPONSE_48;
- host_read_response(&response);
-
- /* Obtain Interface value from the response buffer */
- interface_value = response.cmd_rsp0;
-
- /* Check if volatge lies in range or not */
- if ((interface_value & SD_IF_LV_COND_ARG) == SD_IF_LV_COND_ARG) {
- ocr_value = ((cyg_uint32) (SD_OCR_VALUE_LV_HC) & 0xFFFFFFFF); /* nirp_oct07: <- split OCR to 3.3v and 1.8v cases */
- }
- /* nirp_oct07: otherwise, try with HV_LC settings (set at function start) */
- }
-
- }
-
- /* start timer for a delay of 1.5sec, for ACMD41 */
- hal_delay_us(1500);
-
- /* nirp_oct03: MMCSD_READY_TIMEOUT too long.
- ACMD41 also takes longer than CMD1 (twice - ~200 clocks for CMD55+resp+CMD41+resp */
- /* In any case ,ACMD 41 will loop not more than 1.5 sec */
- while ((voltage_validation_command < 20)
- && (voltage_validation != SUCCESS) && (card_usable == SUCCESS)) {
- /* Configure CMD55 for SD card */
- /* This command expects defualt RCA 0x0000 as argument. */
- mxcmci_cmd_config(&cmd, CMD55, default_rca, READ, RESPONSE_48,
- DATA_PRESENT_NONE, ENABLE, ENABLE);
-
- /* Issue CMD55 to SD Memory card */
- if (host_send_cmd(&cmd) == FAIL) {
- voltage_validation = FAIL;
- //diag_printf("Send CMD55 Failed!\n");
- break;
- } else {
- /* Configure ACMD41 for SD card */
- /* This command expects operating voltage range as argument. */
- /* CODE REVIEW START: Need to check why BUSY was expected */
- /* INTERNAL CODE REVIEW: Accepted - to fix original code if needed */
- /* nirp: changed RESPONSE_48_CHECK_BUSY to RESPONSE_48 */
- /* nirp_oct03: why with busy again? ACMD41 doesn't hold busy line */
- mxcmci_cmd_config(&cmd, ACMD41, ocr_value, READ,
- RESPONSE_48, DATA_PRESENT_NONE,
- DISABLE, DISABLE);
-
- /* CODE REVIEW END: */
-
- /* Issue ACMD41 to SD Memory card to determine OCR value */
- if (host_send_cmd(&cmd) == FAIL) {
- voltage_validation = FAIL;
- diag_printf("Send ACMD41 Failed!\n");
- break;
- } else {
- /* Read Response from CMDRSP0 Register */
- response.format = RESPONSE_48;
- host_read_response(&response);
-
- /* Obtain OCR Values from the response */
- /* Obtain OCR value from the response buffer
- */
- ocr_value = response.cmd_rsp0;
-
- /* Check if card busy bit is cleared or not */
- if (!(response.cmd_rsp0 & CARD_BUSY_BIT)) {
- /* Iterate One more time */
- voltage_validation_command++;
- } else {
- /*CODE REVIEW START: Update code and check only bit 30, HC or LC card type. All voltage bits needs to be masked. */
- /* INTERNAL CODE REVIEW: Accepted - need fix the code accordingly */
- /* nirp: It may be better to check the actual power supply voltage - requiring the entire range (0xff8000) may fail the sequence even if the device can be supported */
- /*CODE REVIEW END: */
-
- if ((response.cmd_rsp0 & SD_OCR_HC_RES) == SD_OCR_HC_RES) {
- address_mode = SECT_MODE;
- voltage_validation = SUCCESS;
- }
- /* CODE REVIEW 3: (same as above) Check is logically correct, but seems redundent.
- Anything that fails the HC check, is assumed Low Capacity */
- /* nirp_oct03: this can be just an "else". the LC macro is 0 anyway,
- and anything not HC is LC by default */
- else {
- address_mode = BYTE_MODE;
- voltage_validation = SUCCESS;
- }
- }
- }
-
- }
-
- hal_delay_us(1000);
-
- }
-
- return voltage_validation;
+ //wait max timeout (unit: ms)
+ cyg_uint32 timeout = 15000;
+
+ command_t cmd;
+ command_response_t response;
+ cyg_uint32 voltage_validation_command = 0;
+ cyg_uint32 default_rca = 0;
+
+ cyg_uint32 ocr_value = SD_OCR_VALUE_HV_LC; /* nirp_oct07: <- split OCR to 3.3v and 1.8v cases */
+ cyg_uint32 voltage_validation = FAIL;
+ cyg_uint32 interface_value = 0;
+ cyg_uint32 card_usable = SUCCESS;
+
+ /* Configure Command CMD8 to check for High capacity support */
+ /* try 3.3V first */
+ mxcmci_cmd_config(&cmd, CMD8, SD_IF_HV_COND_ARG, READ, RESPONSE_48,
+ DATA_PRESENT_NONE, ENABLE, ENABLE);
+
+ /* Issue Command CMD8 to SD Memory card */
+ if (host_send_cmd(&cmd) == SUCCESS) { /* nirp_oct07: <- changed order of detection */
+ //diag_printf("%s:CMD8 OK!\n", __FUNCTION__);
+ response.format = RESPONSE_48;
+ host_read_response(&response);
+
+ /* Obtain Interface value from the response buffer */
+ interface_value = response.cmd_rsp0;
+
+ /* Check if volatge lies in range or not */
+ if ((interface_value & SD_IF_HV_COND_ARG) == SD_IF_HV_COND_ARG) {
+ ocr_value = ((cyg_uint32) (SD_OCR_VALUE_HV_HC) & 0xFFFFFFFF); /* nirp_oct07: <- split OCR to 3.3v and 1.8v cases */
+ }
+
+ /* start timer for a delay of 1.5sec, for ACMD41 */
+ hal_delay_us(1500);
+
+ while ((voltage_validation_command < 20)
+ && (voltage_validation != SUCCESS)
+ && (card_usable == SUCCESS)) {
+ /* Configure CMD55 for SD card */
+ /* This command expects defualt RCA 0x0000 as argument. */
+ mxcmci_cmd_config(&cmd, CMD55, default_rca, READ,
+ RESPONSE_48, DATA_PRESENT_NONE,
+ ENABLE, ENABLE);
+
+ /* Issue CMD55 to SD Memory card */
+ if (host_send_cmd(&cmd) == FAIL) {
+ voltage_validation = FAIL;
+ //diag_printf("Send CMD55 Failed.\n");
+ break;
+ } else {
+ /* Configure ACMD41 for SD card */
+ /* This command expects operating voltage range as argument. */
+ /* CODE REVIEW START: Need to check why BUSY was expected */
+ /* INTERNAL CODE REVIEW: Accepted - to fix original code if needed */
+ /* nirp: changed RESPONSE_48_CHECK_BUSY to RESPONSE_48 */
+ /* nirp_oct03: why with busy again? ACMD41 doesn't hold busy line */
+ mxcmci_cmd_config(&cmd, ACMD41, ocr_value, READ,
+ RESPONSE_48, DATA_PRESENT_NONE, DISABLE,
+ DISABLE);
+
+ /* Issue ACMD41 to SD Memory card to determine OCR value */
+ if (host_send_cmd(&cmd) == FAIL) {
+ voltage_validation = FAIL;
+ diag_printf("Send CMD41 Failed.\n");
+ break;
+ } else {
+ /* Read Response from CMDRSP0 Register */
+ response.format = RESPONSE_48;
+ host_read_response(&response);
+
+ /* Obtain OCR Values from the response */
+ /* Obtain OCR value from the response buffer */
+ ocr_value = response.cmd_rsp0;
+
+ /* Check if card busy bit is cleared or not */
+ if (!(response.cmd_rsp0 & CARD_BUSY_BIT)) {
+ /* Iterate One more time */
+ voltage_validation_command++;
+ } else {
+
+ /*CODE REVIEW START: Update code and check only bit 30, HC or LC card type. All voltage bits needs to be masked. */
+ /* INTERNAL CODE REVIEW: Accepted - need fix the code accordingly */
+ /* nirp: It may be better to check the actual power supply voltage - requiring the entire range (0xff8000) may fail the sequence even if the device can be supported */
+ /*CODE REVIEW END: */
+
+ if ((response.cmd_rsp0 & SD_OCR_HC_RES) == SD_OCR_HC_RES) {
+ address_mode = SECT_MODE;
+ voltage_validation = SUCCESS;
+ }
+ /* CODE REVIEW 3: (same as above) Check is logically correct, but seems redundent.
+ Anything that fails the HC check, is assumed Low Capacity */
+ /* nirp_oct03: this can be just an "else". the LC macro is 0 anyway,
+ and anything not HC is LC by default */
+ /* removed else if */
+ else {
+ address_mode = BYTE_MODE;
+ voltage_validation = SUCCESS;
+ }
+ }
+ }
+ }
+
+ hal_delay_us(1000);
+ }
+
+ if (voltage_validation == FAIL) {
+ card_usable = FAIL;
+ }
+
+ } else {
+ /*3.3v test failed, try to test 1.8v mode! */
+ mxcmci_cmd_config(&cmd, CMD8, SD_IF_LV_COND_ARG, READ,
+ RESPONSE_48, DATA_PRESENT_NONE, ENABLE,
+ ENABLE);
+
+ /* Issue Command CMD8 to SD Memory card */
+ if (host_send_cmd(&cmd) == FAIL) {
+ //diag_printf("%s:CMD8 for 1.8v failed!\n", __FUNCTION__);
+ /* nirp_oct07: CMD8 failed both in 3.3 and in 1.8v, try SD 1.x case - no CMD8, LC, 3.3v only */
+ ocr_value = ((cyg_uint32) (SD_OCR_VALUE_HV_LC) & 0xFFFFFFFF); /* nirp_oct07: <- changed order of detection */
+ } else {
+ //diag_printf("%s:CMD8 for 1.8v OK!\n", __FUNCTION__);
+ response.format = RESPONSE_48;
+ host_read_response(&response);
+
+ /* Obtain Interface value from the response buffer */
+ interface_value = response.cmd_rsp0;
+
+ /* Check if volatge lies in range or not */
+ if ((interface_value & SD_IF_LV_COND_ARG) == SD_IF_LV_COND_ARG) {
+ ocr_value = ((cyg_uint32) (SD_OCR_VALUE_LV_HC) & 0xFFFFFFFF); /* nirp_oct07: <- split OCR to 3.3v and 1.8v cases */
+ }
+ /* nirp_oct07: otherwise, try with HV_LC settings (set at function start) */
+ }
+
+ }
+
+ /* start timer for a delay of 1.5sec, for ACMD41 */
+ hal_delay_us(1500);
+
+ /* nirp_oct03: MMCSD_READY_TIMEOUT too long.
+ ACMD41 also takes longer than CMD1 (twice - ~200 clocks for CMD55+resp+CMD41+resp */
+ /* In any case ,ACMD 41 will loop not more than 1.5 sec */
+ while ((voltage_validation_command < 20)
+ && (voltage_validation != SUCCESS) && (card_usable == SUCCESS)) {
+ /* Configure CMD55 for SD card */
+ /* This command expects defualt RCA 0x0000 as argument. */
+ mxcmci_cmd_config(&cmd, CMD55, default_rca, READ, RESPONSE_48,
+ DATA_PRESENT_NONE, ENABLE, ENABLE);
+
+ /* Issue CMD55 to SD Memory card */
+ if (host_send_cmd(&cmd) == FAIL) {
+ voltage_validation = FAIL;
+ //diag_printf("Send CMD55 Failed!\n");
+ break;
+ } else {
+ /* Configure ACMD41 for SD card */
+ /* This command expects operating voltage range as argument. */
+ /* CODE REVIEW START: Need to check why BUSY was expected */
+ /* INTERNAL CODE REVIEW: Accepted - to fix original code if needed */
+ /* nirp: changed RESPONSE_48_CHECK_BUSY to RESPONSE_48 */
+ /* nirp_oct03: why with busy again? ACMD41 doesn't hold busy line */
+ mxcmci_cmd_config(&cmd, ACMD41, ocr_value, READ,
+ RESPONSE_48, DATA_PRESENT_NONE,
+ DISABLE, DISABLE);
+
+ /* CODE REVIEW END: */
+
+ /* Issue ACMD41 to SD Memory card to determine OCR value */
+ if (host_send_cmd(&cmd) == FAIL) {
+ voltage_validation = FAIL;
+ diag_printf("Send ACMD41 Failed!\n");
+ break;
+ } else {
+ /* Read Response from CMDRSP0 Register */
+ response.format = RESPONSE_48;
+ host_read_response(&response);
+
+ /* Obtain OCR Values from the response */
+ /* Obtain OCR value from the response buffer
+ */
+ ocr_value = response.cmd_rsp0;
+
+ /* Check if card busy bit is cleared or not */
+ if (!(response.cmd_rsp0 & CARD_BUSY_BIT)) {
+ /* Iterate One more time */
+ voltage_validation_command++;
+ } else {
+ /*CODE REVIEW START: Update code and check only bit 30, HC or LC card type. All voltage bits needs to be masked. */
+ /* INTERNAL CODE REVIEW: Accepted - need fix the code accordingly */
+ /* nirp: It may be better to check the actual power supply voltage - requiring the entire range (0xff8000) may fail the sequence even if the device can be supported */
+ /*CODE REVIEW END: */
+
+ if ((response.cmd_rsp0 & SD_OCR_HC_RES) == SD_OCR_HC_RES) {
+ address_mode = SECT_MODE;
+ voltage_validation = SUCCESS;
+ }
+ /* CODE REVIEW 3: (same as above) Check is logically correct, but seems redundent.
+ Anything that fails the HC check, is assumed Low Capacity */
+ /* nirp_oct03: this can be just an "else". the LC macro is 0 anyway,
+ and anything not HC is LC by default */
+ else {
+ address_mode = BYTE_MODE;
+ voltage_validation = SUCCESS;
+ }
+ }
+ }
+
+ }
+
+ hal_delay_us(1000);
+
+ }
+
+ return voltage_validation;
- command_t cmd;
- cyg_uint32 rd_data_buff[128];
- cyg_uint32 bit4_mode_support;
- command_response_t response;
- cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
-
- /* Configure CMD55 for SD card */
- /* This command expects RCA as argument. */
- mxcmci_cmd_config(&cmd, CMD55, card_address, READ, RESPONSE_48,
- DATA_PRESENT_NONE, ENABLE, ENABLE);
-
- /* Issue CMD55 to SD Memory card */
- if (host_send_cmd(&cmd) == FAIL) {
- bit4_mode_support = 0;
- } else {
- /* Read Command response */
- response.format = RESPONSE_48;
- host_read_response(&response);
-
- /* Afetr giving ACMD Command, the R1 response should have
- * STATUS_APP_CMD set
- */
- if (response.cmd_rsp0 & SD_R1_STATUS_APP_CMD_MSK) {
-
- /* Configure ACMD51 for SD card */
- /* This command expects No argument. */
-
- mxcmci_cmd_config(&cmd, ACMD51, NO_ARG, READ,
- RESPONSE_48, DATA_PRESENT, ENABLE,
- ENABLE);
-
- /* Issue ACMD51 to SD Memory card */
- if (host_send_cmd(&cmd) == FAIL) {
- bit4_mode_support = 0;
- } else {
- /* Read Response from e-SDHC buffer */
- host_data_read(rd_data_buff, 512);
-
- /* Check for bus width supported */
- bit4_mode_support = (rd_data_buff[SD_BUS_WIDTH_OFFSET] & BIT_MODE_4_SUPPORT);
-
- if (bit4_mode_support) {
- bit4_mode_support = BIT_4_MODE;
- }
-
- }
- }
- }
-
- return bit4_mode_support;
+ command_t cmd;
+ cyg_uint32 rd_data_buff[128];
+ cyg_uint32 bit4_mode_support;
+ command_response_t response;
+ cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
+
+ /* Configure CMD55 for SD card */
+ /* This command expects RCA as argument. */
+ mxcmci_cmd_config(&cmd, CMD55, card_address, READ, RESPONSE_48,
+ DATA_PRESENT_NONE, ENABLE, ENABLE);
+
+ /* Issue CMD55 to SD Memory card */
+ if (host_send_cmd(&cmd) == FAIL) {
+ bit4_mode_support = 0;
+ } else {
+ /* Read Command response */
+ response.format = RESPONSE_48;
+ host_read_response(&response);
+
+ /* Afetr giving ACMD Command, the R1 response should have
+ * STATUS_APP_CMD set
+ */
+ if (response.cmd_rsp0 & SD_R1_STATUS_APP_CMD_MSK) {
+
+ /* Configure ACMD51 for SD card */
+ /* This command expects No argument. */
+
+ mxcmci_cmd_config(&cmd, ACMD51, NO_ARG, READ,
+ RESPONSE_48, DATA_PRESENT, ENABLE,
+ ENABLE);
+
+ /* Issue ACMD51 to SD Memory card */
+ if (host_send_cmd(&cmd) == FAIL) {
+ bit4_mode_support = 0;
+ } else {
+ /* Read Response from e-SDHC buffer */
+ host_data_read(rd_data_buff, 512);
+
+ /* Check for bus width supported */
+ bit4_mode_support = (rd_data_buff[SD_BUS_WIDTH_OFFSET] & BIT_MODE_4_SUPPORT);
+
+ if (bit4_mode_support) {
+ bit4_mode_support = BIT_4_MODE;
+ }
+
+ }
+ }
+ }
+
+ return bit4_mode_support;