* Patch by Rahul Shanbhag, 28 Jan 2004:
[platform/kernel/u-boot.git] / board / omap1610inn / flash.c
index 0108545..ae7fb3b 100644 (file)
@@ -54,7 +54,6 @@ flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips    */
 #define mb() __asm__ __volatile__ ("" : : : "memory")
 
 
-
 /* Flash Organization Structure */
 typedef struct OrgDef {
        unsigned int sector_number;
@@ -94,6 +93,8 @@ unsigned long flash_init (void)
                case 0:
                        flash_get_size ((FPW *) PHYS_FLASH_1, &flash_info[i]);
                        flash_get_offsets (PHYS_FLASH_1, &flash_info[i]);
+                       /* to reset the lock bit */
+                       flash_unlock(&flash_info[i]);
                        break;
                default:
                        panic ("configured too many flash banks!\n");
@@ -117,6 +118,19 @@ unsigned long flash_init (void)
 
 /*-----------------------------------------------------------------------
  */
+flash_unlock(flash_info_t * info)
+{
+        int j;
+        for (j=2;j<CFG_MAX_FLASH_SECT;j++){
+        FPWV *addr = (FPWV *) (info->start[j]);
+        flash_unprotect_sectors (addr);
+        *addr = (FPW) 0x00500050;/* clear status register */
+        *addr = (FPW) 0x00FF00FF;/* resest to read mode */
+        }
+}
+
+/*-----------------------------------------------------------------------
+ */
 static void flash_get_offsets (ulong base, flash_info_t * info)
 {
        int i;
@@ -240,8 +254,6 @@ static ulong flash_get_size (FPW * addr, flash_info_t * info)
 }
 
 
-
-
 /* unprotects a sector for write and erase
  * on some intel parts, this unprotects the entire chip, but it
  * wont hurt to call this additional times per sector...
@@ -298,8 +310,6 @@ int flash_erase (flash_info_t * info, int s_first, int s_last)
        }
 
 
-
-
        start = get_timer (0);
        last = start;
 
@@ -326,7 +336,7 @@ int flash_erase (flash_info_t * info, int s_first, int s_last)
                        while (((status =
                                *addr) & (FPW) 0x00800080) !=
                                (FPW) 0x00800080) {
-                                       if (get_timer_masked () > 
+                                       if (get_timer_masked () >
                                        CFG_FLASH_ERASE_TOUT) {
                                        printf ("Timeout\n");
                                        /* suspend erase     */
@@ -452,7 +462,6 @@ static int write_data (flash_info_t * info, ulong dest, FPW data)
                printf ("not erased at %08lx (%x)\n", (ulong) addr, *addr);
                return (2);
        }
-       flash_unprotect_sectors (addr);
        /* Disable interrupts which might cause a timeout here */
        flag = disable_interrupts ();
        *addr = (FPW) 0x00400040;       /* write setup */