]> git.karo-electronics.de Git - karo-tx-redboot.git/blobdiff - packages/devs/flash/arm/mxc/v2_0/src/mxcmci_mmc.c
TX51 pre-release
[karo-tx-redboot.git] / packages / devs / flash / arm / mxc / v2_0 / src / mxcmci_mmc.c
index 11c33a9ee3e54301b2435c9ed8767e50d91290e2..cf80b2a699b6c47644f43c044679518a5bd1872b 100644 (file)
@@ -66,245 +66,245 @@ cyg_uint32 address_mode;    /* Global variable for addressing mode */
 
 cyg_uint32 mmc_init(cyg_uint32 bus_width)
 {
-    cyg_uint32 status = FAIL;
-    cyg_uint32 spec_version;
-    /* Get CID number of MMC Card */
-    if (!mxcmci_get_cid()) {
-        /* Set RCA of the MMC Card */
-        if (!mmc_set_rca()) {
-            flash_dprintf(FLASH_DEBUG_MAX, "%s:  mmc_set_rca OK!",
-                      __FUNCTION__);
-            /* Get Spec version supported by the card */
-            spec_version = mmc_get_spec_ver();
-            //diag_printf("SPEC Version:  %d\n", spec_version);
-
-            /*Enable operating frequency */
-            host_cfg_clock(OPERATING_FREQ);
-
-            /*Put MMC in Transfer State */
-            if (!mxcmci_trans_prepare()) {
+       cyg_uint32 status = FAIL;
+       cyg_uint32 spec_version;
+       /* Get CID number of MMC Card */
+       if (!mxcmci_get_cid()) {
+               /* Set RCA of the MMC Card */
+               if (!mmc_set_rca()) {
+                       flash_dprintf(FLASH_DEBUG_MAX, "%s:  mmc_set_rca OK!",
+                                               __FUNCTION__);
+                       /* Get Spec version supported by the card */
+                       spec_version = mmc_get_spec_ver();
+                       //diag_printf("SPEC Version:  %d\n", spec_version);
+
+                       /*Enable operating frequency */
+                       host_cfg_clock(OPERATING_FREQ);
+
+                       /*Put MMC in Transfer State */
+                       if (!mxcmci_trans_prepare()) {
 #if 0
-                if (mmc_set_high_speed_mode()) {
-                    return FAIL;
-                }
+                               if (mmc_set_high_speed_mode()) {
+                                       return FAIL;
+                               }
 #endif
 
-                /* Set block length for transfer */
-                //diag_printf("Send CMD to Set Block Length.\n");
-                if (sdmmc_set_blklen(BLK_LEN))
-                    return FAIL;
+                               /* Set block length for transfer */
+                               //diag_printf("Send CMD to Set Block Length.\n");
+                               if (sdmmc_set_blklen(BLK_LEN))
+                                       return FAIL;
 
-                flash_dprintf(FLASH_DEBUG_MAX, "%s:  mxcmci_trans_prepare OK!",
-                          __FUNCTION__);
+                               flash_dprintf(FLASH_DEBUG_MAX, "%s:  mxcmci_trans_prepare OK!",
+                                                       __FUNCTION__);
 
-                if (!mmc_set_bus_width(bus_width)) {
-                    esdhc_base_pointer->protocol_control &= ~(0x3 << 1);
-                    esdhc_base_pointer->protocol_control |= (bus_width >> 2) << 1;
-                    status = SUCCESS;
-                    diag_printf("Bus Width:    %d\n",
-                            bus_width);
-                }
+                               if (!mmc_set_bus_width(bus_width)) {
+                                       esdhc_base_pointer->protocol_control &= ~(0x3 << 1);
+                                       esdhc_base_pointer->protocol_control |= (bus_width >> 2) << 1;
+                                       status = SUCCESS;
+                                       diag_printf("Bus Width:    %d\n",
+                                                               bus_width);
+                               }
 
-            }
-        }
-    }
+                       }
+               }
+       }
 
-    return status;
+       return status;
 
 }
 
 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;
