]> git.sur5r.net Git - u-boot/blobdiff - board/eric/flash.c
ppc4xx: icon: add support for SM502 chip
[u-boot] / board / eric / flash.c
index c3f6e15bc54019c815d39f23e316702cc280590c..fded41271f176146cc96bfb73c6c34ab93ae9f57 100644 (file)
 #include <ppc4xx.h>
 #include <asm/processor.h>
 
-flash_info_t   flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips        */
+flash_info_t   flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */
 
 
-#ifdef CFG_FLASH_16BIT
+#ifdef CONFIG_SYS_FLASH_16BIT
 #define FLASH_WORD_SIZE        unsigned short
 #define        FLASH_ID_MASK   0xFFFF
 #else
@@ -42,7 +42,7 @@ flash_info_t  flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips        */
 /* stolen from esteem192e/flash.c */
 ulong flash_get_size (volatile FLASH_WORD_SIZE *addr, flash_info_t *info);
 
-#ifndef CFG_FLASH_16BIT
+#ifndef CONFIG_SYS_FLASH_16BIT
 static int write_word (flash_info_t *info, ulong dest, ulong data);
 #else
 static int write_short (flash_info_t *info, ulong dest, ushort data);
@@ -57,11 +57,11 @@ unsigned long flash_init (void)
 {
        unsigned long size_b0, size_b1;
        int i;
-        uint pbcr;
-        unsigned long base_b0, base_b1;
+       uint pbcr;
+       unsigned long base_b0, base_b1;
 
        /* Init: no FLASHes known */
-       for (i=0; i<CFG_MAX_FLASH_BANKS; ++i) {
+       for (i=0; i<CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
                flash_info[i].flash_id = FLASH_UNKNOWN;
        }
 
@@ -75,7 +75,7 @@ unsigned long flash_init (void)
        }
 
        /* Only one bank */
-       if (CFG_MAX_FLASH_BANKS == 1)
+       if (CONFIG_SYS_MAX_FLASH_BANKS == 1)
          {
            /* Setup offsets */
            flash_get_offsets (FLASH_BASE0_PRELIM, &flash_info[0]);
@@ -83,14 +83,14 @@ unsigned long flash_init (void)
            /* Monitor protection ON by default */
 #if 0      /* sand: */
            (void)flash_protect(FLAG_PROTECT_SET,
-                               FLASH_BASE0_PRELIM-CFG_MONITOR_LEN+size_b0,
+                               FLASH_BASE0_PRELIM-monitor_flash_len+size_b0,
                                FLASH_BASE0_PRELIM-1+size_b0,
                                &flash_info[0]);
 #else
            (void)flash_protect(FLAG_PROTECT_SET,
-                               CFG_MONITOR_BASE,
-                               CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
-                               &flash_info[0]);
+                               CONFIG_SYS_MONITOR_BASE,
+                               CONFIG_SYS_MONITOR_BASE+monitor_flash_len-1,
+                               &flash_info[0]);
 #endif
            size_b1 = 0 ;
            flash_info[0].size = size_b0;
@@ -105,24 +105,24 @@ unsigned long flash_init (void)
 
            if (size_b1)
              {
-               mtdcr(ebccfga, pb0cr);
-               pbcr = mfdcr(ebccfgd);
-               mtdcr(ebccfga, pb0cr);
+               mtdcr(EBC0_CFGADDR, PB0CR);
+               pbcr = mfdcr(EBC0_CFGDATA);
+               mtdcr(EBC0_CFGADDR, PB0CR);
                base_b1 = -size_b1;
                pbcr = (pbcr & 0x0001ffff) | base_b1 | (((size_b1/1024/1024)-1)<<17);
-               mtdcr(ebccfgd, pbcr);
-               /*          printf("pb1cr = %x\n", pbcr); */
+               mtdcr(EBC0_CFGDATA, pbcr);
+               /*          printf("PB1CR = %x\n", pbcr); */
              }
 
            if (size_b0)
              {
-               mtdcr(ebccfga, pb1cr);
-               pbcr = mfdcr(ebccfgd);
-               mtdcr(ebccfga, pb1cr);
+               mtdcr(EBC0_CFGADDR, PB1CR);
+               pbcr = mfdcr(EBC0_CFGDATA);
+               mtdcr(EBC0_CFGADDR, PB1CR);
                base_b0 = base_b1 - size_b0;
                pbcr = (pbcr & 0x0001ffff) | base_b0 | (((size_b0/1024/1024)-1)<<17);
-               mtdcr(ebccfgd, pbcr);
-               /*            printf("pb0cr = %x\n", pbcr); */
+               mtdcr(EBC0_CFGDATA, pbcr);
+               /*            printf("PB0CR = %x\n", pbcr); */
              }
 
            size_b0 = flash_get_size((volatile FLASH_WORD_SIZE *)base_b0, &flash_info[0]);
@@ -132,14 +132,14 @@ unsigned long flash_init (void)
            /* monitor protection ON by default */
 #if 0      /* sand: */
            (void)flash_protect(FLAG_PROTECT_SET,
-                               FLASH_BASE0_PRELIM-CFG_MONITOR_LEN+size_b0,
+                               FLASH_BASE0_PRELIM-monitor_flash_len+size_b0,
                                FLASH_BASE0_PRELIM-1+size_b0,
                                &flash_info[0]);
 #else
            (void)flash_protect(FLAG_PROTECT_SET,
-                               CFG_MONITOR_BASE,
-                               CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
-                               &flash_info[0]);
+                               CONFIG_SYS_MONITOR_BASE,
+                               CONFIG_SYS_MONITOR_BASE+monitor_flash_len-1,
+                               &flash_info[0]);
 #endif
 
            if (size_b1) {
@@ -150,12 +150,12 @@ unsigned long flash_init (void)
 
              /* monitor protection ON by default */
              (void)flash_protect(FLAG_PROTECT_SET,
-                                 base_b1+size_b1-CFG_MONITOR_LEN,
+                                 base_b1+size_b1-monitor_flash_len,
                                  base_b1+size_b1-1,
                                  &flash_info[1]);
              /* monitor protection OFF by default (one is enough) */
              (void)flash_protect(FLAG_PROTECT_CLEAR,
-                                 base_b0+size_b0-CFG_MONITOR_LEN,
+                                 base_b0+size_b0-monitor_flash_len,
                                  base_b0+size_b0-1,
                                  &flash_info[0]);
            } else {
@@ -170,7 +170,6 @@ unsigned long flash_init (void)
 }
 
 
