]> git.sur5r.net Git - u-boot/blobdiff - drivers/mmc/mmc-uclass.c
SPDX: Convert all of our single license tags to Linux Kernel style
[u-boot] / drivers / mmc / mmc-uclass.c
index 16cc91ebdfd002d845227e457422a63c9c9c3be7..f73f07254be664cdd5bd5c053b208c57cff47c0e 100644 (file)
@@ -1,8 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2015 Google, Inc
  * Written by Simon Glass <sjg@chromium.org>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -10,12 +9,8 @@
 #include <dm.h>
 #include <dm/device-internal.h>
 #include <dm/lists.h>
-#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)
 {
@@ -52,6 +47,35 @@ int mmc_set_ios(struct mmc *mmc)
        return dm_mmc_set_ios(mmc->dev);
 }
 
+void dm_mmc_send_init_stream(struct udevice *dev)
+{
+       struct dm_mmc_ops *ops = mmc_get_ops(dev);
+
+       if (ops->send_init_stream)
+               ops->send_init_stream(dev);
+}
+
+void mmc_send_init_stream(struct mmc *mmc)
+{
+       dm_mmc_send_init_stream(mmc->dev);
+}
+
+#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
+int dm_mmc_wait_dat0(struct udevice *dev, int state, int timeout)
+{
+       struct dm_mmc_ops *ops = mmc_get_ops(dev);
+
+       if (!ops->wait_dat0)
+               return -ENOSYS;
+       return ops->wait_dat0(dev, state, timeout);
+}
+
+int mmc_wait_dat0(struct mmc *mmc, int state, int timeout)
+{
+       return dm_mmc_wait_dat0(mmc->dev, state, timeout);
+}
+#endif
+
 int dm_mmc_get_wp(struct udevice *dev)
 {
        struct dm_mmc_ops *ops = mmc_get_ops(dev);
@@ -79,8 +103,73 @@ int mmc_getcd(struct mmc *mmc)
 {
        return dm_mmc_get_cd(mmc->dev);
 }
+
+#ifdef MMC_SUPPORTS_TUNING
+int dm_mmc_execute_tuning(struct udevice *dev, uint opcode)
+{
+       struct dm_mmc_ops *ops = mmc_get_ops(dev);
+
+       if (!ops->execute_tuning)
+               return -ENOSYS;
+       return ops->execute_tuning(dev, opcode);
+}
+
+int mmc_execute_tuning(struct mmc *mmc, uint opcode)
+{
+       return dm_mmc_execute_tuning(mmc->dev, opcode);
+}
 #endif
 
+int mmc_of_parse(struct udevice *dev, struct mmc_config *cfg)
+{
+       int val;
+
+       val = dev_read_u32_default(dev, "bus-width", 1);
+
+       switch (val) {
+       case 0x8:
+               cfg->host_caps |= MMC_MODE_8BIT;
+               /* fall through */
+       case 0x4:
+               cfg->host_caps |= MMC_MODE_4BIT;
+               /* fall through */
+       case 0x1:
+               cfg->host_caps |= MMC_MODE_1BIT;
+               break;
+       default:
+               dev_err(dev, "Invalid \"bus-width\" value %u!\n", val);
+               return -EINVAL;
+       }
+
+       /* f_max is obtained from the optional "max-frequency" property */
+       dev_read_u32(dev, "max-frequency", &cfg->f_max);
+
+       if (dev_read_bool(dev, "cap-sd-highspeed"))
+               cfg->host_caps |= MMC_CAP(SD_HS);
+       if (dev_read_bool(dev, "cap-mmc-highspeed"))
+               cfg->host_caps |= MMC_CAP(MMC_HS);
+       if (dev_read_bool(dev, "sd-uhs-sdr12"))
+               cfg->host_caps |= MMC_CAP(UHS_SDR12);
+       if (dev_read_bool(dev, "sd-uhs-sdr25"))
+               cfg->host_caps |= MMC_CAP(UHS_SDR25);
+       if (dev_read_bool(dev, "sd-uhs-sdr50"))
+               cfg->host_caps |= MMC_CAP(UHS_SDR50);
+       if (dev_read_bool(dev, "sd-uhs-sdr104"))
+               cfg->host_caps |= MMC_CAP(UHS_SDR104);
+       if (dev_read_bool(dev, "sd-uhs-ddr50"))
+               cfg->host_caps |= MMC_CAP(UHS_DDR50);
+       if (dev_read_bool(dev, "mmc-ddr-1_8v"))
+               cfg->host_caps |= MMC_CAP(MMC_DDR_52);
+       if (dev_read_bool(dev, "mmc-ddr-1_2v"))
+               cfg->host_caps |= MMC_CAP(MMC_DDR_52);
+       if (dev_read_bool(dev, "mmc-hs200-1_8v"))
+               cfg->host_caps |= MMC_CAP(MMC_HS_200);
+       if (dev_read_bool(dev, "mmc-hs200-1_2v"))
+               cfg->host_caps |= MMC_CAP(MMC_HS_200);
+
+       return 0;
+}
+
 struct mmc *mmc_get_mmc_dev(struct udevice *dev)
 {
        struct mmc_uclass_priv *upriv;
@@ -91,13 +180,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 +197,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,13 +287,12 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg)
        struct udevice *bdev;
        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 */
-       fdtdec_get_alias_seq(gd->fdt_blob, "mmc", dev_of_offset(dev), &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,
@@ -276,7 +366,7 @@ static int mmc_blk_probe(struct udevice *dev)
 
 static const struct blk_ops mmc_blk_ops = {
        .read   = mmc_bread,
-#ifndef CONFIG_SPL_BUILD
+#if CONFIG_IS_ENABLED(MMC_WRITE)
        .write  = mmc_bwrite,
        .erase  = mmc_berase,
 #endif