]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/mmc/mmc.c
Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'
[karo-tx-uboot.git] / drivers / mmc / mmc.c
index eccdbc4b617716fea2dad4916fa5e0b3e376a79a..55c2c68cdb23218945d0af727632745897278d72 100644 (file)
@@ -150,6 +150,8 @@ int mmc_send_status(struct mmc *mmc, int timeout)
 #endif
                return TIMEOUT;
        }
+       if (cmd.response[0] & MMC_STATUS_SWITCH_ERROR)
+               return SWITCH_ERR;
 
        return 0;
 }
@@ -158,6 +160,9 @@ int mmc_set_blocklen(struct mmc *mmc, int len)
 {
        struct mmc_cmd cmd;
 
+       if (mmc->card_caps & MMC_MODE_DDR_52MHz)
+               return 0;
+
        cmd.cmdidx = MMC_CMD_SET_BLOCKLEN;
        cmd.resp_type = MMC_RSP_R1;
        cmd.cmdarg = len;
@@ -501,7 +506,7 @@ static int mmc_change_freq(struct mmc *mmc)
        err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, 1);
 
        if (err)
-               return err;
+               return err == SWITCH_ERR ? 0 : err;
 
        /* Now check to see that it worked */
        err = mmc_send_ext_csd(mmc, ext_csd);
@@ -514,10 +519,13 @@ static int mmc_change_freq(struct mmc *mmc)
                return 0;
 
        /* High Speed is set, there are two types: 52MHz and 26MHz */
-       if (cardtype & MMC_HS_52MHZ)
+       if (cardtype & EXT_CSD_CARD_TYPE_52) {
+               if (cardtype & EXT_CSD_CARD_TYPE_DDR_52)
+                       mmc->card_caps |= MMC_MODE_DDR_52MHz;
                mmc->card_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
-       else
+       } else {
                mmc->card_caps |= MMC_MODE_HS;
+       }
 
        return 0;
 }
@@ -550,6 +558,32 @@ static int mmc_set_capacity(struct mmc *mmc, int part_num)
        return 0;
 }
 
+int mmc_select_hwpart(int dev_num, int hwpart)
+{
+       struct mmc *mmc = find_mmc_device(dev_num);
+       int ret;
+
+       if (!mmc)
+               return -1;
+
+       if (mmc->part_num == hwpart)
+               return 0;
+
+       if (mmc->part_config == MMCPART_NOAVAILABLE) {
+               printf("Card doesn't support part_switch\n");
+               return -1;
+       }
+
+       ret = mmc_switch_part(dev_num, hwpart);
+       if (ret)
+               return -1;
+
+       mmc->part_num = hwpart;
+
+       return 0;
+}
+
+
 int mmc_switch_part(int dev_num, unsigned int part_num)
 {
        struct mmc *mmc = find_mmc_device(dev_num);
@@ -1054,6 +1088,8 @@ static int mmc_startup(struct mmc *mmc)
 
                /* An array of possible bus widths in order of preference */
                static unsigned ext_csd_bits[] = {
+                       EXT_CSD_DDR_BUS_WIDTH_8,
+                       EXT_CSD_DDR_BUS_WIDTH_4,
                        EXT_CSD_BUS_WIDTH_8,
                        EXT_CSD_BUS_WIDTH_4,
                        EXT_CSD_BUS_WIDTH_1,
@@ -1061,13 +1097,15 @@ static int mmc_startup(struct mmc *mmc)
 
                /* An array to map CSD bus widths to host cap bits */
                static unsigned ext_to_hostcaps[] = {
+                       [EXT_CSD_DDR_BUS_WIDTH_4] = MMC_MODE_DDR_52MHz,
+                       [EXT_CSD_DDR_BUS_WIDTH_8] = MMC_MODE_DDR_52MHz,
                        [EXT_CSD_BUS_WIDTH_4] = MMC_MODE_4BIT,
                        [EXT_CSD_BUS_WIDTH_8] = MMC_MODE_8BIT,
                };
 
                /* An array to map chosen bus width to an integer */
                static unsigned widths[] = {
-                       8, 4, 1,
+                       8, 4, 8, 4, 1,
                };
 
                for (idx=0; idx < ARRAY_SIZE(ext_csd_bits); idx++) {
@@ -1310,10 +1348,13 @@ static int mmc_complete_init(struct mmc *mmc)
 int mmc_init(struct mmc *mmc)
 {
        int err = IN_PROGRESS;
-       unsigned start = get_timer(0);
+       unsigned start;
 
        if (mmc->has_init)
                return 0;
+
+       start = get_timer(0);
+
        if (!mmc->init_in_progress)
                err = mmc_start_init(mmc);
 
@@ -1513,4 +1554,16 @@ int mmc_set_part_conf(struct mmc *mmc, u8 ack, u8 part_num, u8 access)
                return err;
        return 0;
 }
+
+/*
+ * Modify EXT_CSD[162] which is RST_n_FUNCTION based on the given value
+ * for enable.  Note that this is a write-once field for non-zero values.
+ *
+ * Returns 0 on success.
+ */
+int mmc_set_rst_n_function(struct mmc *mmc, u8 enable)
+{
+       return mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_RST_N_FUNCTION,
+                         enable);
+}
 #endif