qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: <marcin.krzeminski@nokia.com>
To: qemu-devel@nongnu.org
Cc: crosthwaitepeter@gmail.com, pawel.lenkow@itlen.com,
	rfsw-patches@mlist.emea.nsn-intra.net, peter.maydell@linaro.org,
	clg@fr.ibm.com
Subject: [Qemu-devel] [PATCH 1/9] m25p80: Replace JEDEC ID masking with function.
Date: Wed, 15 Jun 2016 15:41:03 +0200	[thread overview]
Message-ID: <1465998071-7355-2-git-send-email-marcin.krzeminski@nokia.com> (raw)
In-Reply-To: <1465998071-7355-1-git-send-email-marcin.krzeminski@nokia.com>

From: Marcin Krzeminski <marcin.krzeminski@nokia.com>

Instead of always reading and comparing jededc ID,
replace it by function.

Signed-off-by: Marcin Krzeminski <marcin.krzeminski@nokia.com>
---
 hw/block/m25p80.c | 49 ++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 40 insertions(+), 9 deletions(-)

diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
index 4c856f5..15765f5 100644
--- a/hw/block/m25p80.c
+++ b/hw/block/m25p80.c
@@ -307,6 +307,14 @@ typedef enum {
     STATE_READING_DATA,
 } CMDState;
 