-
-    /* Assing length of data to be read */
-    SectorNum = length / blk_len;
-    if ((length % blk_len) != 0)
-        SectorNum++;
-    /* hight capacity card uses sector mode */
-    if(HighCapacityCard)
-       offset = offset/512;
-
-    /* wait until in transfer mode */
-    while (mxcmci_trans_status()) {
-        hal_delay_us(5);
-    }
-
-      reread:
-    /* Configure interface block and number of blocks */
-    host_cfg_block(BLK_LEN, SectorNum);
-
-    if (SectorNum == 1) {
-        //diag_printf("Send CMD17...\n");
-        /* Comfigure command CMD17 for single block read */
-        mxcmci_cmd_config(&cmd, CMD17, offset, READ, RESPONSE_48,
-                  DATA_PRESENT, ENABLE, ENABLE);
-
-        if (host_send_cmd(&cmd) == FAIL) {
-            diag_printf("%s: Can't send CMD17!\n", __FUNCTION__);
-            esdhc_softreset(ESDHC_RESET_CMD_MSK |
-                    ESDHC_RESET_DAT_MSK);
-            read_block_status = FAIL;
-
-        } else {
-            //diag_printf("host_data_read! dest_ptr: 0%x \n", dest_ptr);
-            /* Call interface Data read function */
-            read_block_status = host_data_read(dest_ptr, BLK_LEN);
-
-            if (read_block_status) {    /* fail */
-                //diag_printf("%s: Failed, read_block_status =%d\n", __FUNCTION__, read_block_status);
-                /* re-transfer if data transfer error occurs */
-                goto reread;
-            }
-        }
-    } else {        /* read multi-blocks */
-
-        /* Comfigure command CMD18 for multiple block read */
-        mxcmci_cmd_config(&cmd, CMD18, offset, READ, RESPONSE_48,
-                  DATA_PRESENT, ENABLE, ENABLE);
-
-        if (host_send_cmd(&cmd) == FAIL) {
-            diag_printf("%s: Can't send CMD18!\n", __FUNCTION__);
-            esdhc_softreset(ESDHC_RESET_CMD_MSK | ESDHC_RESET_DAT_MSK);
-            read_block_status = FAIL;
-        } else {
-            /* Call interface Data read function */
-            read_block_status =
-                host_data_read(dest_ptr, BLK_LEN * SectorNum);
-
-            /* Comfigure command CMD12 for multi-block 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 (read_block_status) {    /* fail */
-                //diag_printf("%s: Failed, read_block_status =%d\n", __FUNCTION__, read_block_status);
-                /* re-transfer if data transfer error occurs */
-                goto reread;
-            }
-
-        }
-
-    }
-    return read_block_status;
+       command_t cmd;
+       int len;
+       cyg_uint32 read_block_status = 0;
+       cyg_uint32 blk_len = BLK_LEN;
+       unsigned int SectorNum = 0;
+
+       /* Assing length of data to be read */
+       SectorNum = length / blk_len;
+       if ((length % blk_len) != 0)
+               SectorNum++;
+       /* hight capacity card uses sector mode */
+       if(HighCapacityCard)
+               offset = offset/512;
+
+       /* wait until in transfer mode */
+       while (mxcmci_trans_status()) {
+               hal_delay_us(5);
+       }
+
+reread:
+       /* Configure interface block and number of blocks */
+       host_cfg_block(BLK_LEN, SectorNum);
+
+       if (SectorNum == 1) {
+               //diag_printf("Send CMD17...\n");
+               /* Comfigure command CMD17 for single block read */
+               mxcmci_cmd_config(&cmd, CMD17, offset, READ, RESPONSE_48,
+                                               DATA_PRESENT, ENABLE, ENABLE);
+
+               if (host_send_cmd(&cmd) == FAIL) {
+                       diag_printf("%s: Can't send CMD17!\n", __FUNCTION__);
+                       esdhc_softreset(ESDHC_RESET_CMD_MSK |
+                                                       ESDHC_RESET_DAT_MSK);
+                       read_block_status = FAIL;
+
+               } else {
+                       //diag_printf("host_data_read! dest_ptr: 0%x \n", dest_ptr);
+                       /* Call interface Data read function */
+                       read_block_status = host_data_read(dest_ptr, BLK_LEN);
+
+                       if (read_block_status) {    /* fail */
+                               //diag_printf("%s: Failed, read_block_status =%d\n", __FUNCTION__, read_block_status);
+                               /* re-transfer if data transfer error occurs */
+                               goto reread;
+                       }
+               }
+       } else {        /* read multi-blocks */
+
+               /* Comfigure command CMD18 for multiple block read */
+               mxcmci_cmd_config(&cmd, CMD18, offset, READ, RESPONSE_48,
+                                               DATA_PRESENT, ENABLE, ENABLE);
+
+               if (host_send_cmd(&cmd) == FAIL) {
+                       diag_printf("%s: Can't send CMD18!\n", __FUNCTION__);
+                       esdhc_softreset(ESDHC_RESET_CMD_MSK | ESDHC_RESET_DAT_MSK);
+                       read_block_status = FAIL;
+               } else {
+                       /* Call interface Data read function */
+                       read_block_status =
+                               host_data_read(dest_ptr, BLK_LEN * SectorNum);
+
+                       /* Comfigure command CMD12 for multi-block 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 (read_block_status) {    /* fail */
+                               //diag_printf("%s: Failed, read_block_status =%d\n", __FUNCTION__, read_block_status);
+                               /* re-transfer if data transfer error occurs */
+                               goto reread;
+                       }
+
+               }
+
+       }
+       return read_block_status;
 }
 
 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;
