Patchwork [v2] hw/nand.c: bug fix to BUSY/READY status bit

login
register
mail settings
Submitter Kuo-Jung Su
Date Jan. 25, 2013, 7:20 a.m.
Message ID <1359098434-11003-1-git-send-email-dantesu@gmail.com>
Download mbox | patch
Permalink /patch/215567/
State New
Headers show

Comments

Kuo-Jung Su - Jan. 25, 2013, 7:20 a.m.
From: Kuo-Jung Su <dantesu@faraday-tech.com>

The status register coding for BUSY/READY(BIT6)
is actually [Busy:0, Ready:1].
BTW, this patch not only apply the bug fix to status bit,
but also update the Busy/Ready status upon nand flash read/write/erase.

Signed-off-by: Kuo-Jung Su <dantesu@faraday-tech.com>
Cc: balrog@zabor.org
---

Changes for v2:
   - coding style fix

---
 hw/nand.c |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

Patch

diff --git a/hw/nand.c b/hw/nand.c
index 4a71265..4ddb22b 100644
--- a/hw/nand.c
+++ b/hw/nand.c
@@ -46,7 +46,7 @@ 
 # define NAND_IOSTATUS_PLANE1	(1 << 2)
 # define NAND_IOSTATUS_PLANE2	(1 << 3)
 # define NAND_IOSTATUS_PLANE3	(1 << 4)
-# define NAND_IOSTATUS_BUSY	(1 << 6)
+# define NAND_IOSTATUS_READY    (1 << 6)
 # define NAND_IOSTATUS_UNPROTCT	(1 << 7)
 
 # define MAX_PAGE		0x800
@@ -647,6 +647,8 @@  static void glue(nand_blk_write_, PAGE_SIZE)(NANDFlashState *s)
     if (PAGE(s->addr) >= s->pages)
         return;
 
+    s->status &= ~NAND_IOSTATUS_READY;
+
     if (!s->bdrv) {
         mem_and(s->storage + PAGE_START(s->addr) + (s->addr & PAGE_MASK) +
                         s->offset, s->io, s->iolen);
@@ -656,6 +658,7 @@  static void glue(nand_blk_write_, PAGE_SIZE)(NANDFlashState *s)
         soff = SECTOR_OFFSET(s->addr);
         if (bdrv_read(s->bdrv, sector, iobuf, PAGE_SECTORS) < 0) {
             printf("%s: read error in sector %" PRIu64 "\n", __func__, sector);
+            s->status |= NAND_IOSTATUS_READY;
             return;
         }
 
@@ -675,6 +678,7 @@  static void glue(nand_blk_write_, PAGE_SIZE)(NANDFlashState *s)
         soff = off & 0x1ff;
         if (bdrv_read(s->bdrv, sector, iobuf, PAGE_SECTORS + 2) < 0) {
             printf("%s: read error in sector %" PRIu64 "\n", __func__, sector);
+            s->status |= NAND_IOSTATUS_READY;
             return;
         }
 
@@ -685,6 +689,8 @@  static void glue(nand_blk_write_, PAGE_SIZE)(NANDFlashState *s)
         }
     }
     s->offset = 0;
+
+    s->status |= NAND_IOSTATUS_READY;
 }
 
 /* Erase a single block */
@@ -697,6 +703,8 @@  static void glue(nand_blk_erase_, PAGE_SIZE)(NANDFlashState *s)
     if (PAGE(addr) >= s->pages)
         return;
 
+    s->status &= ~NAND_IOSTATUS_READY;
+
     if (!s->bdrv) {
         memset(s->storage + PAGE_START(addr),
                         0xff, (PAGE_SIZE + OOB_SIZE) << s->erase_shift);
@@ -738,6 +746,8 @@  static void glue(nand_blk_erase_, PAGE_SIZE)(NANDFlashState *s)
             printf("%s: write error in sector %" PRIu64 "\n", __func__, page);
         }
     }
+
+    s->status |= NAND_IOSTATUS_READY;
 }
 
 static void glue(nand_blk_load_, PAGE_SIZE)(NANDFlashState *s,
@@ -746,6 +756,8 @@  static void glue(nand_blk_load_, PAGE_SIZE)(NANDFlashState *s,
     if (PAGE(addr) >= s->pages)
         return;
 
+    s->status &= ~NAND_IOSTATUS_READY;
+
     if (s->bdrv) {
         if (s->mem_oob) {
             if (bdrv_read(s->bdrv, SECTOR(addr), s->io, PAGE_SECTORS) < 0) {
@@ -769,6 +781,8 @@  static void glue(nand_blk_load_, PAGE_SIZE)(NANDFlashState *s,
                         offset, PAGE_SIZE + OOB_SIZE - offset);
         s->ioaddr = s->io;
     }
+
+    s->status |= NAND_IOSTATUS_READY;
 }
 
 static void glue(nand_init_, PAGE_SIZE)(NANDFlashState *s)