]> git.kernelconcepts.de Git - karo-tx-redboot.git/blobdiff - packages/devs/flash/arm/mxc/v2_0/src/mxcmci_mmc.c
TX51 Release 2011-07-27
[karo-tx-redboot.git] / packages / devs / flash / arm / mxc / v2_0 / src / mxcmci_mmc.c
index 4a8751c1ff979b51d337aed339a5c2d513b9f2c1..cf80b2a699b6c47644f43c044679518a5bd1872b 100644 (file)
 //
 //==========================================================================
 
-#include <cyg/infra/diag.h>
 #include <cyg/io/mxcmci_host.h>
 #include <cyg/io/mxcmci_core.h>
 #include <cyg/io/mxcmci_mmc.h>
 #include <cyg/io/mxc_mmc.h>
-#include <cyg/hal/hal_intr.h>
+
+extern int HighCapacityCard;
 
 static cyg_uint32 mmc_set_rca(void);
 static cyg_uint32 mmc_set_bus_width(cyg_uint32 bus_width);
+static cyg_uint32 mmc_set_high_speed_mode(void);
 
 cyg_uint32 address_mode;    /* Global variable for addressing mode */
 
@@ -87,6 +88,7 @@ cyg_uint32 mmc_init(cyg_uint32 bus_width)
                                        return FAIL;
                                }
 #endif
+
                                /* Set block length for transfer */
                                //diag_printf("Send CMD to Set Block Length.\n");
                                if (sdmmc_set_blklen(BLK_LEN))
@@ -111,10 +113,11 @@ cyg_uint32 mmc_init(cyg_uint32 bus_width)
 
 }
 
