[U-Boot] [PATCH V2] mmc: seperate block number into small parts for multi-write cmd

Lei Wen leiwen at marvell.com
Mon Oct 11 05:42:06 CEST 2010


As suggested by Reinhard, I add two additional member in mmc structure,
so that we could specify its value in each driver. If that value is 0, then
the behavior would be the same as original, as no seperation.

Signed-off-by: Lei Wen <leiwen at marvell.com>
Cc: Reinhard Meyer <u-boot at emk-elektronik.de>
---
V2: add additional members in mmc structure

 drivers/mmc/bfin_sdh.c      |    1 +
 drivers/mmc/fsl_esdhc.c     |    1 +
 drivers/mmc/gen_atmel_mci.c |    1 +
 drivers/mmc/mmc.c           |   62 +++++++++++++++++++++++++++----------------
 drivers/mmc/mxcmmc.c        |    1 +
 include/mmc.h               |    2 +
 6 files changed, 45 insertions(+), 23 deletions(-)

diff --git a/drivers/mmc/bfin_sdh.c b/drivers/mmc/bfin_sdh.c
index 27d9bf6..6803322 100644
--- a/drivers/mmc/bfin_sdh.c
+++ b/drivers/mmc/bfin_sdh.c
@@ -246,6 +246,7 @@ int bfin_mmc_init(bd_t *bis)
 	if (!mmc)
 		return -ENOMEM;
 	sprintf(mmc->name, "Blackfin SDH");
+	mmc->host_maxblk = mmc->host_maxdmalen = 0;
 	mmc->send_cmd = bfin_sdh_request;
 	mmc->set_ios = bfin_sdh_set_ios;
 	mmc->init = bfin_sdh_init;
diff --git a/drivers/mmc/fsl_esdhc.c b/drivers/mmc/fsl_esdhc.c
index a368fe6..ba98de0 100644
--- a/drivers/mmc/fsl_esdhc.c
+++ b/drivers/mmc/fsl_esdhc.c
@@ -457,6 +457,7 @@ int fsl_esdhc_initialize(bd_t *bis, struct fsl_esdhc_cfg *cfg)
 	/* First reset the eSDHC controller */
 	esdhc_reset(regs);
 
+	mmc->host_maxblk = mmc->host_maxdmalen = 0;
 	mmc->priv = cfg;
 	mmc->send_cmd = esdhc_send_cmd;
 	mmc->set_ios = esdhc_set_ios;
diff --git a/drivers/mmc/gen_atmel_mci.c b/drivers/mmc/gen_atmel_mci.c
index fa4df99..054f62d 100644
--- a/drivers/mmc/gen_atmel_mci.c
+++ b/drivers/mmc/gen_atmel_mci.c
@@ -332,6 +332,7 @@ int atmel_mci_init(void *regs)
 	if (!mmc)
 		return -1;
 	strcpy(mmc->name, "mci");
+	mmc->host_maxblk = mmc->host_maxdmalen = 0;
 	mmc->priv = regs;
 	mmc->send_cmd = mci_send_cmd;
 	mmc->set_ios = mci_set_ios;
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 80cd9bf..b7bd2f9 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -77,33 +77,13 @@ struct mmc *find_mmc_device(int dev_num)
 	return NULL;
 }
 
-static ulong
-mmc_bwrite(int dev_num, ulong start, lbaint_t blkcnt, const void*src)
+int mmc_write_block(struct mmc *mmc, ulong *src, ulong start, uint blkcnt)
 {
 	struct mmc_cmd cmd;
 	struct mmc_data data;
-	int err;
-	int stoperr = 0;
-	struct mmc *mmc = find_mmc_device(dev_num);
-	int blklen;
-
-	if (!mmc)
-		return -1;
+	int blklen, err;
 
 	blklen = mmc->write_bl_len;
-
-	if ((start + blkcnt) > mmc->block_dev.lba) {
-		printf("MMC: block number 0x%lx exceeds max(0x%lx)",
-			start + blkcnt, mmc->block_dev.lba);
-		return 0;
-	}
-	err = mmc_set_blocklen(mmc, mmc->write_bl_len);
-
-	if (err) {
-		printf("set write bl len failed\n\r");
-		return err;
-	}
-
 	if (blkcnt > 1)
 		cmd.cmdidx = MMC_CMD_WRITE_MULTIPLE_BLOCK;
 	else
@@ -134,12 +114,48 @@ mmc_bwrite(int dev_num, ulong start, lbaint_t blkcnt, const void*src)
 		cmd.cmdarg = 0;
 		cmd.resp_type = MMC_RSP_R1b;
 		cmd.flags = 0;
-		stoperr = mmc_send_cmd(mmc, &cmd, NULL);
+		mmc_send_cmd(mmc, &cmd, NULL);
 	}
 
 	return blkcnt;
 }
 
+static ulong
+mmc_bwrite(int dev_num, ulong start, lbaint_t blkcnt, const void*src)
+{
+	int err;
+	struct mmc *mmc = find_mmc_device(dev_num);
+	unsigned int max;
+	lbaint_t tmp = blkcnt, cur;
+
+	if (!mmc)
+		return -1;
+
+	if ((start + blkcnt ) > mmc->block_dev.lba) {
+		printf("MMC: block number 0x%lx exceeds max(0x%lx)",
+			start + blkcnt, mmc->block_dev.lba);
+		return 0;
+	}
+	err = mmc_set_blocklen(mmc, mmc->write_bl_len);
+	if (err) {
+		printf("set write bl len failed\n\r");
+		return err;
+	}
+
+	max = ((mmc->host_maxdmalen / mmc->write_bl_len) > mmc->host_maxblk)
+	      ? mmc->host_maxblk :(mmc->host_maxdmalen / mmc->write_bl_len);
+	max = (!max) ? tmp : max;
+	do {
+		cur = (tmp > max) ? max : tmp;
+		if(mmc_write_block(mmc, src, start, cur) != cur)
+			return -1;
+		tmp -= cur;
+		start += cur;
+		src += cur * mmc->write_bl_len;
+	} while (tmp > 0);
+	return blkcnt;
+}
+
 int mmc_read_block(struct mmc *mmc, void *dst, uint blocknum)
 {
 	struct mmc_cmd cmd;
diff --git a/drivers/mmc/mxcmmc.c b/drivers/mmc/mxcmmc.c
index 5963953..76501ed 100644
--- a/drivers/mmc/mxcmmc.c
+++ b/drivers/mmc/mxcmmc.c
@@ -497,6 +497,7 @@ static int mxcmci_initialize(bd_t *bis)
 		return -ENOMEM;
 
 	sprintf(mmc->name, "MXC MCI");
+	mmc->host_maxblk = mmc->host_maxdmalen = 0;
 	mmc->send_cmd = mxcmci_request;
 	mmc->set_ios = mxcmci_set_ios;
 	mmc->init = mxcmci_init;
diff --git a/include/mmc.h b/include/mmc.h
index 9f94f42..ad28ad2 100644
--- a/include/mmc.h
+++ b/include/mmc.h
@@ -260,6 +260,8 @@ struct mmc {
 	uint clock;
 	uint card_caps;
 	uint host_caps;
+	uint host_maxblk;
+	uint host_maxdmalen;
 	uint ocr;
 	uint scr[2];
 	uint csd[4];
-- 
1.7.0.4



More information about the U-Boot mailing list