]> git.sur5r.net Git - u-boot/blobdiff - drivers/mmc/mmc.c
pinctrl: uniphier: fix NAND and SD pin-mux settings for PH1-LD11/LD20
[u-boot] / drivers / mmc / mmc.c
index 3a34028c9177ef1d917910dfd61a7c4b14e12749..d3c22abfd5a8c198499308cb4b8e24f161f9be3d 100644 (file)
@@ -61,7 +61,10 @@ int mmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
        printf("CMD_SEND:%d\n", cmd->cmdidx);
        printf("\t\tARG\t\t\t 0x%08X\n", cmd->cmdarg);
        ret = mmc->cfg->ops->send_cmd(mmc, cmd, data);
-       switch (cmd->resp_type) {
+       if (ret) {
+               printf("\t\tRET\t\t\t %d\n", ret);
+       } else {
+               switch (cmd->resp_type) {
                case MMC_RSP_NONE:
                        printf("\t\tMMC_RSP_NONE\n");
                        break;
@@ -101,6 +104,7 @@ int mmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
                default:
                        printf("\t\tERROR MMC rsp not supported\n");
                        break;
+               }
        }
 #else
        ret = mmc->cfg->ops->send_cmd(mmc, cmd, data);
@@ -182,7 +186,7 @@ struct mmc *find_mmc_device(int dev_num)
        list_for_each(entry, &mmc_devices) {
                m = list_entry(entry, struct mmc, link);
 
-               if (m->block_dev.dev == dev_num)
+               if (m->block_dev.devnum == dev_num)
                        return m;
        }
 
@@ -234,8 +238,11 @@ static int mmc_read_blocks(struct mmc *mmc, void *dst, lbaint_t start,
        return blkcnt;
 }
 
-static ulong mmc_bread(int dev_num, lbaint_t start, lbaint_t blkcnt, void *dst)
+static ulong mmc_bread(struct blk_desc *block_dev, lbaint_t start,
+                      lbaint_t blkcnt, void *dst)
 {
+       int dev_num = block_dev->devnum;
+       int err;
        lbaint_t cur, blocks_todo = blkcnt;
 
        if (blkcnt == 0)
@@ -245,6 +252,10 @@ static ulong mmc_bread(int dev_num, lbaint_t start, lbaint_t blkcnt, void *dst)
        if (!mmc)
                return 0;
 
+       err = mmc_select_hwpart(dev_num, block_dev->hwpart);
+       if (err < 0)
+               return 0;
+
        if ((start + blkcnt) > mmc->block_dev.lba) {
 #if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
                printf("MMC: block number 0x" LBAF " exceeds max(0x" LBAF ")\n",
@@ -579,7 +590,7 @@ int mmc_select_hwpart(int dev_num, int hwpart)
        if (!mmc)
                return -ENODEV;
 
-       if (mmc->part_num == hwpart)
+       if (mmc->block_dev.hwpart == hwpart)
                return 0;
 
        if (mmc->part_config == MMCPART_NOAVAILABLE) {
@@ -591,8 +602,6 @@ int mmc_select_hwpart(int dev_num, int hwpart)
        if (ret)
                return ret;
 
-       mmc->part_num = hwpart;
-
        return 0;
 }
 
@@ -613,8 +622,10 @@ int mmc_switch_part(int dev_num, unsigned int part_num)
         * Set the capacity if the switch succeeded or was intended
         * to return to representing the raw device.
         */
-       if ((ret == 0) || ((ret == -ENODEV) && (part_num == 0)))
+       if ((ret == 0) || ((ret == -ENODEV) && (part_num == 0))) {
                ret = mmc_set_capacity(mmc, part_num);
+               mmc->block_dev.hwpart = part_num;
+       }
 
        return ret;
 }
@@ -899,20 +910,20 @@ retry_scr:
        mmc->scr[1] = __be32_to_cpu(scr[1]);
 
        switch ((mmc->scr[0] >> 24) & 0xf) {
-               case 0:
-                       mmc->version = SD_VERSION_1_0;
-                       break;
-               case 1:
-                       mmc->version = SD_VERSION_1_10;
-                       break;
-               case 2:
-                       mmc->version = SD_VERSION_2;
-                       if ((mmc->scr[0] >> 15) & 0x1)
-                               mmc->version = SD_VERSION_3;
-                       break;
-               default:
-                       mmc->version = SD_VERSION_1_0;
-                       break;
+       case 0:
+               mmc->version = SD_VERSION_1_0;
+               break;
+       case 1:
+               mmc->version = SD_VERSION_1_10;
+               break;
+       case 2:
+               mmc->version = SD_VERSION_2;
+               if ((mmc->scr[0] >> 15) & 0x1)
+                       mmc->version = SD_VERSION_3;
+               break;
+       default:
+               mmc->version = SD_VERSION_1_0;
+               break;
        }
 
        if (mmc->scr[0] & SD_DATA_4BIT)
@@ -1095,24 +1106,24 @@ static int mmc_startup(struct mmc *mmc)
                int version = (cmd.response[0] >> 26) & 0xf;
 
                switch (version) {
-                       case 0:
-                               mmc->version = MMC_VERSION_1_2;
-                               break;
-                       case 1:
-                               mmc->version = MMC_VERSION_1_4;
-                               break;
-                       case 2:
-                               mmc->version = MMC_VERSION_2_2;
-                               break;
-                       case 3:
-                               mmc->version = MMC_VERSION_3;
-                               break;
-                       case 4:
-                               mmc->version = MMC_VERSION_4;
-                               break;
-                       default:
-                               mmc->version = MMC_VERSION_1_2;
-                               break;
+               case 0:
+                       mmc->version = MMC_VERSION_1_2;
+                       break;
+               case 1:
+                       mmc->version = MMC_VERSION_1_4;
+                       break;
+               case 2:
+                       mmc->version = MMC_VERSION_2_2;
+                       break;
+               case 3:
+                       mmc->version = MMC_VERSION_3;
+                       break;
+               case 4:
+                       mmc->version = MMC_VERSION_4;
+                       break;
+               default:
+                       mmc->version = MMC_VERSION_1_2;
+                       break;
                }
        }
 
@@ -1324,7 +1335,7 @@ static int mmc_startup(struct mmc *mmc)
                mmc->wr_rel_set = ext_csd[EXT_CSD_WR_REL_SET];
        }
 
-       err = mmc_set_capacity(mmc, mmc->part_num);
+       err = mmc_set_capacity(mmc, mmc->block_dev.hwpart);
        if (err)
                return err;
 
@@ -1465,6 +1476,7 @@ static int mmc_startup(struct mmc *mmc)
 
        /* fill in device description */
        mmc->block_dev.lun = 0;
+       mmc->block_dev.hwpart = 0;
        mmc->block_dev.type = 0;
        mmc->block_dev.blksz = mmc->read_bl_len;
        mmc->block_dev.log2blksz = LOG2(mmc->block_dev.blksz);
@@ -1487,7 +1499,7 @@ static int mmc_startup(struct mmc *mmc)
        mmc->block_dev.revision[0] = 0;
 #endif
 #if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBDISK_SUPPORT)
-       init_part(&mmc->block_dev);
+       part_init(&mmc->block_dev);
 #endif
 
        return 0;
@@ -1548,7 +1560,7 @@ struct mmc *mmc_create(const struct mmc_config *cfg, void *priv)
        mmc->dsr = 0xffffffff;
        /* Setup the universal parts of the block interface just once */
        mmc->block_dev.if_type = IF_TYPE_MMC;
-       mmc->block_dev.dev = cur_dev_num++;
+       mmc->block_dev.devnum = cur_dev_num++;
        mmc->block_dev.removable = 1;
        mmc->block_dev.block_read = mmc_bread;
        mmc->block_dev.block_write = mmc_bwrite;
@@ -1571,7 +1583,7 @@ void mmc_destroy(struct mmc *mmc)
 }
 
 #ifdef CONFIG_PARTITIONS
