public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Heiko Schocher <hs@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 5/6] spi: add config option to enable the WP pin function on st micron flashes
Date: Wed, 16 Jul 2014 10:51:35 +0200	[thread overview]
Message-ID: <1405500696-32597-6-git-send-email-hs@denx.de> (raw)
In-Reply-To: <1405500696-32597-1-git-send-email-hs@denx.de>

enable the W#/Vpp signal to disable writing to the status
register on ST MICRON flashes like the N25Q128 through
the new config option CONFIG_SYS_SPI_ST_ENABLE_WP_PIN

Signed-off-by: Heiko Schocher <hs@denx.de>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
---
 README                        | 11 +++++++++++
 drivers/mtd/spi/sf_internal.h |  4 ++++
 drivers/mtd/spi/sf_probe.c    | 30 ++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+)

diff --git a/README b/README
index 9f07831..63617ce 100644
--- a/README
+++ b/README
@@ -2937,6 +2937,17 @@ CBFS (Coreboot Filesystem) support
 		CONFIG_SPI_FLASH_MTD
 		add  MTD translation layer driver.
 
+		CONFIG_SYS_SPI_ST_ENABLE_WP_PIN
+		enable the W#/Vpp signal to disable writing to the status
+		register on ST MICRON flashes like the N25Q128.
+		The status register write enable/disable bit, combined with
+		the W#/VPP signal provides hardware data protection for the
+		device as follows: When the enable/disable bit is set to 1,
+		and the W#/VPP signal is driven LOW, the status register
+		nonvolatile bits become read-only and the WRITE STATUS REGISTER
+		operation will not execute. The only way to exit this
+		hardware-protected mode is to drive W#/VPP HIGH.
+
 - SystemACE Support:
 		CONFIG_SYSTEMACE
 
diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h
index c883d1d..4839d81 100644
--- a/drivers/mtd/spi/sf_internal.h
+++ b/drivers/mtd/spi/sf_internal.h
@@ -60,6 +60,10 @@
 #define STATUS_QEB_MXIC			(1 << 6)
 #define STATUS_PEC			(1 << 7)
 
+#ifdef CONFIG_SYS_SPI_ST_ENABLE_WP_PIN
+#define STATUS_SRWD			(1 << 7) /* SR write protect */
+#endif
+
 /* Flash timeout values */
 #define SPI_FLASH_PROG_TIMEOUT		(2 * CONFIG_SYS_HZ)
 #define SPI_FLASH_PAGE_ERASE_TIMEOUT	(5 * CONFIG_SYS_HZ)
diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
index f6d793b..6c50766 100644
--- a/drivers/mtd/spi/sf_probe.c
+++ b/drivers/mtd/spi/sf_probe.c
@@ -281,6 +281,34 @@ int spi_flash_decode_fdt(const void *blob, struct spi_flash *flash)
 }
 #endif /* CONFIG_OF_CONTROL */
 
+#ifdef CONFIG_SYS_SPI_ST_ENABLE_WP_PIN
+/* enable the W#/Vpp signal to disable writing to the status register */
+static int spi_enable_wp_pin(struct spi_flash *flash)
+{
+	u8 status;
+	int ret;
+
+	ret = spi_flash_cmd_read_status(flash, &status);
+	if (ret < 0)
+		return ret;
+
+	ret = spi_flash_cmd_write_status(flash, STATUS_SRWD);
+	if (ret < 0)
+		return ret;
+
+	ret = spi_flash_cmd_write_disable(flash);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+#else
+static int spi_enable_wp_pin(struct spi_flash *flash)
+{
+	return 0;
+}
+#endif
+
 static struct spi_flash *spi_flash_probe_slave(struct spi_slave *spi)
 {
 	struct spi_flash *flash = NULL;
@@ -351,6 +379,8 @@ static struct spi_flash *spi_flash_probe_slave(struct spi_slave *spi)
 		puts(" Full access #define CONFIG_SPI_FLASH_BAR\n");
 	}
 #endif
+	if (spi_enable_wp_pin(flash))
+		puts("Enable WP pin failed\n");
 
 	/* Release spi bus */
 	spi_release_bus(spi);
-- 
1.8.3.1

  parent reply	other threads:[~2014-07-16  8:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-16  8:51 [U-Boot] [PATCH v3 0/6] arm, imx6: add aristainetos board support Heiko Schocher
2014-07-16  8:51 ` [U-Boot] [PATCH v3 1/6] imx6: add gpr2 usb_otg_id iomux select control define Heiko Schocher
2014-07-16  8:51 ` [U-Boot] [PATCH v3 2/6] i.MX6: define struct pwm_regs and PWMCR_* defines Heiko Schocher
2014-07-16  8:51 ` [U-Boot] [PATCH v3 3/6] pwm, imx6: add support for pwm modul on imx6 Heiko Schocher
2014-07-16  9:14   ` Stefano Babic
2014-07-16  9:21     ` Heiko Schocher
2014-07-16  9:44     ` Wolfgang Denk
2014-07-16  8:51 ` [U-Boot] [PATCH v3 4/6] i.MX6: add enable_spi_clk() Heiko Schocher
2014-07-16  8:51 ` Heiko Schocher [this message]
2014-07-16  8:51 ` [U-Boot] [PATCH v3 6/6] arm, imx6: add aristainetos board Heiko Schocher
2014-07-16  9:20   ` Stefano Babic

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=1405500696-32597-6-git-send-email-hs@denx.de \
    --to=hs@denx.de \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox