eeprom/at25: bugfix "not ready" timeout after write

Under certain circumstances msleep(1) within the loop, which waits for the
EEPROM to be finished, might take longer than the timeout.  On the next
loop the status register might now return to be ready and therefore the
loop finishes.  The following check now tests if a timeout occurred and if
so returns an error although the device reported it was ready.

This fix replaces testing the occurrence of the timeout by testing the
"not ready" bit in the status register.

Signed-off-by: Sebastian Heutling <heutling@who-ing.de>
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Sebastian Heutling 2009-07-29 15:04:05 -07:00 committed by Linus Torvalds
parent 096b7fe012
commit f0d83679a8

View file

@ -173,6 +173,7 @@ at25_ee_write(struct at25_data *at25, const char *buf, loff_t off,
unsigned segment; unsigned segment;
unsigned offset = (unsigned) off; unsigned offset = (unsigned) off;
u8 *cp = bounce + 1; u8 *cp = bounce + 1;
int sr;
*cp = AT25_WREN; *cp = AT25_WREN;
status = spi_write(at25->spi, cp, 1); status = spi_write(at25->spi, cp, 1);
@ -214,7 +215,6 @@ at25_ee_write(struct at25_data *at25, const char *buf, loff_t off,
timeout = jiffies + msecs_to_jiffies(EE_TIMEOUT); timeout = jiffies + msecs_to_jiffies(EE_TIMEOUT);
retries = 0; retries = 0;
do { do {
int sr;
sr = spi_w8r8(at25->spi, AT25_RDSR); sr = spi_w8r8(at25->spi, AT25_RDSR);
if (sr < 0 || (sr & AT25_SR_nRDY)) { if (sr < 0 || (sr & AT25_SR_nRDY)) {
@ -228,7 +228,7 @@ at25_ee_write(struct at25_data *at25, const char *buf, loff_t off,
break; break;
} while (retries++ < 3 || time_before_eq(jiffies, timeout)); } while (retries++ < 3 || time_before_eq(jiffies, timeout));
if (time_after(jiffies, timeout)) { if ((sr < 0) || (sr & AT25_SR_nRDY)) {
dev_err(&at25->spi->dev, dev_err(&at25->spi->dev,
"write %d bytes offset %d, " "write %d bytes offset %d, "
"timeout after %u msecs\n", "timeout after %u msecs\n",