]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/pdk.git/blobdiff - packages/ti/drv/mmcsd/src/v2/MMCSD_v2.c
Implemented the changes from am57x
[processor-sdk/pdk.git] / packages / ti / drv / mmcsd / src / v2 / MMCSD_v2.c
index 8b81f2e0b684e9a4d76b5f3804ac9a98ca02aba7..a01540fcde0d9a69e68e8a77ee4d5529355552a2 100755 (executable)
@@ -7,7 +7,7 @@
  */
 
 /*
- * Copyright (C) 2017-2018 Texas Instruments Incorporated - http://www.ti.com/
+ * Copyright (C) 2017-2021 Texas Instruments Incorporated - http://www.ti.com/
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -52,6 +52,8 @@
 #include <ti/drv/mmcsd/soc/MMCSD_soc.h>
 #include <ti/drv/mmcsd/src/MMCSD_osal.h>
 
+
+
 #define MMCSD_log                UART_printf
 
 #define MMCSD_DEBUG_TRAP   {while(mmcsd_emuwait_trap);}
 /** \brief Command to configure for data write. */
 #define MMCSD_CMDRSP_WRITE          (BIT(8U))
 
+/** \brief Command to configure for Read or Write interrupt */
+#define MMCSD_CMDREQ_WR_RD          (BIT(31U))
+
 /** \brief SD voltage enumeration as per VHS field, after the CHECK PATTERN FIELD */
 #define MMCSD_VOLT_2P7_3P6          (0x000100U)
 #define MMCSD_VOLT_LOW_RANGE        (0x000200U)
 #define MMCSD_ECSD_STROBE_SUPPORT_ENHANCED_DIS    (0U)
 #define MMCSD_ECSD_STROBE_SUPPORT_ENHANCED_EN    (1U)
 
-
+#define        HS_MMCSD_INTR_ALL_ERR   (\
+       HS_MMCSD_INTR_ADMAERROR |\
+       HS_MMCSD_INTR_ACMDERR |\
+       HS_MMCSD_INTR_DATABITERR |\
+       HS_MMCSD_INTR_DATACRCERR |\
+       HS_MMCSD_INTR_DATATIMEOUT |\
+       HS_MMCSD_INTR_CMDINDXERR |\
+       HS_MMCSD_INTR_CMDBITERR |\
+       HS_MMCSD_INTR_CMDCRCERR |\
+       HS_MMCSD_INTR_CMDTIMEOUT\
+)
 
 volatile uint32_t mmcsd_emuwait_trap=1;
 
