From: wdenk Date: Sat, 20 Oct 2001 09:39:53 +0000 (+0000) Subject: Add support for Fujitsu flash chips X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=9981eb23d65b5e4f029ac0984e22daeb14b37830;p=users%2Frw%2Fppcboot.git Add support for Fujitsu flash chips --- diff --git a/board/tqm8260/flash.c b/board/tqm8260/flash.c index e89df9e..bbc6221 100644 --- a/board/tqm8260/flash.c +++ b/board/tqm8260/flash.c @@ -38,8 +38,7 @@ flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; */ void flash_reset(void) { - if( flash_info[0].flash_id != FLASH_UNKNOWN ) - { + if( flash_info[0].flash_id != FLASH_UNKNOWN ) { V_ULONG( flash_info[0].start[0] ) = 0x00F000F0; V_ULONG( flash_info[0].start[0] + 4 ) = 0x00F000F0; } @@ -62,23 +61,27 @@ ulong flash_get_size( ulong baseaddr, flash_info_t *info ) flashtest_h = V_ULONG( baseaddr ); /* manufacturer ID */ flashtest_l = V_ULONG( baseaddr + 4 ); - if (flashtest_h != AMD_MANUFACT) - { - info->flash_id = FLASH_UNKNOWN; - info->sector_count = 0; - info->size = 0; - return( 0 ); /* no or unknown flash */ - } - info->flash_id = AMD_MANUFACT << 16; /* set manufacturer offset */ + switch ((int)flashtest_h) { + case AMD_MANUFACT: + info->flash_id = FLASH_MAN_AMD; + break; + case FUJ_MANUFACT: + info->flash_id = FLASH_MAN_FUJ; + break; + default: + info->flash_id = FLASH_UNKNOWN; + info->sector_count = 0; + info->size = 0; + return (0); /* no or unknown flash */ + } flashtest_h = V_ULONG( baseaddr + 8 ); /* device ID */ flashtest_l = V_ULONG( baseaddr + 12 ); - if( flashtest_h != flashtest_l ) + if( flashtest_h != flashtest_l ) { info->flash_id = FLASH_UNKNOWN; - else - switch( flashtest_h ) - { + } else { + switch( flashtest_h ) { case AMD_ID_LV800T: info->flash_id += FLASH_AM800T; info->sector_count = 19; @@ -119,42 +122,46 @@ ulong flash_get_size( ulong baseaddr, flash_info_t *info ) info->flash_id = FLASH_UNKNOWN; return( 0 ); /* no or unknown flash */ } + } + + if (flashtest_h == AMD_ID_LV640U) { - if (flashtest_h == AMD_ID_LV640U) - { /* set up sector start adress table (uniform sector type) */ for( i = 0; i < info->sector_count; i++ ) info->start[i] = baseaddr + (i * 0x00040000); - } - else if (info->flash_id & FLASH_BTYPE) - { + + } else if (info->flash_id & FLASH_BTYPE) { + /* set up sector start adress table (bottom sector type) */ info->start[0] = baseaddr + 0x00000000; info->start[1] = baseaddr + 0x00010000; info->start[2] = baseaddr + 0x00018000; info->start[3] = baseaddr + 0x00020000; - for( i = 4; i < info->sector_count; i++ ) + for( i = 4; i < info->sector_count; i++ ) { info->start[i] = baseaddr + (i * 0x00040000) - 0x000C0000; - } - else - { + } + + } else { + /* set up sector start adress table (top sector type) */ i = info->sector_count - 1; info->start[i--] = baseaddr + info->size - 0x00010000; info->start[i--] = baseaddr + info->size - 0x00018000; info->start[i--] = baseaddr + info->size - 0x00020000; - for( ; i >= 0; i-- ) + for( ; i >= 0; i-- ) { info->start[i] = baseaddr + i * 0x00040000; + } } /* check for protected sectors */ - for( i = 0; i < info->sector_count; i++ ) - { + for( i = 0; i < info->sector_count; i++ ) { /* read sector protection at sector address, (A7 .. A0) = 0x02 */ if( (V_ULONG( info->start[i] + 16 ) & 0x00010001) || - (V_ULONG( info->start[i] + 20 ) & 0x00010001) ) - info->protect[i] = 1; /* D0 = 1 if protected */ - else info->protect[i] = 0; + (V_ULONG( info->start[i] + 20 ) & 0x00010001) ) { + info->protect[i] = 1; /* D0 = 1 if protected */ + } else { + info->protect[i] = 0; + } } flash_reset(); @@ -169,16 +176,14 @@ unsigned long flash_init (void) int i; /* Init: no FLASHes known */ - for (i=0; i>20); } @@ -213,62 +218,45 @@ void flash_print_info (flash_info_t *info) { int i; - if (info->flash_id == FLASH_UNKNOWN) - { + if (info->flash_id == FLASH_UNKNOWN) { printf ("missing or unknown FLASH type\n"); return; } - switch ((info->flash_id >> 16) & 0xff) - { - case 0x1: - printf ("AMD "); - break; - default: - printf ("Unknown Vendor "); - break; + switch ((info->flash_id >> 16) & 0xff) { + case FLASH_MAN_AMD: printf ("AMD "); break; + case FLASH_MAN_FUJ: printf ("FUJITSU "); break; + default: printf ("Unknown Vendor "); break; } - switch (info->flash_id & FLASH_TYPEMASK) - { - case FLASH_AM800T: - printf ("29LV800T (8 M, top sector)\n"); - break; - case FLASH_AM800B: - printf ("29LV800T (8 M, bottom sector)\n"); - break; - case FLASH_AM160T: - printf ("29LV160T (16 M, top sector)\n"); - break; - case FLASH_AM160B: - printf ("29LV160B (16 M, bottom sector)\n"); - break; - case FLASH_AMDL322T: - printf ("29DL322T (32 M, top sector)\n"); - break; - case FLASH_AMDL322B: - printf ("29DL322B (32 M, bottom sector)\n"); - break; - case FLASH_AMDL323T: - printf ("29DL323T (32 M, top sector)\n"); - break; - case FLASH_AMDL323B: - printf ("29DL323B (32 M, bottom sector)\n"); - break; - case FLASH_AM640U: - printf ("29LV640D (64 M, uniform sector)\n"); - break; - default: - printf ("Unknown Chip Type\n"); - break; + switch (info->flash_id & FLASH_TYPEMASK) { + case FLASH_AM800T: printf ("29LV800T (8 M, top sector)\n"); + break; + case FLASH_AM800B: printf ("29LV800T (8 M, bottom sector)\n"); + break; + case FLASH_AM160T: printf ("29LV160T (16 M, top sector)\n"); + break; + case FLASH_AM160B: printf ("29LV160B (16 M, bottom sector)\n"); + break; + case FLASH_AMDL322T: printf ("29DL322T (32 M, top sector)\n"); + break; + case FLASH_AMDL322B: printf ("29DL322B (32 M, bottom sector)\n"); + break; + case FLASH_AMDL323T: printf ("29DL323T (32 M, top sector)\n"); + break; + case FLASH_AMDL323B: printf ("29DL323B (32 M, bottom sector)\n"); + break; + case FLASH_AM640U: printf ("29LV640D (64 M, uniform sector)\n"); + break; + default: printf ("Unknown Chip Type\n"); + break; } printf (" Size: %ld MB in %d Sectors\n", info->size >> 20, info->sector_count); printf (" Sector Start Addresses:"); - for (i=0; isector_count; ++i) - { + for (i=0; isector_count; ++i) { if ((i % 5) == 0) printf ("\n "); printf (" %08lX%s", @@ -287,10 +275,8 @@ int flash_erase (flash_info_t *info, int s_first, int s_last) int flag, prot, sect, l_sect; ulong start, now, last; - if ((s_first < 0) || (s_first > s_last)) - { - if (info->flash_id == FLASH_UNKNOWN) - { + if ((s_first < 0) || (s_first > s_last)) { + if (info->flash_id == FLASH_UNKNOWN) { printf ("- missing\n"); } else { printf ("- no sectors to erase\n"); @@ -299,18 +285,15 @@ int flash_erase (flash_info_t *info, int s_first, int s_last) } prot = 0; - for (sect = s_first; sect <= s_last; sect++) - { + for (sect = s_first; sect <= s_last; sect++) { if (info->protect[sect]) prot++; } - if (prot) - { + if (prot) { printf ("- Warning: %d protected sectors will not be erased!\n", prot); - } else - { + } else { printf ("\n"); } @@ -332,10 +315,8 @@ int flash_erase (flash_info_t *info, int s_first, int s_last) udelay (1000); /* Start erase on unprotected sectors */ - for (sect = s_first; sect<=s_last; sect++) - { - if (info->protect[sect] == 0) - { /* not protected */ + for (sect = s_first; sect<=s_last; sect++) { + if (info->protect[sect] == 0) { /* not protected */ V_ULONG( info->start[sect] ) = 0x00300030; V_ULONG( info->start[sect] + 4 ) = 0x00300030; l_sect = sect; @@ -360,14 +341,12 @@ int flash_erase (flash_info_t *info, int s_first, int s_last) while ((V_ULONG( info->start[l_sect] ) & 0x00800080) != 0x00800080 || (V_ULONG( info->start[l_sect] + 4 ) & 0x00800080) != 0x00800080) { - if ((now = get_timer(start)) > CFG_FLASH_ERASE_TOUT) - { + if ((now = get_timer(start)) > CFG_FLASH_ERASE_TOUT) { printf ("Timeout\n"); return 1; } /* show that we're waiting */ - if ((now - last) > 1000) - { /* every second */ + if ((now - last) > 1000) { /* every second */ serial_putc ('.'); last = now; } @@ -401,8 +380,7 @@ int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt) /* * handle unaligned start bytes */ - if ((l = addr - dp) != 0) - { + if ((l = addr - dp) != 0) { for (i = 0; i < 8; i++) bb[i] = (i < l || (i-l) >= cc) ? V_BYTE(dp+i) : *src++; if ((rc = write_dword(info, dp, bb)) != 0) @@ -416,10 +394,8 @@ int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt) /* * handle word aligned part */ - while (cc >= 8) - { - if ((rc = write_dword(info, dp, src)) != 0) - { + while (cc >= 8) { + if ((rc = write_dword(info, dp, src)) != 0) { return (rc); } dp += 8; @@ -427,16 +403,14 @@ int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt) cc -= 8; } - if (cc <= 0) - { + if (cc <= 0) { return (0); } /* * handle unaligned tail bytes */ - for (i = 0; i < 8; i++) - { + for (i = 0; i < 8; i++) { bb[i] = (i < cc) ? *src++ : V_BYTE(dp+i); } return (write_dword(info, dp, bb)); @@ -486,11 +460,9 @@ static int write_dword (flash_info_t *info, ulong dest, unsigned char * pdata) while( ((V_ULONG( dest ) & 0x00800080) != (ch & 0x00800080)) || ((V_ULONG( dest + 4 ) & 0x00800080) != (cl & 0x00800080)) ) { - if (get_timer(start) > CFG_FLASH_WRITE_TOUT) - { + if (get_timer(start) > CFG_FLASH_WRITE_TOUT) { return (1); } } return (0); } -