Commit 6be95ccf9ff52d629526d1c20c5343c2a91d9e72
Committed by
Andy Fleming
1 parent
83800959a8
Exists in
master
and in
54 other branches
MMC: unify mmc read and write operation
mmc read and write command has so many in common, unfiy those two to force consistency across the those two. Signed-off-by: Lei Wen <leiwen@marvell.com> Acked-by: Mike Frysinger <vapier@gentoo.org> Acked-by: Andy Fleming <afleming@freescale.com>
Showing 1 changed file with 35 additions and 32 deletions Side-by-side Diff
common/cmd_mmc.c
... | ... | @@ -87,6 +87,11 @@ |
87 | 87 | ); |
88 | 88 | #else /* !CONFIG_GENERIC_MMC */ |
89 | 89 | |
90 | +enum mmc_state { | |
91 | + MMC_INVALID, | |
92 | + MMC_READ, | |
93 | + MMC_WRITE, | |
94 | +}; | |
90 | 95 | static void print_mmcinfo(struct mmc *mmc) |
91 | 96 | { |
92 | 97 | printf("Device: %s\n", mmc->name); |
... | ... | @@ -144,6 +149,8 @@ |
144 | 149 | |
145 | 150 | int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
146 | 151 | { |
152 | + enum mmc_state state; | |
153 | + | |
147 | 154 | if (argc < 2) |
148 | 155 | return cmd_usage(cmdtp); |
149 | 156 | |
150 | 157 | |
151 | 158 | |
152 | 159 | |
153 | 160 | |
154 | 161 | |
155 | 162 | |
156 | 163 | |
157 | 164 | |
... | ... | @@ -239,53 +246,49 @@ |
239 | 246 | curr_device, mmc->part_num); |
240 | 247 | |
241 | 248 | return 0; |
242 | - } else if (strcmp(argv[1], "read") == 0) { | |
243 | - void *addr = (void *)simple_strtoul(argv[2], NULL, 16); | |
244 | - u32 cnt = simple_strtoul(argv[4], NULL, 16); | |
245 | - u32 n; | |
246 | - u32 blk = simple_strtoul(argv[3], NULL, 16); | |
247 | - struct mmc *mmc = find_mmc_device(curr_device); | |
249 | + } | |
248 | 250 | |
249 | - if (!mmc) { | |
250 | - printf("no mmc device at slot %x\n", curr_device); | |
251 | - return 1; | |
252 | - } | |
251 | + if (strcmp(argv[1], "read") == 0) | |
252 | + state = MMC_READ; | |
253 | + else if (strcmp(argv[1], "write") == 0) | |
254 | + state = MMC_WRITE; | |
255 | + else | |
256 | + state = MMC_INVALID; | |
253 | 257 | |
254 | - printf("\nMMC read: dev # %d, block # %d, count %d ... ", | |
255 | - curr_device, blk, cnt); | |
256 | - | |
257 | - mmc_init(mmc); | |
258 | - | |
259 | - n = mmc->block_dev.block_read(curr_device, blk, cnt, addr); | |
260 | - | |
261 | - /* flush cache after read */ | |
262 | - flush_cache((ulong)addr, cnt * 512); /* FIXME */ | |
263 | - | |
264 | - printf("%d blocks read: %s\n", | |
265 | - n, (n==cnt) ? "OK" : "ERROR"); | |
266 | - return (n == cnt) ? 0 : 1; | |
267 | - } else if (strcmp(argv[1], "write") == 0) { | |
258 | + if (state != MMC_INVALID) { | |
259 | + struct mmc *mmc = find_mmc_device(curr_device); | |
268 | 260 | void *addr = (void *)simple_strtoul(argv[2], NULL, 16); |
261 | + u32 blk = simple_strtoul(argv[3], NULL, 16); | |
269 | 262 | u32 cnt = simple_strtoul(argv[4], NULL, 16); |
270 | 263 | u32 n; |
271 | - struct mmc *mmc = find_mmc_device(curr_device); | |
272 | 264 | |
273 | - int blk = simple_strtoul(argv[3], NULL, 16); | |
274 | - | |
275 | 265 | if (!mmc) { |
276 | 266 | printf("no mmc device at slot %x\n", curr_device); |
277 | 267 | return 1; |
278 | 268 | } |
279 | 269 | |
280 | - printf("\nMMC write: dev # %d, block # %d, count %d ... ", | |
281 | - curr_device, blk, cnt); | |
270 | + printf("\nMMC %s: dev # %d, block # %d, count %d ... ", | |
271 | + argv[1], curr_device, blk, cnt); | |
282 | 272 | |
283 | 273 | mmc_init(mmc); |
284 | 274 | |
285 | - n = mmc->block_dev.block_write(curr_device, blk, cnt, addr); | |
275 | + switch (state) { | |
276 | + case MMC_READ: | |
277 | + n = mmc->block_dev.block_read(curr_device, blk, | |
278 | + cnt, addr); | |
279 | + /* flush cache after read */ | |
280 | + flush_cache((ulong)addr, cnt * 512); /* FIXME */ | |
281 | + break; | |
282 | + case MMC_WRITE: | |
283 | + n = mmc->block_dev.block_write(curr_device, blk, | |
284 | + cnt, addr); | |
285 | + break; | |
286 | + default: | |
287 | + BUG(); | |
288 | + } | |
286 | 289 | |
287 | - printf("%d blocks written: %s\n", | |
288 | - n, (n == cnt) ? "OK" : "ERROR"); | |
290 | + printf("%d blocks %s: %s\n", | |
291 | + n, argv[1], (n == cnt) ? "OK" : "ERROR"); | |
289 | 292 | return (n == cnt) ? 0 : 1; |
290 | 293 | } |
291 | 294 |