#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)
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)
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)
int mmc_get_next_devnum(void)
{
- int ret;
-
- ret = blk_find_max_devnum(IF_TYPE_MMC);
- if (ret < 0)
- return ret;
-
- return ret;
+ return blk_find_max_devnum(IF_TYPE_MMC);
}
struct blk_desc *mmc_get_blk_desc(struct mmc *mmc)
{
struct blk_desc *bdesc;
struct udevice *bdev;
- int ret;
+ int ret, devnum = -1;
+
+#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 */
+ 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, -1, 512,
- 0, &bdev);
+ 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;
device_find_first_child(dev, &bdev);
if (bdev) {
- device_remove(bdev);
+ device_remove(bdev, DM_REMOVE_NORMAL);
device_unbind(bdev);
}
struct udevice *mmc_dev = dev_get_parent(bdev);
struct mmc *mmc = mmc_get_mmc_dev(mmc_dev);
struct blk_desc *desc = dev_get_uclass_platdata(bdev);
- int ret;
if (desc->hwpart == hwpart)
return 0;
if (mmc->part_config == MMCPART_NOAVAILABLE)
return -EMEDIUMTYPE;
- ret = mmc_switch_part(mmc, hwpart);
- if (ret)
+ 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;
}
.read = mmc_bread,
#ifndef CONFIG_SPL_BUILD
.write = mmc_bwrite,
+ .erase = mmc_berase,
#endif
.select_hwpart = mmc_select_hwpart,
};
.name = "mmc_blk",
.id = UCLASS_BLK,
.ops = &mmc_blk_ops,
+ .probe = mmc_blk_probe,
};
#endif /* CONFIG_BLK */