diff mbox series

[4/9] hw/block: m25p80: Fix the number of dummy bytes needed for Spansion flashes

Message ID 20210114150902.11515-5-bmeng.cn@gmail.com
State New
Headers show
Series hw/block: m25p80: Fix the mess of dummy bytes needed for fast read commands | expand

Commit Message

Bin Meng Jan. 14, 2021, 3:08 p.m. UTC
From: Bin Meng <bin.meng@windriver.com>

Per datasheet [1], the number of dummy cycles for Spansion flashes
is configurable via 4 volatible bits in a configuration register.

Do the same dummy cycle to dummy byte conversion fix as others.

[1] https://www.cypress.com/file/316171/download

Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

 hw/block/m25p80.c | 43 +++++++++++++++++++++++++++++++------------
 1 file changed, 31 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
index 44508b3da9..e1e5d5a76f 100644
--- a/hw/block/m25p80.c
+++ b/hw/block/m25p80.c
@@ -955,10 +955,25 @@  static void decode_fast_read_cmd(Flash *s)
         s->needed_bytes += 1;
         break;
     case MAN_SPANSION:
-        s->needed_bytes += extract32(s->spansion_cr2v,
-                                    SPANSION_DUMMY_CLK_POS,
-                                    SPANSION_DUMMY_CLK_LEN
-                                    );
+        if (extract32(s->spansion_cr2v, SPANSION_DUMMY_CLK_POS,
+                      SPANSION_DUMMY_CLK_LEN) != 8) {
+            qemu_log_mask(LOG_UNIMP,
+                          "M25P80: the number of dummy bits is not multiple of 8");
+        }
+        switch (s->cmd_in_progress) {
+        case FAST_READ:
+        case FAST_READ4:
+            s->needed_bytes += 1;
+            break;
+        case DOR:
+        case DOR4:
+            s->needed_bytes += 2;
+            break;
+        case QOR:
+        case QOR4:
+            s->needed_bytes += 4;
+            break;
+        }
         break;
     default:
         break;
@@ -978,10 +993,12 @@  static void decode_dio_read_cmd(Flash *s)
         break;
     case MAN_SPANSION:
         s->needed_bytes += SPANSION_CONTINUOUS_READ_MODE_CMD_LEN;
-        s->needed_bytes += extract32(s->spansion_cr2v,
-                                    SPANSION_DUMMY_CLK_POS,
-                                    SPANSION_DUMMY_CLK_LEN
-                                    );
+        if (extract32(s->spansion_cr2v, SPANSION_DUMMY_CLK_POS,
+                      SPANSION_DUMMY_CLK_LEN) != 8) {
+            qemu_log_mask(LOG_UNIMP,
+                          "M25P80: the number of dummy bits is not multiple of 8");
+        }
+        s->needed_bytes += 2;
         break;
     case MAN_NUMONYX:
         s->needed_bytes += numonyx_extract_cfg_num_dummies(s);
@@ -1018,10 +1035,12 @@  static void decode_qio_read_cmd(Flash *s)
         break;
     case MAN_SPANSION:
         s->needed_bytes += SPANSION_CONTINUOUS_READ_MODE_CMD_LEN;
-        s->needed_bytes += extract32(s->spansion_cr2v,
-                                    SPANSION_DUMMY_CLK_POS,
-                                    SPANSION_DUMMY_CLK_LEN
-                                    );
+        if (extract32(s->spansion_cr2v, SPANSION_DUMMY_CLK_POS,
+                      SPANSION_DUMMY_CLK_LEN) != 8) {
+            qemu_log_mask(LOG_UNIMP,
+                          "M25P80: the number of dummy bits is not multiple of 8");
+        }
+        s->needed_bytes += 4;
         break;
     case MAN_NUMONYX:
         s->needed_bytes += numonyx_extract_cfg_num_dummies(s);