From: Shreyas Joshi <shreyasjoshi15@gmail.com>
To: marek.vasut@gmail.com, tudor.ambarus@microchip.com,
linux-mtd@lists.infradead.org, shreyasjoshi15@gmail.com
Subject: [PATCH] driver/mtd/spi-nor: Regression lock/unlock fail
Date: Thu, 19 Sep 2019 11:49:16 +1000 [thread overview]
Message-ID: <20190919014916.1303-1-shreyas.joshi@biamp.com> (raw)
From: shreyas <shreyasjoshi15@gmail.com>
The n25q128 micron chips cannot be treated similar to STM SPI NOR
when it comes to flash lock/unlock. The JDEC ID read here is just 1 byte
and it is not sufficient to distinguish between different chips. Thus,
memory type is used here in addition to JDEC ID to distinguish further.
Once the unique manufacture id is detected, it will invoke the required
lock/unlock function required for n25 micron chipsets.
Signed-off-by: shreyas <shreyasjoshi15@gmail.com>
---
drivers/mtd/spi-nor/spi-nor.c | 20 +++++++++++---------
include/linux/mtd/spi-nor.h | 4 ++--
2 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index f3b2df2c52b4..6dfdd95a5961 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -1356,6 +1356,7 @@ static int n25q_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
int status_old, status_new;
uint32_t offset = ofs;
int ret = 0;
+
status_old = read_sr(nor);
if (status_old < 0)
return status_old;
@@ -1373,7 +1374,8 @@ static int n25q_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
status_new = (status_old & ~(SR_BP2|SR_BP0)) | SR_BP1;
else
status_new = (status_old & ~(SR_BP2|SR_BP1)) | SR_BP0;
- if ((status_new & (SR_BP2|SR_BP1|SR_BP0)) > (status_old & (SR_BP2|SR_BP1|SR_BP0))) {
+ if ((status_new & (SR_BP2|SR_BP1|SR_BP0)) >
+ (status_old & (SR_BP2|SR_BP1|SR_BP0))) {
write_enable(nor);
if (write_sr(nor, status_new) < 0)
return -EINVAL;
@@ -1392,6 +1394,7 @@ static int n25q_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len)
int status_old, status_new;
uint32_t offset = ofs;
int ret = 0;
+
status_old = read_sr(nor);
if (status_old < 0)
return status_old;
@@ -4266,14 +4269,13 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
if (JEDEC_MFR(info) == SNOR_MFR_ST ||
JEDEC_MFR(info) == SNOR_MFR_MICRON ||
info->flags & SPI_NOR_HAS_LOCK) {
- if (JEDEC_MT(info) == SNOR_MT_MICRON) {
- nor->flash_lock = n25q_lock;
- nor->flash_unlock = n25q_unlock;
- }
- else {
- nor->flash_lock = stm_lock;
- nor->flash_unlock = stm_unlock;
- }
+ if (JEDEC_MT(info) == SNOR_MT_MICRON) {
+ nor->flash_lock = n25q_lock;
+ nor->flash_unlock = n25q_unlock;
+ } else {
+ nor->flash_lock = stm_lock;
+ nor->flash_unlock = stm_unlock;
+ }
nor->flash_is_locked = stm_is_locked;
}
if (nor->flash_lock && nor->flash_unlock && nor->flash_is_locked) {
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index aaa3c1065b3b..3939cd77d778 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -27,8 +27,8 @@
#define SNOR_MFR_WINBOND 0xef /* Also used by some Spansion */
/* Manufacturer Memory Type
-* The second byte returned from the flash after sending opcode SPINOR_OP_RDID.
-*/
+ * The second byte returned from the flash after sending opcode SPINOR_OP_RDID.
+ */
#define SNOR_MT_MICRON 0xba
#define SNOR_MT_ST 0x20
--
2.20.1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next reply other threads:[~2019-09-19 1:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-19 1:49 Shreyas Joshi [this message]
2019-09-19 5:05 ` [PATCH] driver/mtd/spi-nor: Regression lock/unlock fail Tudor.Ambarus
[not found] ` <CABY4bmpv4cdYDHaLvXX9ReACytqQktTTv867BUB4MNH-NHoCxw@mail.gmail.com>
2020-04-20 7:29 ` Tudor.Ambarus
[not found] ` <CABY4bmrSwLdnUMa5vJhfi2Hvbq4FHxU=hcXJX90o5dFXBi1Q4w@mail.gmail.com>
2020-04-21 4:42 ` Tudor.Ambarus
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=20190919014916.1303-1-shreyas.joshi@biamp.com \
--to=shreyasjoshi15@gmail.com \
--cc=linux-mtd@lists.infradead.org \
--cc=marek.vasut@gmail.com \
--cc=tudor.ambarus@microchip.com \
/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).