All of lore.kernel.org
 help / color / mirror / Atom feed
From: Angelo Dureghello <sysamfw@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/1] mtd/cfi: add support for SST 4KB sector granularity
Date: Sat, 1 Dec 2012 01:14:18 +0100	[thread overview]
Message-ID: <20121201001417.GA643@angel3> (raw)

Add support for SST 4KB sector granularity.

Many recent SST flashes, i.e. SST39VF3201B and similar of this family 
are declared CFI-conformant from SST. They support CFI query, but implement 
2 different sector sizes in the same memory: a 64KB sector (they call it 
"block", std AMD erase cmd=0x30), and a 4KB sector (they call it "sector", 
erase cmd=0x50). Also, CFI query on these chips, reading from address 0x2dh 
of cfi query struct, detects a number of secotrs for the 4KB granularity
(flinfo shows it). 

For all other aspects, they are CFI compliant, so, as Linux do, i think 
it's a good idea to handle these chips in the CFI driver, with a fixup
to allow 4KB granularity, as should be expected, instead of 64KB.

Signed-off-by: Angelo Dureghello <sysamfw@gmail.com>
Cc: Stefan Rose <sr@denx.de>
---
 drivers/mtd/cfi_flash.c |   25 ++++++++++++++++++++++++-
 include/flash.h         |    1 +
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c
index b2dfc53..b46f1ca 100644
--- a/drivers/mtd/cfi_flash.c
+++ b/drivers/mtd/cfi_flash.c
@@ -1128,7 +1128,7 @@ int flash_erase (flash_info_t * info, int s_first, int s_last)
 						AMD_CMD_ERASE_START);
 				flash_unlock_seq (info, sect);
 				flash_write_cmd (info, sect, 0,
-						 AMD_CMD_ERASE_SECTOR);
+						 info->cmd_erase_sector);
 				break;
 #ifdef CONFIG_FLASH_CFI_LEGACY
 			case CFI_CMDSET_AMD_LEGACY:
@@ -1733,6 +1733,7 @@ static void cmdset_amd_read_jedec_ids(flash_info_t *info)
 static int cmdset_amd_init(flash_info_t *info, struct cfi_qry *qry)
 {
 	info->cmd_reset = AMD_CMD_RESET;
+	info->cmd_erase_sector = AMD_CMD_ERASE_SECTOR;
 
 	cmdset_amd_read_jedec_ids(info);
 	flash_write_cmd(info, 0, info->cfi_offset, FLASH_CMD_CFI);
@@ -2003,6 +2004,25 @@ static void flash_fixup_stm(flash_info_t *info, struct cfi_qry *qry)
 	}
 }
 
+static void flash_fixup_sst(flash_info_t *info, struct cfi_qry *qry)
+{
+	/*
+	 * SST, for many recent nor parallel flashes, says they are
+	 * CFI-conformant. This is not true, since qry struct. 
+	 * reports a std. AMD command set (0x0002), while SST allows to
+	 * erase two different sector sizes for the same memory.
+	 * 64KB sector (SST call it block)  needs 0x30 to be erased.
+	 * 4KB  sector (SST call it sector) needs 0x50 to be erased.
+	 * Since CFI query detect the 4KB number of sectors, users expects 
+	 * a sector granularity of 4KB, and it is here set.
+	 */ 
+	if (info->device_id == 0x5D23 || /* SST39VF3201B */
+	    info->device_id == 0x5C23) { /* SST39VF3202B */
+		/* set sector granularity to 4KB */	
+		info->cmd_erase_sector=0x50;
+	}
+}
+
 /*
  * The following code cannot be run from FLASH!
  *
@@ -2081,6 +2101,9 @@ ulong flash_get_size (phys_addr_t base, int banknum)
 		case 0x0020:
 			flash_fixup_stm(info, &qry);
 			break;
+		case 0x00bf: /* SST */
+			flash_fixup_sst(info, &qry);
+			break;
 		}
 
 		debug ("manufacturer is %d\n", info->vendor);
diff --git a/include/flash.h b/include/flash.h
index a04ce90..0ba2d33 100644
--- a/include/flash.h
+++ b/include/flash.h
@@ -44,6 +44,7 @@ typedef struct {
 	ulong	buffer_write_tout;	/* maximum buffer write timeout		*/
 	ushort	vendor;			/* the primary vendor id		*/
 	ushort	cmd_reset;		/* vendor specific reset command	*/
+	uchar   cmd_erase_sector;	/* vendor specific erase sect. command	*/
 	ushort	interface;		/* used for x8/x16 adjustments		*/
 	ushort	legacy_unlock;		/* support Intel legacy (un)locking	*/
 	ushort	manufacturer_id;	/* manufacturer id			*/

             reply	other threads:[~2012-12-01  0:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-01  0:14 Angelo Dureghello [this message]
2013-01-10 14:31 ` [U-Boot] [PATCH 1/1] mtd/cfi: add support for SST 4KB sector granularity Stefan Roese

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=20121201001417.GA643@angel3 \
    --to=sysamfw@gmail.com \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.