+typedef enum {
+    MAN_SPANSION,
+    MAN_MACRONIX,
+    MAN_NUMONYX,
+    MAN_WINBOND,
+    MAN_GENERIC,
+} Manufacturer;
+
 typedef struct Flash {
     SSISlave parent_obj;
 
@@ -350,6 +358,22 @@ typedef struct M25P80Class {
 #define M25P80_GET_CLASS(obj) \
      OBJECT_GET_CLASS(M25P80Class, (obj), TYPE_M25P80)
 
+static inline Manufacturer get_man(Flash *s)
+{
+    switch (((s->pi->jedec >> 16) & 0xFF)) {
+    case 0x20:
+        return MAN_NUMONYX;
+    case 0xEF:
+        return MAN_WINBOND;
+    case 0x01:
+        return MAN_SPANSION;
+    case 0xC2:
+        return MAN_MACRONIX;
+    default:
+        return MAN_GENERIC;
+    }
+}
+
 static void blk_sync_complete(void *opaque, int ret)
 {
     /* do nothing. Masters do not directly interact with the backing store,
@@ -562,7 +586,8 @@ static void reset_memory(Flash *s)
     s->write_enable = false;
     s->reset_enable = false;
 
-    if (((s->pi->jedec >> 16) & 0xFF) == JEDEC_NUMONYX) {
+    switch (get_man(s)) {
+    case MAN_NUMONYX:
         s->volatile_cfg = 0;
         s->volatile_cfg |= VCFG_DUMMY;
         s->volatile_cfg |= VCFG_WRAP_SEQUENTIAL;
@@ -594,6 +619,9 @@ static void reset_memory(Flash *s)
         if (!(s->nonvolatile_cfg & NVCFG_LOWER_SEGMENT_MASK)) {
             s->ear = CFG_UPPER_128MB_SEG_ENABLED;
         }
+        break;
+    default:
+        break;
     }
 
     DB_PRINT_L(0, "Reset done.\n");
@@ -634,9 +662,12 @@ static void decode_new_cmd(Flash *s, uint32_t value)
     case QOR:
     case QOR4:
         s->needed_bytes = get_addr_length(s);
-        if (((s->pi->jedec >> 16) & 0xFF) == JEDEC_NUMONYX) {
-            /* Dummy cycles modeled with bytes writes instead of bits */
+        switch (get_man(s)) {
+        case MAN_NUMONYX:
             s->needed_bytes += extract32(s->volatile_cfg, 4, 4);
+            break;
+        default:
+            break;
         }
         s->pos = 0;
         s->len = 0;
@@ -645,9 +676,9 @@ static void decode_new_cmd(Flash *s, uint32_t value)
 
     case DIOR:
     case DIOR4:
-        switch ((s->pi->jedec >> 16) & 0xFF) {
-        case JEDEC_WINBOND:
-        case JEDEC_SPANSION:
+        switch (get_man(s)) {
+        case MAN_WINBOND:
+        case MAN_SPANSION:
             s->needed_bytes = 4;
             break;
         default:
@@ -662,9 +693,9 @@ static void decode_new_cmd(Flash *s, uint32_t value)
 
     case QIOR:
     case QIOR4:
-        switch ((s->pi->jedec >> 16) & 0xFF) {
-        case JEDEC_WINBOND:
-        case JEDEC_SPANSION:
+        switch (get_man(s)) {
+        case MAN_WINBOND:
+        case MAN_SPANSION:
             s->needed_bytes = 6;
             break;
         default:
-- 
2.7.4

  reply	other threads:[~2016-06-15 14:28 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-15 13:41 [Qemu-devel] [PATCH 0/9] m25p80: Add new 512Mbit and 1Gbit devices marcin.krzeminski
2016-06-15 13:41 ` marcin.krzeminski [this message]
2016-06-15 14:05   ` [Qemu-devel] [PATCH 1/9] m25p80: Replace JEDEC ID masking with function Cédric Le Goater
2016-06-15 17:09     ` [Qemu-devel] Odp.: " Krzeminski, Marcin (Nokia - PL/Wroclaw)
2016-06-15 13:41 ` [Qemu-devel] [PATCH 2/9] m25p80: Make a table for JEDEC ID marcin.krzeminski
2016-06-15 14:17   ` Cédric Le Goater
2016-06-15 13:41 ` [Qemu-devel] [PATCH 3/9] m25p80: Allow more than four banks marcin.krzeminski
2016-06-16  7:09   ` Cédric Le Goater
2016-06-15 13:41 ` [Qemu-devel] [PATCH 4/9] m25p80: Introduce COLLECTING_VAR_LEN_DATA state marcin.krzeminski
2016-06-16  7:13   ` Cédric Le Goater
2016-06-16  7:43     ` Krzeminski, Marcin (Nokia - PL/Wroclaw)
2016-06-16  8:13       ` Cédric Le Goater
2016-06-15 13:41 ` [Qemu-devel] [PATCH 5/9] m25p80: Add additional flash commands: marcin.krzeminski
2016-06-16  7:14   ` Cédric Le Goater
2016-06-15 13:41 ` [Qemu-devel] [PATCH 6/9] m25p80: Introduce quad and equad modes marcin.krzeminski
2016-06-15 14:25   ` Cédric Le Goater
2016-06-15 17:40     ` [Qemu-devel] Odp.: " Krzeminski, Marcin (Nokia - PL/Wroclaw)
2016-06-17 12:43       ` Cédric Le Goater
2016-06-15 13:41 ` [Qemu-devel] [PATCH 7/9] m25p80: Introduce configuration registers marcin.krzeminski
2016-06-16  7:24   ` Cédric Le Goater
2016-06-16  7:52     ` Krzeminski, Marcin (Nokia - PL/Wroclaw)
2016-06-16  8:05       ` Cédric Le Goater
2016-06-17 10:31         ` Krzeminski, Marcin (Nokia - PL/Wroclaw)
2016-06-15 13:41 ` [Qemu-devel] [PATCH 8/9] m25p80: Fast read commands family changes marcin.krzeminski
2016-06-16  7:19   ` Cédric Le Goater
2016-06-16  7:53     ` Krzeminski, Marcin (Nokia - PL/Wroclaw)
2016-06-15 13:41 ` [Qemu-devel] [PATCH 9/9] m25p80: New flash devices marcin.krzeminski
2016-06-16  7:20   ` Cédric Le Goater

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1465998071-7355-2-git-send-email-marcin.krzeminski@nokia.com \
    --to=marcin.krzeminski@nokia.com \
    --cc=clg@fr.ibm.com \
    --cc=crosthwaitepeter@gmail.com \
    --cc=pawel.lenkow@itlen.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rfsw-patches@mlist.emea.nsn-intra.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).