@@ -448,12 +463,14 @@ static MMCSD_Error MMCSD_v2_setBusFreq(MMCSD_Handle handle, const uint32_t *busF
 static MMCSD_Error MMCSD_v2_getBusWidth(MMCSD_Handle handle, uint32_t *busWidth);
 static MMCSD_Error MMCSD_v2_getBusFreq(MMCSD_Handle handle, uint32_t *busFreq);
 static MMCSD_Error MMCSD_v2_getMediaParams(MMCSD_Handle handle, MMCSD_mediaParams *params);
+static MMCSD_Error MMCSD_v2_getErrorStatus(MMCSD_Handle handle, uint32_t *errorStat);
 void MMCSD_v2_hwiFxn(uintptr_t arg);
 static void MMCSD_v2_cmdStatusFxn(uintptr_t arg);
 static void MMCSD_v2_xferStatusFxn(uintptr_t arg);
 
 static MMCSD_Error mmcsd_tuning_procedure(MMCSD_Handle handle);
 static void MMCSD_v2_xferStatusFxn_CMD19(uintptr_t arg);
+static void MMCSD_v2_controllerReset(MMCSD_v2_Object *,MMCSD_v2_HwAttrs const *);
 static MMCSD_Error MMCSD_switch_card_speed(MMCSD_Handle handle,uint32_t cmd16_grp1_fn);
 /* Delay function */
 static void delay(uint32_t delayValue);
@@ -474,7 +491,7 @@ typedef struct {
 } adma2_desc_t;
 
 adma2_desc_t adma2_desc;
-#if defined(__ARM_ARCH_7A__) || defined(__aarch64__) || defined(__TI_ARM_V7R4__)
+#if defined(__ARM_ARCH_7A__) || defined(__aarch64__) || ((__ARM_ARCH == 7) && (__ARM_ARCH_PROFILE == 'R'))
 __attribute__((aligned(SOC_CACHELINE_SIZE))) // GCC way of aligning
 #endif
 
@@ -609,6 +626,7 @@ static MMCSD_Error MMCSD_v2_write(MMCSD_Handle handle,
     MMCSD_Error                 ret = MMCSD_ERR;
     uint32_t                    key;
     uint32_t                    address = 0U;
+    uint32_t                    isrErr = MMCSD_ISR_RET_OK;
     MMCSD_v2_Object            *object = NULL;
     MMCSD_v2_Transaction        transaction;
 
@@ -658,7 +676,7 @@ static MMCSD_Error MMCSD_v2_write(MMCSD_Handle handle,
             address = block * object->blockSize;
         }
 
-        transaction.flags = MMCSD_CMDRSP_WRITE | MMCSD_CMDRSP_DATA;
+        transaction.flags = MMCSD_CMDRSP_WRITE | MMCSD_CMDRSP_DATA | MMCSD_CMDREQ_WR_RD;
         transaction.arg = address;
         transaction.blockCount = numBlks;
         transaction.blockSize = object->blockSize;
@@ -675,6 +693,7 @@ static MMCSD_Error MMCSD_v2_write(MMCSD_Handle handle,
         }
 
         ret = MMCSD_v2_transfer(handle, &transaction);
+               isrErr = object->intStatusErr;
     } else {
                MMCSD_DEBUG_TRAP
        }       
@@ -692,7 +711,10 @@ static MMCSD_Error MMCSD_v2_write(MMCSD_Handle handle,
             ret = MMCSD_v2_transfer(handle, &transaction);
         }
     }
-
+    if ((ret != MMCSD_OK) || (isrErr != MMCSD_ISR_RET_OK))
+    {
+           ret = MMCSD_ERR;
+       }
     return (ret);
 }
 
@@ -707,6 +729,7 @@ static MMCSD_Error MMCSD_v2_read(MMCSD_Handle handle,
     MMCSD_Error                 ret = MMCSD_ERR;
     uint32_t                    key;
     uint32_t                    address = 0U;
+    uint32_t                    isrErr = MMCSD_ISR_RET_OK;
     MMCSD_v2_Object            *object = NULL;
     MMCSD_v2_Transaction        transaction;
 
@@ -757,7 +780,7 @@ static MMCSD_Error MMCSD_v2_read(MMCSD_Handle handle,
             address = block * object->blockSize;
         }
 
-        transaction.flags = MMCSD_CMDRSP_READ | MMCSD_CMDRSP_DATA;
+        transaction.flags = MMCSD_CMDRSP_READ | MMCSD_CMDRSP_DATA | MMCSD_CMDREQ_WR_RD;
         transaction.arg = address;
         transaction.blockCount = numBlks;
         transaction.blockSize = object->blockSize;
@@ -773,6 +796,7 @@ static MMCSD_Error MMCSD_v2_read(MMCSD_Handle handle,
         }
 
         ret = MMCSD_v2_transfer(handle, &transaction);
+               isrErr = object->intStatusErr;
     } else {
                MMCSD_DEBUG_TRAP
        }       
@@ -790,6 +814,10 @@ static MMCSD_Error MMCSD_v2_read(MMCSD_Handle handle,
             ret = MMCSD_v2_transfer(handle, &transaction);
         }
     }
+    if ((ret != MMCSD_OK) || (isrErr != MMCSD_ISR_RET_OK))
+    {
+           ret = MMCSD_ERR;
+    }
     return (ret);
 }
 
@@ -813,6 +841,12 @@ static MMCSD_Error MMCSD_v2_close(MMCSD_Handle handle)
         object = (MMCSD_v2_Object *)((MMCSD_Config *) handle)->object;
         hwAttrs = (MMCSD_v2_HwAttrs const *)((MMCSD_Config *) handle)->hwAttrs;
 