-    //int counter;
-    //diag_printf("%s: src: 0x%x, offset: 0x%x, length: 0x%x\n", __FUNCTION__, (unsigned int)src_ptr, offset, length);
-    /* Write data size aligned with block size */
-    SectorNum = length / blk_len;
-    if ((length % blk_len) != 0)
-        SectorNum++;
-
-    /* hight capacity card uses sector mode */
-    if(HighCapacityCard)
-        offset = offset/512;
-
-    //need waiting until CARD out of Prg status, or will cause CMD25 timeout
-    //hal_delay_us(100);
-
-    //StartCounter();
-
-    while (mxcmci_trans_status()) {
-        hal_delay_us(2);
-    }
-
-    //counter = StopCounter();
-    //diag_printf("counter: 0x%x\n",counter);
-
-      rewrite:
-    /* Configure interface block and number of blocks , SctorNum will decrease to zero after transfer */
-    host_cfg_block(BLK_LEN, SectorNum);
-
-    if (SectorNum == 1) {
-        //diag_printf("Send CMD24...\n");
-        /* Comfigure command CMD24 for single block write */
-        mxcmci_cmd_config(&cmd, CMD24, offset, WRITE, RESPONSE_48,
-                  DATA_PRESENT, ENABLE, ENABLE);
-
-        if (host_send_cmd(&cmd) == FAIL) {
-            diag_printf("%s: Failed in configuring CMD24\n",
-                    __FUNCTION__);
-            esdhc_softreset(ESDHC_RESET_CMD_MSK | ESDHC_RESET_DAT_MSK);
-            write_block_status = FAIL;
-
-            //hal_delay_us(1000);
-            goto rewrite;
-
-        } else {
-            //diag_printf("Start host_data_write:\n");
-            /* Call interface write read function */
-            write_block_status = host_data_write(src_ptr, BLK_LEN);
-            //diag_printf("0x%x\n", esdhc_base_pointer->present_state);
-
-            if (write_block_status) {    /* fail */
-                //diag_printf("transfer failed.(0x%x)\n", esdhc_base_pointer->block_attributes);
-                while (mxcmci_trans_status()) ;
-                //diag_printf("%s: Failed, write_block_status=%d\n", __FUNCTION__, write_block_status);
-                /* re-transfer */
-                goto rewrite;
-            }
-
-        }
-    } else {        /* multi-block write */
-
-        //diag_printf("Send CMD25...\n");
-        /* Comfigure command CMD25 for single block write */
-        mxcmci_cmd_config(&cmd, CMD25, offset, WRITE, RESPONSE_48,
-                  DATA_PRESENT, ENABLE, ENABLE);
-
-        if (host_send_cmd(&cmd) == FAIL) {
-            //diag_printf("%s: Failed in configuring CMD25\n",
-            //        __FUNCTION__);
-            esdhc_softreset(ESDHC_RESET_CMD_MSK | ESDHC_RESET_DAT_MSK);
-            write_block_status = FAIL;
-            goto rewrite;
-        } else {
-            /* Call interface write read function */
-            write_block_status =
-                host_data_write(src_ptr, SectorNum * BLK_LEN);
-
-            /* Comfigure command CMD12 for multi-block 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);
-                //write_block_status = FAIL;
-            }
-
-            if (write_block_status) {    /* fail */
-                //diag_printf("%s: Failed, write_block_status=%d\n", __FUNCTION__, write_block_status);
-                while (mxcmci_trans_status());
-                /* re-transfer */
-                goto rewrite;
-            }
-        }
-    }
-
-    return write_block_status;
+       command_t cmd;
+       cyg_int32 len;
+       cyg_uint32 blk_len = BLK_LEN;
+       cyg_uint32 write_block_status = SUCCESS;
+       unsigned int SectorNum;
+       //int counter;
+       //diag_printf("%s: src: 0x%x, offset: 0x%x, length: 0x%x\n", __FUNCTION__, (unsigned int)src_ptr, offset, length);
+       /* Write data size aligned with block size */
+       SectorNum = length / blk_len;
+       if ((length % blk_len) != 0)
+               SectorNum++;
+
+       /* hight capacity card uses sector mode */
+       if(HighCapacityCard)
+               offset = offset/512;
+
+       //need waiting until CARD out of Prg status, or will cause CMD25 timeout
+       //hal_delay_us(100);
+
+       //StartCounter();
+
+       while (mxcmci_trans_status()) {
+               hal_delay_us(2);
+       }
+
+       //counter = StopCounter();
+       //diag_printf("counter: 0x%x\n",counter);
+
+rewrite:
+       /* Configure interface block and number of blocks , SctorNum will decrease to zero after transfer */
+       host_cfg_block(BLK_LEN, SectorNum);
+
+       if (SectorNum == 1) {
+               //diag_printf("Send CMD24...\n");
+               /* Comfigure command CMD24 for single block write */
+               mxcmci_cmd_config(&cmd, CMD24, offset, WRITE, RESPONSE_48,
+                                               DATA_PRESENT, ENABLE, ENABLE);
+
+               if (host_send_cmd(&cmd) == FAIL) {
+                       diag_printf("%s: Failed in configuring CMD24\n",
+                                               __FUNCTION__);
+                       esdhc_softreset(ESDHC_RESET_CMD_MSK | ESDHC_RESET_DAT_MSK);
+                       write_block_status = FAIL;
+
+                       //hal_delay_us(1000);
+                       goto rewrite;
+
+               } else {
+                       //diag_printf("Start host_data_write:\n");
+                       /* Call interface write read function */
+                       write_block_status = host_data_write(src_ptr, BLK_LEN);
+                       //diag_printf("0x%x\n", esdhc_base_pointer->present_state);
+
+                       if (write_block_status) {    /* fail */
+                               //diag_printf("transfer failed.(0x%x)\n", esdhc_base_pointer->block_attributes);
+                               while (mxcmci_trans_status()) ;
+                               //diag_printf("%s: Failed, write_block_status=%d\n", __FUNCTION__, write_block_status);
+                               /* re-transfer */
+                               goto rewrite;
+                       }
+
+               }
+       } else {        /* multi-block write */
+
+               //diag_printf("Send CMD25...\n");
+               /* Comfigure command CMD25 for single block write */
+               mxcmci_cmd_config(&cmd, CMD25, offset, WRITE, RESPONSE_48,
+                                               DATA_PRESENT, ENABLE, ENABLE);
+
+               if (host_send_cmd(&cmd) == FAIL) {
+                       //diag_printf("%s: Failed in configuring CMD25\n",
+                       //        __FUNCTION__);
+                       esdhc_softreset(ESDHC_RESET_CMD_MSK | ESDHC_RESET_DAT_MSK);
+                       write_block_status = FAIL;
+                       goto rewrite;
+               } else {
+                       /* Call interface write read function */
+                       write_block_status =
+                               host_data_write(src_ptr, SectorNum * BLK_LEN);
+
+                       /* Comfigure command CMD12 for multi-block 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);
+                               //write_block_status = FAIL;
+                       }
+
+                       if (write_block_status) {    /* fail */
+                               //diag_printf("%s: Failed, write_block_status=%d\n", __FUNCTION__, write_block_status);
+                               while (mxcmci_trans_status());
+                               /* re-transfer */
+                               goto rewrite;
+                       }
+               }
+       }
+
+       return write_block_status;
 
 }