Merge branch 'next' of git://git.denx.de/u-boot
[oweals/u-boot.git] / drivers / mmc / sdhci.c
index 4a92453463c671186c4c7f1f446206b9a8ac8564..1709643da83b66585b0e9d5c7ae1851da2defaa1 100644 (file)
@@ -81,8 +81,9 @@ static void sdhci_transfer_pio(struct sdhci_host *host, struct mmc_data *data)
 static int sdhci_transfer_data(struct sdhci_host *host, struct mmc_data *data,
                                unsigned int start_addr)
 {
-       unsigned int stat, rdy, mask, block = 0;
+       unsigned int stat, rdy, mask, timeout, block = 0;
 
+       timeout = 10000;
        rdy = SDHCI_INT_SPACE_AVAIL | SDHCI_INT_DATA_AVAIL;
        mask = SDHCI_DATA_AVAILABLE | SDHCI_SPACE_AVAILABLE;
        do {
@@ -103,11 +104,17 @@ static int sdhci_transfer_data(struct sdhci_host *host, struct mmc_data *data,
 #ifdef CONFIG_MMC_SDMA
                if (stat & SDHCI_INT_DMA_END) {
                        sdhci_writel(host, SDHCI_INT_DMA_END, SDHCI_INT_STATUS);
-                       start_addr &= SDHCI_DEFAULT_BOUNDARY_SIZE - 1;
+                       start_addr &= ~(SDHCI_DEFAULT_BOUNDARY_SIZE - 1);
                        start_addr += SDHCI_DEFAULT_BOUNDARY_SIZE;
                        sdhci_writel(host, start_addr, SDHCI_DMA_ADDRESS);
                }
 #endif
+               if (timeout-- > 0)
+                       udelay(10);
+               else {
+                       printf("Transfer data timeout\n");
+                       return -1;
+               }
        } while (!(stat & SDHCI_INT_DATA_END));
        return 0;
 }
@@ -121,6 +128,7 @@ int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd,
        int trans_bytes = 0, is_aligned = 1;
        u32 mask, flags, mode;
        unsigned int timeout, start_addr = 0;
+       unsigned int retry = 10000;
 
        /* Wait max 10 ms */
        timeout = 10;
@@ -203,8 +211,19 @@ int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd,
                stat = sdhci_readl(host, SDHCI_INT_STATUS);
                if (stat & SDHCI_INT_ERROR)
                        break;
+               if (--retry == 0)
+                       break;
        } while ((stat & mask) != mask);
 
+       if (retry == 0) {
+               if (host->quirks & SDHCI_QUIRK_BROKEN_R1B)
+                       return 0;
+               else {
+                       printf("Timeout for status update!\n");
+                       return TIMEOUT;
+               }
+       }
+
        if ((stat & (SDHCI_INT_ERROR | mask)) == mask) {
                sdhci_cmd_done(host, cmd);
                sdhci_writel(host, mask, SDHCI_INT_STATUS);
@@ -318,6 +337,9 @@ void sdhci_set_ios(struct mmc *mmc)
        u32 ctrl;
        struct sdhci_host *host = (struct sdhci_host *)mmc->priv;
 
+       if (host->set_control_reg)
+               host->set_control_reg(host);
+
        if (mmc->clock != host->clock)
                sdhci_set_clock(mmc, mmc->clock);
 
@@ -341,6 +363,9 @@ void sdhci_set_ios(struct mmc *mmc)
        else
                ctrl &= ~SDHCI_CTRL_HISPD;
 
+       if (host->quirks & SDHCI_QUIRK_NO_HISPD_BIT)
+               ctrl &= ~SDHCI_CTRL_HISPD;
+
        sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
 }
 
@@ -377,11 +402,13 @@ int add_sdhci(struct sdhci_host *host, u32 max_clk, u32 min_clk)
        }
 
        mmc->priv = host;
+       host->mmc = mmc;
 
        sprintf(mmc->name, "%s", host->name);
        mmc->send_cmd = sdhci_send_command;
        mmc->set_ios = sdhci_set_ios;
        mmc->init = sdhci_init;
+       mmc->getcd = NULL;
 
        caps = sdhci_readl(host, SDHCI_CAPABILITIES);
 #ifdef CONFIG_MMC_SDMA
@@ -422,9 +449,15 @@ int add_sdhci(struct sdhci_host *host, u32 max_clk, u32 min_clk)
                mmc->voltages |= MMC_VDD_29_30 | MMC_VDD_30_31;
        if (caps & SDHCI_CAN_VDD_180)
                mmc->voltages |= MMC_VDD_165_195;
+
+       if (host->quirks & SDHCI_QUIRK_BROKEN_VOLTAGE)
+               mmc->voltages |= host->voltages;
+
        mmc->host_caps = MMC_MODE_HS | MMC_MODE_HS_52MHz | MMC_MODE_4BIT;
        if (caps & SDHCI_CAN_DO_8BIT)
                mmc->host_caps |= MMC_MODE_8BIT;
+       if (host->host_caps)
+               mmc->host_caps |= host->host_caps;
 
        sdhci_reset(host, SDHCI_RESET_ALL);
        mmc_register(mmc);