-cyg_uint32 mmc_data_read(cyg_uint32 *dest_ptr, cyg_uint32 length,
-                                               cyg_uint32 offset)
+cyg_uint32 mmc_data_read(cyg_uint32 * dest_ptr, cyg_uint32 length,
+             cyg_uint32 offset)
 {
        command_t cmd;
+       int len;
        cyg_uint32 read_block_status = 0;
        cyg_uint32 blk_len = BLK_LEN;
        unsigned int SectorNum = 0;
@@ -129,7 +132,7 @@ cyg_uint32 mmc_data_read(cyg_uint32 *dest_ptr, cyg_uint32 length,
 
        /* wait until in transfer mode */
        while (mxcmci_trans_status()) {
-               HAL_DELAY_US(5);
+               hal_delay_us(5);
        }
 
 reread:
@@ -197,11 +200,12 @@ reread:
        return read_block_status;
 }
 
-cyg_uint32 mmc_data_write(cyg_uint32 *src_ptr, cyg_uint32 length,
-                                               cyg_uint32 offset)
+cyg_uint32 mmc_data_write(cyg_uint32 * src_ptr, cyg_uint32 length,
+              cyg_uint32 offset)
 {
 
        command_t cmd;
+       cyg_int32 len;
        cyg_uint32 blk_len = BLK_LEN;
        cyg_uint32 write_block_status = SUCCESS;
        unsigned int SectorNum;
@@ -217,12 +221,12 @@ cyg_uint32 mmc_data_write(cyg_uint32 *src_ptr, cyg_uint32 length,
                offset = offset/512;
 
        //need waiting until CARD out of Prg status, or will cause CMD25 timeout
-       //HAL_DELAY_US(100);
+       //hal_delay_us(100);
 
        //StartCounter();
 
        while (mxcmci_trans_status()) {
-               HAL_DELAY_US(2);
+               hal_delay_us(2);
        }
 
        //counter = StopCounter();
@@ -244,7 +248,7 @@ rewrite:
                        esdhc_softreset(ESDHC_RESET_CMD_MSK | ESDHC_RESET_DAT_MSK);
                        write_block_status = FAIL;
 
-                       //HAL_DELAY_US(1000);
+                       //hal_delay_us(1000);
                        goto rewrite;
 
                } else {
@@ -301,378 +305,390 @@ rewrite:
        }
 
        return write_block_status;
+
 }
 
 cyg_uint32 mmc_data_erase(cyg_uint32 offset, cyg_uint32 size)
 {
-       command_t cmd;
-       extern int Card_Mode;
-       cyg_uint8 startEraseBlockCmd = CMD35;
-       cyg_uint8 endEraseBlockCmd = CMD36;
-
-       cyg_uint32 startBlock = offset / BLK_LEN;
-       cyg_uint32 endBlock = (offset + size - 1) / BLK_LEN;
-       cyg_uint32 ret;
+    command_t cmd;
+    extern int Card_Mode;
+    cyg_uint8 startEraseBlockCmd = CMD35;
+    cyg_uint8 endEraseBlockCmd = CMD36;
+
+    cyg_uint32 startBlock = offset / BLK_LEN;
+    cyg_uint32 endBlock = (offset + size - 1) / BLK_LEN;
+    cyg_uint32 ret;
 //    diag_printf("card_data_erase\n");
-       if (Card_Mode == 0) {
-               startBlock *= BLK_LEN;
-               endBlock *= BLK_LEN;
-               startEraseBlockCmd = CMD35;
-               endEraseBlockCmd = CMD36;
-       }
-
-       else if (Card_Mode == 1) {
-               startBlock *= BLK_LEN;
-               endBlock *= BLK_LEN;
-               startEraseBlockCmd = CMD32;
-               endEraseBlockCmd = CMD33;
-       }
+    if (Card_Mode == 0) {
+        startBlock *= BLK_LEN;
+        endBlock *= BLK_LEN;
+        startEraseBlockCmd = CMD35;
+        endEraseBlockCmd = CMD36;
+    }
+
+    else if (Card_Mode == 1) {
+        startBlock *= BLK_LEN;
+        endBlock *= BLK_LEN;
+        startEraseBlockCmd = CMD32;
+        endEraseBlockCmd = CMD33;
+    }
 #if 1
-       /* hight capacity card uses sector mode */
-       if(HighCapacityCard)
-               startBlock /= BLK_LEN;
-       endBlock /= BLK_LEN;
+    /* hight capacity card uses sector mode */
+    if(HighCapacityCard)
+        startBlock /= BLK_LEN;
+        endBlock /= BLK_LEN;
 #endif
 //     diag_printf("0x%x - 0x%x, size: 0x%x\n", startBlock, endBlock, size);
-       /* Configure start erase command to set first block */
-       mxcmci_cmd_config(&cmd, startEraseBlockCmd, startBlock, READ,
-                                       RESPONSE_48, DATA_PRESENT_NONE, ENABLE, ENABLE);
-       /* wait response */
-       if ((ret = host_send_cmd(&cmd)) == SUCCESS) {
-               flash_dprintf(FLASH_DEBUG_MAX,
-                                       "%s: successful for host_send_cmd\n",
-                                       __FUNCTION__);
-               /* Configure end erase command to set end block */
-               mxcmci_cmd_config(&cmd, endEraseBlockCmd, endBlock, READ,
-                                               RESPONSE_48, DATA_PRESENT_NONE, ENABLE, ENABLE);
-               if ((ret = host_send_cmd(&cmd)) == SUCCESS) {
-                       flash_dprintf(FLASH_DEBUG_MAX,
-                                               "%s: successful for host_send_cmd:2\n",
-                                               __FUNCTION__);
-                       /* Comfigure command to start erase */
-                       mxcmci_cmd_config(&cmd, CMD38, 0, READ, RESPONSE_48,
-                                                       DATA_PRESENT_NONE, ENABLE, ENABLE);
-                       if ((ret = host_send_cmd(&cmd)) == SUCCESS) {
-                               flash_dprintf(FLASH_DEBUG_MAX,
-                                                       "%s: successful for host_send_cmd:3\n",
-                                                       __FUNCTION__);
-                               //wait for completion
-                               return ret;
-                       }
-               }
-       }
-
-       flash_dprintf(FLASH_DEBUG_MAX, "%s: Error return (%d)\n", __FUNCTION__,
-                               ret);
-       return ret;
+    /* Configure start erase command to set first block */
+    mxcmci_cmd_config(&cmd, startEraseBlockCmd, startBlock, READ,
+              RESPONSE_48, DATA_PRESENT_NONE, ENABLE, ENABLE);
+    /* wait response */
+    if ((ret = host_send_cmd(&cmd)) == SUCCESS) {
+        flash_dprintf(FLASH_DEBUG_MAX,
+                  "%s: successful for host_send_cmd\n",
+                  __FUNCTION__);
+        /* Configure end erase command to set end block */
+        mxcmci_cmd_config(&cmd, endEraseBlockCmd, endBlock, READ,
+                  RESPONSE_48, DATA_PRESENT_NONE, ENABLE, ENABLE);
+        if ((ret = host_send_cmd(&cmd)) == SUCCESS) {
+            flash_dprintf(FLASH_DEBUG_MAX,
+                      "%s: successful for host_send_cmd:2\n",
+                      __FUNCTION__);
+            /* Comfigure command to start erase */
+            mxcmci_cmd_config(&cmd, CMD38, 0, READ, RESPONSE_48,
+                      DATA_PRESENT_NONE, ENABLE, ENABLE);
+            if ((ret = host_send_cmd(&cmd)) == SUCCESS) {
+                flash_dprintf(FLASH_DEBUG_MAX,
+                          "%s: successful for host_send_cmd:3\n",
+                          __FUNCTION__);
+                //wait for completion
+                return ret;
+            }
+        }
+    }
+
+    flash_dprintf(FLASH_DEBUG_MAX, "%s: Error return (%d)\n", __FUNCTION__,
+              ret);
+    return ret;
 }
 
 cyg_uint32 mmc_voltage_validation(void)
 {
-       command_t cmd;
-       command_response_t response;
-       cyg_uint32 voltage_validation_command = 0;
-       cyg_uint32 ocr_val = 0;
-       cyg_uint32 voltage_validation = FAIL;
-
-       ocr_val = (cyg_uint32) ((MMC_OCR_VALUE) & 0xFFFFFFFF);
-
-       while ((voltage_validation_command < MMCSD_READY_TIMEOUT)
-               && (voltage_validation != SUCCESS)) {
-               /* Configure CMD1 for MMC card */
-               mxcmci_cmd_config(&cmd, CMD1, ocr_val, READ, RESPONSE_48,
-                                               DATA_PRESENT_NONE, DISABLE, DISABLE);
-
-               /* Issue CMD1 to MMC card to determine OCR value */
-               if (host_send_cmd(&cmd) == FAIL) {
-                       voltage_validation = FAIL;
-                       break;
-               } else {
-                       /* Read Response from CMDRSP0 Register */
-                       response.format = RESPONSE_48;
-                       host_read_response(&response);
-
-                       /* Check if card busy bit is cleared or not */
-                       if (!(response.cmd_rsp0 & CARD_BUSY_BIT)) {
-                               /* Iterate One more time */
-                               voltage_validation_command++;
-                       } else {
-                               if ((response.cmd_rsp0 & MMC_OCR_HC_RES) ==
-                                       MMC_OCR_HC_RES) {
-                                       address_mode = SECT_MODE;
-                                       voltage_validation = SUCCESS;
-                               } else if ((response.cmd_rsp0 & MMC_OCR_LC_RES)
-                                               == MMC_OCR_LC_RES) {
-                                       address_mode = BYTE_MODE;
-                                       voltage_validation = SUCCESS;
-                               }
-                       }
-
-               }
-       }
-
-       return voltage_validation;
+    command_t cmd;
+    command_response_t response;
+    cyg_uint32 voltage_validation_command = 0;
+    cyg_uint32 ocr_val = 0;
+    cyg_uint32 voltage_validation = FAIL;
+
+    ocr_val = (cyg_uint32) ((MMC_OCR_VALUE) & 0xFFFFFFFF);
+
+    while ((voltage_validation_command < MMCSD_READY_TIMEOUT)
+           && (voltage_validation != SUCCESS)) {
+        /* Configure CMD1 for MMC card */
+        mxcmci_cmd_config(&cmd, CMD1, ocr_val, READ, RESPONSE_48,
+                  DATA_PRESENT_NONE, DISABLE, DISABLE);
+
+        /* Issue CMD1 to MMC card to determine OCR value */
+        if (host_send_cmd(&cmd) == FAIL) {
+            voltage_validation = FAIL;
+            break;
+        } else {
+            /* Read Response from CMDRSP0 Register */
+            response.format = RESPONSE_48;
+            host_read_response(&response);
+
+            /* Check if card busy bit is cleared or not */
+            if (!(response.cmd_rsp0 & CARD_BUSY_BIT)) {
+                /* Iterate One more time */
+                voltage_validation_command++;
+            } else {
+                if ((response.cmd_rsp0 & MMC_OCR_HC_RES) ==
+                    MMC_OCR_HC_RES) {
+                    address_mode = SECT_MODE;
+                    voltage_validation = SUCCESS;
+                } else if ((response.cmd_rsp0 & MMC_OCR_LC_RES)
+                       == MMC_OCR_LC_RES) {
+                    address_mode = BYTE_MODE;
+                    voltage_validation = SUCCESS;
+                }
+            }
+
+        }
+    }
+
+    return voltage_validation;
 }
 
 static cyg_uint32 mmc_set_rca(void)
 {
-       command_t cmd;
-       cyg_uint32 card_state = 0;
-       cyg_uint32 rca_request = 0;
-       command_response_t response;
-       cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
-
-       /* Configure CMD3 for MMC card */
-       /* 32bit card address is expected as Argument */
-       mxcmci_cmd_config(&cmd, CMD3, card_address, READ, RESPONSE_48,
-                                       DATA_PRESENT_NONE, ENABLE, ENABLE);
-
-       /* Assigns relative address to the card
-        */
-
-       if (host_send_cmd(&cmd) == FAIL) {
-               rca_request = FAIL;
-       }
-
-       else {
-               /* Read Command response */
-               response.format = RESPONSE_48;
-               host_read_response(&response);
-               card_state = CURR_CARD_STATE(response.cmd_rsp0);
-               if (card_state == IDENT) {
-                       rca_request = SUCCESS;
-
-               } else {
-                       rca_request = FAIL;
-               }
-       }
-
-       return rca_request;
+    command_t cmd;
+    cyg_uint32 card_state = 0;
+    cyg_uint32 rca_request = 0;
+    command_response_t response;
+    cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
+
+    /* Configure CMD3 for MMC card */
+    /* 32bit card address is expected as Argument */
+    mxcmci_cmd_config(&cmd, CMD3, card_address, READ, RESPONSE_48,
+              DATA_PRESENT_NONE, ENABLE, ENABLE);
+
+    /* Assigns relative address to the card
+     */
+
+    if (host_send_cmd(&cmd) == FAIL) {
+        rca_request = FAIL;
+    }
+
+    else {
+        /* Read Command response */
+        response.format = RESPONSE_48;
+        host_read_response(&response);
+        card_state = CURR_CARD_STATE(response.cmd_rsp0);
+        if (card_state == IDENT) {
+            rca_request = SUCCESS;
+
+        } else {
+            rca_request = FAIL;
+        }
+    }
+
+    return rca_request;
 }
 
 cyg_uint32 mmc_get_spec_ver(void)
 {
 
-       cyg_uint32 mmc_spec_version;
+    cyg_uint32 mmc_spec_version;
 
-       if (card_get_csd() == FAIL) {
-               mmc_spec_version = 0;
-       } else {
-               mmc_spec_version = ((csd.csd3 && MMC_SPEC_VER) >> MMC_SPEC_VER_SHIFT);
-       }
+    if (card_get_csd() == FAIL) {
+        mmc_spec_version = 0;
+    } else {
+        mmc_spec_version = ((csd.csd3 && MMC_SPEC_VER) >> MMC_SPEC_VER_SHIFT);
+    }
+
+    return mmc_spec_version;
 
-       return mmc_spec_version;
 }
 
 cyg_uint32 card_flash_query(void *data)
 {
-       command_t cmd;
-       cyg_uint32 cid_request = FAIL;
-       command_response_t response;
-
-       /* Configure CMD2 for card */
-       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;
-               flash_dprintf(FLASH_DEBUG_MAX, "%s: can't send query command\n",
-                                       __FUNCTION__);
-       } else {
-               cyg_uint32 *d = (cyg_uint32 *) data;
-               /* Read Command response  */
-               response.format = RESPONSE_136;
-               host_read_response(&response);
-               /* Assign CID values to mmc_cid structures */
-               *d++ = response.cmd_rsp0;
-               *d++ = response.cmd_rsp1;
-               *d++ = response.cmd_rsp2;
-               *d = response.cmd_rsp3;
-
-               /* Assign cid_request as SUCCESS */
-               cid_request = SUCCESS;
-       }
-       flash_dprintf(FLASH_DEBUG_MAX,
-                               "%s(Success?=%d):(ID=0x%x: 0x%x, 0x%x, 0x%x)\n",
-                               __FUNCTION__, cid_request, *(cyg_uint32 *) (data),
-                               *(cyg_uint32 *) ((cyg_uint32) data + 4),
-                               *(cyg_uint8 *) ((cyg_uint32) data + 8),
-                               *(cyg_uint8 *) ((cyg_uint32) data + 12));
-       return cid_request;
+    command_t cmd;
+    cyg_uint32 cid_request = FAIL;
+    command_response_t response;
+
+    /* Configure CMD2 for card */
+    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;
+        flash_dprintf(FLASH_DEBUG_MAX, "%s: can't send query command\n",
+                  __FUNCTION__);
+    } else {
+        cyg_uint32 *d = (cyg_uint32 *) data;
+        /* Read Command response  */
+        response.format = RESPONSE_136;
+        host_read_response(&response);
+        /* Assign CID values to mmc_cid structures */
+        *d++ = response.cmd_rsp0;
+        *d++ = response.cmd_rsp1;
+        *d++ = response.cmd_rsp2;
+        *d = response.cmd_rsp3;
+
+        /* Assign cid_request as SUCCESS */
+        cid_request = SUCCESS;
+    }
+    flash_dprintf(FLASH_DEBUG_MAX,
+              "%s(Success?=%d):(ID=0x%x: 0x%x, 0x%x, 0x%x)\n",
+              __FUNCTION__, cid_request, *(cyg_uint32 *) (data),
+              *(cyg_uint32 *) ((cyg_uint32) data + 4),
+              *(cyg_uint8 *) ((cyg_uint32) data + 8),
+              *(cyg_uint8 *) ((cyg_uint32) data + 12));
+    return;
 }
 
 static cyg_uint32 mmc_set_bus_width(cyg_uint32 bus_width)
 {
-       command_t cmd;
-       cyg_uint32 set_bus_width_status = FAIL;
+    command_t cmd;
+    cyg_uint32 set_bus_width_status = FAIL;
+    command_response_t response;
+    cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
 
-       if ((bus_width == 4) || (bus_width == 8) || (bus_width == 1)) {
+    if ((bus_width == FOUR) || (bus_width == EIGHT) || (bus_width == ONE)) {
 
-               /* Configure CMD6 to write to EXT_CSD register for BUS_WIDTH */
-               mxcmci_cmd_config(&cmd, CMD6, 0x03b70001 | ((bus_width >> 2) << 8), READ,
-                                               RESPONSE_48, DATA_PRESENT_NONE, ENABLE, ENABLE);
+        /* Configure CMD6 to write to EXT_CSD register for BUS_WIDTH */
+        mxcmci_cmd_config(&cmd, CMD6, 0x03b70001 | ((bus_width >> 2) << 8), READ,
+                  RESPONSE_48, DATA_PRESENT_NONE, ENABLE, ENABLE);
 
-               if (host_send_cmd(&cmd) == SUCCESS) {
-                       set_bus_width_status = SUCCESS;
-               } else {
-                       diag_printf("Setting MMC bus width failed.\n");
-               }
-       }
+        if (host_send_cmd(&cmd) == SUCCESS) {
+            set_bus_width_status = SUCCESS;
+        } else {
+            diag_printf("Setting MMC bus width failed.\n");
+        }
+    }
 
-       return set_bus_width_status;
+    return set_bus_width_status;
 }
 
