]> git.sur5r.net Git - u-boot/blobdiff - board/innokom/flash.c
vision2: Place machine ID into board config
[u-boot] / board / innokom / flash.c
index b8e97e18652d59fde088e6c0768f42477086e459..ed4b9872a2fbfa95165d969ed4310fa56f8d4839 100644 (file)
@@ -9,6 +9,10 @@
  * (C) Copyright 2002
  * Robert Schwebel, Pengutronix, <r.schwebel@pengutronix.de>
  *
+ * (C) Copyright 2002
+ * Auerswald GmbH & Co KG, Germany
+ * Kai-Uwe Bloem <kai-uwe.bloem@auerswald.de>
+ *
  * See file CREDITS for list of people who contributed to this
  * project.
  *
 #include <common.h>
 #include <asm/arch/pxa-regs.h>
 
-#define FLASH_BANK_SIZE 0x02000000
-#define MAIN_SECT_SIZE  0x40000         /* 2x16 = 256k per sector */
+/* Debugging macros ------------------------------------------------------  */
+
+#undef FLASH_DEBUG
+
+/* Some debug macros */
+#if (FLASH_DEBUG > 2 )
+#define PRINTK3(args...) printf(args)
+#else
+#define PRINTK3(args...)
+#endif
+
+#if FLASH_DEBUG > 1
+#define PRINTK2(args...) printf(args)
+#else
+#define PRINTK2(args...)
+#endif
 
-flash_info_t    flash_info[CFG_MAX_FLASH_BANKS];
+#ifdef FLASH_DEBUG
+#define PRINTK(args...) printf(args)
+#else
+#define PRINTK(args...)
+#endif
 
+/* ------------------------------------------------------------------------ */
+
+/* Development system: we have only 16 MB Flash                             */
+#ifdef CONFIG_MTD_INNOKOM_16MB
+#define FLASH_BANK_SIZE 0x01000000     /* 16 MB (during development)       */
+#define MAIN_SECT_SIZE  0x00020000     /* 128k per sector                  */
+#endif
+
+/* Production system: we have 64 MB Flash                                   */
+#ifdef CONFIG_MTD_INNOKOM_64MB
+#define FLASH_BANK_SIZE 0x04000000     /* 64 MB                            */
+#define MAIN_SECT_SIZE  0x00020000     /* 128k per sector                  */
+#endif
+
+flash_info_t    flash_info[CONFIG_SYS_MAX_FLASH_BANKS];
 
 /**
  * flash_init: - initialize data structures for flash chips
@@ -48,21 +85,21 @@ ulong flash_init(void)
        int i, j;
        ulong size = 0;
 
-       for (i = 0; i < CFG_MAX_FLASH_BANKS; i++) {
+       for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++) {
                ulong flashbase = 0;
                flash_info[i].flash_id =
-                       (INTEL_MANUFACT & FLASH_VENDMASK) |
-                       (INTEL_ID_28F128J3 & FLASH_TYPEMASK);
+                       (INTEL_MANUFACT & FLASH_VENDMASK) |
+                       (INTEL_ID_28F128J3 & FLASH_TYPEMASK);
                flash_info[i].size = FLASH_BANK_SIZE;
-               flash_info[i].sector_count = CFG_MAX_FLASH_SECT;
-               memset(flash_info[i].protect, 0, CFG_MAX_FLASH_SECT);
+               flash_info[i].sector_count = CONFIG_SYS_MAX_FLASH_SECT;
+               memset(flash_info[i].protect, 0, CONFIG_SYS_MAX_FLASH_SECT);
 
                switch (i) {
                        case 0:
                                flashbase = PHYS_FLASH_1;
                                break;
                        default:
-                               panic("configured to many flash banks!\n");
+                               panic("configured too many flash banks!\n");
                                break;
                }
                for (j = 0; j < flash_info[i].sector_count; j++) {
@@ -71,16 +108,16 @@ ulong flash_init(void)
                size += flash_info[i].size;
        }
 
-       /* Protect monitor and environment sectors */
+       /* Protect u-boot sectors */
        flash_protect(FLAG_PROTECT_SET,
-                       CFG_FLASH_BASE,
-                       CFG_FLASH_BASE + _armboot_end_data - _armboot_start,
+                       CONFIG_SYS_FLASH_BASE,
+                       CONFIG_SYS_FLASH_BASE + (256*1024) - 1,
                        &flash_info[0]);
 
-#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_SIZE - 1,
+                       CONFIG_ENV_ADDR,
+                       CONFIG_ENV_ADDR + CONFIG_ENV_SIZE - 1,
                        &flash_info[0]);
 #endif
 