-
 /*-----------------------------------------------------------------------
  */
 
@@ -186,9 +185,9 @@ static void flash_get_offsets (ulong base, flash_info_t *info)
                info->start[i] = base + (i * info->size/info->sector_count);
            }
        } else if (info->flash_id & FLASH_BTYPE) {
-             if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_INTEL) {
+            if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_INTEL) {
 
-#ifndef CFG_FLASH_16BIT
+#ifndef CONFIG_SYS_FLASH_16BIT
                /* set sector offsets for bottom boot block type        */
                info->start[0] = base + 0x00000000;
                info->start[1] = base + 0x00004000;
@@ -200,9 +199,9 @@ static void flash_get_offsets (ulong base, flash_info_t *info)
                info->start[7] = base + 0x0001C000;
                for (i = 8; i < info->sector_count; i++) {
                        info->start[i] = base + (i * 0x00020000) - 0x000E0000;
-               }
-               }
-             else {
+               }
+              }
+            else {
                /* set sector offsets for bottom boot block type        */
                info->start[0] = base + 0x00000000;
                info->start[1] = base + 0x00008000;
@@ -224,9 +223,9 @@ static void flash_get_offsets (ulong base, flash_info_t *info)
                info->start[7] = base + 0x0000E000;
                for (i = 8; i < info->sector_count; i++) {
                        info->start[i] = base + (i * 0x00010000) - 0x00070000;
-               }
+               }
               }
-             else {
+            else {
                /* set sector offsets for bottom boot block type        */
                info->start[0] = base + 0x00000000;
                info->start[1] = base + 0x00004000;
@@ -240,9 +239,9 @@ static void flash_get_offsets (ulong base, flash_info_t *info)
        } else {
                /* set sector offsets for top boot block type           */
                i = info->sector_count - 1;
-             if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_INTEL) {
+            if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_INTEL) {
 
-#ifndef CFG_FLASH_16BIT
+#ifndef CONFIG_SYS_FLASH_16BIT
                info->start[i--] = base + info->size - 0x00004000;
                info->start[i--] = base + info->size - 0x00008000;
                info->start[i--] = base + info->size - 0x0000C000;
@@ -254,7 +253,7 @@ static void flash_get_offsets (ulong base, flash_info_t *info)
                        info->start[i] = base + i * 0x00020000;
                }
 
-               } else {
+              } else {
 
                info->start[i--] = base + info->size - 0x00008000;
                info->start[i--] = base + info->size - 0x0000C000;
@@ -275,7 +274,7 @@ static void flash_get_offsets (ulong base, flash_info_t *info)
                        info->start[i] = base + i * 0x00010000;
                }
 
