linux-mmc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ben Gardiner <ben.l.gardiner@gmail.com>
To: cjb@laptop.org
Cc: linux-mmc@vger.kernel.org
Subject: [PATCH 3/3] support setting the OTP write reliability settings
Date: Thu, 19 Sep 2013 11:14:29 -0400	[thread overview]
Message-ID: <06c38eb8dcbf25bee62d50a6a9b9162c734ce7ad.1379602866.git.ben.l.gardiner@gmail.com> (raw)
In-Reply-To: <cover.1379602866.git.ben.l.gardiner@gmail.com>
In-Reply-To: <cover.1379602866.git.ben.l.gardiner@gmail.com>

Signed-off-by: Ben Gardiner <ben.l.gardiner@gmail.com>
---
 mmc.c      |  5 +++++
 mmc_cmds.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 mmc_cmds.h |  1 +
 3 files changed, 68 insertions(+)

diff --git a/mmc.c b/mmc.c
index 725b842..926e92f 100644
--- a/mmc.c
+++ b/mmc.c
@@ -75,6 +75,11 @@ static struct Command commands[] = {
 		"Enable the enhanced user area for the <device>.\nDry-run only unless -y is passed.\nNOTE!  This is a one-time programmable (unreversible) change.",
 	  NULL
 	},
+	{ do_write_reliability_set, -2,
+	  "write_reliability set", "<-y|-n> " "<partition> " "<device>\n"
+		"Enable write reliability per partition for the <device>.\nDry-run only unless -y is passed.\nNOTE!  This is a one-time programmable (unreversible) change.",
+	  NULL
+	},
 	{ do_status_get, -1,
 	  "status get", "<device>\n"
 	  "Print the response to STATUS_SEND (CMD13).",
diff --git a/mmc_cmds.c b/mmc_cmds.c
index 7874b23..079f322 100644
--- a/mmc_cmds.c
+++ b/mmc_cmds.c
@@ -632,6 +632,68 @@ int do_enh_area_set(int nargs, char **argv)
 	return 0;
 }
 
+int do_write_reliability_set(int nargs, char **argv)
+{
+	__u8 value;
+	__u8 ext_csd[512];
+	int fd, ret;
+
+	int dry_run = 1;
+	int partition;
+	char *device;
+
+	CHECK(nargs != 4, "Usage: mmc write_reliability set <-y|-n> "
+			"<partition> </path/to/mmcblkX>\n", exit(1));
+
+	if (!strcmp("-y", argv[1]))
+		dry_run = 0;
+
+	partition = strtol(argv[2], NULL, 10);
+	device = argv[3];
+
+	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);
+	}
+
+	/* assert not PARTITION_SETTING_COMPLETED */
+	if (ext_csd[EXT_CSD_PARTITION_SETTING_COMPLETED])
+	{
+		printf(" Device is already partitioned\n");
+		exit(1);
+	}
+
+	/* assert HS_CTRL_REL */
+	if (!(ext_csd[EXT_CSD_WR_REL_PARAM] & HS_CTRL_REL)) {
+		printf("Cannot set write reliability parameters, WR_REL_SET is "
+				"read-only\n");
+		exit(1);
+	}
+
+	value = ext_csd[EXT_CSD_WR_REL_SET] | (1<<partition);
+	ret = write_extcsd_value(fd, EXT_CSD_WR_REL_SET, value);
+	if (ret) {
+		fprintf(stderr, "Could not write 0x%02x to EXT_CSD[%d] in %s\n",
+				value, EXT_CSD_WR_REL_SET, device);
+		exit(1);
+	}
+
+	printf("Done setting EXT_CSD_WR_REL_SET to 0x%02x on %s\n",
+		value, device);
+
+	if (!set_partitioning_setting_completed(dry_run, device, fd))
+		exit(1);
+
+	return 0;
+}
+
 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 fa347f5..f06cc10 100644
--- a/mmc_cmds.h
+++ b/mmc_cmds.h
@@ -27,3 +27,4 @@ int do_hwreset_dis(int nargs, char **argv);
 int do_sanitize(int nargs, char **argv);
 int do_status_get(int nargs, char **argv);
 int do_enh_area_set(int nargs, char **argv);
+int do_write_reliability_set(int nargs, char **argv);
-- 
1.8.1.2


  parent reply	other threads:[~2013-09-19 15:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-19 15:14 [PATCH 0/3] Write-reliability settings support Ben Gardiner
2013-09-19 15:14 ` [PATCH 1/3] extract PARTITION_SETTING_COMPLETE function Ben Gardiner
2015-02-26 18:50   ` Andrew Dyer
2013-09-19 15:14 ` [PATCH 2/3] pretty print write reliability settings Ben Gardiner
2013-09-19 15:14 ` Ben Gardiner [this message]
2013-09-26  2:18 ` [PATCH 0/3] Write-reliability settings support Chris Ball

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=06c38eb8dcbf25bee62d50a6a9b9162c734ce7ad.1379602866.git.ben.l.gardiner@gmail.com \
    --to=ben.l.gardiner@gmail.com \
    --cc=cjb@laptop.org \
    --cc=linux-mmc@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).