]> git.sur5r.net Git - u-boot/blobdiff - drivers/cfi_flash.c
* Code cleanup
[u-boot] / drivers / cfi_flash.c
index 7a7575b26861d91d4e35381ef080a7238aee06b6..e89f975ce6681dc7ac63c1fecf60a4c907ac2456 100644 (file)
@@ -46,6 +46,7 @@
 
 #include <common.h>
 #include <asm/processor.h>
+#include <asm/byteorder.h>
 #include <linux/byteorder/swab.h>
 #ifdef CFG_FLASH_CFI_DRIVER
 
 #define AMD_CMD_WRITE                  0xA0
 #define AMD_CMD_ERASE_START            0x80
 #define AMD_CMD_ERASE_SECTOR           0x30
+#define AMD_CMD_UNLOCK_START           0xAA
+#define AMD_CMD_UNLOCK_ACK             0x55
 
 #define AMD_STATUS_TOGGLE              0x40
 #define AMD_STATUS_ERROR               0x20
+#define AMD_ADDR_ERASE_START           0x555
+#define AMD_ADDR_START                 0x555
+#define AMD_ADDR_ACK                   0x2AA
 
 #define FLASH_OFFSET_CFI               0x55
 #define FLASH_OFFSET_CFI_RESP          0x10
@@ -344,11 +350,11 @@ int flash_erase (flash_info_t * info, int s_first, int s_last)
        flash_sect_t sect;
 
        if (info->flash_id != FLASH_MAN_CFI) {
-               printf ("Can't erase unknown flash type - aborted\n");
+               puts ("Can't erase unknown flash type - aborted\n");
                return 1;
        }
        if ((s_first < 0) || (s_first > s_last)) {
-               printf ("- no sectors to erase\n");
+               puts ("- no sectors to erase\n");
                return 1;
        }
 
@@ -361,7 +367,7 @@ int flash_erase (flash_info_t * info, int s_first, int s_last)
        if (prot) {
                printf ("- Warning: %d protected sectors will not be erased!\n", prot);
        } else {
-               printf ("\n");
+               putc ('\n');
        }
 
 
@@ -377,7 +383,8 @@ int flash_erase (flash_info_t * info, int s_first, int s_last)
                        case CFI_CMDSET_AMD_STANDARD:
                        case CFI_CMDSET_AMD_EXTENDED:
                                flash_unlock_seq (info, sect);
-                               flash_write_cmd (info, sect, 0x555, AMD_CMD_ERASE_START);
+                               flash_write_cmd (info, sect, AMD_ADDR_ERASE_START,
+                                                       AMD_CMD_ERASE_START);
                                flash_unlock_seq (info, sect);
                                flash_write_cmd (info, sect, 0, AMD_CMD_ERASE_SECTOR);
                                break;
@@ -391,10 +398,10 @@ int flash_erase (flash_info_t * info, int s_first, int s_last)
                            (info, sect, info->erase_blk_tout, "erase")) {
                                rcode = 1;
                        } else
-                               printf (".");
+                               putc ('.');
                }
        }
-       printf (" done\n");
+       puts (" done\n");
        return rcode;
 }
 
@@ -405,7 +412,7 @@ void flash_print_info (flash_info_t * info)
        int i;
 
        if (info->flash_id != FLASH_MAN_CFI) {
-               printf ("missing or unknown FLASH type\n");
+               puts ("missing or unknown FLASH type\n");
                return;
        }
 
@@ -419,7 +426,7 @@ void flash_print_info (flash_info_t * info)
                info->buffer_write_tout,
                info->buffer_size);
 
-       printf ("  Sector Start Addresses:");
+       puts ("  Sector Start Addresses:");
        for (i = 0; i < info->sector_count; ++i) {
 #ifdef CFG_FLASH_EMPTY_INFO
                int k;
@@ -455,10 +462,10 @@ void flash_print_info (flash_info_t * info)
                if ((i % 5) == 0)
                        printf ("\n   ");
                printf (" %08lX%s",
-                       info->start[i], info->protect[i] ? " (RO)" : "     ");
+                       info->start[i], info->protect[i] ? " (RO)" : "     ");
 #endif
        }
-       printf ("\n");
+       putc ('\n');
        return;
 }
 
@@ -479,24 +486,6 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
 #ifdef CFG_FLASH_USE_BUFFER_WRITE
        int buffered_size;
 #endif
-       int x8mode = 0;
-
-       /* special handling of 16 bit devices in 8 bit mode */
-       if ((info->interface == FLASH_CFI_X8X16)
-           && (info->chipwidth == FLASH_CFI_BY8)) {
-               switch (info->vendor) {
-               case CFI_CMDSET_INTEL_STANDARD:
-               case CFI_CMDSET_INTEL_EXTENDED:
-                       x8mode = info->portwidth;
-                       info->portwidth >>= 1;  /* XXX - Need to test on x9/x16 in parallel. */
-                       /*info->portwidth = FLASH_CFI_8BIT; */ /* XXX - Need to test on x9/x16 in parallel. */
-                       break;
-               case CFI_CMDSET_AMD_STANDARD:
-               case CFI_CMDSET_AMD_EXTENDED:
-               default:
-                       break;
-               }
-       }
        /* get lower aligned address */
        /* get lower aligned address */
        wp = (addr & ~(info->portwidth - 1));
