common: Drop linux/delay.h from common header
[oweals/u-boot.git] / drivers / mmc / mmc.c
index bfcdaa665dc954bf1b2f36d990ad6a30b4e81afd..02494db75a7d796a7779769b3a1ed14998f8c044 100644 (file)
@@ -8,12 +8,15 @@
 
 #include <config.h>
 #include <common.h>
+#include <blk.h>
 #include <command.h>
 #include <dm.h>
+#include <log.h>
 #include <dm/device-internal.h>
 #include <errno.h>
 #include <mmc.h>
 #include <part.h>
+#include <linux/delay.h>
 #include <power/regulator.h>
 #include <malloc.h>
 #include <memalign.h>
@@ -409,6 +412,16 @@ static int mmc_read_blocks(struct mmc *mmc, void *dst, lbaint_t start,
        return blkcnt;
 }
 
+#if !CONFIG_IS_ENABLED(DM_MMC)
+static int mmc_get_b_max(struct mmc *mmc, void *dst, lbaint_t blkcnt)
+{
+       if (mmc->cfg->ops->get_b_max)
+               return mmc->cfg->ops->get_b_max(mmc, dst, blkcnt);
+       else
+               return mmc->cfg->b_max;
+}
+#endif
+
 #if CONFIG_IS_ENABLED(BLK)
 ulong mmc_bread(struct udevice *dev, lbaint_t start, lbaint_t blkcnt, void *dst)
 #else
@@ -422,6 +435,7 @@ ulong mmc_bread(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt,
        int dev_num = block_dev->devnum;
        int err;
        lbaint_t cur, blocks_todo = blkcnt;
+       uint b_max;
 
        if (blkcnt == 0)
                return 0;
@@ -451,9 +465,10 @@ ulong mmc_bread(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt,
                return 0;
        }
 
+       b_max = mmc_get_b_max(mmc, dst, blkcnt);
+
        do {
-               cur = (blocks_todo > mmc->cfg->b_max) ?
-                       mmc->cfg->b_max : blocks_todo;
+               cur = (blocks_todo > b_max) ? b_max : blocks_todo;
                if (mmc_read_blocks(mmc, dst, start, cur) != cur) {
                        pr_debug("%s: Failed to read blocks\n", __func__);
                        return 0;
@@ -810,6 +825,11 @@ int mmc_switch(struct mmc *mmc, u8 set, u8 index, u8 value)
        return __mmc_switch(mmc, set, index, value, true);
 }
 
+int mmc_boot_wp(struct mmc *mmc)
+{
+       return mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BOOT_WP, 1);
+}
+
 #if !CONFIG_IS_ENABLED(MMC_TINY)
 static int mmc_set_card_speed(struct mmc *mmc, enum bus_mode mode,
                              bool hsdowngrade)