From: Jagan Teki <jteki@openedev.com>
To: linux-mtd@lists.infradead.org
Cc: linux-kernel@vger.kernel.org, Jagan Teki <jteki@openedev.com>,
Hou Zhiqiang <B48286@freescale.com>,
"Mingkai.Hu" <Mingkai.Hu@freescale.com>,
David Woodhouse <dwmw2@infradead.org>,
Brian Norris <computersforpeace@gmail.com>
Subject: [PATCH 3/3] mtd: spi-nor: sf: Add clear flag status register support
Date: Wed, 19 Aug 2015 15:26:45 +0530 [thread overview]
Message-ID: <1439978205-6092-3-git-send-email-jteki@openedev.com> (raw)
In-Reply-To: <1439978205-6092-1-git-send-email-jteki@openedev.com>
The clear flag status register operation was required by Micron
SPI-NOR chips, which support FSR. And if an error bit of FSR
have been set like protection, voltage, erase, and program,
it must be cleared by the clear FSR operation.
Signed-off-by: Jagan Teki <jteki@openedev.com>
Cc: Hou Zhiqiang <B48286@freescale.com>
Cc: Mingkai.Hu <Mingkai.Hu@freescale.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Brian Norris <computersforpeace@gmail.com>
---
drivers/mtd/spi-nor/spi-nor.c | 35 +++++++++++++++++++++++++++++++----
include/linux/mtd/spi-nor.h | 9 +++++++++
2 files changed, 40 insertions(+), 4 deletions(-)
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index f954d03..c5c472d5 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -100,6 +100,28 @@ static int read_fsr(struct spi_nor *nor)
}
/*
+ * Read the clear flag status register.
+ * The clear flag status register operation was required by Micron
+ * SPI-NOR chips, which support FSR. And if an error bit of FSR
+ * have been set like protection, voltage, erase, and program,
+ * it must be cleared by the clear FSR operation.
+ * Returns zero for FSR bits cleared and negative if error occurred.
+ */
+static int read_cfsr(struct spi_nor *nor)
+{
+ int ret;
+ u8 val;
+
+ ret = nor->read_reg(nor, SPINOR_OP_RDCFSR, &val, 1);
+ if (ret < 0) {
+ pr_err("error %d reading CFSR\n", ret);
+ return ret;
+ }
+
+ return val;
+}
+
+/*
* Read configuration register, returning its value in the
* location. Return the configuration register value.
* Returns negative if error occured.
@@ -209,10 +231,15 @@ static inline int spi_nor_sr_ready(struct spi_nor *nor)
static inline int spi_nor_fsr_ready(struct spi_nor *nor)
{
int fsr = read_fsr(nor);
- if (fsr < 0)
- return fsr;
- else
- return fsr & FSR_READY;
+ if (fsr & FSR_ERR_MASK) {
+ pr_err("flag status(0x%x) error occured\n", fsr);
+ int cfsr = read_cfsr(nor);
+ if (cfsr < 0)
+ return cfsr;
+ return -1;
+ }
+
+ return fsr & FSR_READY;
}
static int spi_nor_ready(struct spi_nor *nor)
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index c5a58c4..36c1681 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -35,6 +35,7 @@
#define SPINOR_OP_RDID 0x9f /* Read JEDEC ID */
#define SPINOR_OP_RDCR 0x35 /* Read configuration register */
#define SPINOR_OP_RDFSR 0x70 /* Read flag status register */
+#define SPINOR_OP_RDCFSR 0x50 /* Read clear flag status register */
/* 4-byte address opcodes - used on Spansion and some Macronix flashes. */
#define SPINOR_OP_READ4 0x13 /* Read data bytes (low frequency) */
@@ -74,6 +75,14 @@
/* Enhanced Volatile Configuration Register bits */
#define EVCR_QUAD_EN_MICRON 0x80 /* Micron Quad I/O */
+/* Flag Status Register Error bits */
+#define FSR_ERR_PROT 0x2 /* Protection */
+#define FSR_ERR_VOLT 0x8 /* Voltage on Vpp */
+#define FSR_ERR_PROG 0x10 /* Program operation */
+#define FSR_ERR_ERASE 0x20 /* Erase operation */
+#define FSR_ERR_MASK (FSR_ERR_PROT | FSR_ERR_VOLT | \
+ FSR_ERR_PROG | FSR_ERR_ERASE)
+
/* Flag Status Register bits */
#define FSR_READY 0x80
--
1.9.1
next prev parent reply other threads:[~2015-08-19 9:57 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-19 9:56 [PATCH 1/3] mtd: spi-nor: Use write_sr for write status Jagan Teki
2015-08-19 9:56 ` [PATCH 2/3] mtd: spi-nor: Zap unneeded write_enable from write_reg Jagan Teki
2015-09-04 11:28 ` Jagan Teki
2015-09-11 23:14 ` Brian Norris
2015-08-19 9:56 ` Jagan Teki [this message]
2015-08-19 12:12 ` [PATCH 3/3] mtd: spi-nor: sf: Add clear flag status register support Hou Zhiqiang
2015-08-19 17:49 ` Jagan Teki
2015-08-20 3:06 ` Hou Zhiqiang
2015-08-21 7:12 ` Jagan Teki
2015-08-25 2:22 ` Hou Zhiqiang
2015-08-26 10:37 ` Jagan Teki
2015-09-04 11:27 ` [PATCH 1/3] mtd: spi-nor: Use write_sr for write status Jagan Teki
2015-09-11 22:59 ` Brian Norris
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=1439978205-6092-3-git-send-email-jteki@openedev.com \
--to=jteki@openedev.com \
--cc=B48286@freescale.com \
--cc=Mingkai.Hu@freescale.com \
--cc=computersforpeace@gmail.com \
--cc=dwmw2@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.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).