mmc: atmel_mci: fix print incorrect buffer content for debug
[oweals/u-boot.git] / drivers / mmc / fsl_esdhc.c
index d64962652c133a538f7cbc00c584bc6017aba244..55416136ab2a46b15371be43517837b7c46b4aae 100644 (file)
@@ -96,7 +96,7 @@ static uint esdhc_xfertyp(struct mmc_cmd *cmd, struct mmc_data *data)
        else if (cmd->resp_type & MMC_RSP_PRESENT)
                xfertyp |= XFERTYP_RSPTYP_48;
 
-#if defined(CONFIG_MX53) || defined(CONFIG_T4240QDS)
+#if defined(CONFIG_MX53) || defined(CONFIG_PPC_T4240)
        if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
                xfertyp |= XFERTYP_CMDTYP_ABORT;
 #endif
@@ -174,7 +174,7 @@ static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data)
        int timeout;
        struct fsl_esdhc_cfg *cfg = mmc->priv;
        struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base;
-#ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
+
        uint wml_value;
 
        wml_value = data->blocksize/4;
@@ -184,12 +184,15 @@ static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data)
                        wml_value = WML_RD_WML_MAX_VAL;
 
                esdhc_clrsetbits32(&regs->wml, WML_RD_WML_MASK, wml_value);
+#ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
                esdhc_write32(&regs->dsaddr, (u32)data->dest);
+#endif
        } else {
+#ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
                flush_dcache_range((ulong)data->src,
                                   (ulong)data->src+data->blocks
                                         *data->blocksize);
-
+#endif
                if (wml_value > WML_WR_WML_MAX)
                        wml_value = WML_WR_WML_MAX_VAL;
                if ((esdhc_read32(&regs->prsstat) & PRSSTAT_WPSPL) == 0) {
@@ -199,19 +202,10 @@ static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data)
 
                esdhc_clrsetbits32(&regs->wml, WML_WR_WML_MASK,
                                        wml_value << 16);
+#ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
                esdhc_write32(&regs->dsaddr, (u32)data->src);
+#endif
        }
-#else  /* CONFIG_SYS_FSL_ESDHC_USE_PIO */
-       if (!(data->flags & MMC_DATA_READ)) {
-               if ((esdhc_read32(&regs->prsstat) & PRSSTAT_WPSPL) == 0) {
-                       printf("\nThe SD card is locked. "
-                               "Can not write to a locked card.\n\n");
-                       return TIMEOUT;
-               }
-               esdhc_write32(&regs->dsaddr, (u32)data->src);
-       } else
-               esdhc_write32(&regs->dsaddr, (u32)data->dest);
-#endif /* CONFIG_SYS_FSL_ESDHC_USE_PIO */
 
        esdhc_write32(&regs->blkattr, data->blocks << 16 | data->blocksize);
 
@@ -221,16 +215,16 @@ static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data)
         * 2)Timeout period should be minimum 0.250sec as per SD Card spec
         *  So, Number of SD Clock cycles for 0.25sec should be minimum
         *              (SD Clock/sec * 0.25 sec) SD Clock cycles
-        *              = (mmc->tran_speed * 1/4) SD Clock cycles
+        *              = (mmc->clock * 1/4) SD Clock cycles
         * As 1) >=  2)
-        * => (2^(timeout+13)) >= mmc->tran_speed * 1/4
+        * => (2^(timeout+13)) >= mmc->clock * 1/4
         * Taking log2 both the sides
-        * => timeout + 13 >= log2(mmc->tran_speed/4)
+        * => timeout + 13 >= log2(mmc->clock/4)
         * Rounding up to next power of 2
-        * => timeout + 13 = log2(mmc->tran_speed/4) + 1
-        * => timeout + 13 = fls(mmc->tran_speed/4)
+        * => timeout + 13 = log2(mmc->clock/4) + 1
+        * => timeout + 13 = fls(mmc->clock/4)
         */
-       timeout = fls(mmc->tran_speed/4);
+       timeout = fls(mmc->clock/4);
        timeout -= 13;
 
        if (timeout > 14)
@@ -244,11 +238,15 @@ static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data)
                timeout++;
 #endif
 
