All of lore.kernel.org
 help / color / mirror / Atom feed
From: George McCollister <george.mccollister@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/5] sf: Add status register protect for STMICRO, SST
Date: Mon, 10 Oct 2016 13:57:58 -0500	[thread overview]
Message-ID: <20161010185801.27991-3-george.mccollister@gmail.com> (raw)
In-Reply-To: <20161010185801.27991-1-george.mccollister@gmail.com>

STMICRO parts such as M25PX64 and SST parts such as SST26VF032B support
a single status register protect bit. When set this bit cause writes to
the status register to be blocked when the write protect signal is low.

Implement sr_protect for these devices.

Signed-off-by: George McCollister <george.mccollister@gmail.com>
---
 drivers/mtd/spi/sf_internal.h |  1 +
 drivers/mtd/spi/spi_flash.c   | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h
index cde4cfb..1b576e8 100644
--- a/drivers/mtd/spi/sf_internal.h
+++ b/drivers/mtd/spi/sf_internal.h
@@ -81,6 +81,7 @@ enum spi_nor_option_flags {
 #define SR_BP0				BIT(2)  /* Block protect 0 */
 #define SR_BP1				BIT(3)  /* Block protect 1 */
 #define SR_BP2				BIT(4)  /* Block protect 2 */
+#define SR_SRP0				BIT(7)	/* Status register protect 0 */
 
 /* Flash timeout values */
 #define SPI_FLASH_PROG_TIMEOUT		(2 * CONFIG_SYS_HZ)
diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c
index 7f6e9ae..0e33901 100644
--- a/drivers/mtd/spi/spi_flash.c
+++ b/drivers/mtd/spi/spi_flash.c
@@ -837,6 +837,40 @@ int stm_unlock(struct spi_flash *flash, u32 ofs, size_t len)
 
 	return 0;
 }
+
+/*
+ * Set status register protection method for parts with one protection bit
+ *
+ * Returns negative on errors, 0 on success.
+ */
+int stm_sr_protect(struct spi_flash *flash, enum srp_method method)
+{
+	uint8_t status_old, status_new;
+	u8 mask = SR_SRP0;
+	u8 val;
+	int ret;
+
+	ret = read_sr(flash, &status_old);
+	if (ret < 0)
+		return ret;
+
+	switch (method) {
+	case SRP_SOFTWARE:
+		val = 0;
+		break;
+	case SRP_HARDWARE:
+		val = SR_SRP0;
+		break;
+	default:
+		return -EOPNOTSUPP;
+	}
+
+	status_new = (status_old & ~mask) | val;
+
+	write_sr(flash, status_new);
+
+	return 0;
+}
 #endif
 
 
@@ -1125,6 +1159,7 @@ int spi_flash_scan(struct spi_flash *flash)
 		flash->flash_lock = stm_lock;
 		flash->flash_unlock = stm_unlock;
 		flash->flash_is_locked = stm_is_locked;
+		flash->sr_protect = stm_sr_protect;
 #endif
 		break;
 	default:
-- 
2.9.3

  parent reply	other threads:[~2016-10-10 18:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-10 18:57 [U-Boot] [PATCH 0/5] sf: Add support for status register protect George McCollister
2016-10-10 18:57 ` [U-Boot] [PATCH 1/5] sf: Add status register protection mechanism George McCollister
2016-10-11  2:05   ` Bin Meng
2016-10-10 18:57 ` George McCollister [this message]
2016-10-11  2:05   ` [U-Boot] [PATCH 2/5] sf: Add status register protect for STMICRO, SST Bin Meng
2016-10-10 18:57 ` [U-Boot] [PATCH 3/5] sf: Use stm_lock/unlock for Spansion and Winbond George McCollister
2016-10-11  2:05   ` Bin Meng
2016-10-10 18:58 ` [U-Boot] [PATCH 4/5] sf: Add status register protect for Winbond George McCollister
2016-10-11  2:05   ` Bin Meng
2016-10-10 18:58 ` [U-Boot] [PATCH 5/5] sf: Add sr-protect sub-command George McCollister
2016-10-11  2:05   ` Bin Meng
2016-10-28 17:06 ` [U-Boot] [PATCH 0/5] sf: Add support for status register protect George McCollister
2016-10-28 17:24   ` Jagan Teki

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=20161010185801.27991-3-george.mccollister@gmail.com \
    --to=george.mccollister@gmail.com \
    --cc=u-boot@lists.denx.de \
    /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 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.