]> git.sur5r.net Git - u-boot/blobdiff - drivers/mtd/cfi_flash.c
CFI: Small cleanup for FLASH_SHOW_PROGRESS
[u-boot] / drivers / mtd / cfi_flash.c
index 4f61e365e84ec448e2e1a02d0ab4443fe3f37ef1..f04c72d05a33bc6a2c0e2f6cefb660e001994416 100644 (file)
@@ -1179,6 +1179,27 @@ void flash_print_info (flash_info_t * info)
        return;
 }
 
+/*-----------------------------------------------------------------------
+ * This is used in a few places in write_buf() to show programming
+ * progress.  Making it a function is nasty because it needs to do side
+ * effect updates to digit and dots.  Repeated code is nasty too, so
+ * we define it once here.
+ */
+#ifdef CONFIG_FLASH_SHOW_PROGRESS
+#define FLASH_SHOW_PROGRESS(scale, dots, digit, dots_sub) \
+       dots -= dots_sub; \
+       if ((scale > 0) && (dots <= 0)) { \
+               if ((digit % 5) == 0) \
+                       printf ("%d", digit / 5); \
+               else \
+                       putc ('.'); \
+               digit--; \
+               dots += scale; \
+       }
+#else
+#define FLASH_SHOW_PROGRESS(scale, dots, digit, dots_sub)
+#endif
+
 /*-----------------------------------------------------------------------
  * Copy memory to flash, returns:
  * 0 - OK
@@ -1192,10 +1213,23 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
        int aln;
        cfiword_t cword;
        int i, rc;
-
 #ifdef CFG_FLASH_USE_BUFFER_WRITE
        int buffered_size;
 #endif
+#ifdef CONFIG_FLASH_SHOW_PROGRESS
+       int digit = CONFIG_FLASH_SHOW_PROGRESS;
+       int scale = 0;
+       int dots  = 0;
+
+       /*
+        * Suppress if there are fewer than CONFIG_FLASH_SHOW_PROGRESS writes.
+        */
+       if (cnt >= CONFIG_FLASH_SHOW_PROGRESS) {
+               scale = (int)((cnt + CONFIG_FLASH_SHOW_PROGRESS - 1) /
+                       CONFIG_FLASH_SHOW_PROGRESS);
+       }
+#endif
+
        /* get lower aligned address */
        wp = (addr & ~(info->portwidth - 1));
 
@@ -1219,6 +1253,7 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
                        return rc;
 
                wp += i;
+               FLASH_SHOW_PROGRESS(scale, dots, digit, i);
        }
 
        /* handle the aligned part */
@@ -1248,6 +1283,7 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
                wp += i;
                src += i;
                cnt -= i;
+               FLASH_SHOW_PROGRESS(scale, dots, digit, i);
        }
 #else
        while (cnt >= info->portwidth) {
@@ -1259,8 +1295,10 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
                        return rc;
                wp += info->portwidth;
                cnt -= info->portwidth;
+               FLASH_SHOW_PROGRESS(scale, dots, digit, info->portwidth);
        }
 #endif /* CFG_FLASH_USE_BUFFER_WRITE */
+
        if (cnt == 0) {
                return (0);
        }
@@ -1446,11 +1484,11 @@ static void flash_read_jedec_ids (flash_info_t * info)
        switch (info->vendor) {
        case CFI_CMDSET_INTEL_STANDARD:
        case CFI_CMDSET_INTEL_EXTENDED:
-               flash_read_jedec_ids_intel(info);
+               cmdset_intel_read_jedec_ids(info);
                break;
        case CFI_CMDSET_AMD_STANDARD:
        case CFI_CMDSET_AMD_EXTENDED:
-               flash_read_jedec_ids_amd(info);
+               cmdset_amd_read_jedec_ids(info);
                break;
        default:
                break;
@@ -1538,7 +1576,12 @@ static int __flash_detect_cfi (flash_info_t * info, struct cfi_qry *qry)
 {
        int cfi_offset;
 
-       flash_write_cmd (info, 0, 0, info->cmd_reset);
+       /* We do not yet know what kind of commandset to use, so we issue
+          the reset command in both Intel and AMD variants, in the hope
+          that AMD flash roms ignore the Intel command. */
+       flash_write_cmd (info, 0, 0, AMD_CMD_RESET);
+       flash_write_cmd (info, 0, 0, FLASH_CMD_RESET);
+
        for (cfi_offset=0;
             cfi_offset < sizeof(flash_offset_cfi) / sizeof(uint);
             cfi_offset++) {