-cyg_uint32 mmc_set_high_speed_mode(void)
+static cyg_uint32 mmc_set_high_speed_mode(void)
 {
-       command_t cmd;
-       cyg_uint32 status;
-
-       //diag_printf("Send CMD6 to Set High Speed Mode.\n");
-       /* Configure CMD6 to write to EXT_CSD register for BUS_WIDTH */
-       mxcmci_cmd_config(&cmd, CMD6, 0x03b90100, READ, RESPONSE_48,
-                                       DATA_PRESENT_NONE, ENABLE, ENABLE);
-
-       status = host_send_cmd(&cmd);
-       if (status == SUCCESS) {
-               /* wait until in transfer mode */
-               while (mxcmci_trans_status()) {
-                       HAL_DELAY_US(5);
-               }
-       } else {
-               diag_printf("Setting MMC High Speed Mode FAILED.\n");
-       }
-
-       return status;
+    command_t cmd;
+    command_response_t response;
+    cyg_uint32 status = FAIL;
+
+    //diag_printf("Send CMD6 to Set High Speed Mode.\n");
+    /* Configure CMD6 to write to EXT_CSD register for BUS_WIDTH */
+    mxcmci_cmd_config(&cmd, CMD6, 0x03b90100, READ, RESPONSE_48,
+              DATA_PRESENT_NONE, ENABLE, ENABLE);
+
+    if (host_send_cmd(&cmd) == SUCCESS) {
+        /* wait until in transfer mode */
+        while (mxcmci_trans_status()) {
+            hal_delay_us(5);
+        }
+
+        status = SUCCESS;
+    } else {
+        diag_printf("Setting MMC High Speed Mode FAILED.\n");
+    }
+
+    return status;
 }
 
 int sdmmc_set_blklen(int len)
 {
-       int status;
-       command_t cmd;
-
-       /* Configure CMD16 to set block length as 512 bytes. */
-       mxcmci_cmd_config(&cmd, CMD16, len, READ, RESPONSE_48,
-                                       DATA_PRESENT_NONE, ENABLE, ENABLE);
-
-       /* Issue command CMD16 to set block length as 512 bytes */
-       if (host_send_cmd(&cmd) == FAIL) {
-               diag_printf("%s: Can't set block length!(CMD16)\n",
-                                       __FUNCTION__);
-               esdhc_softreset(ESDHC_RESET_CMD_MSK);
-               status = FAIL;
-       } else {
-               status = SUCCESS;
-       }
-
-       return status;
+    int status = FAIL;
+    command_t cmd;
+    command_response_t response;
+
+    /* Configure CMD16 to set block length as 512 bytes. */
+    mxcmci_cmd_config(&cmd, CMD16, len, READ, RESPONSE_48,
+              DATA_PRESENT_NONE, ENABLE, ENABLE);
+
+    /* Issue command CMD16 to set block length as 512 bytes */
+    if (host_send_cmd(&cmd) == FAIL) {
+        diag_printf("%s: Can't set block length!(CMD16)\n",
+                __FUNCTION__);
+        esdhc_softreset(ESDHC_RESET_CMD_MSK);
+        status = FAIL;
+    } else {
+        status = SUCCESS;
+    }
+
+    return status;
 }
 
 int sdmmc_stop_transmission(void)
 {
-       command_t cmd;
+    int status = FAIL;
+    command_t cmd;
+    command_response_t response;
 
-       /* Comfigure command CMD12 for read stop */
-       mxcmci_cmd_config(&cmd, CMD12, 0, READ, RESPONSE_48,
-                                       DATA_PRESENT_NONE, ENABLE, ENABLE);
+    /* Comfigure command CMD12 for read stop */
+    mxcmci_cmd_config(&cmd, CMD12, 0, READ, RESPONSE_48,
+              DATA_PRESENT_NONE, ENABLE, ENABLE);
 
-       if (host_send_cmd(&cmd) == FAIL) {
-               //diag_printf("%s: Can't send CMD12!\n", __FUNCTION__);
-               //esdhc_softreset(ESDHC_RESET_CMD_MSK | ESDHC_RESET_DAT_MSK);
-               //read_block_status = FAIL;
-       }
+    if (host_send_cmd(&cmd) == FAIL) {
+        //diag_printf("%s: Can't send CMD12!\n", __FUNCTION__);
+        //esdhc_softreset(ESDHC_RESET_CMD_MSK | ESDHC_RESET_DAT_MSK);
+        //read_block_status = FAIL;
+    }
 
-       return 0;
+    return 0;
 }
 
 static unsigned int mmc_set_extendCSD(unsigned int ECSD_index, unsigned int value, unsigned int access_mode)
 {
-       unsigned int argument = 0;
-       command_t cmd;
-
-       /* access mode: 0b01 set bits/ 0b10 clear bits/ 0b11 write bytes */
-       argument = (access_mode << 24) | (ECSD_index << 16) | (value << 8);
-       //argument = 0x1b30000;
-
-       mxcmci_cmd_config(&cmd, CMD6, argument, READ, RESPONSE_48,
-                                       DATA_PRESENT_NONE, ENABLE, ENABLE);
-
-       if(host_send_cmd(&cmd) == SUCCESS) {
-               return 0;
-       } else {
-               //diag_printf("%s: Setting MMC boot Failed.\n", __FUNCTION__);
-               return 1;
-       }
+    unsigned int argument = 0;
+    command_t cmd;
+
+    /* access mode: 0b01 set bits/ 0b10 clear bits/ 0b11 write bytes */
+    argument = (access_mode << 24) | (ECSD_index << 16) | (value << 8);
+    //argument = 0x1b30000;
+
+    mxcmci_cmd_config(&cmd, CMD6, argument, READ, RESPONSE_48,
+                      DATA_PRESENT_NONE, ENABLE, ENABLE);
+
+    if(host_send_cmd(&cmd) == SUCCESS) {
+        return 0;
+    } else {
+        //diag_printf("%s: Setting MMC boot Failed.\n", __FUNCTION__);
+        return 1;
+    }
 }
 
