2 * (C) Copyright 2004-2005
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * (C) Copyright 2002 Jun Gu <jung@artesyncp.com>
6 * Add support for Am29F016D and dynamic switch setting.
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * Wait for completion of each sector erase command issued
31 * Chris Hallinan - DS4.COM, Inc. - clh@net1plus.com
36 #include <asm/processor.h>
38 flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */
40 /*-----------------------------------------------------------------------
43 static int write_word(flash_info_t * info, ulong dest, ulong data);
44 #ifdef CFG_FLASH_2ND_16BIT_DEV
45 static int write_word_1(flash_info_t * info, ulong dest, ulong data);
46 static int write_word_2(flash_info_t * info, ulong dest, ulong data);
47 static int flash_erase_1(flash_info_t * info, int s_first, int s_last);
48 static int flash_erase_2(flash_info_t * info, int s_first, int s_last);
49 static ulong flash_get_size_1(vu_long * addr, flash_info_t * info);
50 static ulong flash_get_size_2(vu_long * addr, flash_info_t * info);
53 void flash_print_info(flash_info_t * info)
59 volatile unsigned long *flash;
61 if (info->flash_id == FLASH_UNKNOWN) {
62 printf("missing or unknown FLASH type\n");
66 switch (info->flash_id & FLASH_VENDMASK) {
83 printf("Unknown Vendor ");
87 switch (info->flash_id & FLASH_TYPEMASK) {
89 printf("AM29F040 (512 Kbit, uniform sector size)\n");
92 printf("AM29LV400B (4 Mbit, bottom boot sect)\n");
95 printf("AM29LV400T (4 Mbit, top boot sector)\n");
98 printf("AM29LV800B (8 Mbit, bottom boot sect)\n");
101 printf("AM29LV800T (8 Mbit, top boot sector)\n");
104 printf("AM29F016D (16 Mbit, uniform sector size)\n");
107 printf("AM29LV160B (16 Mbit, bottom boot sect)\n");
110 printf("AM29LV160T (16 Mbit, top boot sector)\n");
113 printf("AM29LV320B (32 Mbit, bottom boot sect)\n");
116 printf("AM29LV320T (32 Mbit, top boot sector)\n");
119 printf("AM29LV033C (32 Mbit, top boot sector)\n");
122 printf("SST39LF/VF800 (8 Mbit, uniform sector size)\n");
125 printf("SST39LF/VF160 (16 Mbit, uniform sector size)\n");
127 case FLASH_STMW320DT:
128 printf ("M29W320DT (32 M, top sector)\n");
131 printf ("MXLV320T (32 Mbit, top sector)\n");
134 printf("Unknown Chip Type\n");
138 printf(" Size: %ld KB in %d Sectors\n",
139 info->size >> 10, info->sector_count);
141 printf(" Sector Start Addresses:");
142 for (i = 0; i < info->sector_count; ++i) {
144 * Check if whole sector is erased
146 if (i != (info->sector_count - 1))
147 size = info->start[i + 1] - info->start[i];
149 size = info->start[0] + info->size - info->start[i];
151 flash = (volatile unsigned long *)info->start[i];
152 size = size >> 2; /* divide by 4 for longword access */
153 for (k = 0; k < size; k++) {
154 if (*flash++ != 0xffffffff) {
164 erased ? " E" : " ", info->protect[i] ? "RO " : " ");
172 * The following code cannot be run from FLASH!
174 #ifdef CFG_FLASH_2ND_16BIT_DEV
175 static ulong flash_get_size(vu_long * addr, flash_info_t * info)
177 /* bit 0 used for big flash marking */
178 if ((ulong)addr & 0x1) {
179 return flash_get_size_2((vu_long *)((ulong)addr & 0xfffffffe), info);
181 return flash_get_size_1(addr, info);
185 static ulong flash_get_size_1(vu_long * addr, flash_info_t * info)
187 static ulong flash_get_size(vu_long * addr, flash_info_t * info)
191 CFG_FLASH_WORD_SIZE value;
192 ulong base = (ulong) addr;
193 volatile CFG_FLASH_WORD_SIZE *addr2 = (CFG_FLASH_WORD_SIZE *) addr;
195 DEBUGF("FLASH ADDR: %08x\n", (unsigned)addr);
197 /* Write auto select command: read Manufacturer ID */
198 addr2[CFG_FLASH_ADDR0] = (CFG_FLASH_WORD_SIZE) 0x00AA00AA;
199 addr2[CFG_FLASH_ADDR1] = (CFG_FLASH_WORD_SIZE) 0x00550055;
200 addr2[CFG_FLASH_ADDR0] = (CFG_FLASH_WORD_SIZE) 0x00900090;
204 DEBUGF("FLASH MANUFACT: %x\n", value);
207 case (CFG_FLASH_WORD_SIZE) AMD_MANUFACT:
208 info->flash_id = FLASH_MAN_AMD;
210 case (CFG_FLASH_WORD_SIZE) FUJ_MANUFACT:
211 info->flash_id = FLASH_MAN_FUJ;
213 case (CFG_FLASH_WORD_SIZE) SST_MANUFACT:
214 info->flash_id = FLASH_MAN_SST;
216 case (CFG_FLASH_WORD_SIZE) STM_MANUFACT:
217 info->flash_id = FLASH_MAN_STM;
220 info->flash_id = FLASH_UNKNOWN;
221 info->sector_count = 0;
223 return (0); /* no or unknown flash */
226 value = addr2[1]; /* device ID */
227 DEBUGF("\nFLASH DEVICEID: %x\n", value);
230 case (CFG_FLASH_WORD_SIZE) AMD_ID_LV040B:
231 info->flash_id += FLASH_AM040;
232 info->sector_count = 8;
233 info->size = 0x0080000; /* => 512 KiB */
236 case (CFG_FLASH_WORD_SIZE) AMD_ID_F040B:
237 info->flash_id += FLASH_AM040;
238 info->sector_count = 8;
239 info->size = 0x0080000; /* => 512 KiB */
242 case (CFG_FLASH_WORD_SIZE) STM_ID_M29W040B:
243 info->flash_id += FLASH_AM040;
244 info->sector_count = 8;
245 info->size = 0x0080000; /* => 512 KiB */
248 case (CFG_FLASH_WORD_SIZE) AMD_ID_F016D:
249 info->flash_id += FLASH_AMD016;
250 info->sector_count = 32;
251 info->size = 0x00200000; /* => 2 MiB */
254 case (CFG_FLASH_WORD_SIZE) AMD_ID_LV033C:
255 info->flash_id += FLASH_AMDLV033C;
256 info->sector_count = 64;
257 info->size = 0x00400000; /* => 4 MiB */
260 case (CFG_FLASH_WORD_SIZE) AMD_ID_LV400T:
261 info->flash_id += FLASH_AM400T;
262 info->sector_count = 11;
263 info->size = 0x00080000; /* => 512 KiB */
266 case (CFG_FLASH_WORD_SIZE) AMD_ID_LV400B:
267 info->flash_id += FLASH_AM400B;
268 info->sector_count = 11;
269 info->size = 0x00080000; /* => 512 KiB */
272 case (CFG_FLASH_WORD_SIZE) AMD_ID_LV800T:
273 info->flash_id += FLASH_AM800T;
274 info->sector_count = 19;
275 info->size = 0x00100000; /* => 1 MiB */
278 case (CFG_FLASH_WORD_SIZE) AMD_ID_LV800B:
279 info->flash_id += FLASH_AM800B;
280 info->sector_count = 19;
281 info->size = 0x00100000; /* => 1 MiB */
284 case (CFG_FLASH_WORD_SIZE) AMD_ID_LV160T:
285 info->flash_id += FLASH_AM160T;
286 info->sector_count = 35;
287 info->size = 0x00200000; /* => 2 MiB */
290 case (CFG_FLASH_WORD_SIZE) AMD_ID_LV160B:
291 info->flash_id += FLASH_AM160B;
292 info->sector_count = 35;
293 info->size = 0x00200000; /* => 2 MiB */
297 info->flash_id = FLASH_UNKNOWN;
298 return (0); /* => no or unknown flash */
301 /* set up sector start address table */
302 if (((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST) ||
303 ((info->flash_id & FLASH_TYPEMASK) == FLASH_AM040) ||
304 ((info->flash_id & FLASH_TYPEMASK) == FLASH_AMD016)) {
305 for (i = 0; i < info->sector_count; i++)
306 info->start[i] = base + (i * 0x00010000);
308 if (info->flash_id & FLASH_BTYPE) {
309 /* set sector offsets for bottom boot block type */
310 info->start[0] = base + 0x00000000;
311 info->start[1] = base + 0x00004000;
312 info->start[2] = base + 0x00006000;
313 info->start[3] = base + 0x00008000;
314 for (i = 4; i < info->sector_count; i++) {
316 base + (i * 0x00010000) - 0x00030000;
319 /* set sector offsets for top boot block type */
320 i = info->sector_count - 1;
321 info->start[i--] = base + info->size - 0x00004000;
322 info->start[i--] = base + info->size - 0x00006000;
323 info->start[i--] = base + info->size - 0x00008000;
324 for (; i >= 0; i--) {
325 info->start[i] = base + i * 0x00010000;
330 /* check for protected sectors */
331 for (i = 0; i < info->sector_count; i++) {
332 /* read sector protection at sector address, (A7 .. A0) = 0x02 */
333 /* D0 = 1 if protected */
334 addr2 = (volatile CFG_FLASH_WORD_SIZE *)(info->start[i]);
336 /* For AMD29033C flash we need to resend the command of *
337 * reading flash protection for upper 8 Mb of flash */
339 addr2[CFG_FLASH_ADDR0] = (CFG_FLASH_WORD_SIZE) 0xAAAAAAAA;
340 addr2[CFG_FLASH_ADDR1] = (CFG_FLASH_WORD_SIZE) 0x55555555;
341 addr2[CFG_FLASH_ADDR0] = (CFG_FLASH_WORD_SIZE) 0x90909090;
344 if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST)
345 info->protect[i] = 0;
347 info->protect[i] = addr2[2] & 1;
350 /* issue bank reset to return to read mode */
351 addr2[0] = (CFG_FLASH_WORD_SIZE) 0x00F000F0;
356 static int wait_for_DQ7_1(flash_info_t * info, int sect)
358 ulong start, now, last;
359 volatile CFG_FLASH_WORD_SIZE *addr =
360 (CFG_FLASH_WORD_SIZE *) (info->start[sect]);
362 start = get_timer(0);
364 while ((addr[0] & (CFG_FLASH_WORD_SIZE) 0x00800080) !=
365 (CFG_FLASH_WORD_SIZE) 0x00800080) {
366 if ((now = get_timer(start)) > CFG_FLASH_ERASE_TOUT) {
370 /* show that we're waiting */
371 if ((now - last) > 1000) { /* every second */
379 #ifdef CFG_FLASH_2ND_16BIT_DEV
380 int flash_erase(flash_info_t * info, int s_first, int s_last)
382 if (((info->flash_id & FLASH_TYPEMASK) == FLASH_AM320B) ||
383 ((info->flash_id & FLASH_TYPEMASK) == FLASH_AM320T) ||
384 ((info->flash_id & FLASH_TYPEMASK) == FLASH_MXLV320T) ||
385 ((info->flash_id & FLASH_TYPEMASK) == FLASH_STMW320DT)) {
386 return flash_erase_2(info, s_first, s_last);
388 return flash_erase_1(info, s_first, s_last);
392 static int flash_erase_1(flash_info_t * info, int s_first, int s_last)
394 int flash_erase(flash_info_t * info, int s_first, int s_last)
397 volatile CFG_FLASH_WORD_SIZE *addr = (CFG_FLASH_WORD_SIZE *) (info->start[0]);
398 volatile CFG_FLASH_WORD_SIZE *addr2;
399 int flag, prot, sect, l_sect;
402 if ((s_first < 0) || (s_first > s_last)) {
403 if (info->flash_id == FLASH_UNKNOWN) {
404 printf("- missing\n");
406 printf("- no sectors to erase\n");
411 if (info->flash_id == FLASH_UNKNOWN) {
412 printf("Can't erase unknown flash type - aborted\n");
417 for (sect = s_first; sect <= s_last; ++sect) {
418 if (info->protect[sect]) {
424 printf("- Warning: %d protected sectors will not be erased!\n",
432 /* Disable interrupts which might cause a timeout here */
433 flag = disable_interrupts();
435 /* Start erase on unprotected sectors */
436 for (sect = s_first; sect <= s_last; sect++) {
437 if (info->protect[sect] == 0) { /* not protected */
438 addr2 = (CFG_FLASH_WORD_SIZE *) (info->start[sect]);
440 if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST) {
441 addr[CFG_FLASH_ADDR0] = (CFG_FLASH_WORD_SIZE) 0x00AA00AA;
442 addr[CFG_FLASH_ADDR1] = (CFG_FLASH_WORD_SIZE) 0x00550055;
443 addr[CFG_FLASH_ADDR0] = (CFG_FLASH_WORD_SIZE) 0x00800080;
444 addr[CFG_FLASH_ADDR0] = (CFG_FLASH_WORD_SIZE) 0x00AA00AA;
445 addr[CFG_FLASH_ADDR1] = (CFG_FLASH_WORD_SIZE) 0x00550055;
446 addr2[0] = (CFG_FLASH_WORD_SIZE) 0x00500050; /* block erase */
447 for (i = 0; i < 50; i++)
448 udelay(1000); /* wait 1 ms */
450 addr[CFG_FLASH_ADDR0] = (CFG_FLASH_WORD_SIZE) 0x00AA00AA;
451 addr[CFG_FLASH_ADDR1] = (CFG_FLASH_WORD_SIZE) 0x00550055;
452 addr[CFG_FLASH_ADDR0] = (CFG_FLASH_WORD_SIZE) 0x00800080;
453 addr[CFG_FLASH_ADDR0] = (CFG_FLASH_WORD_SIZE) 0x00AA00AA;
454 addr[CFG_FLASH_ADDR1] = (CFG_FLASH_WORD_SIZE) 0x00550055;
455 addr2[0] = (CFG_FLASH_WORD_SIZE) 0x00300030; /* sector erase */
459 * Wait for each sector to complete, it's more
460 * reliable. According to AMD Spec, you must
461 * issue all erase commands within a specified
462 * timeout. This has been seen to fail, especially
463 * if printf()s are included (for debug)!!
465 wait_for_DQ7_1(info, sect);
469 /* re-enable interrupts if necessary */
473 /* wait at least 80us - let's wait 1 ms */
476 /* reset to read mode */
477 addr = (CFG_FLASH_WORD_SIZE *) info->start[0];
478 addr[0] = (CFG_FLASH_WORD_SIZE) 0x00F000F0; /* reset bank */
484 /*-----------------------------------------------------------------------
485 * Copy memory to flash, returns:
488 * 2 - Flash not erased
490 int write_buff(flash_info_t * info, uchar * src, ulong addr, ulong cnt)
495 wp = (addr & ~3); /* get lower word aligned address */
498 * handle unaligned start bytes
500 if ((l = addr - wp) != 0) {
502 for (i = 0, cp = wp; i < l; ++i, ++cp) {
503 data = (data << 8) | (*(uchar *) cp);
505 for (; i < 4 && cnt > 0; ++i) {
506 data = (data << 8) | *src++;
510 for (; cnt == 0 && i < 4; ++i, ++cp) {
511 data = (data << 8) | (*(uchar *) cp);
514 if ((rc = write_word(info, wp, data)) != 0) {
521 * handle word aligned part
525 for (i = 0; i < 4; ++i) {
526 data = (data << 8) | *src++;
528 if ((rc = write_word(info, wp, data)) != 0) {
540 * handle unaligned tail bytes
543 for (i = 0, cp = wp; i < 4 && cnt > 0; ++i, ++cp) {
544 data = (data << 8) | *src++;
547 for (; i < 4; ++i, ++cp) {
548 data = (data << 8) | (*(uchar *) cp);
551 return (write_word(info, wp, data));
554 /*-----------------------------------------------------------------------
555 * Copy memory to flash, returns:
558 * 2 - Flash not erased
560 #ifdef CFG_FLASH_2ND_16BIT_DEV
561 static int write_word(flash_info_t * info, ulong dest, ulong data)
563 if (((info->flash_id & FLASH_TYPEMASK) == FLASH_AM320B) ||
564 ((info->flash_id & FLASH_TYPEMASK) == FLASH_AM320T) ||
565 ((info->flash_id & FLASH_TYPEMASK) == FLASH_MXLV320T) ||
566 ((info->flash_id & FLASH_TYPEMASK) == FLASH_STMW320DT)) {
567 return write_word_2(info, dest, data);
569 return write_word_1(info, dest, data);
573 static int write_word_1(flash_info_t * info, ulong dest, ulong data)
575 static int write_word(flash_info_t * info, ulong dest, ulong data)
578 volatile CFG_FLASH_WORD_SIZE *addr2 = (CFG_FLASH_WORD_SIZE *) (info->start[0]);
579 volatile CFG_FLASH_WORD_SIZE *dest2 = (CFG_FLASH_WORD_SIZE *) dest;
580 volatile CFG_FLASH_WORD_SIZE *data2 = (CFG_FLASH_WORD_SIZE *) & data;
584 /* Check if Flash is (sufficiently) erased */
585 if ((*((vu_long *)dest) & data) != data) {
589 for (i = 0; i < 4 / sizeof(CFG_FLASH_WORD_SIZE); i++) {
592 /* Disable interrupts which might cause a timeout here */
593 flag = disable_interrupts();
595 addr2[CFG_FLASH_ADDR0] = (CFG_FLASH_WORD_SIZE) 0x00AA00AA;
596 addr2[CFG_FLASH_ADDR1] = (CFG_FLASH_WORD_SIZE) 0x00550055;
597 addr2[CFG_FLASH_ADDR0] = (CFG_FLASH_WORD_SIZE) 0x00A000A0;
601 /* re-enable interrupts if necessary */
605 /* data polling for D7 */
606 start = get_timer(0);
607 while ((dest2[i] & (CFG_FLASH_WORD_SIZE) 0x00800080) !=
608 (data2[i] & (CFG_FLASH_WORD_SIZE) 0x00800080)) {
610 if (get_timer(start) > CFG_FLASH_WRITE_TOUT) {
619 #ifdef CFG_FLASH_2ND_16BIT_DEV
621 #undef CFG_FLASH_WORD_SIZE
622 #define CFG_FLASH_WORD_SIZE unsigned short
625 * The following code cannot be run from FLASH!
627 static ulong flash_get_size_2(vu_long * addr, flash_info_t * info)
631 CFG_FLASH_WORD_SIZE value;
632 ulong base = (ulong) addr;
633 volatile CFG_FLASH_WORD_SIZE *addr2 = (CFG_FLASH_WORD_SIZE *) addr;
635 DEBUGF("FLASH ADDR: %08x\n", (unsigned)addr);
637 /* Write auto select command: read Manufacturer ID */
638 addr2[CFG_FLASH_ADDR0] = (CFG_FLASH_WORD_SIZE) 0x00AA00AA;
639 addr2[CFG_FLASH_ADDR1] = (CFG_FLASH_WORD_SIZE) 0x00550055;
640 addr2[CFG_FLASH_ADDR0] = (CFG_FLASH_WORD_SIZE) 0x00900090;
644 DEBUGF("FLASH MANUFACT: %x\n", value);
647 case (CFG_FLASH_WORD_SIZE) AMD_MANUFACT:
648 info->flash_id = FLASH_MAN_AMD;
650 case (CFG_FLASH_WORD_SIZE) FUJ_MANUFACT:
651 info->flash_id = FLASH_MAN_FUJ;
653 case (CFG_FLASH_WORD_SIZE) SST_MANUFACT:
654 info->flash_id = FLASH_MAN_SST;
656 case (CFG_FLASH_WORD_SIZE) STM_MANUFACT:
657 info->flash_id = FLASH_MAN_STM;
659 case (CFG_FLASH_WORD_SIZE) MX_MANUFACT:
660 info->flash_id = FLASH_MAN_MX;
663 info->flash_id = FLASH_UNKNOWN;
664 info->sector_count = 0;
666 return (0); /* no or unknown flash */
669 value = addr2[1]; /* device ID */
671 DEBUGF("\nFLASH DEVICEID: %x\n", value);
675 case (CFG_FLASH_WORD_SIZE)AMD_ID_LV320T:
676 info->flash_id += FLASH_AM320T;
677 info->sector_count = 71;
678 info->size = 0x00400000; break; /* => 4 MiB */
680 case (CFG_FLASH_WORD_SIZE)AMD_ID_LV320B:
681 info->flash_id += FLASH_AM320B;
682 info->sector_count = 71;
683 info->size = 0x00400000; break; /* => 4 MiB */
685 case (CFG_FLASH_WORD_SIZE)STM_ID_29W320DT:
686 info->flash_id += FLASH_STMW320DT;
687 info->sector_count = 67;
688 info->size = 0x00400000; break; /* => 4 MiB */
690 case (CFG_FLASH_WORD_SIZE)MX_ID_LV320T:
691 info->flash_id += FLASH_MXLV320T;
692 info->sector_count = 71;
693 info->size = 0x00400000;
697 info->flash_id = FLASH_UNKNOWN;
698 return (0); /* => no or unknown flash */
701 /* set up sector start address table */
702 if (((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST) ||
703 ((info->flash_id & FLASH_TYPEMASK) == FLASH_AM040) ||
704 ((info->flash_id & FLASH_TYPEMASK) == FLASH_AMD016)) {
705 for (i = 0; i < info->sector_count; i++)
706 info->start[i] = base + (i * 0x00010000);
707 } else if ((info->flash_id & FLASH_TYPEMASK) == FLASH_STMW320DT) {
708 /* set sector offsets for top boot block type */
710 i = info->sector_count;
711 /* 1 x 16k boot sector */
714 info->start[i] = base;
715 /* 2 x 8k boot sectors */
716 for (n=0; n<2; ++n) {
719 info->start[i] = base;
721 /* 1 x 32k boot sector */
724 info->start[i] = base;
726 while (i > 0) { /* 64k regular sectors */
729 info->start[i] = base;
731 } else if ((info->flash_id & FLASH_TYPEMASK) == FLASH_MXLV320T) {
732 i = info->sector_count - 1;
733 info->start[i--] = base + info->size - 0x00002000;
734 info->start[i--] = base + info->size - 0x00004000;
735 info->start[i--] = base + info->size - 0x00006000;
736 info->start[i--] = base + info->size - 0x00008000;
737 info->start[i--] = base + info->size - 0x0000a000;
738 info->start[i--] = base + info->size - 0x0000c000;
739 info->start[i--] = base + info->size - 0x0000e000;
740 info->start[i--] = base + info->size - 0x00010000;
743 info->start[i] = base + i * 0x00010000;
745 if (info->flash_id & FLASH_BTYPE) {
746 /* set sector offsets for bottom boot block type */
747 info->start[0] = base + 0x00000000;
748 info->start[1] = base + 0x00004000;
749 info->start[2] = base + 0x00006000;
750 info->start[3] = base + 0x00008000;
751 for (i = 4; i < info->sector_count; i++) {
753 base + (i * 0x00010000) - 0x00030000;
756 /* set sector offsets for top boot block type */
757 i = info->sector_count - 1;
758 info->start[i--] = base + info->size - 0x00004000;
759 info->start[i--] = base + info->size - 0x00006000;
760 info->start[i--] = base + info->size - 0x00008000;
761 for (; i >= 0; i--) {
762 info->start[i] = base + i * 0x00010000;
767 /* check for protected sectors */
768 for (i = 0; i < info->sector_count; i++) {
769 /* read sector protection at sector address, (A7 .. A0) = 0x02 */
770 /* D0 = 1 if protected */
771 addr2 = (volatile CFG_FLASH_WORD_SIZE *)(info->start[i]);
773 /* For AMD29033C flash we need to resend the command of *
774 * reading flash protection for upper 8 Mb of flash */
776 addr2[CFG_FLASH_ADDR0] = (CFG_FLASH_WORD_SIZE) 0xAAAAAAAA;
777 addr2[CFG_FLASH_ADDR1] = (CFG_FLASH_WORD_SIZE) 0x55555555;
778 addr2[CFG_FLASH_ADDR0] = (CFG_FLASH_WORD_SIZE) 0x90909090;
781 if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST)
782 info->protect[i] = 0;
784 info->protect[i] = addr2[2] & 1;
787 /* issue bank reset to return to read mode */
788 addr2[0] = (CFG_FLASH_WORD_SIZE) 0x00F000F0;
793 static int wait_for_DQ7_2(flash_info_t * info, int sect)
795 ulong start, now, last;
796 volatile CFG_FLASH_WORD_SIZE *addr =
797 (CFG_FLASH_WORD_SIZE *) (info->start[sect]);
799 start = get_timer(0);
801 while ((addr[0] & (CFG_FLASH_WORD_SIZE) 0x00800080) !=
802 (CFG_FLASH_WORD_SIZE) 0x00800080) {
803 if ((now = get_timer(start)) > CFG_FLASH_ERASE_TOUT) {
807 /* show that we're waiting */
808 if ((now - last) > 1000) { /* every second */
816 static int flash_erase_2(flash_info_t * info, int s_first, int s_last)
818 volatile CFG_FLASH_WORD_SIZE *addr = (CFG_FLASH_WORD_SIZE *) (info->start[0]);
819 volatile CFG_FLASH_WORD_SIZE *addr2;
820 int flag, prot, sect, l_sect;
823 if ((s_first < 0) || (s_first > s_last)) {
824 if (info->flash_id == FLASH_UNKNOWN) {
825 printf("- missing\n");
827 printf("- no sectors to erase\n");
832 if (info->flash_id == FLASH_UNKNOWN) {
833 printf("Can't erase unknown flash type - aborted\n");
838 for (sect = s_first; sect <= s_last; ++sect) {
839 if (info->protect[sect]) {
845 printf("- Warning: %d protected sectors will not be erased!\n",
853 /* Disable interrupts which might cause a timeout here */
854 flag = disable_interrupts();
856 /* Start erase on unprotected sectors */
857 for (sect = s_first; sect <= s_last; sect++) {
858 if (info->protect[sect] == 0) { /* not protected */
859 addr2 = (CFG_FLASH_WORD_SIZE *) (info->start[sect]);
861 if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST) {
862 addr[CFG_FLASH_ADDR0] = (CFG_FLASH_WORD_SIZE) 0x00AA00AA;
863 addr[CFG_FLASH_ADDR1] = (CFG_FLASH_WORD_SIZE) 0x00550055;
864 addr[CFG_FLASH_ADDR0] = (CFG_FLASH_WORD_SIZE) 0x00800080;
865 addr[CFG_FLASH_ADDR0] = (CFG_FLASH_WORD_SIZE) 0x00AA00AA;
866 addr[CFG_FLASH_ADDR1] = (CFG_FLASH_WORD_SIZE) 0x00550055;
867 addr2[0] = (CFG_FLASH_WORD_SIZE) 0x00500050; /* block erase */
868 for (i = 0; i < 50; i++)
869 udelay(1000); /* wait 1 ms */
871 addr[CFG_FLASH_ADDR0] = (CFG_FLASH_WORD_SIZE) 0x00AA00AA;
872 addr[CFG_FLASH_ADDR1] = (CFG_FLASH_WORD_SIZE) 0x00550055;
873 addr[CFG_FLASH_ADDR0] = (CFG_FLASH_WORD_SIZE) 0x00800080;
874 addr[CFG_FLASH_ADDR0] = (CFG_FLASH_WORD_SIZE) 0x00AA00AA;
875 addr[CFG_FLASH_ADDR1] = (CFG_FLASH_WORD_SIZE) 0x00550055;
876 addr2[0] = (CFG_FLASH_WORD_SIZE) 0x00300030; /* sector erase */
880 * Wait for each sector to complete, it's more
881 * reliable. According to AMD Spec, you must
882 * issue all erase commands within a specified
883 * timeout. This has been seen to fail, especially
884 * if printf()s are included (for debug)!!
886 wait_for_DQ7_2(info, sect);
890 /* re-enable interrupts if necessary */
894 /* wait at least 80us - let's wait 1 ms */
897 /* reset to read mode */
898 addr = (CFG_FLASH_WORD_SIZE *) info->start[0];
899 addr[0] = (CFG_FLASH_WORD_SIZE) 0x00F000F0; /* reset bank */
905 static int write_word_2(flash_info_t * info, ulong dest, ulong data)
907 volatile CFG_FLASH_WORD_SIZE *addr2 = (CFG_FLASH_WORD_SIZE *) (info->start[0]);
908 volatile CFG_FLASH_WORD_SIZE *dest2 = (CFG_FLASH_WORD_SIZE *) dest;
909 volatile CFG_FLASH_WORD_SIZE *data2 = (CFG_FLASH_WORD_SIZE *) & data;
913 /* Check if Flash is (sufficiently) erased */
914 if ((*((vu_long *)dest) & data) != data) {
918 for (i = 0; i < 4 / sizeof(CFG_FLASH_WORD_SIZE); i++) {
921 /* Disable interrupts which might cause a timeout here */
922 flag = disable_interrupts();
924 addr2[CFG_FLASH_ADDR0] = (CFG_FLASH_WORD_SIZE) 0x00AA00AA;
925 addr2[CFG_FLASH_ADDR1] = (CFG_FLASH_WORD_SIZE) 0x00550055;
926 addr2[CFG_FLASH_ADDR0] = (CFG_FLASH_WORD_SIZE) 0x00A000A0;
930 /* re-enable interrupts if necessary */
934 /* data polling for D7 */
935 start = get_timer(0);
936 while ((dest2[i] & (CFG_FLASH_WORD_SIZE) 0x00800080) !=
937 (data2[i] & (CFG_FLASH_WORD_SIZE) 0x00800080)) {
939 if (get_timer(start) > CFG_FLASH_WRITE_TOUT) {
947 #endif /* CFG_FLASH_2ND_16BIT_DEV */