* [PATCHv2] mmc-utils: Add CMD0 softreset and preidle command
@ 2022-10-18 10:44 Christian Löhle
2022-10-18 10:50 ` Avri Altman
0 siblings, 1 reply; 2+ messages in thread
From: Christian Löhle @ 2022-10-18 10:44 UTC (permalink / raw)
To: Avri Altman, Ulf Hansson, Linux MMC List
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>
---
-v2: Use macro for cmd0 argument
Note: A previous version has been discussed as
mmc-utils: Add softreset command for issuing CMD0
but with the addition of preidle I considered this to be
a different patch
mmc.c | 10 ++++++++++
mmc.h | 5 +++++
mmc_cmds.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
mmc_cmds.h | 2 ++
4 files changed, 68 insertions(+)
diff --git a/mmc.c b/mmc.c
index 6c56387..50493f3 100644
--- a/mmc.c
+++ b/mmc.c
@@ -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 }
};
diff --git a/mmc.h b/mmc.h
index daff62c..6511dbc 100644
--- a/mmc.h
+++ b/mmc.h
@@ -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 */
diff --git a/mmc_cmds.c b/mmc_cmds.c
index 2957aa9..94e30e0 100644
--- a/mmc_cmds.c
+++ b/mmc_cmds.c
@@ -3044,3 +3044,54 @@ out:
close(dev_fd);
return ret;
}
+
+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;
+}
diff --git a/mmc_cmds.h b/mmc_cmds.h
index 0f7c004..faab362 100644
--- a/mmc_cmds.h
+++ b/mmc_cmds.h
@@ -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);
--
2.37.3
Hyperstone GmbH | Reichenaustr. 39a | 78467 Konstanz
Managing Director: Dr. Jan Peter Berns.
Commercial register of local courts: Freiburg HRB381782
^ permalink raw reply related [flat|nested] 2+ messages in thread
* RE: [PATCHv2] mmc-utils: Add CMD0 softreset and preidle command
2022-10-18 10:44 [PATCHv2] mmc-utils: Add CMD0 softreset and preidle command Christian Löhle
@ 2022-10-18 10:50 ` Avri Altman
0 siblings, 0 replies; 2+ messages in thread
From: Avri Altman @ 2022-10-18 10:50 UTC (permalink / raw)
To: Christian Löhle, Ulf Hansson, Linux MMC List
> 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>
> ---
> -v2: Use macro for cmd0 argument
> Note: A previous version has been discussed as
> mmc-utils: Add softreset command for issuing CMD0
> but with the addition of preidle I considered this to be
> a different patch
> mmc.c | 10 ++++++++++
> mmc.h | 5 +++++
> mmc_cmds.c | 51
> +++++++++++++++++++++++++++++++++++++++++++++++++++
> mmc_cmds.h | 2 ++
> 4 files changed, 68 insertions(+)
>
> diff --git a/mmc.c b/mmc.c
> index 6c56387..50493f3 100644
> --- a/mmc.c
> +++ b/mmc.c
> @@ -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 }
> };
>
> diff --git a/mmc.h b/mmc.h
> index daff62c..6511dbc 100644
> --- a/mmc.h
> +++ b/mmc.h
> @@ -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 */
> diff --git a/mmc_cmds.c b/mmc_cmds.c
> index 2957aa9..94e30e0 100644
> --- a/mmc_cmds.c
> +++ b/mmc_cmds.c
> @@ -3044,3 +3044,54 @@ out:
> close(dev_fd);
> return ret;
> }
> +
> +void issue_cmd0(char *device, __u32 arg)
Static ?
Thanks,
Avri
> +{
> + 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;
> +}
> diff --git a/mmc_cmds.h b/mmc_cmds.h
> index 0f7c004..faab362 100644
> --- a/mmc_cmds.h
> +++ b/mmc_cmds.h
> @@ -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);
> --
> 2.37.3
>
> Hyperstone GmbH | Reichenaustr. 39a | 78467 Konstanz
> Managing Director: Dr. Jan Peter Berns.
> Commercial register of local courts: Freiburg HRB381782
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-10-18 10:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-18 10:44 [PATCHv2] mmc-utils: Add CMD0 softreset and preidle command Christian Löhle
2022-10-18 10:50 ` Avri Altman
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.