-block_dev_desc_t *mmc_get_dev(int dev)
+struct blk_desc *mmc_get_dev(int dev)
 {
        struct mmc *mmc = find_mmc_device(dev);
        if (!mmc || mmc_init(mmc))
@@ -1624,7 +1636,7 @@ int mmc_start_init(struct mmc *mmc)
                return err;
 
        /* The internal partition reset to user partition(0) at every CMD0*/
-       mmc->part_num = 0;
+       mmc->block_dev.hwpart = 0;
 
        /* Test for SD version 2 */
        err = mmc_send_if_cond(mmc);
@@ -1720,7 +1732,7 @@ void print_mmc_devices(char separator)
                else
                        mmc_type = NULL;
 
-               printf("%s: %d", m->cfg->name, m->block_dev.dev);
+               printf("%s: %d", m->cfg->name, m->block_dev.devnum);
                if (mmc_type)
                        printf(" (%s)", mmc_type);
 
@@ -1772,18 +1784,28 @@ static int mmc_probe(bd_t *bis)
 #elif defined(CONFIG_DM_MMC)
 static int mmc_probe(bd_t *bis)
 {
-       int ret;
+       int ret, i;
        struct uclass *uc;
-       struct udevice *m;
+       struct udevice *dev;
 
        ret = uclass_get(UCLASS_MMC, &uc);
        if (ret)
                return ret;
 
-       uclass_foreach_dev(m, uc) {
-               ret = device_probe(m);
+       /*
+        * Try to add them in sequence order. Really with driver model we
+        * should allow holes, but the current MMC list does not allow that.
+        * So if we request 0, 1, 3 we will get 0, 1, 2.
+        */
+       for (i = 0; ; i++) {
+               ret = uclass_get_device_by_seq(UCLASS_MMC, i, &dev);
+               if (ret == -ENODEV)
+                       break;
+       }
+       uclass_foreach_dev(dev, uc) {
+               ret = device_probe(dev);
                if (ret)
-                       printf("%s - probe failed: %d\n", m->name, ret);
+                       printf("%s - probe failed: %d\n", dev->name, ret);
        }
 
        return 0;