-               } else {
+              } else {
 
                info->start[i--] = base + info->size - 0x00004000;
                info->start[i--] = base + info->size - 0x00006000;
@@ -404,12 +403,12 @@ ulong flash_get_size (volatile FLASH_WORD_SIZE *addr, flash_info_t *info)
        /* Write auto select command: read Manufacturer ID */
 
 
-#ifndef CFG_FLASH_16BIT
+#ifndef CONFIG_SYS_FLASH_16BIT
 
        /*
         * Note: if it is an AMD flash and the word at addr[0000]
-         * is 0x00890089 this routine will think it is an Intel
-         * flash device and may(most likely) cause trouble.
+        * is 0x00890089 this routine will think it is an Intel
+        * flash device and may(most likely) cause trouble.
         */
 
        addr[0x0000] = 0x00900090;
@@ -421,8 +420,8 @@ ulong flash_get_size (volatile FLASH_WORD_SIZE *addr, flash_info_t *info)
 
        /*
         * Note: if it is an AMD flash and the word at addr[0000]
-         * is 0x0089 this routine will think it is an Intel
-         * flash device and may(most likely) cause trouble.
+        * is 0x0089 this routine will think it is an Intel
+        * flash device and may(most likely) cause trouble.
         */
 
        addr[0x0000] = 0x0090;
@@ -565,17 +564,17 @@ ulong flash_get_size (volatile FLASH_WORD_SIZE *addr, flash_info_t *info)
                info->flash_id += FLASH_28F320J3A;
                info->sector_count = 32;
                info->size = 0x00400000;
-               break;                          /* => 32 MBit   */
+               break;                          /* => 32 MBit   */
        case (INTEL_ID_28F640J3A & FLASH_ID_MASK):
                info->flash_id += FLASH_28F640J3A;
                info->sector_count = 64;
                info->size = 0x00800000;
-               break;                          /* => 64 MBit   */
+               break;                          /* => 64 MBit   */
        case (INTEL_ID_28F128J3A & FLASH_ID_MASK):
                info->flash_id += FLASH_28F128J3A;
                info->sector_count = 128;
                info->size = 0x01000000;
-               break;                          /* => 128 MBit          */
+               break;                          /* => 128 MBit  */
 
        default:
                /* FIXME*/
@@ -631,7 +630,7 @@ int flash_erase (flash_info_t *info, int s_first, int s_last)
 
        if ((info->flash_id == FLASH_UNKNOWN) ||
            ((info->flash_id > FLASH_AMD_COMP) &&
-             ( (info->flash_id & FLASH_VENDMASK) != FLASH_MAN_INTEL ) ) ){
+            ( (info->flash_id & FLASH_VENDMASK) != FLASH_MAN_INTEL ) ) ){
                printf ("Can't erase unknown flash type - aborted\n");
                return 1;
        }
