Title: [3999] trunk/drivers/mtd/devices/m25p80.c: Fix bug [#3755], add correct handling flash->command length in read/write/erase operation
Revision
3999
Author
cooloney
Date
2007-12-07 01:37:27 -0600 (Fri, 07 Dec 2007)

Log Message

Fix bug [#3755], add correct handling flash->command length in read/write/erase operation

M25P80 operation, only FAST_READ command needs an extra dummy bytes in SPI transcation.
So add correct handling flash->command length in write/erase operation will fix this bug.

Diffstat

 m25p80.c |   38 ++++++++++++++++++++++++++------------
 1 files changed, 26 insertions(+), 12 deletions(-)

Modified Paths

Diff

Modified: trunk/drivers/mtd/devices/m25p80.c (3998 => 3999)


--- trunk/drivers/mtd/devices/m25p80.c	2007-12-06 09:10:12 UTC (rev 3998)
+++ trunk/drivers/mtd/devices/m25p80.c	2007-12-07 07:37:27 UTC (rev 3999)
@@ -178,7 +178,12 @@
 	flash->command[2] = offset >> 8;
 	flash->command[3] = offset;
 
-	spi_write(flash->spi, flash->command, sizeof(flash->command));
+	/* NOTE:
+	 * When using FAST_READ, sizeof(flash->command) including
+	 * 1 byte DUMMY_BYTE. So cut 1 byte in erasing operation.
+	 */
+	spi_write(flash->spi, flash->command,
+		(sizeof(flash->command) - FAST_READ_DUMMY_BYTE));
 
 	return 0;
 }
@@ -260,8 +265,12 @@
 	spi_message_init(&m);
 	memset(t, 0, (sizeof t));
 
+	/* NOTE:
+	 * OPCODE_FAST_READ (if available) is faster.
+	 * sizeof(flash->command) including 1 byte DUMMY_BYTE.
+	 */
 	t[0].tx_buf = flash->command;
-	t[0].len = sizeof(flash->command) + FAST_READ_DUMMY_BYTE;
+	t[0].len = sizeof(flash->command);
 	spi_message_add_tail(&t[0], &m);
 
 	t[1].rx_buf = buf;
@@ -281,8 +290,6 @@
 		return 1;
 	}
 
-	/* NOTE:  OPCODE_FAST_READ (if available) is faster... */
-
 	/* Set up the write data buffer. */
 	flash->command[0] = OPCODE_READ;
 	flash->command[1] = from >> 16;
@@ -291,9 +298,9 @@
 
 	spi_sync(flash->spi, &m);
 
-	*retlen = m.actual_length - sizeof(flash->command) - FAST_READ_DUMMY_BYTE;
+	*retlen = m.actual_length - sizeof(flash->command);
 
-  	up(&flash->lock);
+	up(&flash->lock);
 
 	return 0;
 }
@@ -328,8 +335,12 @@
 	spi_message_init(&m);
 	memset(t, 0, (sizeof t));
 
+	/* NOTE:
+	 * When using FAST_READ, sizeof(flash->command) including
+	 * 1 byte DUMMY_BYTE. So cut 1 byte in writing operation.
+	 */
 	t[0].tx_buf = flash->command;
-	t[0].len = sizeof(flash->command);
+	t[0].len = sizeof(flash->command) - FAST_READ_DUMMY_BYTE;
 	spi_message_add_tail(&t[0], &m);
 
 	t[1].tx_buf = buf;
@@ -358,7 +369,8 @@
 
 		spi_sync(flash->spi, &m);
 
-		*retlen = m.actual_length - sizeof(flash->command);
+		*retlen = m.actual_length - sizeof(flash->command)
+				+ FAST_READ_DUMMY_BYTE;
 	} else {
 		u32 i;
 
@@ -368,7 +380,8 @@
 		t[1].len = page_size;
 		spi_sync(flash->spi, &m);
 
-		*retlen = m.actual_length - sizeof(flash->command);
+		*retlen = m.actual_length - sizeof(flash->command)
+				+ FAST_READ_DUMMY_BYTE;
 
 		/* write everything in PAGESIZE chunks */
 		for (i = page_size; i < len; i += page_size) {
@@ -392,9 +405,10 @@
 
 			if (retlen)
 				*retlen += m.actual_length
-					- sizeof(flash->command);
-	        }
- 	}
+					- sizeof(flash->command)
+					+ FAST_READ_DUMMY_BYTE;
+		}
+	}
 
 	up(&flash->lock);
 
_______________________________________________
Linux-kernel-commits mailing list
[email protected]
http://blackfin.uclinux.org/mailman/listinfo/linux-kernel-commits

Reply via email to