@@ -98,7 +135,7 @@ void flash_print_info  (flash_info_t *info)
 {
        int i, j;
 
-       for (j=0; j<CFG_MAX_FLASH_BANKS; j++) {
+       for (j=0; j<CONFIG_SYS_MAX_FLASH_BANKS; j++) {
 
                switch (info->flash_id & FLASH_VENDMASK) {
 
@@ -145,6 +182,7 @@ int flash_erase(flash_info_t *info, int s_first, int s_last)
 {
        int flag, prot, sect;
        int rc = ERR_OK;
+       ulong start;
 
        if (info->flash_id == FLASH_UNKNOWN)
                return ERR_UNKNOWN_FLASH_TYPE;
@@ -178,32 +216,38 @@ int flash_erase(flash_info_t *info, int s_first, int s_last)
 
                printf("Erasing sector %2d ... ", sect);
 
+               PRINTK("\n");
+
                /* arm simple, non interrupt dependent timer */
-               reset_timer_masked();
+               start = get_timer(0);
 
                if (info->protect[sect] == 0) { /* not protected */
-                       u32 * volatile addr = (u32 * volatile)(info->start[sect]);
-
-                       /* erase sector:                                    */
-                       /* The strata flashs are aligned side by side on    */
-                       /* the data bus, so we have to write the commands   */
-                       /* to both chips here:                              */
-
-                       *addr = 0x00200020;     /* erase setup */
-                       *addr = 0x00D000D0;     /* erase confirm */
-
-                       while ((*addr & 0x00800080) != 0x00800080) {
-                               if (get_timer_masked() > CFG_FLASH_ERASE_TOUT) {
-                                       *addr = 0x00B000B0; /* suspend erase*/
-                                       *addr = 0x00FF00FF; /* read mode    */
+                       u16 * volatile addr = (u16 * volatile)(info->start[sect]);
+
+                       PRINTK("unlocking sector\n");
+                       *addr = 0x0060;
+                       *addr = 0x00d0;
+                       *addr = 0x00ff;
+
+                       PRINTK("erasing sector\n");
+                       *addr = 0x0020;
+                       PRINTK("confirming erase\n");
+                       *addr = 0x00D0;
+
+                       while ((*addr & 0x0080) != 0x0080) {
+                               PRINTK(".");
+                               if (get_timer(start) > CONFIG_SYS_FLASH_ERASE_TOUT) {
+                                       *addr = 0x00B0; /* suspend erase*/
+                                       *addr = 0x00FF; /* read mode    */
                                        rc = ERR_TIMOUT;
                                        goto outahere;
                                }
                        }
 
-                       *addr = 0x00500050; /* clear status register cmd.   */
-                       *addr = 0x00FF00FF; /* resest to read mode          */
-
+                       PRINTK("clearing status register\n");
+                       *addr = 0x0050;
+                       PRINTK("resetting to read mode");
+                       *addr = 0x00FF;
                }
 
                printf("ok.\n");
@@ -233,9 +277,10 @@ int flash_erase(flash_info_t *info, int s_first, int s_last)
 
 static int write_word (flash_info_t *info, ulong dest, ushort data)
 {
-       ushort *addr = (ushort *)dest, val;
+       volatile u16 *addr = (u16 *)dest, val;
        int rc = ERR_OK;
        int flag;
+       ulong start;
 
        /* Check if Flash is (sufficiently) erased */
        if ((*addr & data) != data) return ERR_NOT_ERASED;
@@ -259,11 +304,11 @@ static int write_word (flash_info_t *info, ulong dest, ushort data)
        *addr = data;
 
        /* arm simple, non interrupt dependent timer */
-       reset_timer_masked();
+       start = get_timer(0);
 
        /* wait while polling the status register */
        while(((val = *addr) & 0x80) != 0x80) {
-               if (get_timer_masked() > CFG_FLASH_WRITE_TOUT) {
+               if (get_timer(start) > CONFIG_SYS_FLASH_WRITE_TOUT) {
                        rc = ERR_TIMOUT;
                        *addr = 0xB0; /* suspend program command */
                        goto outahere;
@@ -307,7 +352,7 @@ static int write_word (flash_info_t *info, ulong dest, ushort data)
  * @param info:
  * @param src: source of copy transaction
  * @param addr:        where to copy to
- * @param cnt:         number of bytes to copy
+ * @param cnt: number of bytes to copy
  *
  * @return     error code
  */
@@ -374,4 +419,3 @@ int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt)
 
        return write_word(info, wp, data);
 }
-