* [PATCH v2] mtd: spi-nor: wait until lock/unlock operations are ready
@ 2015-12-28 20:54 Ezequiel Garcia
2016-01-07 1:20 ` Brian Norris
0 siblings, 1 reply; 4+ messages in thread
From: Ezequiel Garcia @ 2015-12-28 20:54 UTC (permalink / raw)
To: linux-mtd
Cc: Brian Norris, Gregory Clement, Thomas Petazzoni, Stas Sergeev,
Ezequiel Garcia
On Micron and Numonyx devices, the status register write command
(WRSR), raises a work-in-progress bit (WIP) on the status register.
The datasheets for these devices specify that while the status
register write is in progress, the status register WIP bit can still
be read to check the end of the operation.
This commit adds a wait_till_ready call on lock/unlock operations,
only for these manufacturers. This is needed to prevent applications
from issuing erase or program operations before the unlock operation
is completed.
Reported-by: Stas Sergeev <stsp@list.ru>
Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
---
Changes from v1:
* Simplify style by tail calling spi_nor_wait_till_ready
drivers/mtd/spi-nor/spi-nor.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 7e5051e604b0..835a010d9339 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -481,6 +481,7 @@ static int stm_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
int status_old, status_new;
u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
u8 shift = ffs(mask) - 1, pow, val;
+ int ret;
status_old = read_sr(nor);
if (status_old < 0)
@@ -519,7 +520,10 @@ static int stm_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
return -EINVAL;
write_enable(nor);
- return write_sr(nor, status_new);
+ ret = write_sr(nor, status_new);
+ if (ret)
+ return ret;
+ return spi_nor_wait_till_ready(nor);
}
/*
@@ -533,6 +537,7 @@ static int stm_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len)
int status_old, status_new;
u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
u8 shift = ffs(mask) - 1, pow, val;
+ int ret;
status_old = read_sr(nor);
if (status_old < 0)
@@ -569,7 +574,10 @@ static int stm_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len)
return -EINVAL;
write_enable(nor);
- return write_sr(nor, status_new);
+ ret = write_sr(nor, status_new);
+ if (ret)
+ return ret;
+ return spi_nor_wait_till_ready(nor);
}
/*
--
2.6.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] mtd: spi-nor: wait until lock/unlock operations are ready
2015-12-28 20:54 [PATCH v2] mtd: spi-nor: wait until lock/unlock operations are ready Ezequiel Garcia
@ 2016-01-07 1:20 ` Brian Norris
2016-01-07 12:42 ` Ezequiel Garcia
0 siblings, 1 reply; 4+ messages in thread
From: Brian Norris @ 2016-01-07 1:20 UTC (permalink / raw)
To: Ezequiel Garcia
Cc: linux-mtd, Gregory Clement, Thomas Petazzoni, Stas Sergeev
On Mon, Dec 28, 2015 at 05:54:51PM -0300, Ezequiel Garcia wrote:
> On Micron and Numonyx devices, the status register write command
> (WRSR), raises a work-in-progress bit (WIP) on the status register.
> The datasheets for these devices specify that while the status
> register write is in progress, the status register WIP bit can still
> be read to check the end of the operation.
>
> This commit adds a wait_till_ready call on lock/unlock operations,
> only for these manufacturers. This is needed to prevent applications
Edited the above sentence, since you're not doing this "only for these
manufacturers"; you're doing it for all that support lock/unlock.
Instead, it'll read:
"This commit adds a wait_till_ready call on lock/unlock operations,
which is required for Micron and Numonyx but should be harmless for
others."
With that, applied to l2-mtd.git
Brian
> from issuing erase or program operations before the unlock operation
> is completed.
>
> Reported-by: Stas Sergeev <stsp@list.ru>
> Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
> ---
> Changes from v1:
> * Simplify style by tail calling spi_nor_wait_till_ready
>
> drivers/mtd/spi-nor/spi-nor.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index 7e5051e604b0..835a010d9339 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -481,6 +481,7 @@ static int stm_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
> int status_old, status_new;
> u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
> u8 shift = ffs(mask) - 1, pow, val;
> + int ret;
>
> status_old = read_sr(nor);
> if (status_old < 0)
> @@ -519,7 +520,10 @@ static int stm_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
> return -EINVAL;
>
> write_enable(nor);
> - return write_sr(nor, status_new);
> + ret = write_sr(nor, status_new);
> + if (ret)
> + return ret;
> + return spi_nor_wait_till_ready(nor);
> }
>
> /*
> @@ -533,6 +537,7 @@ static int stm_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len)
> int status_old, status_new;
> u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
> u8 shift = ffs(mask) - 1, pow, val;
> + int ret;
>
> status_old = read_sr(nor);
> if (status_old < 0)
> @@ -569,7 +574,10 @@ static int stm_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len)
> return -EINVAL;
>
> write_enable(nor);
> - return write_sr(nor, status_new);
> + ret = write_sr(nor, status_new);
> + if (ret)
> + return ret;
> + return spi_nor_wait_till_ready(nor);
> }
>
> /*
> --
> 2.6.4
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] mtd: spi-nor: wait until lock/unlock operations are ready
2016-01-07 1:20 ` Brian Norris
@ 2016-01-07 12:42 ` Ezequiel Garcia
2016-01-07 17:08 ` Brian Norris
0 siblings, 1 reply; 4+ messages in thread
From: Ezequiel Garcia @ 2016-01-07 12:42 UTC (permalink / raw)
To: Brian Norris
Cc: linux-mtd@lists.infradead.org, Gregory Clement, Thomas Petazzoni,
Stas Sergeev
On 6 January 2016 at 22:20, Brian Norris <computersforpeace@gmail.com> wrote:
> On Mon, Dec 28, 2015 at 05:54:51PM -0300, Ezequiel Garcia wrote:
>> On Micron and Numonyx devices, the status register write command
>> (WRSR), raises a work-in-progress bit (WIP) on the status register.
>> The datasheets for these devices specify that while the status
>> register write is in progress, the status register WIP bit can still
>> be read to check the end of the operation.
>>
>> This commit adds a wait_till_ready call on lock/unlock operations,
>> only for these manufacturers. This is needed to prevent applications
>
> Edited the above sentence, since you're not doing this "only for these
> manufacturers"; you're doing it for all that support lock/unlock.
Just to make sure we are on the same page here, this commit only
changes stm_lock, stm_unlock. So the change currently affects devices that
match JEDEC_MFR(info) == SNOR_MFR_MICRON.
--
Ezequiel García, VanguardiaSur
www.vanguardiasur.com.ar
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] mtd: spi-nor: wait until lock/unlock operations are ready
2016-01-07 12:42 ` Ezequiel Garcia
@ 2016-01-07 17:08 ` Brian Norris
0 siblings, 0 replies; 4+ messages in thread
From: Brian Norris @ 2016-01-07 17:08 UTC (permalink / raw)
To: Ezequiel Garcia
Cc: linux-mtd@lists.infradead.org, Gregory Clement, Thomas Petazzoni,
Stas Sergeev
On Thu, Jan 07, 2016 at 09:42:54AM -0300, Ezequiel Garcia wrote:
> On 6 January 2016 at 22:20, Brian Norris <computersforpeace@gmail.com> wrote:
> > Edited the above sentence, since you're not doing this "only for these
> > manufacturers"; you're doing it for all that support lock/unlock.
>
> Just to make sure we are on the same page here, this commit only
> changes stm_lock, stm_unlock. So the change currently affects devices that
> match JEDEC_MFR(info) == SNOR_MFR_MICRON.
Yes, that's currently correct. There were attempts to make this work for
Winbond too, but those were mostly reverted recently due to regressions.
I plan to re-extend that support again soon. So depending on when we're
talking about, that statement changes.
Brian
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-01-07 17:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-28 20:54 [PATCH v2] mtd: spi-nor: wait until lock/unlock operations are ready Ezequiel Garcia
2016-01-07 1:20 ` Brian Norris
2016-01-07 12:42 ` Ezequiel Garcia
2016-01-07 17:08 ` Brian Norris
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).