From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43737) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDr4a-0007L1-Ue for qemu-devel@nongnu.org; Fri, 17 Jun 2016 06:32:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bDr4W-00032H-Ta for qemu-devel@nongnu.org; Fri, 17 Jun 2016 06:32:24 -0400 Received: from mail-db3on0134.outbound.protection.outlook.com ([157.55.234.134]:35088 helo=emea01-db3-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDr4W-000320-F3 for qemu-devel@nongnu.org; Fri, 17 Jun 2016 06:32:20 -0400 From: Date: Fri, 17 Jun 2016 12:28:26 +0200 Message-ID: <1466159314-28597-3-git-send-email-marcin.krzeminski@nokia.com> In-Reply-To: <1466159314-28597-1-git-send-email-marcin.krzeminski@nokia.com> References: <1466159314-28597-1-git-send-email-marcin.krzeminski@nokia.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v2 02/10] m25p80: Make a table for JEDEC ID. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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, clg@kaod.org From: Marcin Krzeminski Since it is now longer than 4. This work based on Pawel Lenkow changes and the kernel SPI framework. Signed-off-by: Marcin Krzeminski Reviewed-by: C=C3=A9dric Le Goater --- hw/block/m25p80.c | 61 ++++++++++++++++++++++++++++++++++++++-------------= ---- 1 file changed, 42 insertions(+), 19 deletions(-) diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c index 15765f5..342f7c9 100644 --- a/hw/block/m25p80.c +++ b/hw/block/m25p80.c @@ -53,12 +53,17 @@ /* 16 MiB max in 3 byte address mode */ #define MAX_3BYTES_SIZE 0x1000000 =20 +#define SPI_NOR_MAX_ID_LEN 6 + typedef struct FlashPartInfo { const char *part_name; - /* jedec code. (jedec >> 16) & 0xff is the 1st byte, >> 8 the 2nd etc = */ - uint32_t jedec; - /* extended jedec code */ - uint16_t ext_jedec; + /* + * This array stores the ID bytes. + * The first three bytes are the JEDIC ID. + * JEDEC ID zero means "no ID" (mostly older chips). + */ + uint8_t id[SPI_NOR_MAX_ID_LEN]; + uint8_t id_len; /* there is confusion between manufacturers as to what a sector is. In= this * device model, a "sector" is the size that is erased by the ERASE_SE= CTOR * command (opcode 0xd8). @@ -70,11 +75,33 @@ typedef struct FlashPartInfo { } FlashPartInfo; =20 /* adapted from linux */ - -#define INFO(_part_name, _jedec, _ext_jedec, _sector_size, _n_sectors, _fl= ags)\ - .part_name =3D (_part_name),\ - .jedec =3D (_jedec),\ - .ext_jedec =3D (_ext_jedec),\ +/* Used when the "_ext_id" is two bytes at most */ +#define INFO(_part_name, _jedec_id, _ext_id, _sector_size, _n_sectors, _fl= ags)\ + .part_name =3D _part_name,\ + .id =3D {\ + ((_jedec_id) >> 16) & 0xff,\ + ((_jedec_id) >> 8) & 0xff,\ + (_jedec_id) & 0xff,\ + ((_ext_id) >> 8) & 0xff,\ + (_ext_id) & 0xff,\ + },\ + .id_len =3D (!(_jedec_id) ? 0 : (3 + ((_ext_id) ? 2 : 0))),\ + .sector_size =3D (_sector_size),\ + .n_sectors =3D (_n_sectors),\ + .page_size =3D 256,\ + .flags =3D (_flags), + +#define INFO6(_part_name, _jedec_id, _ext_id, _sector_size, _n_sectors, _f= lags)\ + .part_name =3D _part_name,\ + .id =3D {\ + ((_jedec_id) >> 16) & 0xff,\ + ((_jedec_id) >> 8) & 0xff,\ + (_jedec_id) & 0xff,\ + ((_ext_id) >> 16) & 0xff,\ + ((_ext_id) >> 8) & 0xff,\ + (_ext_id) & 0xff,\ + },\ + .id_len =3D 6,\ .sector_size =3D (_sector_size),\ .n_sectors =3D (_n_sectors),\ .page_size =3D 256,\ @@ -360,7 +387,7 @@ typedef struct M25P80Class { =20 static inline Manufacturer get_man(Flash *s) { - switch (((s->pi->jedec >> 16) & 0xFF)) { + switch (s->pi->id[0]) { case 0x20: return MAN_NUMONYX; case 0xEF: @@ -630,6 +657,7 @@ static void reset_memory(Flash *s) static void decode_new_cmd(Flash *s, uint32_t value) { s->cmd_in_progress =3D value; + int i; DB_PRINT_L(0, "decoded new command:%x\n", value); =20 if (value !=3D RESET_MEMORY) { @@ -743,16 +771,11 @@ static void decode_new_cmd(Flash *s, uint32_t value) =20 case JEDEC_READ: DB_PRINT_L(0, "populated jedec code\n"); - s->data[0] =3D (s->pi->jedec >> 16) & 0xff; - s->data[1] =3D (s->pi->jedec >> 8) & 0xff; - s->data[2] =3D s->pi->jedec & 0xff; - if (s->pi->ext_jedec) { - s->data[3] =3D (s->pi->ext_jedec >> 8) & 0xff; - s->data[4] =3D s->pi->ext_jedec & 0xff; - s->len =3D 5; - } else { - s->len =3D 3; + for (i =3D 0; i < s->pi->id_len; i++) { + s->data[i] =3D s->pi->id[i]; } + + s->len =3D s->pi->id_len; s->pos =3D 0; s->state =3D STATE_READING_DATA; break; --=20 2.7.4