Merge branch 'next' of git://git.denx.de/u-boot
[oweals/u-boot.git] / drivers / mmc / fsl_esdhc.c
index 07370b57291daaded12e4da93edad61965f424f7..b6c969d2c8440571fb660d00415c714837e04c55 100644 (file)
@@ -190,6 +190,10 @@ static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data)
                esdhc_clrsetbits32(&regs->wml, WML_RD_WML_MASK, wml_value);
                esdhc_write32(&regs->dsaddr, (u32)data->dest);
        } else {
+               flush_dcache_range((ulong)data->src,
+                                  (ulong)data->src+data->blocks
+                                        *data->blocksize);
+
                if (wml_value > WML_WR_WML_MAX)
                        wml_value = WML_WR_WML_MAX_VAL;
                if ((esdhc_read32(&regs->prsstat) & PRSSTAT_WPSPL) == 0) {
@@ -249,7 +253,15 @@ static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data)
        return 0;
 }
 
-
+static void check_and_invalidate_dcache_range
+       (struct mmc_cmd *cmd,
+        struct mmc_data *data) {
+       unsigned start = (unsigned)data->dest ;
+       unsigned size = roundup(ARCH_DMA_MINALIGN,
+                               data->blocks*data->blocksize);
+       unsigned end = start+size ;
+       invalidate_dcache_range(start, end);
+}
 /*
  * Sends a command out on the bus.  Takes the mmc pointer,
  * a command pointer, and an optional data pointer.
@@ -315,6 +327,9 @@ esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
        while (!(esdhc_read32(&regs->irqstat) & (IRQSTAT_CC | IRQSTAT_CTOE)))
                ;
 
+       if (data && (data->flags & MMC_DATA_READ))
+               check_and_invalidate_dcache_range(cmd, data);
+
        irqstat = esdhc_read32(&regs->irqstat);
        esdhc_write32(&regs->irqstat, irqstat);
 
@@ -528,6 +543,9 @@ int fsl_esdhc_initialize(bd_t *bis, struct fsl_esdhc_cfg *cfg)
        /* First reset the eSDHC controller */
        esdhc_reset(regs);
 
+       esdhc_setbits32(&regs->sysctl, SYSCTL_PEREN | SYSCTL_HCKEN
+                               | SYSCTL_IPGEN | SYSCTL_CKEN);
+
        mmc->priv = cfg;
        mmc->send_cmd = esdhc_send_cmd;
        mmc->set_ios = esdhc_set_ios;