From 27c357db04350b75b0fceaae8bfb9ce99c50866b Mon Sep 17 00:00:00 2001 From: Ben Gardiner Date: Thu, 30 May 2013 17:12:47 -0400 Subject: [PATCH] Support SEND_STATUS command mmc status get Signed-off-by: Ben Gardiner Signed-off-by: Chris Ball --- mmc.c | 5 +++++ mmc.h | 2 ++ mmc_cmds.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ mmc_cmds.h | 1 + 4 files changed, 55 insertions(+) diff --git a/mmc.c b/mmc.c index a757c8f..dcbab18 100644 --- a/mmc.c +++ b/mmc.c @@ -70,6 +70,11 @@ static struct Command commands[] = { "Set the eMMC data sector size to 4KB by disabling emulation on\n.", NULL }, + { do_status_get, -1, + "status get", "\n" + "Print the response to STATUS_SEND (CMD13).", + NULL + }, { do_write_boot_en, -3, "bootpart enable", " " " " "\n" "Enable the boot partition for the .\nTo receive acknowledgment of boot from the card set \nto 1, else set it to 0.", diff --git a/mmc.h b/mmc.h index b9869e5..c6fcc83 100644 --- a/mmc.h +++ b/mmc.h @@ -26,6 +26,8 @@ /* From kernel linux/mmc/mmc.h */ #define MMC_SWITCH 6 /* ac [31:0] See below R1b */ #define MMC_SEND_EXT_CSD 8 /* adtc R1 */ +#define MMC_SEND_STATUS 13 /* ac [31:16] RCA R1 */ +#define R1_SWITCH_ERROR (1 << 7) /* sx, c */ #define MMC_SWITCH_MODE_WRITE_BYTE 0x03 /* Set target to value */ /* diff --git a/mmc_cmds.c b/mmc_cmds.c index 84f9c4c..6dfbfee 100644 --- a/mmc_cmds.c +++ b/mmc_cmds.c @@ -72,6 +72,25 @@ int write_extcsd_value(int fd, __u8 index, __u8 value) return ret; } +int send_status(int fd, __u32 *response) +{ + int ret = 0; + struct mmc_ioc_cmd idata; + + memset(&idata, 0, sizeof(idata)); + idata.opcode = MMC_SEND_STATUS; + idata.arg = (1 << 16); + idata.flags = MMC_RSP_R1 | MMC_CMD_AC; + + ret = ioctl(fd, MMC_IOC_CMD, &idata); + if (ret) + perror("ioctl"); + + *response = idata.response[0]; + + return ret; +} + void print_writeprotect_status(__u8 *ext_csd) { __u8 reg; @@ -377,6 +396,34 @@ int do_write_bkops_en(int nargs, char **argv) return ret; } +int do_status_get(int nargs, char **argv) +{ + __u32 response; + int fd, ret; + char *device; + + CHECK(nargs != 2, "Usage: mmc status get \n", + exit(1)); + + device = argv[1]; + + fd = open(device, O_RDWR); + if (fd < 0) { + perror("open"); + exit(1); + } + + ret = send_status(fd, &response); + if (ret) { + fprintf(stderr, "Could not read response to SEND_STATUS from %s\n", device); + exit(1); + } + + printf("SEND_STATUS response: 0x%08x\n", response); + + return ret; +} + int do_read_extcsd(int nargs, char **argv) { __u8 ext_csd[512], ext_csd_rev, reg; diff --git a/mmc_cmds.h b/mmc_cmds.h index ec22eee..4fb01c8 100644 --- a/mmc_cmds.h +++ b/mmc_cmds.h @@ -25,3 +25,4 @@ int do_write_bkops_en(int nargs, char **argv); int do_hwreset_en(int nargs, char **argv); int do_hwreset_dis(int nargs, char **argv); int do_sanitize(int nargs, char **argv); +int do_status_get(int nargs, char **argv);