+        ret = MMCSD_socPhyConfigure((MMCSD_v2_HwAttrs const *)hwAttrs, MODE_DEFAULT, 0, 0);
+        if(ret != MMCSD_OK)
+        {
+            MMCSD_DEBUG_TRAP
+        }
+
         if(0U != hwAttrs->enableInterrupt)
         {
            /* Release the interrupt path */
@@ -853,7 +887,7 @@ static MMCSD_Error MMCSD_v2_close(MMCSD_Handle handle)
         memset(object, 0, sizeof(MMCSD_v2_Object));
 
     #ifdef LOG_EN
-        MMCSD_drv_log(Diags_USER1, "MMCSD: Object closed 0x%x", ((MMCSD_Config *) handle)->hwAttrs->baseAddr);
+        MMCSD_drv_log4(Diags_USER1, "MMCSD: Object closed 0x%x", hwAttrs->baseAddr);
     #endif
     }
     return (ret);
@@ -1026,11 +1060,11 @@ static MMCSD_Error MMCSD_v2_open(MMCSD_Handle handle, MMCSD_Params params)
        if(inputClockRet!=0) {
 
          if(inputClockRet!=hwAttrs->inputClk) {
-                 MMCSD_drv_log4(Diags_USER1,"Input clock[%d] to MMC is different from what is set in hwAttrs",inputClockRet);
+                 MMCSD_drv_log4(Diags_USER1,"Input clock[%d] to MMC is different from what is set in hwAttrs\n",inputClockRet);
             hwAttrs->inputClk=inputClockRet;
          }
        } else {
-        MMCSD_drv_log(Diags_USER1,"Something is wrong. Input clock is not enabled!!");
+        MMCSD_drv_log(Diags_USER1,"Something is wrong. Input clock is not enabled!!\n");
         ret = MMCSD_ERR;
        }
     }
@@ -1062,24 +1096,9 @@ static MMCSD_Error MMCSD_v2_open(MMCSD_Handle handle, MMCSD_Params params)
     return (ret);
 }
 /* Data buffer for message transmission, it is not stack allocated to allow cache aligning */
-#if defined(__GNUC__) && !defined(__ti__)
-CSL_SET_DALIGN(256)  /* GCC way of aligning */
-#else
-CSL_SET_DALIGN(dataBuffer, 256)
-#endif
-static uint8_t                     dataBuffer[512];
-
-#if defined(__GNUC__) && !defined(__ti__)
-CSL_SET_DALIGN(256)            /* GCC way of aligning */
-#else
-CSL_SET_DALIGN(cmd6_response_buf, 256)
-#endif
-static uint8_t                     cmd6_response_buf[512];
-
-
-
-
+static uint8_t dataBuffer[512] __attribute__((aligned(256)));
 
+static uint8_t cmd6_response_buf[512] __attribute__((aligned(256)));
 
 /*
  *  ======== MMCSD_v2_initSd ========
@@ -1119,8 +1138,8 @@ static MMCSD_Error MMCSD_v2_initSd(MMCSD_Handle handle)
         if (STW_SOK != status)
         {
 #ifdef LOG_EN
-            MMCSD_drv_log(Diags_USER1,
-                    "MMCSD:(%p) HS MMC/SD Reset failed", hwAttrs->baseAddr);
+            MMCSD_drv_log4(Diags_USER1,
+                    "MMCSD:(%p) HS MMC/SD Reset failed\n", hwAttrs->baseAddr);
 #endif
             ret = MMCSD_ERR;
         }
@@ -1210,8 +1229,8 @@ static MMCSD_Error MMCSD_v2_initSd(MMCSD_Handle handle)
         if (STW_SOK != status)
         {
 #ifdef LOG_EN
-            MMCSD_drv_log(Diags_USER1,
-                    "MMCSD:(%p) HS MMC/SD Power on failed", hwAttrs->baseAddr);
+            MMCSD_drv_log4(Diags_USER1,
+                    "MMCSD:(%p) HS MMC/SD Power on failed\n", hwAttrs->baseAddr);
 #endif
             ret = MMCSD_ERR;
         }
@@ -1399,8 +1418,29 @@ static MMCSD_Error MMCSD_v2_initSd(MMCSD_Handle handle)
                                                   MMCSD_DEBUG_TRAP
                                           }
 
+                        HSMMCSDUhsModeSet(hwAttrs->baseAddr,MMC_AC12_UHSMS_SDR12);
+                        HSMMCSDHSModeSet(hwAttrs->baseAddr,MMC_HCTL_HSPE_NORMALSPEED);
+
+                        /* Set the initialization frequency */
+                        status = HSMMCSDBusFreqSet(hwAttrs->baseAddr, hwAttrs->inputClk,hwAttrs->outputClk, FALSE);
+
+                        Osal_delay(10);
+                        if(status !=STW_SOK) {
+                        MMCSD_DEBUG_TRAP
+                        }
+
+                        /* PHY configurae */
+                        MMCSD_socPhyDisableDLL((MMCSD_v2_HwAttrs const *)hwAttrs);
+
+                        Osal_delay(50);
+
+                        /* Configure the Phy accordignly */
+                        ret = MMCSD_socPhyConfigure((MMCSD_v2_HwAttrs const *)hwAttrs, MODE_SDR12, 25000000U, 0);
+                        if(ret != MMCSD_OK)
+                        {
+                            MMCSD_DEBUG_TRAP
+                        }
 
