summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Ball <cjb@laptop.org>2012-10-19 16:49:55 -0400
committerChris Ball <cjb@laptop.org>2012-10-19 17:28:08 -0400
commitf74dfe23cd00894aa9f235374468e05acb793e17 (patch)
treeb949ad457fb17ee67650da0364a32a24997bb9eb
parentbf4ae7d4e936ac70eab71ee7fc85b01b4ecf8786 (diff)
downloadmmc-utils-f74dfe23cd00894aa9f235374468e05acb793e17.tar.gz
Support enable/disable of eMMC H/W Reset function
(Note: one-time programmable fuse.) $ mmc hwreset enable /dev/mmcblk0 $ mmc hwreset disable /dev/mmcblk0
-rw-r--r--mmc.c10
-rw-r--r--mmc.h4
-rw-r--r--mmc_cmds.c59
-rw-r--r--mmc_cmds.h2
4 files changed, 75 insertions, 0 deletions
diff --git a/mmc.c b/mmc.c
index 56f621c..a2de863 100644
--- a/mmc.c
+++ b/mmc.c
@@ -80,6 +80,16 @@ static struct Command commands[] = {
"Enable the eMMC BKOPS feature on <device>.\nNOTE! This is a one-time programmable (unreversible) change.",
NULL
},
+ { do_hwreset_en, -1,
+ "hwreset enable", "<device>\n"
+ "Permanently enable the eMMC H/W Reset feature on <device>.\nNOTE! This is a one-time programmable (unreversible) change.",
+ NULL
+ },
+ { do_hwreset_dis, -1,
+ "hwreset disable", "<device>\n"
+ "Permanently disable the eMMC H/W Reset feature on <device>.\nNOTE! This is a one-time programmable (unreversible) change.",
+ NULL
+ },
{ 0, 0, 0, 0 }
};
diff --git a/mmc.h b/mmc.h
index 3d77b38..c863751 100644
--- a/mmc.h
+++ b/mmc.h
@@ -39,6 +39,7 @@
#define EXT_CSD_BOOT_WP 173
#define EXT_CSD_WR_REL_PARAM 166
#define EXT_CSD_BKOPS_EN 163 /* R/W */
+#define EXT_CSD_RST_N_FUNCTION 162 /* R/W */
#define EXT_CSD_NATIVE_SECTOR_SIZE 63 /* R */
#define EXT_CSD_USE_NATIVE_SECTOR 62 /* R/W */
#define EXT_CSD_DATA_SECTOR_SIZE 61 /* R */
@@ -70,6 +71,9 @@
#define EXT_CSD_BOOT_CFG_ACK (1<<6)
#define EXT_CSD_BOOT_CFG_EN (0x38)
#define EXT_CSD_BOOT_CFG_ACC (0x03)
+#define EXT_CSD_RST_N_EN_MASK (0x03)
+#define EXT_CSD_HW_RESET_EN (0x01)
+#define EXT_CSD_HW_RESET_DIS (0x02)
#define EXT_CSD_PART_CONFIG_ACC_MASK (0x7)
#define EXT_CSD_PART_CONFIG_ACC_BOOT0 (0x1)
#define EXT_CSD_PART_CONFIG_ACC_BOOT1 (0x2)
diff --git a/mmc_cmds.c b/mmc_cmds.c
index 05d7e13..b407f65 100644
--- a/mmc_cmds.c
+++ b/mmc_cmds.c
@@ -280,6 +280,65 @@ int do_write_boot_en(int nargs, char **argv)
return ret;
}
+int do_hwreset(int value, int nargs, char **argv)
+{
+ __u8 ext_csd[512];
+ int fd, ret;
+ char *device;
+
+ CHECK(nargs != 2, "Usage: mmc hwreset enable </path/to/mmcblkX>\n",
+ exit(1));
+
+ device = argv[1];
+
+ fd = open(device, O_RDWR);
+ if (fd < 0) {
+ perror("open");
+ exit(1);
+ }
+
+ ret = read_extcsd(fd, ext_csd);
+ if (ret) {
+ fprintf(stderr, "Could not read EXT_CSD from %s\n", device);
+ exit(1);
+ }
+
+ if ((ext_csd[EXT_CSD_RST_N_FUNCTION] & EXT_CSD_RST_N_EN_MASK) ==
+ EXT_CSD_HW_RESET_EN) {
+ fprintf(stderr,
+ "H/W Reset is already permanently enabled on %s\n",
+ device);
+ exit(1);
+ }
+ if ((ext_csd[EXT_CSD_RST_N_FUNCTION] & EXT_CSD_RST_N_EN_MASK) ==
+ EXT_CSD_HW_RESET_DIS) {
+ fprintf(stderr,
+ "H/W Reset is already permanently disabled on %s\n",
+ device);
+ exit(1);
+ }
+
+ ret = write_extcsd_value(fd, EXT_CSD_RST_N_FUNCTION, value);
+ if (ret) {
+ fprintf(stderr,
+ "Could not write 0x%02x to EXT_CSD[%d] in %s\n",
+ value, EXT_CSD_RST_N_FUNCTION, device);
+ exit(1);
+ }
+
+ return ret;
+}
+
+int do_hwreset_en(int nargs, char **argv)
+{
+ return do_hwreset(EXT_CSD_HW_RESET_EN, nargs, argv);
+}
+
+int do_hwreset_dis(int nargs, char **argv)
+{
+ return do_hwreset(EXT_CSD_HW_RESET_DIS, nargs, argv);
+}
+
int do_write_bkops_en(int nargs, char **argv)
{
__u8 ext_csd[512], value = 0;
diff --git a/mmc_cmds.h b/mmc_cmds.h
index 1dd4324..e52d622 100644
--- a/mmc_cmds.h
+++ b/mmc_cmds.h
@@ -22,3 +22,5 @@ int do_writeprotect_set(int nargs, char **argv);
int do_disable_512B_emulation(int nargs, char **argv);
int do_write_boot_en(int nargs, char **argv);
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);