]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/mtd/cfi_flash.c
rename CFG_ENV macros to CONFIG_ENV
[karo-tx-uboot.git] / drivers / mtd / cfi_flash.c
index c0ea97be70ec2316530d665bb9b76625e9c1cce8..0d1ee8a459d0cd01d5880ae4a92ce1c8e64fded7 100644 (file)
@@ -39,7 +39,6 @@
 #include <asm/io.h>
 #include <asm/byteorder.h>
 #include <environment.h>
-#ifdef CFG_FLASH_CFI_DRIVER
 
 /*
  * This file implements a Common Flash Interface (CFI) driver for
 #define AMD_STATUS_TOGGLE              0x40
 #define AMD_STATUS_ERROR               0x20
 
+#define ATM_CMD_UNLOCK_SECT            0x70
+#define ATM_CMD_SOFTLOCK_START         0x80
+#define ATM_CMD_LOCK_SECT              0x40
+
 #define FLASH_OFFSET_MANUFACTURER_ID   0x00
 #define FLASH_OFFSET_DEVICE_ID         0x01
 #define FLASH_OFFSET_DEVICE_ID2                0x0E
@@ -158,13 +161,13 @@ static uint flash_offset_cfi[2] = { FLASH_OFFSET_CFI, FLASH_OFFSET_CFI_ALT };
 
 /* use CFG_MAX_FLASH_BANKS_DETECT if defined */
 #ifdef CFG_MAX_FLASH_BANKS_DETECT
-static ulong bank_base[CFG_MAX_FLASH_BANKS_DETECT] = CFG_FLASH_BANKS_LIST;
-flash_info_t flash_info[CFG_MAX_FLASH_BANKS_DETECT];   /* FLASH chips info */
+# define CFI_MAX_FLASH_BANKS   CFG_MAX_FLASH_BANKS_DETECT
 #else
-static ulong bank_base[CFG_MAX_FLASH_BANKS] = CFG_FLASH_BANKS_LIST;
-flash_info_t flash_info[CFG_MAX_FLASH_BANKS];          /* FLASH chips info */
+# define CFI_MAX_FLASH_BANKS   CFG_MAX_FLASH_BANKS
 #endif
 
+flash_info_t flash_info[CFI_MAX_FLASH_BANKS];  /* FLASH chips info */
+
 /*
  * Check if chip width is defined. If not, start detecting with 8bit.
  */
@@ -252,7 +255,7 @@ u64 flash_read64(void *addr)__attribute__((weak, alias("__flash_read64")));
 
 /*-----------------------------------------------------------------------
  */
