[U-Boot] [PATCH 1/2] mmc: New abstract function (do_mmcops_safe) for MMC subsystem

Lukasz Majewski l.majewski at samsung.com
Fri Jul 27 10:35:15 CEST 2012


The new do_mmcops_safe function has been added to the mmc subsystem.
It is necessary to decouple the core mmc read/write operation from
code responsible for parsing user input.

The do_mmcops_safe function shall be used from other subsystems to
read/write data to MMC devices.

Signed-off-by: Lukasz Majewski <l.majewski at samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park at samsung.com>
Cc: Andy Fleming <afleming at gmail.com>
---
 common/cmd_mmc.c |   69 +++++++++++++++++++++++++++++-------------------------
 include/mmc.h    |    9 +++++++
 2 files changed, 46 insertions(+), 32 deletions(-)

diff --git a/common/cmd_mmc.c b/common/cmd_mmc.c
index 750509d..60e6873 100644
--- a/common/cmd_mmc.c
+++ b/common/cmd_mmc.c
@@ -87,12 +87,6 @@ U_BOOT_CMD(
 );
 #else /* !CONFIG_GENERIC_MMC */
 
-enum mmc_state {
-	MMC_INVALID,
-	MMC_READ,
-	MMC_WRITE,
-	MMC_ERASE,
-};
 static void print_mmcinfo(struct mmc *mmc)
 {
 	printf("Device: %s\n", mmc->name);
@@ -148,7 +142,42 @@ U_BOOT_CMD(
 	""
 );
 
-int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+u32 do_mmcops_safe(enum mmc_state state, int curr_device, u32 blk,
+		   u32 cnt, void *addr)
+{
+	struct mmc *mmc = find_mmc_device(curr_device);
+	u32 n = 0;
+
+	if (!mmc) {
+		printf("no mmc device at slot %x\n", curr_device);
+		return 1;
+	}
+
+	mmc_init(mmc);
+
+	switch (state) {
+	case MMC_READ:
+		n = mmc->block_dev.block_read(curr_device, blk,
+					      cnt, addr);
+		/* flush cache after read */
+		flush_cache((ulong)addr, cnt * 512); /* FIXME */
+		break;
+	case MMC_WRITE:
+		n = mmc->block_dev.block_write(curr_device, blk,
+					       cnt, addr);
+		break;
+	case MMC_ERASE:
+		n = mmc->block_dev.block_erase(curr_device, blk, cnt);
+		break;
+	default:
+		BUG();
+	}
+
+	return n;
+}
+
+int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc,
+		       char * const argv[])
 {
 	enum mmc_state state;
 
@@ -261,7 +290,6 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		state = MMC_INVALID;
 
 	if (state != MMC_INVALID) {
-		struct mmc *mmc = find_mmc_device(curr_device);
 		int idx = 2;
 		u32 blk, cnt, n;
 		void *addr;
@@ -274,33 +302,10 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		blk = simple_strtoul(argv[idx], NULL, 16);
 		cnt = simple_strtoul(argv[idx + 1], NULL, 16);
 
-		if (!mmc) {
-			printf("no mmc device at slot %x\n", curr_device);
-			return 1;
-		}
-
 		printf("\nMMC %s: dev # %d, block # %d, count %d ... ",
 				argv[1], curr_device, blk, cnt);
 
-		mmc_init(mmc);
-
-		switch (state) {
-		case MMC_READ:
-			n = mmc->block_dev.block_read(curr_device, blk,
-						      cnt, addr);
-			/* flush cache after read */
-			flush_cache((ulong)addr, cnt * 512); /* FIXME */
-			break;
-		case MMC_WRITE:
-			n = mmc->block_dev.block_write(curr_device, blk,
-						      cnt, addr);
-			break;
-		case MMC_ERASE:
-			n = mmc->block_dev.block_erase(curr_device, blk, cnt);
-			break;
-		default:
-			BUG();
-		}
+		n = do_mmcops_safe(state, curr_device, blk, cnt, addr);
 
 		printf("%d blocks %s: %s\n",
 				n, argv[1], (n == cnt) ? "OK" : "ERROR");
diff --git a/include/mmc.h b/include/mmc.h
index 2305986..5686e1b 100644
--- a/include/mmc.h
+++ b/include/mmc.h
@@ -199,6 +199,13 @@
 #define PART_ACCESS_MASK	(0x7)
 #define PART_SUPPORT		(0x1)
 
+enum mmc_state {
+	MMC_INVALID,
+	MMC_READ,
+	MMC_WRITE,
+	MMC_ERASE,
+};
+
 struct mmc_cid {
 	unsigned long psn;
 	unsigned short oid;
@@ -274,6 +281,8 @@ int board_mmc_getcd(struct mmc *mmc);
 int mmc_switch_part(int dev_num, unsigned int part_num);
 int mmc_getcd(struct mmc *mmc);
 
+u32 do_mmcops_safe(enum mmc_state state, int curr_device, u32 blk,
+		   u32 cnt, void *addr);
 #ifdef CONFIG_GENERIC_MMC
 #define mmc_host_is_spi(mmc)	((mmc)->host_caps & MMC_MODE_SPI)
 struct mmc *mmc_spi_init(uint bus, uint cs, uint speed, uint mode);
-- 
1.7.2.3



More information about the U-Boot mailing list