@@ -560,10 +549,6 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
                flash_add_byte (info, &cword, (*(uchar *) cp));
        }
 
-       /* special handling of 16 bit devices in 8 bit mode */
-       if (x8mode) {
-               info->portwidth = x8mode;;
-       }
        return flash_write_cfiword (info, wp, cword);
 }
 
@@ -698,19 +683,19 @@ static int flash_full_status_check (flash_info_t * info, flash_sect_t sector,
                        printf ("Flash %s error at address %lx\n", prompt,
                                info->start[sector]);
                        if (flash_isset (info, sector, 0, FLASH_STATUS_ECLBS | FLASH_STATUS_PSLBS)) {
-                               printf ("Command Sequence Error.\n");
+                               puts ("Command Sequence Error.\n");
                        } else if (flash_isset (info, sector, 0, FLASH_STATUS_ECLBS)) {
-                               printf ("Block Erase Error.\n");
+                               puts ("Block Erase Error.\n");
                                retcode = ERR_NOT_ERASED;
                        } else if (flash_isset (info, sector, 0, FLASH_STATUS_PSLBS)) {
-                               printf ("Locking Error\n");
+                               puts ("Locking Error\n");
                        }
                        if (flash_isset (info, sector, 0, FLASH_STATUS_DPS)) {
-                               printf ("Block locked.\n");
+                               puts ("Block locked.\n");
                                retcode = ERR_PROTECTED;
                        }
                        if (flash_isset (info, sector, 0, FLASH_STATUS_VPENS))
-                               printf ("Vpp Low Error.\n");
+                               puts ("Vpp Low Error.\n");
                }
                flash_write_cmd (info, sector, 0, FLASH_CMD_RESET);
                break;
@@ -793,7 +778,7 @@ static void flash_make_cmd (flash_info_t * info, uchar cmd, void *cmdbuf)
                *(uint *) cmdbuf = __swab32 (stmpi);
                break;
        default:
-               printf("WARNING: flash_make_cmd: unsuppported LittleEndian mode\n");
+               puts ("WARNING: flash_make_cmd: unsuppported LittleEndian mode\n");
                break;
        }
 #endif
@@ -847,8 +832,8 @@ static void flash_write_cmd (flash_info_t * info, flash_sect_t sect, uint offset
 
 static void flash_unlock_seq (flash_info_t * info, flash_sect_t sect)
 {
-       flash_write_cmd (info, sect, 0x555, 0xAA);
-       flash_write_cmd (info, sect, 0x2AA, 0x55);
+       flash_write_cmd (info, sect, AMD_ADDR_START, AMD_CMD_UNLOCK_START);
+       flash_write_cmd (info, sect, AMD_ADDR_ACK, AMD_CMD_UNLOCK_ACK);
 }
 
 /*-----------------------------------------------------------------------
@@ -1054,7 +1039,7 @@ static ulong flash_get_size (ulong base, int banknum)
                                (tmp & 0xffff) ? ((tmp & 0xffff) * 256) : 128;
                        tmp >>= 16;
                        erase_region_count = (tmp & 0xffff) + 1;
-                       printf ("erase_region_count = %d erase_region_size = %d\n",
+                       debug ("erase_region_count = %d erase_region_size = %d\n",
                                erase_region_count, erase_region_size);
                        for (j = 0; j < erase_region_count; j++) {
                                info->start[sect_cnt] = sector;
@@ -1078,6 +1063,9 @@ static ulong flash_get_size (ulong base, int banknum)
                tmp = 1 << flash_read_uchar (info, FLASH_OFFSET_WTOUT);
                info->write_tout = (tmp * (1 << flash_read_uchar (info, FLASH_OFFSET_WMAX_TOUT))) / 1000;
                info->flash_id = FLASH_MAN_CFI;
+               if ((info->interface == FLASH_CFI_X8X16) && (info->chipwidth == FLASH_CFI_BY8)) {
+                       info->portwidth >>= 1;  /* XXX - Need to test on x8/x16 in parallel. */
+               }
        }
 
        flash_write_cmd (info, 0, 0, FLASH_CMD_RESET);
@@ -1131,7 +1119,7 @@ static int flash_write_cfiword (flash_info_t * info, ulong dest,
        case CFI_CMDSET_AMD_EXTENDED:
        case CFI_CMDSET_AMD_STANDARD:
                flash_unlock_seq (info, 0);
-               flash_write_cmd (info, 0, 0x555, AMD_CMD_WRITE);
+               flash_write_cmd (info, 0, AMD_ADDR_START, AMD_CMD_WRITE);
                break;
        }
 
@@ -1182,6 +1170,10 @@ static int flash_write_cfibuffer (flash_info_t * info, ulong dest, uchar * cp,
        int retcode;
        volatile cfiptr_t src;
        volatile cfiptr_t dst;
+       /* buffered writes in the AMD chip set is not supported yet */
+       if((info->vendor ==  CFI_CMDSET_AMD_STANDARD) ||
+               (info->vendor == CFI_CMDSET_AMD_EXTENDED))
+               return ERR_INVAL;
 
        src.cp = cp;
        dst.cp = (uchar *) dest;