]> git.karo-electronics.de Git - karo-tx-uboot.git/blobdiff - drivers/mmc/sdhci.c
Merge branch 'master' of git://www.denx.de/git/u-boot-microblaze
[karo-tx-uboot.git] / drivers / mmc / sdhci.c
index f72536b2aa43f70f9aebca6431f29ff83aeac1cc..02d71b934409f56e2ede04c31e40f611fc914987 100644 (file)
 #include <mmc.h>
 #include <sdhci.h>
 
+#if defined(CONFIG_FIXED_SDHCI_ALIGNED_BUFFER)
+void *aligned_buffer = (void *)CONFIG_FIXED_SDHCI_ALIGNED_BUFFER;
+#else
 void *aligned_buffer;
+#endif
 
 static void sdhci_reset(struct sdhci_host *host, u8 mask)
 {
@@ -205,6 +209,17 @@ static int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd,
                                memcpy(aligned_buffer, data->src, trans_bytes);
                }
 
+#if defined(CONFIG_FIXED_SDHCI_ALIGNED_BUFFER)
+               /*
+                * Always use this bounce-buffer when
+                * CONFIG_FIXED_SDHCI_ALIGNED_BUFFER is defined
+                */
+               is_aligned = 0;
+               start_addr = (unsigned long)aligned_buffer;
+               if (data->flags != MMC_DATA_READ)
+                       memcpy(aligned_buffer, data->src, trans_bytes);
+#endif
+
                sdhci_writel(host, start_addr, SDHCI_DMA_ADDRESS);
                mode |= SDHCI_TRNS_DMA;
 #endif
@@ -271,9 +286,25 @@ static int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd,
 static int sdhci_set_clock(struct mmc *mmc, unsigned int clock)
 {
        struct sdhci_host *host = mmc->priv;
-       unsigned int div, clk, timeout;
+       unsigned int div, clk, timeout, reg;
+
+       /* Wait max 20 ms */
+       timeout = 200;
+       while (sdhci_readl(host, SDHCI_PRESENT_STATE) &
+                          (SDHCI_CMD_INHIBIT | SDHCI_DATA_INHIBIT)) {
+               if (timeout == 0) {
+                       printf("%s: Timeout to wait cmd & data inhibit\n",
+                              __func__);
+                       return -1;
+               }
+
+               timeout--;
+               udelay(100);
+       }
 
-       sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL);
+       reg = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+       reg &= ~SDHCI_CLOCK_CARD_EN;
+       sdhci_writew(host, reg, SDHCI_CLOCK_CONTROL);
 
        if (clock == 0)
                return 0;