rename CFG_ENV macros to CONFIG_ENV
[platform/kernel/u-boot.git] / board / lwmon / flash.c
index 4004865..8d98545 100644 (file)
 #include <common.h>
 #include <mpc8xx.h>
 
-#if defined(CFG_ENV_IS_IN_FLASH)
-# ifndef  CFG_ENV_ADDR
-#  define CFG_ENV_ADDR (CFG_FLASH_BASE + CFG_ENV_OFFSET)
+#if defined(CONFIG_ENV_IS_IN_FLASH)
+# ifndef  CONFIG_ENV_ADDR
+#  define CONFIG_ENV_ADDR      (CFG_FLASH_BASE + CONFIG_ENV_OFFSET)
 # endif
-# ifndef  CFG_ENV_SIZE
-#  define CFG_ENV_SIZE CFG_ENV_SECT_SIZE
+# ifndef  CONFIG_ENV_SIZE
+#  define CONFIG_ENV_SIZE      CONFIG_ENV_SECT_SIZE
 # endif
-# ifndef  CFG_ENV_SECT_SIZE
-#  define CFG_ENV_SECT_SIZE  CFG_ENV_SIZE
+# ifndef  CONFIG_ENV_SECT_SIZE
+#  define CONFIG_ENV_SECT_SIZE  CONFIG_ENV_SIZE
 # endif
 #endif
 
@@ -130,11 +130,11 @@ unsigned long flash_init (void)
                      &flash_info[0]);
 #endif
 
-#ifdef CFG_ENV_IS_IN_FLASH
+#ifdef CONFIG_ENV_IS_IN_FLASH
        /* ENV protection ON by default */
        flash_protect(FLAG_PROTECT_SET,
-                     CFG_ENV_ADDR,
-                     CFG_ENV_ADDR+CFG_ENV_SECT_SIZE-1,
+                     CONFIG_ENV_ADDR,
+                     CONFIG_ENV_ADDR+CONFIG_ENV_SECT_SIZE-1,
                      &flash_info[0]);
 #endif
 
@@ -163,11 +163,11 @@ unsigned long flash_init (void)
                              &flash_info[1]);
 #endif
 
-#ifdef CFG_ENV_IS_IN_FLASH
+#ifdef CONFIG_ENV_IS_IN_FLASH
                /* ENV protection ON by default */
                flash_protect(FLAG_PROTECT_SET,
-                             CFG_ENV_ADDR,
-                             CFG_ENV_ADDR+CFG_ENV_SECT_SIZE-1,
+                             CONFIG_ENV_ADDR,
+                             CONFIG_ENV_ADDR+CONFIG_ENV_SECT_SIZE-1,
                              &flash_info[1]);
 #endif
        } else {
@@ -403,6 +403,26 @@ int        flash_erase (flash_info_t *info, int s_first, int s_last)
                        /* Disable interrupts which might cause a timeout here */
                        flag = disable_interrupts();
 
+                       *addr = 0x00600060;     /* clear lock bit setup */
+                       *addr = 0x00D000D0;     /* clear lock bit confirm */
+
+                       udelay (1000);
+                       /* This takes awfully long - up to 50 ms and more */
+                       while (((status = *addr) & 0x00800080) != 0x00800080) {
+                               if ((now=get_timer(start)) > CFG_FLASH_ERASE_TOUT) {
+                                       printf ("Timeout\n");
+                                       *addr = 0x00FF00FF; /* reset to read mode */
+                                       return 1;
+                               }
+
+                               /* show that we're waiting */
+                               if ((now - last) > 1000) {      /* every second */
+                                       putc ('.');
+                                       last = now;
+                               }
+                               udelay (1000);  /* to trigger the watchdog */
+                       }
+
                        *addr = 0x00500050;     /* clear status register */
                        *addr = 0x00200020;     /* erase setup */
                        *addr = 0x00D000D0;     /* erase confirm */
@@ -427,6 +447,7 @@ int flash_erase (flash_info_t *info, int s_first, int s_last)
                                        putc ('.');
                                        last = now;
                                }
+                               udelay (1000);  /* to trigger the watchdog */
                        }
 
                        *addr = 0x00FF00FF;     /* reset to read mode */