@@ -655,7 +654,7 @@ int flash_erase (flash_info_t *info, int s_first, int s_last)
        /* Disable interrupts which might cause a timeout here */
        flag = disable_interrupts();
     if(info->flash_id < FLASH_AMD_COMP) {
-#ifndef CFG_FLASH_16BIT
+#ifndef CONFIG_SYS_FLASH_16BIT
        addr[0x0555] = 0x00AA00AA;
        addr[0x02AA] = 0x00550055;
        addr[0x0555] = 0x00800080;
@@ -696,7 +695,7 @@ int flash_erase (flash_info_t *info, int s_first, int s_last)
        while ((addr[0] & (0x00800080&FLASH_ID_MASK)) !=
                          (0x00800080&FLASH_ID_MASK)  )
        {
-               if ((now = get_timer(start)) > CFG_FLASH_ERASE_TOUT) {
+               if ((now = get_timer(start)) > CONFIG_SYS_FLASH_ERASE_TOUT) {
                        printf ("Timeout\n");
                        return 1;
                }
@@ -717,7 +716,7 @@ DONE:
        for (sect = s_first; sect<=s_last; sect++) {
                if (info->protect[sect] == 0) { /* not protected */
                        barf = 0;
-#ifndef CFG_FLASH_16BIT
+#ifndef CONFIG_SYS_FLASH_16BIT
                        addr = (vu_long*)(info->start[sect]);
                        addr[0] = 0x00200020;
                        addr[0] = 0x00D000D0;
@@ -768,7 +767,7 @@ DONE:
        flash_info_t *info;
        int i;
 
-       for (i=0, info=&flash_info[0]; i<CFG_MAX_FLASH_BANKS; ++i, ++info) {
+       for (i=0, info=&flash_info[0]; i<CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
                if ((addr >= info->start[0]) &&
                    (addr < (info->start[0] + info->size)) ) {
                        return (info);
@@ -845,7 +844,7 @@ DONE:
 
 int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt)
 {
-#ifndef CFG_FLASH_16BIT
+#ifndef CONFIG_SYS_FLASH_16BIT
        ulong cp, wp, data;
        int l;
 #else
@@ -854,7 +853,7 @@ int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt)
 #endif
        int i, rc;
 
-#ifndef CFG_FLASH_16BIT
+#ifndef CONFIG_SYS_FLASH_16BIT
 
 
        wp = (addr & ~3);       /* get lower word aligned address */
@@ -981,150 +980,152 @@ int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt)
  * 1 - write timeout
  * 2 - Flash not erased
  */
-#ifndef CFG_FLASH_16BIT
-static int write_word (flash_info_t *info, ulong dest, ulong data)
+#ifndef CONFIG_SYS_FLASH_16BIT
+static int write_word (flash_info_t * info, ulong dest, ulong data)
 {
-       vu_long *addr = (vu_long*)(info->start[0]);
-       ulong start,barf;
+       vu_long *addr = (vu_long *) (info->start[0]);
+       ulong start, barf;
        int flag;
 
 
        /* Check if Flash is (sufficiently) erased */
-       if ((*((vu_long *)dest) & data) != data) {
+       if ((*((vu_long *) dest) & data) != data) {
                return (2);
        }
 
        /* Disable interrupts which might cause a timeout here */
-       flag = disable_interrupts();
+       flag = disable_interrupts ();
 
-     if(info->flash_id > FLASH_AMD_COMP) {
-       /* AMD stuff */
-       addr[0x0555] = 0x00AA00AA;
-       addr[0x02AA] = 0x00550055;
-       addr[0x0555] = 0x00A000A0;
-     } else {
-       /* intel stuff */
-       *addr = 0x00400040;
-     }
-       *((vu_long *)dest) = data;
+       if (info->flash_id > FLASH_AMD_COMP) {
+               /* AMD stuff */
+               addr[0x0555] = 0x00AA00AA;
+               addr[0x02AA] = 0x00550055;
+               addr[0x0555] = 0x00A000A0;
+       } else {
+               /* intel stuff */
+               *addr = 0x00400040;
+       }
+       *((vu_long *) dest) = data;
 
        /* re-enable interrupts if necessary */
        if (flag)
-               enable_interrupts();
+               enable_interrupts ();
 
        /* data polling for D7 */
        start = get_timer (0);
 
-     if(info->flash_id > FLASH_AMD_COMP) {
+       if (info->flash_id > FLASH_AMD_COMP) {
 
-       while ((*((vu_long *)dest) & 0x00800080) != (data & 0x00800080)) {
-               if (get_timer(start) > CFG_FLASH_WRITE_TOUT) {
-                       return (1);
+               while ((*((vu_long *) dest) & 0x00800080) !=
+                      (data & 0x00800080)) {
+                       if (get_timer (start) > CONFIG_SYS_FLASH_WRITE_TOUT) {
+                               return (1);
+                       }
                }
-       }
 
-     } else {
+       } else {
 
-       while(!(addr[0] & 0x00800080)){         /* wait for error or finish */
-               if (get_timer(start) > CFG_FLASH_WRITE_TOUT) {
-                       return (1);
-       }
+               while (!(addr[0] & 0x00800080)) {       /* wait for error or finish */
+                       if (get_timer (start) > CONFIG_SYS_FLASH_WRITE_TOUT) {
+                               return (1);
+                       }
 
-       if( addr[0] & 0x003A003A) {     /* check for error */
-               barf = addr[0] & 0x003A0000;
-               if( barf ) {
-                       barf >>=16;
-               } else {
-                       barf = addr[0] & 0x0000003A;
-               }
-               printf("\nFlash write error at address %lx\n",(unsigned long)dest);
-               if(barf & 0x0002) printf("Block locked, not erased.\n");
-               if(barf & 0x0010) printf("Programming error.\n");
-               if(barf & 0x0008) printf("Vpp Low error.\n");
-               return(2);
-       }
+                       if (addr[0] & 0x003A003A) {     /* check for error */
+                               barf = addr[0] & 0x003A0000;
+                               if (barf) {
+                                       barf >>= 16;
+                               } else {
+                                       barf = addr[0] & 0x0000003A;
+                               }
+                               printf ("\nFlash write error at address %lx\n",
+                                       (unsigned long) dest);
+                               if (barf & 0x0002)
+                                       printf ("Block locked, not erased.\n");
+                               if (barf & 0x0010)
+                                       printf ("Programming error.\n");
+                               if (barf & 0x0008)
+                                       printf ("Vpp Low error.\n");
+                               return (2);
+                       }
 
 
-     }
+               }
 
-       return (0);
+               return (0);
 
-}
+       }
 
 #else
 
-static int write_short (flash_info_t *info, ulong dest, ushort data)
+static int write_short (flash_info_t * info, ulong dest, ushort data)
 {
-       vu_short *addr = (vu_short*)(info->start[0]);
-       ulong start,barf;
+       vu_short *addr = (vu_short *) (info->start[0]);
+       ulong start, barf;
        int flag;
 
        /* Check if Flash is (sufficiently) erased */
-       if ((*((vu_short *)dest) & data) != data) {
+       if ((*((vu_short *) dest) & data) != data) {
                return (2);
        }
 
        /* Disable interrupts which might cause a timeout here */
-       flag = disable_interrupts();
+       flag = disable_interrupts ();
 
-     if(info->flash_id < FLASH_AMD_COMP) {
-       /* AMD stuff */
-       addr[0x0555] = 0x00AA;
-       addr[0x02AA] = 0x0055;
-       addr[0x0555] = 0x00A0;
-     } else {
-       /* intel stuff */
-        *addr = 0x00D0;
-       *addr = 0x0040;
-     }
-       *((vu_short *)dest) = data;
+       if (info->flash_id < FLASH_AMD_COMP) {
+               /* AMD stuff */
+               addr[0x0555] = 0x00AA;
+               addr[0x02AA] = 0x0055;
+               addr[0x0555] = 0x00A0;
+       } else {
+               /* intel stuff */
+               *addr = 0x00D0;
+               *addr = 0x0040;
+       }
+       *((vu_short *) dest) = data;
 
        /* re-enable interrupts if necessary */
        if (flag)
-               enable_interrupts();
+               enable_interrupts ();
 
        /* data polling for D7 */
        start = get_timer (0);
 
-     if(info->flash_id < FLASH_AMD_COMP) {
-          /* AMD stuff */
-       while ((*((vu_short *)dest) & 0x0080) != (data & 0x0080)) {
-               if (get_timer(start) > CFG_FLASH_WRITE_TOUT) {
-                       return (1);
+       if (info->flash_id < FLASH_AMD_COMP) {
+               /* AMD stuff */
+               while ((*((vu_short *) dest) & 0x0080) != (data & 0x0080)) {
+                       if (get_timer (start) > CONFIG_SYS_FLASH_WRITE_TOUT) {
+                               return (1);
+                       }
                }
-       }
 
-     } else {
-       /* intel stuff */
-       while(!(addr[0] & 0x0080)){     /* wait for error or finish */
-               if (get_timer(start) > CFG_FLASH_WRITE_TOUT) return (1);
-       }
+       } else {
+               /* intel stuff */
+               while (!(addr[0] & 0x0080)) {   /* wait for error or finish */
+                       if (get_timer (start) > CONFIG_SYS_FLASH_WRITE_TOUT)
+                               return (1);
+               }
 
-       if( addr[0] & 0x003A) { /* check for error */
-               barf = addr[0] & 0x003A;
-               printf("\nFlash write error at address %lx\n",(unsigned long)dest);
-               if(barf & 0x0002) printf("Block locked, not erased.\n");
-               if(barf & 0x0010) printf("Programming error.\n");
-               if(barf & 0x0008) printf("Vpp Low error.\n");
-               return(2);
-       }
-       *addr = 0x00B0;
-       *addr = 0x0070;
-       while(!(addr[0] & 0x0080)){     /* wait for error or finish */
-               if (get_timer(start) > CFG_FLASH_WRITE_TOUT) return (1);
+               if (addr[0] & 0x003A) { /* check for error */
+                       barf = addr[0] & 0x003A;
+                       printf ("\nFlash write error at address %lx\n",
+                               (unsigned long) dest);
+                       if (barf & 0x0002)
+                               printf ("Block locked, not erased.\n");
+                       if (barf & 0x0010)
+                               printf ("Programming error.\n");
+                       if (barf & 0x0008)
+                               printf ("Vpp Low error.\n");
+                       return (2);
+               }
+               *addr = 0x00B0;
+               *addr = 0x0070;
+               while (!(addr[0] & 0x0080)) {   /* wait for error or finish */
+                       if (get_timer (start) > CONFIG_SYS_FLASH_WRITE_TOUT)
+                               return (1);
+               }
+               *addr = 0x00FF;
        }
-
-       *addr = 0x00FF;
-
-     }
-
        return (0);
-
 }
-
-
 #endif
-
-/*-----------------------------------------------------------------------
- */
-
+/*-----------------------------------------------------------------------*/