public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: NeilBrown <neil@brown.name>
To: Cyrille Pitchen <cyrille.pitchen@wedev4u.fr>,
	Marek Vasut <marek.vasut@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>,
	Brian Norris <computersforpeace@gmail.com>,
	Boris Brezillon <boris.brezillon@free-electrons.com>,
	Richard Weinberger <richard@nod.at>
Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH] mtd: spi-nor: clear Extended Address Reg on switch to 3-byte addressing.
Date: Sun, 08 Apr 2018 17:04:44 +1000	[thread overview]
Message-ID: <874lkmw54j.fsf@notabene.neil.brown.name> (raw)

[-- Attachment #1: Type: text/plain, Size: 2659 bytes --]


According to section
   8.2.7 Write Extended Address Register (C5h)

of the Winbond W25Q256FV data sheet (256M-BIT SPI flash)

   The Extended Address Register is only effective when the device is
   in the 3-Byte Address Mode.  When the device operates in the 4-Byte
   Address Mode (ADS=1), any command with address input of A31-A24
   will replace the Extended Address Register values. It is
   recommended to check and update the Extended Address Register if
   necessary when the device is switched from 4-Byte to 3-Byte Address
   Mode.

This patch adds code to implement that recommendation.  Without this,
my GNUBEE-PC1 will not successfully reboot, as the Extended Address
Register is left with a value of '1'. When the SOC attempts to read
(in 3-byte address mode) the boot loader, it reads from the wrong
location.

Signed-off-by: NeilBrown <neil@brown.name>
---
 drivers/mtd/spi-nor/spi-nor.c | 10 ++++++++++
 include/linux/mtd/spi-nor.h   |  2 ++
 2 files changed, 12 insertions(+)

diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index d445a4d3b770..c303bf0d2982 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -269,6 +269,7 @@ static inline int set_4byte(struct spi_nor *nor, const struct flash_info *info,
 	int status;
 	bool need_wren = false;
 	u8 cmd;
+	u8 val;
 
 	switch (JEDEC_MFR(info)) {
 	case SNOR_MFR_MICRON:
@@ -283,6 +284,15 @@ static inline int set_4byte(struct spi_nor *nor, const struct flash_info *info,
 		status = nor->write_reg(nor, cmd, NULL, 0);
 		if (need_wren)
 			write_disable(nor);
+		if (!status && !enable &&
+		    nor->read_reg(nor, SPINOR_OP_RDXA, &val, 1) == 0 &&
+		    val != 0) {
+			/* need to reset the Extended Address Register */
+			write_enable(nor);
+			val = 0;
+			nor->write_reg(nor, SPINOR_OP_WRXA, &val, 1);
+			write_disable(nor);
+		}
 
 		return status;
 	default:
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index de36969eb359..42954419cfdf 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -62,6 +62,8 @@
 #define SPINOR_OP_RDCR		0x35	/* Read configuration register */
 #define SPINOR_OP_RDFSR		0x70	/* Read flag status register */
 #define SPINOR_OP_CLFSR		0x50	/* Clear flag status register */
+#define SPINOR_OP_RDXA		0xc8	/* Read Extended Address Register */
+#define SPINOR_OP_WRXA		0xc5	/* Write Extended Address Register */
 
 /* 4-byte address opcodes - used on Spansion and some Macronix flashes. */
 #define SPINOR_OP_READ_4B	0x13	/* Read data bytes (low frequency) */
-- 
2.14.0.rc0.dirty


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

             reply	other threads:[~2018-04-08  7:05 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-08  7:04 NeilBrown [this message]
2018-04-08 10:53 ` [PATCH] mtd: spi-nor: clear Extended Address Reg on switch to 3-byte addressing Marek Vasut
2018-04-08 21:56   ` NeilBrown
2018-04-09 21:58     ` Marek Vasut
2018-04-10  1:05       ` NeilBrown
2018-04-10 23:20         ` Marek Vasut
2018-07-23 18:25         ` Brian Norris
2018-07-23 21:45           ` NeilBrown
2018-07-23 22:17             ` Brian Norris
2018-07-23 22:23               ` NeilBrown
2018-04-10 23:13 ` Marek Vasut
2018-04-15 23:42 ` [PATCH v2] mtd: spi-nor: clear Winbond " NeilBrown
2018-04-20 19:54   ` Boris Brezillon
2018-04-20 21:26     ` [PATCH v3] " NeilBrown
2018-04-20 21:57       ` Marek Vasut
2018-04-20 22:54         ` [PATCH v4] " NeilBrown
2018-04-22 17:22           ` Boris Brezillon
2018-04-20 21:28     ` [PATCH v2] " NeilBrown
2018-04-20 22:10       ` Boris Brezillon
2018-04-20 22:51         ` NeilBrown

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=874lkmw54j.fsf@notabene.neil.brown.name \
    --to=neil@brown.name \
    --cc=boris.brezillon@free-electrons.com \
    --cc=computersforpeace@gmail.com \
    --cc=cyrille.pitchen@wedev4u.fr \
    --cc=dwmw2@infradead.org \
    --cc=marek.vasut@gmail.com \
    --cc=richard@nod.at \
    /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