]> git.sur5r.net Git - u-boot/blobdiff - drivers/mmc/gen_atmel_mci.c
treewide: replace #include <asm/errno.h> with <linux/errno.h>
[u-boot] / drivers / mmc / gen_atmel_mci.c
index da870c646ebbac06734ca1b7a840bd7b01a23806..cca0b04a6028b82d175b84ebc879dfd3f4a12c7d 100644 (file)
@@ -14,7 +14,7 @@
 #include <part.h>
 #include <malloc.h>
 #include <asm/io.h>
-#include <asm/errno.h>
+#include <linux/errno.h>
 #include <asm/byteorder.h>
 #include <asm/arch/clk.h>
 #include <asm/arch/hardware.h>
@@ -36,6 +36,7 @@ struct atmel_mci_priv {
        struct mmc_config       cfg;
        struct atmel_mci        *mci;
        unsigned int            initialized:1;
+       unsigned int            curr_clk;
 };
 
 /* Read Atmel MCI IP version */
@@ -91,7 +92,10 @@ static void mci_set_mode(struct mmc *mmc, u32 hz, u32 blklen)
 
                }
        }
-
+       if (version >= 0x500)
+               priv->curr_clk = bus_hz / (clkdiv * 2 + clkodd + 2);
+       else
+               priv->curr_clk = (bus_hz / (clkdiv + 1)) / 2;
        blklen &= 0xfffc;
 
        mr = MMCI_BF(CLKDIV, clkdiv);
@@ -118,8 +122,6 @@ static void mci_set_mode(struct mmc *mmc, u32 hz, u32 blklen)
        if (mmc->card_caps & mmc->cfg->host_caps & MMC_MODE_HS)
                writel(MMCI_BIT(HSMODE), &mci->cfg);
 
-       udelay(50);
-
        priv->initialized = 1;
 }
 
@@ -211,7 +213,7 @@ mci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
 
        if (!priv->initialized) {
                puts ("MCI not initialized!\n");
-               return COMM_ERR;
+               return -ECOMM;
        }
 
        /* Figure out the transfer arguments */
@@ -236,10 +238,10 @@ mci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
 
        if ((status & error_flags) & MMCI_BIT(RTOE)) {
                dump_cmd(cmdr, cmd->cmdarg, status, "Command Time Out");
-               return TIMEOUT;
+               return -ETIMEDOUT;
        } else if (status & error_flags) {
                dump_cmd(cmdr, cmd->cmdarg, status, "Command Failed");
-               return COMM_ERR;
+               return -ECOMM;
        }
 
        /* Copy the response to the response buffer */
@@ -301,7 +303,7 @@ mci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
                        if (status) {
                                dump_cmd(cmdr, cmd->cmdarg, status,
                                        "Data Transfer Failed");
-                               return COMM_ERR;
+                               return -ECOMM;
                        }
                }
 
@@ -313,7 +315,7 @@ mci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
                        if (status & error_flags) {
                                dump_cmd(cmdr, cmd->cmdarg, status,
                                        "DTIP Wait Failed");
-                               return COMM_ERR;
+                               return -ECOMM;
                        }
                        i++;
                } while ((status & MMCI_BIT(DTIP)) && i < 10000);
@@ -323,6 +325,13 @@ mci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
                }
        }
 
+       /*
+        * After the switch command, wait for 8 clocks before the next
+        * command
+        */
+       if (cmd->cmdidx == MMC_CMD_SWITCH)
+               udelay(8*1000000 / priv->curr_clk); /* 8 clk in us */
+
        return 0;
 }