-                        HSMMCSDSDClockEnable(hwAttrs->baseAddr); /* Enable clock to SD card */
                                            /* Wait for 1 ms */
                                            Osal_delay(1);
 
@@ -1529,6 +1569,7 @@ static MMCSD_Error MMCSD_v2_initSd(MMCSD_Handle handle)
 
                 if(MMCSD_OK == ret)
                 {
+                                       object->blockCount = (object->blockCount * object->blockSize) / 512U;
                     object->blockSize = 512U;
                 }
             }
@@ -1682,7 +1723,7 @@ static MMCSD_Error MMCSD_v2_initSd(MMCSD_Handle handle)
                           }
               ret=MMCSD_switch_card_speed(handle,cmd16_grp1_fn);
                          if(ret==MMCSD_OK) {
-                            MMCSD_drv_log(Diags_USER1," Successfully switched to the above speed");
+                            MMCSD_drv_log(Diags_USER1," Successfully switched to the above speed\n");
                             break;/* Successful switching */
                          }
                    }
@@ -1766,6 +1807,7 @@ static MMCSD_Error MMCSD_switch_card_speed(MMCSD_Handle handle,uint32_t cmd16_gr
            {
                   tranSpeed = MMCSD_TRANSPEED_SDR50;
                   uhsMode=MMC_AC12_UHSMS_SDR50;
+                  sdr104_tuning_required=TRUE;
                   clk_freq=100000000U; /* 100MHz for SDR50  */
                   phy_freq=100000000U;
                   phy_mode = MODE_SDR50;
@@ -1774,6 +1816,7 @@ static MMCSD_Error MMCSD_switch_card_speed(MMCSD_Handle handle,uint32_t cmd16_gr
                {
                   tranSpeed = MMCSD_TRANSPEED_DDR50;
                   uhsMode=MMC_AC12_UHSMS_DDR50;
+                  sdr104_tuning_required=TRUE;
                   clk_freq=50000000U; /* 50MHz for DDR50  */
                   phy_freq=50000000U;
                   phy_mode=MODE_DDR50;
@@ -1837,9 +1880,9 @@ static MMCSD_Error MMCSD_switch_card_speed(MMCSD_Handle handle,uint32_t cmd16_gr
                  /* Set the UHS mode accordingly */
                  if(uhsMode!=0xffff) {
                    HSMMCSDUhsModeSet(hwAttrs->baseAddr,uhsMode);
+            /* SDR50 is rising edge */
             if( (uhsMode==MMC_AC12_UHSMS_SDR12) || 
-                (uhsMode==MMC_AC12_UHSMS_SDR25) ||
-                (uhsMode==MMC_AC12_UHSMS_SDR50) )
+                (uhsMode==MMC_AC12_UHSMS_SDR25) )
             {
                      /* For non-high speed modes the data should be on the falling edge */
                          HSMMCSDHSModeSet(hwAttrs->baseAddr,MMC_HCTL_HSPE_NORMALSPEED);
@@ -2333,8 +2376,8 @@ static MMCSD_Error MMCSD_v2_initEmmc(MMCSD_Handle handle)
         if (STW_SOK != status)
         {
 #ifdef LOG_EN
-            MMCSD_drv_log(Diags_USER1,
-                    "MMCSD:(%p) HS MMC/SD Reset failed", hwAttrs->baseAddr);
+            MMCSD_drv_log4(Diags_USER1,
+                    "MMCSD:(%p) HS MMC/SD Reset failed\n", hwAttrs->baseAddr);
 #endif
             ret = MMCSD_ERR;
         }
@@ -2408,8 +2451,8 @@ static MMCSD_Error MMCSD_v2_initEmmc(MMCSD_Handle handle)
         if (STW_SOK != status)
         {
 #ifdef LOG_EN
-            MMCSD_drv_log(Diags_USER1,
-                    "MMCSD:(%p) HS MMC/SD Power on failed", hwAttrs->baseAddr);
+            MMCSD_drv_log4(Diags_USER1,
+                    "MMCSD:(%p) HS MMC/SD Power on failed\n", hwAttrs->baseAddr);
 #endif
             ret = MMCSD_ERR;
         }
@@ -2423,8 +2466,8 @@ static MMCSD_Error MMCSD_v2_initEmmc(MMCSD_Handle handle)
         if (STW_SOK != status)
         {
 #ifdef LOG_EN
-        MMCSD_drv_log(Diags_USER1,
-          "MMCSD:(%p) HS MMC/SD Bus Frequency set failed", hwAttrs->baseAddr);
+        MMCSD_drv_log4(Diags_USER1,
+          "MMCSD:(%p) HS MMC/SD Bus Frequency set failed\n", hwAttrs->baseAddr);
 #endif
             ret = MMCSD_ERR;
         }
@@ -2709,6 +2752,7 @@ static MMCSD_Error MMCSD_v2_transfer(MMCSD_Handle handle,
     MMCSD_v2_Object        *object = NULL;
     MMCSD_v2_HwAttrs const *hwAttrs = NULL;
     uint32_t params;
+       volatile uint32_t        status = 0U;
 
     if ((handle != NULL) && (transaction != NULL))
     {
@@ -2730,6 +2774,8 @@ static MMCSD_Error MMCSD_v2_transfer(MMCSD_Handle handle,
 
     if(MMCSD_OK == ret)
     {
+        object->intStatusErr = MMCSD_ISR_RET_OK;
+
         /* Configure the command type to be executed from the command flags */
         if (transaction->flags & MMCSD_CMDRSP_STOP)
         {
@@ -2846,7 +2892,8 @@ cmdObj.cmd.xferType = (transaction->flags & MMCSD_CMDRSP_READ) ? \
 
             HSMMCSDIntrStatusEnable(hwAttrs->baseAddr,
                 (HS_MMCSD_INTR_CMDCOMP | HS_MMCSD_INTR_CMDTIMEOUT |
-                 HS_MMCSD_INTR_DATATIMEOUT | HS_MMCSD_INTR_TRNFCOMP | 0x17ff0000));
+                 HS_MMCSD_INTR_DATATIMEOUT | HS_MMCSD_INTR_TRNFCOMP | 0x17ff0000 |
+                 HS_MMCSD_INTR_ALL_ERR));
 
             if(0U != hwAttrs->enableInterrupt)
             {
@@ -2920,8 +2967,8 @@ cmdObj.cmd.xferType = (transaction->flags & MMCSD_CMDRSP_READ) ? \
             /*  MMCSD_osalHardwareIntrEnable(hwAttrs->intNum); */
 
 #ifdef LOG_EN
-            MMCSD_drv_log(Diags_USER1,
-                       "MMCSD:(%p) Pending on commandComplete semaphore",
+            MMCSD_drv_log4(Diags_USER1,
+                       "MMCSD:(%p) Pending on commandComplete semaphore\n",
                        hwAttrs->baseAddr);
 #endif
 
@@ -2952,9 +2999,15 @@ cmdObj.cmd.xferType = (transaction->flags & MMCSD_CMDRSP_READ) ? \
                
 #ifdef LOG_EN
             MMCSD_drv_log4(Diags_USER1,
-                       "MMCSD:(%p) Command transaction completed", hwAttrs->baseAddr);
+                       "MMCSD:(%p) Command transaction completed\n", hwAttrs->baseAddr);
 #endif
 
+            if ((transaction->flags & MMCSD_CMDREQ_WR_RD) != 0)
+                       {
+                HSMMCSDIntrStatusDisable(hwAttrs->baseAddr,
+                       (HS_MMCSD_INTR_CMDBITERR | HS_MMCSD_INTR_CMDCRCERR |
+                        HS_MMCSD_INTR_DATABITERR | HS_MMCSD_INTR_DATACRCERR) );
+                       }
 
             if( object->manualTuning && object->cmdError && ( (cmdObj.cmd.cmdId==MMCSD_CMD(19U)) || (cmdObj.cmd.cmdId==MMCSD_CMD(21U)) ) )  
                    {                              
@@ -3006,8 +3059,8 @@ cmdObj.cmd.xferType = (transaction->flags & MMCSD_CMDRSP_READ) ? \
                 /* Git response for command sent to MMC device */
                 HSMMCSDResponseGet(hwAttrs->baseAddr, transaction->response);
 #ifdef LOG_EN
-                MMCSD_drv_log(Diags_USER1,
-                        "MMCSD:(%p) Command Execution Failed", hwAttrs->baseAddr);
+                MMCSD_drv_log4(Diags_USER1,
+                        "MMCSD:(%p) Command Execution Failed\n", hwAttrs->baseAddr);
 #endif
             }
 
@@ -3018,8 +3071,8 @@ cmdObj.cmd.xferType = (transaction->flags & MMCSD_CMDRSP_READ) ? \
             if(MMCSD_OK == ret)
             {
 #ifdef LOG_EN
-            MMCSD_drv_log(Diags_USER1,
-                           "MMCSD:(%p) Pending on transferComplete semaphore",
+            MMCSD_drv_log4(Diags_USER1,
+                           "MMCSD:(%p) Pending on transferComplete semaphore\n",
                            hwAttrs->baseAddr);
 #endif
 
@@ -3059,8 +3112,8 @@ cmdObj.cmd.xferType = (transaction->flags & MMCSD_CMDRSP_READ) ? \
 
             }
 #ifdef LOG_EN
-                MMCSD_drv_log(Diags_USER1,
-                           "MMCSD:(%p) Data transaction completed", hwAttrs->baseAddr);
+                MMCSD_drv_log4(Diags_USER1,
+                           "MMCSD:(%p) Data transaction completed\n", hwAttrs->baseAddr);
 #endif
 
             if( object->manualTuning && object->cmdError && ( (cmdObj.cmd.cmdId==MMCSD_CMD(19U)) || (cmdObj.cmd.cmdId==MMCSD_CMD(21U)) ) )  
@@ -3080,8 +3133,8 @@ cmdObj.cmd.xferType = (transaction->flags & MMCSD_CMDRSP_READ) ? \
                    MMCSD_DEBUG_TRAP
                    object->xferTimeout = 0;
 #ifdef LOG_EN
-                    MMCSD_drv_log(Diags_USER1,
-                            "MMCSD:(%p) Data Transfer Failed", hwAttrs->baseAddr);
+                    MMCSD_drv_log4(Diags_USER1,
+                            "MMCSD:(%p) Data Transfer Failed\n", hwAttrs->baseAddr);
 #endif
                 }
 
@@ -3091,8 +3144,8 @@ cmdObj.cmd.xferType = (transaction->flags & MMCSD_CMDRSP_READ) ? \
                    ret = MMCSD_OK;
                    object->xferComp = 0;
 #ifdef LOG_EN
-                    MMCSD_drv_log(Diags_USER1,
-                            "MMCSD:(%p) Data Transfer Successful", hwAttrs->baseAddr);
+                    MMCSD_drv_log4(Diags_USER1,
+                            "MMCSD:(%p) Data Transfer Successful\n", hwAttrs->baseAddr);
 #endif
                 }
             }
@@ -3118,7 +3171,7 @@ cmdObj.cmd.xferType = (transaction->flags & MMCSD_CMDRSP_READ) ? \
             cmdObj.enableDma = 0;
 
             HSMMCSDIntrStatusEnable(hwAttrs->baseAddr,
-                (HS_MMCSD_INTR_CMDCOMP | HS_MMCSD_INTR_CMDTIMEOUT));
+                (HS_MMCSD_INTR_CMDCOMP | HS_MMCSD_INTR_ALL_ERR));
 
             if(0U != hwAttrs->enableInterrupt)
             {
@@ -3142,8 +3195,8 @@ cmdObj.cmd.xferType = (transaction->flags & MMCSD_CMDRSP_READ) ? \
                                cmdObj.enableDma,
                                MMC_CMD_ACEN_DISABLE);
 #ifdef LOG_EN
-            MMCSD_drv_log(Diags_USER1,
-                       "MMCSD:(%p) Pending on commandComplete semaphore",
+            MMCSD_drv_log4(Diags_USER1,
+                       "MMCSD:(%p) Pending on commandComplete semaphore\n",
                        hwAttrs->baseAddr);
 #endif
 
@@ -3165,8 +3218,8 @@ cmdObj.cmd.xferType = (transaction->flags & MMCSD_CMDRSP_READ) ? \
             }
 
 #ifdef LOG_EN
-            MMCSD_drv_log(Diags_USER1,
-                       "MMCSD:(%p) Command transaction completed", hwAttrs->baseAddr);
+            MMCSD_drv_log4(Diags_USER1,
+                       "MMCSD:(%p) Command transaction completed\n", hwAttrs->baseAddr);
 #endif
 
             /* Command execution successful */
@@ -3175,21 +3228,34 @@ cmdObj.cmd.xferType = (transaction->flags & MMCSD_CMDRSP_READ) ? \
                 ret = MMCSD_OK;
                 object->cmdComp = 0;
 #ifdef LOG_EN
-                MMCSD_drv_log(Diags_USER1,
-                        "MMCSD:(%p) Command Execution Failed", hwAttrs->baseAddr);
+                MMCSD_drv_log4(Diags_USER1,
+                        "MMCSD:(%p) Command Execution successfull\n", hwAttrs->baseAddr);
 #endif
             }
 
-            /* Command execution fail */
-            if (1 == object->cmdTimeout)
+        /* Data transfer fail or  Command execution fail */
+        if ((1 == object->xferTimeout) || (1 == object->cmdTimeout))
+        {
+            if (1 == object->xferTimeout)
             {
                 ret = MMCSD_ERR;
+                 object->xferTimeout = 0;
+#ifdef LOG_EN
+                 MMCSD_drv_log4(Diags_USER1,
+                         "MMCSD:(%p) Data Transfer Failed", hwAttrs->baseAddr);
+#endif
+            }
+            else
+            {
+               ret = MMCSD_ERR;
                 object->cmdTimeout = 0;
 #ifdef LOG_EN
-                MMCSD_drv_log(Diags_USER1,
+                MMCSD_drv_log4(Diags_USER1,
                         "MMCSD:(%p) Command Execution Failed", hwAttrs->baseAddr);
 #endif
             }
+                MMCSD_v2_controllerReset(object, (MMCSD_v2_HwAttrs *)hwAttrs);
+        }
 
             /* Git response for command sent to MMC device */
             HSMMCSDResponseGet(hwAttrs->baseAddr, transaction->response);
@@ -3255,6 +3321,11 @@ static MMCSD_Error MMCSD_v2_control(MMCSD_Handle handle, uint32_t cmd, const voi
                 break;
             }
 
+                       case MMCSD_CMD_GETERRORSTATUS:
+                       {
+                               ret = MMCSD_v2_getErrorStatus(handle, (uint32_t *)arg);
+                               break;
+                       }
             default:
             ret = MMCSD_UNDEFINEDCMD;
             break;
@@ -3481,6 +3552,37 @@ static MMCSD_Error MMCSD_v2_getMediaParams(MMCSD_Handle handle, MMCSD_mediaParam
     return(ret);
 }
 
+/*
+ *  ======== MMCSD_v2_getErrorStatus ========
+ */
+/*!
+ *  @brief      A function returns a error status for the command timeout
+ *              or data transfer timeout.
+ */
+static MMCSD_Error MMCSD_v2_getErrorStatus(MMCSD_Handle handle, uint32_t *errorStat)
+{
+    MMCSD_Error                 ret = MMCSD_ERR;
+    MMCSD_v2_Object            *object = NULL;
+
+    /* Input parameter validation */
+    if(handle != NULL)
+    {
+      /* Get the pointer to the object and hwAttrs */
+      object = (MMCSD_v2_Object *)((MMCSD_Config *) handle)->object;
+      if(object != NULL)
+      {
+          if ((MMCSD_CARD_SD == object->cardType) ||
+                   (MMCSD_CARD_MMC == object->cardType) ||
+                       (MMCSD_CARD_EMMC == object->cardType))
+          {
+              *errorStat = object->intStatusErr;
+              ret = MMCSD_OK;
+          }
+      }
+    }
+    return(ret);
+}
+
 /*
  *  ======== MMCSD_v2_hwiFxn ========
  *  Hwi interrupt handler to service the MMCSD peripheral
@@ -3714,6 +3816,7 @@ static void MMCSD_v2_cmdStatusFxn(uintptr_t arg)
     {
         
                object->cmdError = 1;
+               object->intStatusErr = MMCSD_ISR_RET_SDSTS;
                
                if (errStatus & HS_MMCSD_INTR_CMDTIMEOUT)
         {
@@ -4019,5 +4122,54 @@ static void delay(uint32_t delayValue)
     volatile uint32_t delay1 = delayValue*10000U;
     while (delay1--) {}
 }
+/*
+ *  ======== MMCSD_v2_controllerReset ========
+ */
+static void MMCSD_v2_controllerReset(MMCSD_v2_Object *object, MMCSD_v2_HwAttrs const *hwAttrs)
+{
+    volatile int32_t            status = CSL_ESYS_FAIL;
+    MMCSD_v2_IodelayParams      iodelayParams = {MMCSD_CARD_SD, MMCSD_TRANSPEED_25MBPS, MMCSD_VOLTAGE_ANY, MMCSD_LOOPBACK_ANY};
+
+    MMCSD_Error           ret = MMCSD_OK;
+
+    if (MMCSD_OK == ret)
+    {
+        /* Lines Reset */
+        HSMMCSDLinesReset(hwAttrs->baseAddr, HS_MMCSD_ALL_RESET);
 
+        /* Set the bus width */
+        HSMMCSDBusWidthSet(hwAttrs->baseAddr, HS_MMCSD_BUS_WIDTH_1BIT);
+
+        /* Set the bus voltage */
+               if(hwAttrs->supportedBusVoltages & MMCSD_BUS_VOLTAGE_3_0V) {
+           HSMMCSDBusVoltSet(hwAttrs->baseAddr, HS_MMCSD_BUS_VOLT_3P0); /* Default */
+               } else  if(hwAttrs->supportedBusVoltages & MMCSD_BUS_VOLTAGE_1_8V) {
+           HSMMCSDBusVoltSet(hwAttrs->baseAddr, HS_MMCSD_BUS_VOLT_1P8);
+        }
+        /* Bus power on */
+        status = ((int32_t)(HSMMCSDBusPower(hwAttrs->baseAddr, MMC_HCTL_SDBP_PWRON)));
+               object->switched_to_v18=FALSE;
+        if (STW_SOK != status)
+        {
+            ret = MMCSD_ERR;
+        }
+    }
+
+    if (MMCSD_OK == ret)
+    {
+        /* Set the initialization frequency */
+        status = HSMMCSDBusFreqSet(hwAttrs->baseAddr, hwAttrs->inputClk,
+            hwAttrs->outputClk, FALSE);
+        if(NULL != hwAttrs->iodelayFxn)
+        {
+            iodelayParams.transferSpeed = MMCSD_TRANSPEED_25MBPS;
+            hwAttrs->iodelayFxn(hwAttrs->instNum, &iodelayParams);
+        }
+
+        if (STW_SOK != status)
+        {
+            ret = MMCSD_ERR;
+        }
+    }
+}