-#if defined(CFG_ENV_IS_IN_FLASH) || defined(CFG_ENV_ADDR_REDUND) || (CFG_MONITOR_BASE >= CFG_FLASH_BASE)
+#if defined(CONFIG_ENV_IS_IN_FLASH) || defined(CONFIG_ENV_ADDR_REDUND) || (CFG_MONITOR_BASE >= CFG_FLASH_BASE)
 static flash_info_t *flash_get_info(ulong base)
 {
        int i;
@@ -301,11 +304,14 @@ static inline void flash_unmap(flash_info_t *info, flash_sect_t sect,
 /*-----------------------------------------------------------------------
  * make a proper sized command based on the port and chip widths
  */
-static void flash_make_cmd (flash_info_t * info, ulong cmd, void *cmdbuf)
+static void flash_make_cmd(flash_info_t *info, u32 cmd, void *cmdbuf)
 {
        int i;
        int cword_offset;
        int cp_offset;
+#if defined(__LITTLE_ENDIAN) || defined(CFG_WRITE_SWAPPED_DATA)
+       u32 cmd_le = cpu_to_le32(cmd);
+#endif
        uchar val;
        uchar *cp = (uchar *) cmdbuf;
 
@@ -313,12 +319,12 @@ static void flash_make_cmd (flash_info_t * info, ulong cmd, void *cmdbuf)
                cword_offset = (info->portwidth-i)%info->chipwidth;
 #if defined(__LITTLE_ENDIAN) || defined(CFG_WRITE_SWAPPED_DATA)
                cp_offset = info->portwidth - i;
-               val = *((uchar*)&cmd + cword_offset);
+               val = *((uchar*)&cmd_le + cword_offset);
 #else
                cp_offset = i - 1;
-               val = *((uchar*)&cmd + sizeof(ulong) - cword_offset - 1);
+               val = *((uchar*)&cmd + sizeof(u32) - cword_offset - 1);
 #endif
-               cp[cp_offset] = (cword_offset >= sizeof(ulong)) ? 0x00 : val;
+               cp[cp_offset] = (cword_offset >= sizeof(u32)) ? 0x00 : val;
        }
 }
 
@@ -433,7 +439,7 @@ static ulong flash_read_long (flash_info_t * info, flash_sect_t sect,
  * Write a proper sized command to the correct address
  */
 static void flash_write_cmd (flash_info_t * info, flash_sect_t sect,
-                            uint offset, ulong cmd)
+                            uint offset, u32 cmd)
 {
 
        void *addr;
@@ -510,7 +516,7 @@ static int flash_isequal (flash_info_t * info, flash_sect_t sect,
                retval = (flash_read16(addr) == cword.w);
                break;
        case FLASH_CFI_32BIT:
-               debug ("is= %8.8lx %8.8lx\n", flash_read32(addr), cword.l);
+               debug ("is= %8.8x %8.8lx\n", flash_read32(addr), cword.l);
                retval = (flash_read32(addr) == cword.l);
                break;
        case FLASH_CFI_64BIT:
@@ -1348,12 +1354,52 @@ int flash_real_protect (flash_info_t * info, long sector, int prot)
 {
        int retcode = 0;
 
-       flash_write_cmd (info, sector, 0, FLASH_CMD_CLEAR_STATUS);
-       flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT);
-       if (prot)
-               flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT_SET);
-       else
-               flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT_CLEAR);
+       switch (info->vendor) {
+               case CFI_CMDSET_INTEL_PROG_REGIONS:
+               case CFI_CMDSET_INTEL_STANDARD:
+               case CFI_CMDSET_INTEL_EXTENDED:
+                       flash_write_cmd (info, sector, 0,
+                                        FLASH_CMD_CLEAR_STATUS);
+                       flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT);
+                       if (prot)
+                               flash_write_cmd (info, sector, 0,
+                                       FLASH_CMD_PROTECT_SET);
+                       else
+                               flash_write_cmd (info, sector, 0,
+                                       FLASH_CMD_PROTECT_CLEAR);
+                       break;
+               case CFI_CMDSET_AMD_EXTENDED:
+               case CFI_CMDSET_AMD_STANDARD:
+                       /* U-Boot only checks the first byte */
+                       if (info->manufacturer_id == (uchar)ATM_MANUFACT) {
+                               if (prot) {
+                                       flash_unlock_seq (info, 0);
+                                       flash_write_cmd (info, 0,
+                                                       info->addr_unlock1,
+                                                       ATM_CMD_SOFTLOCK_START);
+                                       flash_unlock_seq (info, 0);
+                                       flash_write_cmd (info, sector, 0,
+                                                       ATM_CMD_LOCK_SECT);
+                               } else {
+                                       flash_write_cmd (info, 0,
+                                                       info->addr_unlock1,
+                                                       AMD_CMD_UNLOCK_START);
+                                       if (info->device_id == ATM_ID_BV6416)
+                                               flash_write_cmd (info, sector,
+                                                       0, ATM_CMD_UNLOCK_SECT);
+                               }
+                       }
+                       break;
+#ifdef CONFIG_FLASH_CFI_LEGACY
+               case CFI_CMDSET_AMD_LEGACY:
+                       flash_write_cmd (info, sector, 0, FLASH_CMD_CLEAR_STATUS);
+                       flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT);
+                       if (prot)
+                               flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT_SET);
+                       else
+                               flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT_CLEAR);
+#endif
+       };
 
        if ((retcode =
             flash_full_status_check (info, sector, info->erase_blk_tout,
@@ -1909,12 +1955,14 @@ unsigned long flash_init (void)
        char *s = getenv("unlock");
 #endif
 
+#define BANK_BASE(i)   (((unsigned long [CFI_MAX_FLASH_BANKS])CFG_FLASH_BANKS_LIST)[i])
+
        /* Init: no FLASHes known */
        for (i = 0; i < CFG_MAX_FLASH_BANKS; ++i) {
                flash_info[i].flash_id = FLASH_UNKNOWN;
 
-               if (!flash_detect_legacy (bank_base[i], i))
-                       flash_get_size (bank_base[i], i);
+               if (!flash_detect_legacy (BANK_BASE(i), i))
+                       flash_get_size (BANK_BASE(i), i);
                size += flash_info[i].size;
                if (flash_info[i].flash_id == FLASH_UNKNOWN) {
 #ifndef CFG_FLASH_QUIET_TEST
@@ -1983,19 +2031,19 @@ unsigned long flash_init (void)
 #endif
 
        /* Environment protection ON by default */
-#ifdef CFG_ENV_IS_IN_FLASH
+#ifdef CONFIG_ENV_IS_IN_FLASH
        flash_protect (FLAG_PROTECT_SET,
-                      CFG_ENV_ADDR,
-                      CFG_ENV_ADDR + CFG_ENV_SECT_SIZE - 1,
-                      flash_get_info(CFG_ENV_ADDR));
+                      CONFIG_ENV_ADDR,
+                      CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
+                      flash_get_info(CONFIG_ENV_ADDR));
 #endif
 
        /* Redundant environment protection ON by default */
-#ifdef CFG_ENV_ADDR_REDUND
+#ifdef CONFIG_ENV_ADDR_REDUND
        flash_protect (FLAG_PROTECT_SET,
-                      CFG_ENV_ADDR_REDUND,
-                      CFG_ENV_ADDR_REDUND + CFG_ENV_SIZE_REDUND - 1,
-                      flash_get_info(CFG_ENV_ADDR_REDUND));
+                      CONFIG_ENV_ADDR_REDUND,
+                      CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SIZE_REDUND - 1,
+                      flash_get_info(CONFIG_ENV_ADDR_REDUND));
 #endif
 
 #if defined(CFG_FLASH_AUTOPROTECT_LIST)
@@ -2010,5 +2058,3 @@ unsigned long flash_init (void)
 #endif
        return (size);
 }
-
-#endif /* CFG_FLASH_CFI */