mmc: refactor MMC startup to make it easier to support new modes
[oweals/u-boot.git] / drivers / mmc / mmc-uclass.c
index 9c07871d3a2c7751a17b834dc9da8692b9a23c0f..5dda20cda5e7c06189319590342a02a0f332bd26 100644 (file)
@@ -15,7 +15,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#ifdef CONFIG_DM_MMC_OPS
 int dm_mmc_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
                    struct mmc_data *data)
 {
@@ -79,7 +78,6 @@ int mmc_getcd(struct mmc *mmc)
 {
        return dm_mmc_get_cd(mmc->dev);
 }
-#endif
 
 struct mmc *mmc_get_mmc_dev(struct udevice *dev)
 {
@@ -91,13 +89,13 @@ struct mmc *mmc_get_mmc_dev(struct udevice *dev)
        return upriv->mmc;
 }
 
-#ifdef CONFIG_BLK
+#if CONFIG_IS_ENABLED(BLK)
 struct mmc *find_mmc_device(int dev_num)
 {
        struct udevice *dev, *mmc_dev;
        int ret;
 
-       ret = blk_get_device(IF_TYPE_MMC, dev_num, &dev);
+       ret = blk_find_device(IF_TYPE_MMC, dev_num, &dev);
 
        if (ret) {
 #if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
@@ -108,7 +106,9 @@ struct mmc *find_mmc_device(int dev_num)
 
        mmc_dev = dev_get_parent(dev);
 
-       return mmc_get_mmc_dev(mmc_dev);
+       struct mmc *mmc = mmc_get_mmc_dev(mmc_dev);
+
+       return mmc;
 }
 
 int get_mmc_num(void)
@@ -196,9 +196,12 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg)
        struct udevice *bdev;
        int ret, devnum = -1;
 
+       if (!mmc_get_ops(dev))
+               return -ENOSYS;
 #ifndef CONFIG_SPL_BUILD
        /* Use the fixed index with aliase node's index */
-       fdtdec_get_alias_seq(gd->fdt_blob, "mmc", dev->of_offset, &devnum);
+       ret = dev_read_alias_seq(dev, &devnum);
+       debug("%s: alias ret=%d, devnum=%d\n", __func__, ret, devnum);
 #endif
 
        ret = blk_create_devicef(dev, "mmc_blk", "blk", IF_TYPE_MMC,
@@ -256,13 +259,18 @@ static int mmc_select_hwpart(struct udevice *bdev, int hwpart)
 
 static int mmc_blk_probe(struct udevice *dev)
 {
-       struct blk_desc *block_dev = dev_get_uclass_platdata(dev);
-       int dev_num = block_dev->devnum;
-       struct mmc *mmc = find_mmc_device(dev_num);
+       struct udevice *mmc_dev = dev_get_parent(dev);
+       struct mmc_uclass_priv *upriv = dev_get_uclass_priv(mmc_dev);
+       struct mmc *mmc = upriv->mmc;
+       int ret;
 
-       if (!mmc)
-               return -ENODEV;
-       return mmc_init(mmc);
+       ret = mmc_init(mmc);
+       if (ret) {
+               debug("%s: mmc_init() failed (err=%d)\n", __func__, ret);
+               return ret;
+       }
+
+       return 0;
 }
 
 static const struct blk_ops mmc_blk_ops = {