dm: core: Update lists_bind_fdt() to use ofnode
[oweals/u-boot.git] / drivers / mmc / mmc-uclass.c
index 2fe5d61e263761ba71e1d5f0917eccbbc22805f4..16cc91ebdfd002d845227e457422a63c9c9c3be7 100644 (file)
@@ -13,6 +13,8 @@
 #include <dm/root.h>
 #include "mmc_private.h"
 
+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)
@@ -192,10 +194,19 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg)
 {
        struct blk_desc *bdesc;
        struct udevice *bdev;
-       int ret;
+       int ret, devnum = -1;
 
-       ret = blk_create_devicef(dev, "mmc_blk", "blk", IF_TYPE_MMC, -1, 512,
-                                0, &bdev);
+#ifdef CONFIG_DM_MMC_OPS
+       if (!mmc_get_ops(dev))
+               return -ENOSYS;
+#endif
+#ifndef CONFIG_SPL_BUILD
+       /* Use the fixed index with aliase node's index */
+       fdtdec_get_alias_seq(gd->fdt_blob, "mmc", dev_of_offset(dev), &devnum);
+#endif
+
+       ret = blk_create_devicef(dev, "mmc_blk", "blk", IF_TYPE_MMC,
+                       devnum, 512, 0, &bdev);
        if (ret) {
                debug("Cannot create block device\n");
                return ret;
@@ -225,7 +236,7 @@ int mmc_unbind(struct udevice *dev)
 
        device_find_first_child(dev, &bdev);
        if (bdev) {
-               device_remove(bdev);
+               device_remove(bdev, DM_REMOVE_NORMAL);
                device_unbind(bdev);
        }
 
@@ -247,6 +258,22 @@ static int mmc_select_hwpart(struct udevice *bdev, int hwpart)
        return mmc_switch_part(mmc, hwpart);
 }
 
+static int mmc_blk_probe(struct udevice *dev)
+{
+       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;
+
+       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 = {
        .read   = mmc_bread,
 #ifndef CONFIG_SPL_BUILD
@@ -260,6 +287,7 @@ U_BOOT_DRIVER(mmc_blk) = {
        .name           = "mmc_blk",
        .id             = UCLASS_BLK,
        .ops            = &mmc_blk_ops,
+       .probe          = mmc_blk_probe,
 };
 #endif /* CONFIG_BLK */