diff mbox

Fix erase timeout in M25P80 driver

Message ID 20090404143848.GA13480@turtle.localnet
State New, archived
Headers show

Commit Message

Peter Horton April 4, 2009, 2:38 p.m. UTC
Extend erase timeout in M25P80 SPI Flash driver.

The M25P80 drivers fails erasing sectors on a M25P128 because the ready
wait timeout is too short. Change the timeout from a simple loop count to a
suitable number of seconds.

Signed-off-by: Peter Horton <zero@colonel-panic.org>
---

Comments

Martin Michlmayr April 4, 2009, 3:34 p.m. UTC | #1
* Peter Horton <zero@colonel-panic.org> [2009-04-04 15:38]:
> Extend erase timeout in M25P80 SPI Flash driver.
> 
> The M25P80 drivers fails erasing sectors on a M25P128 because the ready
> wait timeout is too short. Change the timeout from a simple loop count to a
> suitable number of seconds.
> 
> Signed-off-by: Peter Horton <zero@colonel-panic.org>

Tested-by: Martin Michlmayr <tbm@cyrius.com>

This solves the problem I've seen on the QNAP TS-219.
Mike Frysinger April 4, 2009, 6:47 p.m. UTC | #2
On Sat, Apr 4, 2009 at 10:38, Peter Horton wrote:
> +       for (deadline = jiffies + MAX_READY_WAIT_JIFFIES; !time_after_eq(jiffies, deadline);) {

this would make more sense as a while loop:
  deadline = jiffies + MAX_READY_WAIT_JIFFIES;
  while (!time_after_eq(jiffies, deadline)) {
maybe even more sense as a do { ... } while (...) ...

a for loop just looks weird ... but it should do what you want, so whatever
-mike
diff mbox

Patch

Index: linux-2.6.29-git12/drivers/mtd/devices/m25p80.c
===================================================================
--- linux-2.6.29-git12.orig/drivers/mtd/devices/m25p80.c	2009-04-04 21:05:44.000000000 +0000
+++ linux-2.6.29-git12/drivers/mtd/devices/m25p80.c	2009-04-04 21:40:06.000000000 +0000
@@ -54,7 +54,7 @@ 
 #define	SR_SRWD			0x80	/* SR write protect */
 
 /* Define max times to check status register before we give up. */
-#define	MAX_READY_WAIT_COUNT	100000
+#define	MAX_READY_WAIT_JIFFIES	(10 * HZ)	/* eg. M25P128 specs 6s max sector erase */
 #define	CMD_SIZE		4
 
 #ifdef CONFIG_M25PXX_USE_FAST_READ
@@ -145,19 +145,16 @@ 
  */
 static int wait_till_ready(struct m25p *flash)
 {
-	int count;
+	unsigned long deadline;
 	int sr;
 
-	/* one chip guarantees max 5 msec wait here after page writes,
-	 * but potentially three seconds (!) after page erase.
-	 */
-	for (count = 0; count < MAX_READY_WAIT_COUNT; count++) {
+	for (deadline = jiffies + MAX_READY_WAIT_JIFFIES; !time_after_eq(jiffies, deadline);) {
 		if ((sr = read_sr(flash)) < 0)
 			break;
 		else if (!(sr & SR_WIP))
 			return 0;
 
-		/* REVISIT sometimes sleeping would be best */
+		cond_resched();
 	}
 
 	return 1;