* Fix a bunch of compiler warnings for gcc 4.0
[oweals/u-boot.git] / board / trab / flash.c
index 764c57b482fc7e06ffe4d26974f8c12c625f85b8..3e8f105a0316632fc435c3f955e7e427cf4d5479 100644 (file)
@@ -83,6 +83,7 @@ ulong flash_init (void)
 
                        switch (info->flash_id & FLASH_TYPEMASK) {
                        case (FLASH_AM320B & FLASH_TYPEMASK):
+                       case (FLASH_MXLV320B & FLASH_TYPEMASK):
                                /* Boot sector type: 8 x 8 + N x 128 kB */
                                flashbase += (j < 8) ? 0x4000 : 0x20000;
                                break;
@@ -130,6 +131,8 @@ void flash_print_info (flash_info_t * info)
                        printf ("AMD ");                break;
        case (FLASH_MAN_FUJ & FLASH_VENDMASK):
                        printf ("FUJITSU ");            break;
+       case (FLASH_MAN_MX  & FLASH_VENDMASK):
+                       printf ("MACRONIX ");           break;
        default:        printf ("Unknown Vendor ");     break;
        }
 
@@ -137,6 +140,9 @@ void flash_print_info (flash_info_t * info)
        case (FLASH_AM320B & FLASH_TYPEMASK):
                printf ("2x Am29LV320DB (32Mbit)\n");
                break;
+       case (FLASH_MXLV320B & FLASH_TYPEMASK):
+               printf ("2x MX29LV320DB (32Mbit)\n");
+               break;
        case (FLASH_AM640U & FLASH_TYPEMASK):
                printf ("2x Am29LV640D (64Mbit)\n");
                break;
@@ -160,7 +166,7 @@ void flash_print_info (flash_info_t * info)
        }
        printf ("\n");
 
-  Done:
+Done:  ;
 }
 
 /*-----------------------------------------------------------------------
@@ -191,6 +197,7 @@ int flash_erase (flash_info_t * info, int s_first, int s_last)
        switch (info->flash_id & FLASH_VENDMASK) {
        case (FLASH_MAN_AMD & FLASH_VENDMASK):  break;  /* OK */
        case (FLASH_MAN_FUJ & FLASH_VENDMASK):  break;  /* OK */
+       case (FLASH_MAN_MX  & FLASH_VENDMASK):  break;  /* OK */
        default:
                debug ("## flash_erase: unknown manufacturer\n");
                return (ERR_UNKNOWN_FLASH_VENDOR);
@@ -274,10 +281,12 @@ int flash_erase (flash_info_t * info, int s_first, int s_last)
 
                        if (chip1 == ERR || chip2 == ERR) {
                                rc = ERR_PROG_ERROR;
+                               printf ("Flash erase error\n");
                                goto outahere;
                        }
                        if (chip1 == TMO) {
                                rc = ERR_TIMOUT;
+                               printf ("Flash erase timeout error\n");
                                goto outahere;
                        }
                }
@@ -301,8 +310,7 @@ outahere:
  * Copy memory to flash
  */
 
-volatile static int write_word (flash_info_t * info, ulong dest,
-                                                               ulong data)
+static int write_word (flash_info_t * info, ulong dest, ulong data)
 {
        vu_long *addr = (vu_long *) dest;
        ulong result;
@@ -334,7 +342,9 @@ volatile static int write_word (flash_info_t * info, ulong dest,
 #endif
        iflag = disable_interrupts ();
 
-       *addr = CMD_PROGRAM;
+       MEM_FLASH_ADDR1 = CMD_UNLOCK1;
+       MEM_FLASH_ADDR2 = CMD_UNLOCK2;
+       MEM_FLASH_ADDR1 = CMD_PROGRAM;
        *addr = data;
 
        /* arm simple, non interrupt dependent timer */
@@ -346,7 +356,7 @@ volatile static int write_word (flash_info_t * info, ulong dest,
                result = *addr;
 
                /* check timeout */
-               if (get_timer_masked () > CFG_FLASH_ERASE_TOUT) {
+               if (get_timer_masked () > CFG_FLASH_WRITE_TOUT) {
                        chip1 = ERR | TMO;
                        break;
                }
@@ -378,8 +388,13 @@ volatile static int write_word (flash_info_t * info, ulong dest,
 
        *addr = CMD_READ_ARRAY;
 
-       if (chip1 == ERR || chip2 == ERR || *addr != data)
+       if (chip1 == ERR || chip2 == ERR || *addr != data) {
                rc = ERR_PROG_ERROR;
+               printf ("Flash program error\n");
+               debug ("chip1: %#x, chip2: %#x, addr: %#lx *addr: %#lx, "
+                      "data: %#lx\n",
+                      chip1, chip2, addr, *addr, data);
+       }
 
        if (iflag)
                enable_interrupts ();
@@ -402,10 +417,6 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
        int l;
        int i, rc;
 
-       MEM_FLASH_ADDR1 = CMD_UNLOCK1;
-       MEM_FLASH_ADDR2 = CMD_UNLOCK2;
-       MEM_FLASH_ADDR1 = CMD_UNLOCK_BYPASS;
-
        wp = (addr & ~3);       /* get lower word aligned address */
 
        /*
@@ -473,9 +484,6 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
 
        Done:
 
-       MEM_FLASH_ADDR = CMD_UNLOCK_BYPASS_RES1;
-       MEM_FLASH_ADDR = CMD_UNLOCK_BYPASS_RES2;
-
        return (rc);
 }
 
@@ -502,11 +510,14 @@ static ulong flash_get_size (vu_long *addr, flash_info_t *info)
        case FUJ_MANUFACT:
                info->flash_id = FLASH_MAN_FUJ;
                break;
+       case MX_MANUFACT:
+               info->flash_id = FLASH_MAN_MX;
+               break;
        default:
                info->flash_id = FLASH_UNKNOWN;
                info->sector_count = 0;
                info->size = 0;
-               addr[0] = 0x00FF00FF;           /* restore read mode */
+               addr[0] = CMD_READ_ARRAY;       /* restore read mode */
                debug ("## flash_init: unknown manufacturer\n");
                return (0);                     /* no or unknown flash  */
        }
@@ -521,7 +532,7 @@ static ulong flash_get_size (vu_long *addr, flash_info_t *info)
                info->sector_count = 71;
                info->size = 0x00800000;
 
-               addr[0] = 0x00FF00FF;           /* restore read mode */
+               addr[0] = CMD_READ_ARRAY;       /* restore read mode */
                break;                          /* =>  8 MB             */
 
        case AMD_ID_LV640U:
@@ -529,13 +540,21 @@ static ulong flash_get_size (vu_long *addr, flash_info_t *info)
                info->sector_count = 128;
                info->size = 0x01000000;
 
-               addr[0] = 0x00F000F0;           /* restore read mode */
+               addr[0] = CMD_READ_ARRAY;       /* restore read mode */
                break;                          /* => 16 MB             */
 
+       case MX_ID_LV320B:
+               info->flash_id += FLASH_MXLV320B;
+               info->sector_count = 71;
+               info->size = 0x00800000;
+
+               addr[0] = CMD_READ_ARRAY;       /* restore read mode */
+               break;                          /* =>  8 MB             */
+
        default:
                debug ("## flash_init: unknown flash chip\n");
                info->flash_id = FLASH_UNKNOWN;
-               addr[0] = 0x00FF00FF;           /* restore read mode */
+               addr[0] = CMD_READ_ARRAY;       /* restore read mode */
                return (0);                     /* => no or unknown flash */
 
        }