--- cfi_cmdset_0002.c	2008/06/26 08:45:52	1.1
+++ cfi_cmdset_0002.c	2008/06/27 12:42:31	1.2
@@ -17,7 +17,7 @@
  *
  * This code is GPL
  *
- * $Id: cfi_cmdset_0002.c,v 1.1 2008/06/26 08:45:52 pt Exp $
+ * $Id: cfi_cmdset_0002.c,v 1.2 2008/06/27 12:42:31 pt Exp $
  *
  */
 
@@ -220,6 +220,46 @@
 	mtd->flags |= MTD_POWERUP_LOCK;
 }
 
+/** While reporting a mostly-correct CFI-Information block
+  * the eraseblock-region information is severely damaged in SST 
+  * parts at least those of the 39VF64xxxB series.
+  * Furthermore they do not support the extended Query-Table 
+  * so we should claim the device is just a JEDEC part. 
+  **/
+static void fixup_sst_cfi(struct mtd_info *mtd, void *param)
+{
+	struct map_info *map = mtd->priv;
+	struct cfi_private *cfi = map->fldrv_priv;
+		
+	  	 cfi->cfi_mode=CFI_MODE_JEDEC;
+		 /** Although the part claims to have two eraseblock-regions
+		   * these refer to the same region within the flash-array.
+		   * Because a really CFI-Compliant part may only return
+		   * one eraseblock-length per physical memory region
+		   * we pretend the part said it had just one region ;)
+		   **/
+		 cfi->cfiq->NumEraseRegions = 1;
+		 mtd->numeraseregions = 1; // Assuming only one chip on the bus
+		 /*Calculate size of one sector, SST stores information 
+		  * about the width of a _sector_ as eraseblock-region 0
+		  **/
+		 mtd->erasesize = ((cfi->cfiq->EraseRegionInfo[1] >> 8) & ~0xff);
+		 mtd->eraseregions[0].offset = 0;
+		 mtd->eraseregions[0].erasesize = mtd->erasesize;
+		 mtd->eraseregions[0].numblocks = (cfi->cfiq->EraseRegionInfo[1] & 0xffff) + 1;
+                cfi->addr_unlock1 = 0x555;
+		cfi->addr_unlock2 = 0x2aa;
+}
+
+/** Used to fix very broken CFI-Tables of SST 39-Series parts
+  * to work with our driver
+  **/
+static struct cfi_fixup cfi_early_fixup_table[] = {
+	{ MANUFACTURER_SST, 0x236C, fixup_sst_cfi,  NULL, }, // SST39VF6402B
+	{ MANUFACTURER_SST, 0x236D, fixup_sst_cfi,  NULL, }, // SST39VF6401B
+	 { 0, 0, NULL, NULL }
+};
+
 static struct cfi_fixup cfi_fixup_table[] = {
 	{ CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL },
 #ifdef AMD_BOOTLOC_BUG
@@ -243,6 +283,7 @@
 	{ 0, 0, NULL, NULL }
 };
 
+
 static struct cfi_fixup fixup_table[] = {
 	/* The CFI vendor ids and the JEDEC vendor IDs appear
 	 * to be common.  It is like the devices id's are as
@@ -279,6 +320,8 @@
 	mtd->flags   = MTD_CAP_NORFLASH;
 	mtd->name    = map->name;
 	mtd->writesize = 1;
+	
+	cfi_fixup(mtd, cfi_early_fixup_table);
 
 	if (cfi->cfi_mode==CFI_MODE_CFI){
 		unsigned char bootloc;
