Commit ad6890a2 authored by Lars Pedersen's avatar Lars Pedersen Committed by Ulf Hansson
Browse files

mmc-utils: Add AUTO_EN support in the BKOPS_EN



This patch adds support to enable auto(AUTO_EN) and
manual(MANUAL_EN) in BKOPS_EN register. Auto bkops
can only be used on eMMC 5.0 or newer.
Signed-off-by: default avatarLars Pedersen <lapeddk@gmail.com>
Reviewed-by: default avatarAvri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20191111110051.16490-1-lapeddk@gmail.com

Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
parent be4cac34
...@@ -131,9 +131,12 @@ static struct Command commands[] = { ...@@ -131,9 +131,12 @@ static struct Command commands[] = {
"<boot_bus_width> must be \"x1|x4|x8\"", "<boot_bus_width> must be \"x1|x4|x8\"",
NULL NULL
}, },
{ do_write_bkops_en, -1, { do_write_bkops_en, -2,
"bkops enable", "<device>\n" "bkops_en", "<auto|manual> <device>\n"
"Enable the eMMC BKOPS feature on <device>.\nNOTE! This is a one-time programmable (unreversible) change.", "Enable the eMMC BKOPS feature on <device>.\n"
"The auto (AUTO_EN) setting is only supported on eMMC 5.0 or newer.\n"
"Setting auto won't have any effect if manual is set.\n"
"NOTE! Setting manual (MANUAL_EN) is one-time programmable (unreversible) change.",
NULL NULL
}, },
{ do_hwreset_en, -1, { do_hwreset_en, -1,
......
...@@ -128,9 +128,10 @@ ...@@ -128,9 +128,10 @@
#define EN_REL_WR (1<<2) #define EN_REL_WR (1<<2)
/* /*
* BKOPS_EN field definition * BKOPS_EN field definitions
*/ */
#define BKOPS_ENABLE (1<<0) #define BKOPS_MAN_ENABLE (1<<0)
#define BKOPS_AUTO_ENABLE (1<<1)
/* /*
* EXT_CSD field definitions * EXT_CSD field definitions
......
...@@ -792,13 +792,15 @@ int do_write_bkops_en(int nargs, char **argv) ...@@ -792,13 +792,15 @@ int do_write_bkops_en(int nargs, char **argv)
__u8 ext_csd[512], value = 0; __u8 ext_csd[512], value = 0;
int fd, ret; int fd, ret;
char *device; char *device;
char *en_type;
if (nargs != 2) { if (nargs != 3) {
fprintf(stderr, "Usage: mmc bkops enable </path/to/mmcblkX>\n"); fprintf(stderr, "Usage: mmc bkops_en <auto|manual> </path/to/mmcblkX>\n");
exit(1); exit(1);
} }
device = argv[1]; en_type = argv[1];
device = argv[2];
fd = open(device, O_RDWR); fd = open(device, O_RDWR);
if (fd < 0) { if (fd < 0) {
...@@ -812,12 +814,19 @@ int do_write_bkops_en(int nargs, char **argv) ...@@ -812,12 +814,19 @@ int do_write_bkops_en(int nargs, char **argv)
exit(1); exit(1);
} }
if (!(ext_csd[EXT_CSD_BKOPS_SUPPORT] & 0x1)) { if (strcmp(en_type, "auto") == 0) {
fprintf(stderr, "%s doesn't support BKOPS\n", device); if (ext_csd[EXT_CSD_REV] < EXT_CSD_REV_V5_0) {
fprintf(stderr, "%s doesn't support AUTO_EN in the BKOPS_EN register\n", device);
exit(1);
}
ret = write_extcsd_value(fd, EXT_CSD_BKOPS_EN, BKOPS_AUTO_ENABLE);
} else if (strcmp(en_type, "manual") == 0) {
ret = write_extcsd_value(fd, EXT_CSD_BKOPS_EN, BKOPS_MAN_ENABLE);
} else {
fprintf(stderr, "%s invalid mode for BKOPS_EN requested: %s. Valid options: auto or manual\n", en_type, device);
exit(1); exit(1);
} }
ret = write_extcsd_value(fd, EXT_CSD_BKOPS_EN, BKOPS_ENABLE);
if (ret) { if (ret) {
fprintf(stderr, "Could not write 0x%02x to EXT_CSD[%d] in %s\n", fprintf(stderr, "Could not write 0x%02x to EXT_CSD[%d] in %s\n",
value, EXT_CSD_BKOPS_EN, device); value, EXT_CSD_BKOPS_EN, device);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment