diff options
author | Christian Löhle <CLoehle@hyperstone.com> | 2022-10-18 11:58:06 +0000 |
---|---|---|
committer | Ulf Hansson <ulf.hansson@linaro.org> | 2022-10-24 19:00:07 +0200 |
commit | 4a32d090dcf6fec6ef0948e59094c4de406906cd (patch) | |
tree | 06b3d397534b8b78cf57396e20d76d2776d76573 | |
parent | 34577b2378d6b931fec71e7a8422ee7f4e26173c (diff) | |
download | mmc-utils-4a32d090dcf6fec6ef0948e59094c4de406906cd.tar.gz |
mmc-utils: Add CMD0 softreset and preidle command
CMD0 may be used to see if the hardware can handle a UHS card
that completed the voltage switch. If a UHS card has problems
coming back up after CMD0 your hardware may not support a hard
reset properly.
Signed-off-by: Christian Loehle <cloehle@hyperstone.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/0657285aa7c64cbe89f9275fd5598345@hyperstone.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
-rw-r--r-- | mmc.c | 10 | ||||
-rw-r--r-- | mmc.h | 5 | ||||
-rw-r--r-- | mmc_cmds.c | 51 | ||||
-rw-r--r-- | mmc_cmds.h | 2 |
4 files changed, 68 insertions, 0 deletions
@@ -245,6 +245,16 @@ static struct Command commands[] = { "be 1.", NULL }, + { do_softreset, -1, + "softreset", "<device>\n" + "Issues a CMD0 softreset, e.g. for testing if hardware reset for UHS works", + NULL + }, + { do_preidle, -1, + "preidle", "<device>\n" + "Issues a CMD0 GO_PRE_IDLE", + NULL + }, { 0, 0, 0, 0 } }; @@ -21,6 +21,9 @@ #include <linux/mmc/ioctl.h> /* From kernel linux/mmc/mmc.h */ +#define MMC_GO_IDLE_STATE 0 /* bc */ +#define MMC_GO_IDLE_STATE_ARG 0x0 +#define MMC_GO_PRE_IDLE_STATE_ARG 0xF0F0F0F0 #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 */ @@ -226,6 +229,7 @@ /* From kernel linux/mmc/core.h */ +#define MMC_RSP_NONE 0 /* no response */ #define MMC_RSP_PRESENT (1 << 0) #define MMC_RSP_136 (1 << 1) /* 136 bit response */ #define MMC_RSP_CRC (1 << 2) /* expect valid crc */ @@ -234,6 +238,7 @@ #define MMC_CMD_AC (0 << 5) #define MMC_CMD_ADTC (1 << 5) +#define MMC_CMD_BC (2 << 5) #define MMC_RSP_SPI_S1 (1 << 7) /* one status byte */ #define MMC_RSP_SPI_BUSY (1 << 10) /* card may send busy */ @@ -3050,3 +3050,54 @@ out: close(dev_fd); return ret; } + +static void issue_cmd0(char *device, __u32 arg) +{ + struct mmc_ioc_cmd idata; + int fd; + + fd = open(device, O_RDWR); + if (fd < 0) { + perror("open"); + exit(1); + } + + memset(&idata, 0, sizeof(idata)); + idata.opcode = MMC_GO_IDLE_STATE; + idata.arg = arg; + idata.flags = MMC_RSP_NONE | MMC_CMD_BC; + + /* No need to check for error, it is expected */ + ioctl(fd, MMC_IOC_CMD, &idata); + close(fd); +} + +int do_softreset(int nargs, char **argv) +{ + char *device; + + if (nargs != 2) { + fprintf(stderr, "Usage: mmc softreset </path/to/mmcblkX>\n"); + exit(1); + } + + device = argv[1]; + issue_cmd0(device, MMC_GO_IDLE_STATE_ARG); + + return 0; +} + +int do_preidle(int nargs, char **argv) +{ + char *device; + + if (nargs != 2) { + fprintf(stderr, "Usage: mmc preidle </path/to/mmcblkX>\n"); + exit(1); + } + + device = argv[1]; + issue_cmd0(device, MMC_GO_PRE_IDLE_STATE_ARG); + + return 0; +} @@ -47,3 +47,5 @@ int do_read_cid(int argc, char **argv); int do_read_csd(int argc, char **argv); int do_erase(int nargs, char **argv); int do_general_cmd_read(int nargs, char **argv); +int do_softreset(int nargs, char **argv); +int do_preidle(int nargs, char **argv); |