Revert "Revert "and added files""
[bcm963xx.git] / bcmdrivers / opensource / char / board / bcm963xx / impl1 / cfiflash.c
index cc0bca1..5002bc8 100755 (executable)
@@ -43,6 +43,8 @@
 
 #include "cfiflash.h"
 
+#define USR9108
+
 static int flash_wait(WORD sector, int offset, UINT16 data);
 static UINT16 flash_get_device_id(void);
 static int flash_get_cfi(struct cfi_query *query, UINT16 *cfi_struct, int flashFamily);
@@ -127,6 +129,7 @@ byte flash_init(void)
     flash_command(FLASH_RESET, 0, 0, 0);
 
     device_id = flash_get_device_id();
+
     switch (device_id) {
         case ID_I28F160C3B:
         case ID_I28F320C3B:
@@ -136,7 +139,7 @@ byte flash_init(void)
             break;
         case ID_AM29DL800B:
         case ID_AM29LV800B:
-//        case ID_AM29LV400B:   
+        case ID_AM29LV400B:   
         case ID_AM29LV160B:
         case ID_AM29LV320B:
         case ID_MX29LV320AB:
@@ -147,11 +150,17 @@ byte flash_init(void)
         case ID_AM29LV320T:
         case ID_MX29LV320AT:
         case ID_AM29LV320MT:
-        case ID_W19L320STT9C:
+    // add ST flash device id  here           
+        case ID_M29W320ET:
+    // add ST flash device id  here        
+        
             flashFamily = FLASH_AMD;
             break;
         case ID_SST39VF1601:
                case ID_SST39VF3201:
+    // add SST flash device id  here        
+               case ID_SST39VF3202:
+    // add SST flash device id  here        
             flashFamily = FLASH_SST;
             break;
         default:
@@ -176,7 +185,7 @@ byte flash_init(void)
     {
         case ID_AM29DL800B:
         case ID_AM29LV800B:
-//        case ID_AM29LV400B:   
+        case ID_AM29LV400B:   
         case ID_AM29LV160B:
         case ID_AM29LV320B:
         case ID_MX29LV320AB:
@@ -195,7 +204,11 @@ byte flash_init(void)
         case ID_AM29LV320T:
         case ID_MX29LV320AT:
         case ID_AM29LV320MT:
-        case ID_W19L320STT9C:
+    // add SST and ST flash device id  here           
+        case ID_SST39VF3202:
+        case ID_M29W320ET:
+    // add SST and ST flash device id  here                         
+        
             flipCFIGeometry = TRUE;
             break;
         default:
@@ -291,29 +304,17 @@ int flash_write_buf(WORD sector, int offset, byte *buffer, int numbytes)
      */
     for( i = 0; i < 3; i++ ) {
         ret = flash_write(sector, offset, buffer, numbytes);
-        if( !memcmp( p, buffer, numbytes ) ) {
+        if( !memcmp( p, buffer, numbytes ) )
             break;
-        }
         /* Erase and try again */
         flash_sector_erase_int(sector);
+        printk("CFIFLASH: Rewriting sector %d\n", sector);
         ret = -1;
     }
 
     if( ret == -1 )
         printk( "Flash write error.  Verify failed\n" );
 
-/*
-  if( ret == -1 ) {
-    int ii;
-    for( ii=0; ii<(numbytes<10 ? numbytes:10); ii++)
-        printk("%x ", *(p+ii));
-    printk("\n");
-    for(ii=0; ii<(numbytes<10 ? numbytes:10); ii++)
-        printk("%x ", *(buffer+ii));
-    printk("\n");
- }
-*/
-
     return( ret );
 }
 
@@ -583,7 +584,7 @@ static int flash_write(WORD sector, int offset, byte *buf, int nbytes)
 static int flash_wait(WORD sector, int offset, UINT16 data)
 {
     volatile UINT16 *flashptr; /* flash window */
-    UINT16 d1;
+    UINT16 d1, dlast;
 
     flashptr = (UINT16 *) flash_get_memptr(sector);
 
@@ -602,17 +603,31 @@ static int flash_wait(WORD sector, int offset, UINT16 data)
             return STATUS_TIMEOUT;
         }
 #else
+  #ifdef USR9108
+        dlast = *flashptr;     // read the first data word outside the loop 
+        do {
+            d1 = dlast;                // temp store the last read word.       
+            dlast = *flashptr;  // read data again to check for toggled bits
+            if (!((d1 ^ dlast) & 0x44))  // if bits 6 & 2 are not tuggled, return with success.
+                return STATUS_READY;
+  // use actual last read word to check bit 5 according to the flash data sheets
+        } while (!(dlast & 0x20)); // continue if bit 5 is zero 
+  #else 
         do {
             d1 = *flashptr;    /* read data */
             d1 ^= *flashptr;   /* read it again and see what toggled */
             if (d1 == 0)       /* no toggles, nothing's happening */
                 return STATUS_READY;
         } while (!(d1 & 0x20));
+  #endif
 
         d1 = *flashptr;        /* read data */
         d1 ^= *flashptr;   /* read it again and see what toggled */
-
+  #ifdef USR9108  
+        if ((d1 & 0x44)) {
+  #else
         if (d1 != 0) {
+  #endif
             flash_command(FLASH_RESET, 0, 0, 0);
             return STATUS_TIMEOUT;
         }