+#ifdef ESDHCI_QUIRK_BROKEN_TIMEOUT_VALUE
+       timeout = 0xE;
+#endif
        esdhc_clrsetbits32(&regs->sysctl, SYSCTL_TIMEOUT_MASK, timeout << 16);
 
        return 0;
 }
 
+#ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
 static void check_and_invalidate_dcache_range
        (struct mmc_cmd *cmd,
         struct mmc_data *data) {
@@ -258,6 +256,8 @@ static void check_and_invalidate_dcache_range
        unsigned end = start+size ;
        invalidate_dcache_range(start, end);
 }
+#endif
+
 /*
  * Sends a command out on the bus.  Takes the mmc pointer,
  * a command pointer, and an optional data pointer.
@@ -265,6 +265,7 @@ static void check_and_invalidate_dcache_range
 static int
 esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
 {
+       int     err = 0;
        uint    xfertyp;
        uint    irqstat;
        struct fsl_esdhc_cfg *cfg = mmc->priv;
@@ -296,8 +297,6 @@ esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
 
        /* Set up for a data transfer if we have one */
        if (data) {
-               int err;
-
                err = esdhc_setup_data(mmc, data);
                if(err)
                        return err;
@@ -325,27 +324,15 @@ esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
 
        irqstat = esdhc_read32(&regs->irqstat);
 
-       /* Reset CMD and DATA portions on error */
-       if (irqstat & (CMD_ERR | IRQSTAT_CTOE)) {
-               esdhc_write32(&regs->sysctl, esdhc_read32(&regs->sysctl) |
-                             SYSCTL_RSTC);
-               while (esdhc_read32(&regs->sysctl) & SYSCTL_RSTC)
-                       ;
-
-               if (data) {
-                       esdhc_write32(&regs->sysctl,
-                                     esdhc_read32(&regs->sysctl) |
-                                     SYSCTL_RSTD);
-                       while ((esdhc_read32(&regs->sysctl) & SYSCTL_RSTD))
-                               ;
-               }
+       if (irqstat & CMD_ERR) {
+               err = COMM_ERR;
+               goto out;
        }
 
-       if (irqstat & CMD_ERR)
-               return COMM_ERR;
-
-       if (irqstat & IRQSTAT_CTOE)
-               return TIMEOUT;
+       if (irqstat & IRQSTAT_CTOE) {
+               err = TIMEOUT;
+               goto out;
+       }
 
        /* Workaround for ESDHC errata ENGcm03648 */
        if (!data && (cmd->resp_type & MMC_RSP_BUSY)) {
@@ -360,7 +347,8 @@ esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
 
                if (timeout <= 0) {
                        printf("Timeout waiting for DAT0 to go high!\n");
-                       return TIMEOUT;
+                       err = TIMEOUT;
+                       goto out;
                }
        }
 
@@ -387,20 +375,42 @@ esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
                do {
                        irqstat = esdhc_read32(&regs->irqstat);
 
-                       if (irqstat & IRQSTAT_DTOE)
-                               return TIMEOUT;
+                       if (irqstat & IRQSTAT_DTOE) {
+                               err = TIMEOUT;
+                               goto out;
+                       }
 
-                       if (irqstat & DATA_ERR)
-                               return COMM_ERR;
+                       if (irqstat & DATA_ERR) {
+                               err = COMM_ERR;
+                               goto out;
+                       }
                } while ((irqstat & DATA_COMPLETE) != DATA_COMPLETE);
-#endif
+
                if (data->flags & MMC_DATA_READ)
                        check_and_invalidate_dcache_range(cmd, data);
+#endif
+       }
+
+out:
+       /* Reset CMD and DATA portions on error */
+       if (err) {
+               esdhc_write32(&regs->sysctl, esdhc_read32(&regs->sysctl) |
+                             SYSCTL_RSTC);
+               while (esdhc_read32(&regs->sysctl) & SYSCTL_RSTC)
+                       ;
+
+               if (data) {
+                       esdhc_write32(&regs->sysctl,
+                                     esdhc_read32(&regs->sysctl) |
+                                     SYSCTL_RSTD);
+                       while ((esdhc_read32(&regs->sysctl) & SYSCTL_RSTD))
+                               ;
+               }
        }
 
        esdhc_write32(&regs->irqstat, -1);
 
-       return 0;
+       return err;
 }
 
 static void set_sysctl(struct mmc *mmc, uint clock)