-void mmc_set_boot_partition_size(unsigned int value)
+static void mmc_set_boot_partition_size(unsigned int value)
 {
-       command_t cmd;
-
-       mxcmci_cmd_config(&cmd, CMD62, 0XEFAC62EC, READ, RESPONSE_48,
-                                       DATA_PRESENT_NONE, ENABLE, ENABLE);
-       host_send_cmd(&cmd);
-
-       mxcmci_cmd_config(&cmd, CMD62, 0X00CBAEA7, READ, RESPONSE_48,
-                                       DATA_PRESENT_NONE, ENABLE, ENABLE);
-       host_send_cmd(&cmd);
-
-       mxcmci_cmd_config(&cmd, CMD62, value, READ, RESPONSE_48,
-                                       DATA_PRESENT, ENABLE, ENABLE);
-       host_send_cmd(&cmd);
+    command_t cmd;
+    command_response_t response;
+    cyg_uint32 card_state = 0;
+    cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
+
+    mxcmci_cmd_config(&cmd, CMD62, 0XEFAC62EC, READ, RESPONSE_48,
+                      DATA_PRESENT_NONE, ENABLE, ENABLE);
+    host_send_cmd(&cmd);
+
+    mxcmci_cmd_config(&cmd, CMD62, 0X00CBAEA7, READ, RESPONSE_48,
+                      DATA_PRESENT_NONE, ENABLE, ENABLE);
+    host_send_cmd(&cmd);
+
+    mxcmci_cmd_config(&cmd, CMD62, value, READ, RESPONSE_48,
+                      DATA_PRESENT, ENABLE, ENABLE);
+    host_send_cmd(&cmd);
 }
 
 cyg_uint32 emmc_set_boot_partition (cyg_uint32 *src_ptr, cyg_uint32 length)
 {
-       cyg_uint32 status=FAIL;
-       unsigned int value;
-       unsigned int eMMCBootDataSize = (length / (128 * 1024)) + 1;
-
-       if (MMC_Spec_vers < 4)
-               return 1;
-
-       /* read back 1KB data as we are programming to user are and want to aviod erasing MBR
-        * will be removed once we program Redboot to boot partition of the card
-        */
-       mmc_data_read(src_ptr, 0x400, 0);
-
-       /* Set boot partition */
-       /* 1. Configure CMD6 to write to EXT_CSD register for eMMC boot partition, Byte 179*/
-       /* boot partition: user area enable and r/w enable */
-       value = (0x7 << 3) | (0x7);
-       //value = (0x1 << 3) | (0x1);
-       status = mmc_set_extendCSD(179, value, 0x3);
-       if(status) {
-               return 1; /* failed */
-       }
-
-       /* 2. Set boot partition size: n*128KB */
-       value = eMMCBootDataSize;
-       //status = mmc_set_extendCSD(226, value, 0x3);
-       //if(status) {
-       //    return 1; /* failed */
-       //}
-       //mmc_set_boot_partition_size(value);
-
-       //diag_printf("Boot partition size: 0x%xKB\n", eMMCBootDataSize * 128);
-
-       /* 3. Program to boot partition, default address is alway 0x0  */
-       status = mmc_data_write (src_ptr, eMMCBootDataSize*128*1024, 0);
-       if (status) {
-               return 1; /* failed */
-       }
-
-       while (mxcmci_trans_status());
-
-       /* 4. Clear boot partition access bits, to protect w/r of boot partition */
-       /* bit 6: send boot ack signal, boot partition: user area enable and r/w access disable */
-       //value = (0x1 << 6) | (0x1 << 3) | (0x0);
-       value = (0x1 << 6) | (0x7 << 3) | (0x0);
-       status = mmc_set_extendCSD(179, value, 0x3);
-       if(status) {
-               return 1; /* failed */
-       }
-
-       return 0;
+    cyg_uint32 status=FAIL;
+    unsigned int value;
+    unsigned int eMMCBootDataSize = (length / (128 * 1024)) + 1;
+
+    if (MMC_Spec_vers < 4)
+        return 1;
+
+    /* read back 1KB data as we are programming to user are and want to aviod erasing MBR
+      * will be removed once we program Redboot to boot partition of the card
+      */
+    mmc_data_read(src_ptr, 0x400, 0);
+
+    /* Set boot partition */
+    /* 1. Configure CMD6 to write to EXT_CSD register for eMMC boot partition, Byte 179*/
+    /* boot partition: user area enable and r/w enable */
+    value = (0x7 << 3) | (0x7);
+    //value = (0x1 << 3) | (0x1);
+    status = mmc_set_extendCSD(179, value, 0x3);
+    if(status) {
+        return 1; /* failed */
+    }
+
+    /* 2. Set boot partition size: n*128KB */
+    value = eMMCBootDataSize;
+    //status = mmc_set_extendCSD(226, value, 0x3);
+    //if(status) {
+    //    return 1; /* failed */
+    //}
+    //mmc_set_boot_partition_size(value);
+
+    //diag_printf("Boot partition size: 0x%xKB\n", eMMCBootDataSize * 128);
+
+    /* 3. Program to boot partition, default address is alway 0x0  */
+    status = mmc_data_write (src_ptr, eMMCBootDataSize*128*1024, 0);
+    if(status) {
+        return 1; /* failed */
+    }
+
+    while (mxcmci_trans_status());
+
+    /* 4. Clear boot partition access bits, to protect w/r of boot partition */
+    /* bit 6: send boot ack signal, boot partition: user area enable and r/w access disable */
+    //value = (0x1 << 6) | (0x1 << 3) | (0x0);
+    value = (0x1 << 6) | (0x7 << 3) | (0x0);
+    status = mmc_set_extendCSD(179, value, 0x3);
+    if(status) {
+        return 1; /* failed */
+    }
+
+    return 0;
 }
 
 /* end of mxcmci_mmc.c */