2 * (C) Copyright 2002-2004
3 * Brad Kemp, Seranoa Networks, Brad.Kemp@seranoa.com
5 * Copyright (C) 2003, 2006 Arabella Software Ltd.
6 * Yuli Barcohen <yuli@arabellasw.com>
12 * Tolunay Orkun <listmember@orkun.us>
14 * See file CREDITS for list of people who contributed to this
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License as
19 * published by the Free Software Foundation; either version 2 of
20 * the License, or (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
34 /* The DEBUG define must be before common to enable debugging */
39 #ifdef CFG_FLASH_CFI_DRIVER
42 #include <asm/processor.h>
43 #include <asm/byteorder.h>
44 #include <environment.h>
47 * This file implements a Common Flash Interface (CFI) driver for U-Boot.
48 * The width of the port and the width of the chips are determined at initialization.
49 * These widths are used to calculate the address for access CFI data structures.
52 * JEDEC Standard JESD68 - Common Flash Interface (CFI)
53 * JEDEC Standard JEP137-A Common Flash Interface (CFI) ID Codes
54 * Intel Application Note 646 Common Flash Interface (CFI) and Command Sets
55 * Intel 290667-008 3 Volt Intel StrataFlash Memory datasheet
56 * AMD CFI Specification, Release 2.0 December 1, 2001
57 * AMD/Spansion Application Note: Migration from Single-byte to Three-byte
58 * Device IDs, Publication Number 25538 Revision A, November 8, 2001
62 #if defined(__LITTLE_ENDIAN) && !defined(CFG_FLASH_CFI_SWAP)
63 #define CFG_FLASH_CFI_SWAP
66 #ifndef CFG_FLASH_BANKS_LIST
67 #define CFG_FLASH_BANKS_LIST { CFG_FLASH_BASE }
70 #define FLASH_CMD_CFI 0x98
71 #define FLASH_CMD_READ_ID 0x90
72 #define FLASH_CMD_RESET 0xff
73 #define FLASH_CMD_BLOCK_ERASE 0x20
74 #define FLASH_CMD_ERASE_CONFIRM 0xD0
75 #define FLASH_CMD_WRITE 0x40
76 #define FLASH_CMD_PROTECT 0x60
77 #define FLASH_CMD_PROTECT_SET 0x01
78 #define FLASH_CMD_PROTECT_CLEAR 0xD0
79 #define FLASH_CMD_CLEAR_STATUS 0x50
80 #define FLASH_CMD_WRITE_TO_BUFFER 0xE8
81 #define FLASH_CMD_WRITE_BUFFER_CONFIRM 0xD0
83 #define FLASH_STATUS_DONE 0x80
84 #define FLASH_STATUS_ESS 0x40
85 #define FLASH_STATUS_ECLBS 0x20
86 #define FLASH_STATUS_PSLBS 0x10
87 #define FLASH_STATUS_VPENS 0x08
88 #define FLASH_STATUS_PSS 0x04
89 #define FLASH_STATUS_DPS 0x02
90 #define FLASH_STATUS_R 0x01
91 #define FLASH_STATUS_PROTECT 0x01
93 #define AMD_CMD_RESET 0xF0
94 #define AMD_CMD_WRITE 0xA0
95 #define AMD_CMD_ERASE_START 0x80
96 #define AMD_CMD_ERASE_SECTOR 0x30
97 #define AMD_CMD_UNLOCK_START 0xAA
98 #define AMD_CMD_UNLOCK_ACK 0x55
99 #define AMD_CMD_WRITE_TO_BUFFER 0x25
100 #define AMD_CMD_WRITE_BUFFER_CONFIRM 0x29
102 #define AMD_STATUS_TOGGLE 0x40
103 #define AMD_STATUS_ERROR 0x20
105 #define AMD_ADDR_ERASE_START ((info->portwidth == FLASH_CFI_8BIT) ? 0xAAA : 0x555)
106 #define AMD_ADDR_START ((info->portwidth == FLASH_CFI_8BIT) ? 0xAAA : 0x555)
107 #define AMD_ADDR_ACK ((info->portwidth == FLASH_CFI_8BIT) ? 0x555 : 0x2AA)
109 #define FLASH_OFFSET_MANUFACTURER_ID 0x00
110 #define FLASH_OFFSET_DEVICE_ID 0x01
111 #define FLASH_OFFSET_DEVICE_ID2 0x0E
112 #define FLASH_OFFSET_DEVICE_ID3 0x0F
113 #define FLASH_OFFSET_CFI 0x55
114 #define FLASH_OFFSET_CFI_ALT 0x555
115 #define FLASH_OFFSET_CFI_RESP 0x10
116 #define FLASH_OFFSET_PRIMARY_VENDOR 0x13
117 #define FLASH_OFFSET_EXT_QUERY_T_P_ADDR 0x15 /* extended query table primary addr */
118 #define FLASH_OFFSET_WTOUT 0x1F
119 #define FLASH_OFFSET_WBTOUT 0x20
120 #define FLASH_OFFSET_ETOUT 0x21
121 #define FLASH_OFFSET_CETOUT 0x22
122 #define FLASH_OFFSET_WMAX_TOUT 0x23
123 #define FLASH_OFFSET_WBMAX_TOUT 0x24
124 #define FLASH_OFFSET_EMAX_TOUT 0x25
125 #define FLASH_OFFSET_CEMAX_TOUT 0x26
126 #define FLASH_OFFSET_SIZE 0x27
127 #define FLASH_OFFSET_INTERFACE 0x28
128 #define FLASH_OFFSET_BUFFER_SIZE 0x2A
129 #define FLASH_OFFSET_NUM_ERASE_REGIONS 0x2C
130 #define FLASH_OFFSET_ERASE_REGIONS 0x2D
131 #define FLASH_OFFSET_PROTECT 0x02
132 #define FLASH_OFFSET_USER_PROTECTION 0x85
133 #define FLASH_OFFSET_INTEL_PROTECTION 0x81
135 #define CFI_CMDSET_NONE 0
136 #define CFI_CMDSET_INTEL_EXTENDED 1
137 #define CFI_CMDSET_AMD_STANDARD 2
138 #define CFI_CMDSET_INTEL_STANDARD 3
139 #define CFI_CMDSET_AMD_EXTENDED 4
140 #define CFI_CMDSET_MITSU_STANDARD 256
141 #define CFI_CMDSET_MITSU_EXTENDED 257
142 #define CFI_CMDSET_SST 258
144 #ifdef CFG_FLASH_CFI_AMD_RESET /* needed for STM_ID_29W320DB on UC100 */
145 # undef FLASH_CMD_RESET
146 # define FLASH_CMD_RESET AMD_CMD_RESET /* use AMD-Reset instead */
153 unsigned long long ll;
157 volatile unsigned char *cp;
158 volatile unsigned short *wp;
159 volatile unsigned long *lp;
160 volatile unsigned long long *llp;
163 #define NUM_ERASE_REGIONS 4 /* max. number of erase regions */
165 static uint flash_offset_cfi[2]={FLASH_OFFSET_CFI,FLASH_OFFSET_CFI_ALT};
167 /* use CFG_MAX_FLASH_BANKS_DETECT if defined */
168 #ifdef CFG_MAX_FLASH_BANKS_DETECT
169 static ulong bank_base[CFG_MAX_FLASH_BANKS_DETECT] = CFG_FLASH_BANKS_LIST;
170 flash_info_t flash_info[CFG_MAX_FLASH_BANKS_DETECT]; /* FLASH chips info */
172 static ulong bank_base[CFG_MAX_FLASH_BANKS] = CFG_FLASH_BANKS_LIST;
173 flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* FLASH chips info */
177 * Check if chip width is defined. If not, start detecting with 8bit.
179 #ifndef CFG_FLASH_CFI_WIDTH
180 #define CFG_FLASH_CFI_WIDTH FLASH_CFI_8BIT
184 /*-----------------------------------------------------------------------
188 typedef unsigned long flash_sect_t;
190 static void flash_add_byte (flash_info_t * info, cfiword_t * cword, uchar c);
191 static void flash_make_cmd (flash_info_t * info, uchar cmd, void *cmdbuf);
192 static void flash_write_cmd (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd);
193 static void flash_unlock_seq (flash_info_t * info, flash_sect_t sect);
194 static int flash_isequal (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd);
195 static int flash_isset (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd);
196 static int flash_toggle (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd);
197 static void flash_read_jedec_ids (flash_info_t * info);
198 static int flash_detect_cfi (flash_info_t * info);
199 static int flash_write_cfiword (flash_info_t * info, ulong dest, cfiword_t cword);
200 static int flash_full_status_check (flash_info_t * info, flash_sect_t sector,
201 ulong tout, char *prompt);
202 ulong flash_get_size (ulong base, int banknum);
203 #if defined(CFG_ENV_IS_IN_FLASH) || defined(CFG_ENV_ADDR_REDUND) || (CFG_MONITOR_BASE >= CFG_FLASH_BASE)
204 static flash_info_t *flash_get_info(ulong base);
206 #ifdef CFG_FLASH_USE_BUFFER_WRITE
207 static int flash_write_cfibuffer (flash_info_t * info, ulong dest, uchar * cp, int len);
210 /*-----------------------------------------------------------------------
211 * create an address based on the offset and the port width
213 inline uchar *flash_make_addr (flash_info_t * info, flash_sect_t sect, uint offset)
215 return ((uchar *) (info->start[sect] + (offset * info->portwidth)));
219 /*-----------------------------------------------------------------------
222 void print_longlong (char *str, unsigned long long data)
227 cp = (unsigned char *) &data;
228 for (i = 0; i < 8; i++)
229 sprintf (&str[i * 2], "%2.2x", *cp++);
231 static void flash_printqry (flash_info_t * info, flash_sect_t sect)
236 for (x = 0; x < 0x40; x += 16U / info->portwidth) {
238 flash_make_addr (info, sect,
239 x + FLASH_OFFSET_CFI_RESP);
240 debug ("%p : ", cptr.cp);
241 for (y = 0; y < 16; y++) {
242 debug ("%2.2x ", cptr.cp[y]);
245 for (y = 0; y < 16; y++) {
246 if (cptr.cp[y] >= 0x20 && cptr.cp[y] <= 0x7e) {
247 debug ("%c", cptr.cp[y]);
258 /*-----------------------------------------------------------------------
259 * read a character at a port width address
261 inline uchar flash_read_uchar (flash_info_t * info, uint offset)
265 cp = flash_make_addr (info, 0, offset);
266 #if defined(CFG_FLASH_CFI_SWAP)
269 return (cp[info->portwidth - 1]);
273 /*-----------------------------------------------------------------------
274 * read a short word by swapping for ppc format.
276 ushort flash_read_ushort (flash_info_t * info, flash_sect_t sect, uint offset)
284 addr = flash_make_addr (info, sect, offset);
287 debug ("ushort addr is at %p info->portwidth = %d\n", addr,
289 for (x = 0; x < 2 * info->portwidth; x++) {
290 debug ("addr[%x] = 0x%x\n", x, addr[x]);
293 #if defined(CFG_FLASH_CFI_SWAP)
294 retval = ((addr[(info->portwidth)] << 8) | addr[0]);
296 retval = ((addr[(2 * info->portwidth) - 1] << 8) |
297 addr[info->portwidth - 1]);
300 debug ("retval = 0x%x\n", retval);
304 /*-----------------------------------------------------------------------
305 * read a long word by picking the least significant byte of each maximum
306 * port size word. Swap for ppc format.
308 ulong flash_read_long (flash_info_t * info, flash_sect_t sect, uint offset)
316 addr = flash_make_addr (info, sect, offset);
319 debug ("long addr is at %p info->portwidth = %d\n", addr,
321 for (x = 0; x < 4 * info->portwidth; x++) {
322 debug ("addr[%x] = 0x%x\n", x, addr[x]);
325 #if defined(CFG_FLASH_CFI_SWAP)
326 retval = (addr[0] << 16) | (addr[(info->portwidth)] << 24) |
327 (addr[(2 * info->portwidth)]) | (addr[(3 * info->portwidth)] << 8);
329 retval = (addr[(2 * info->portwidth) - 1] << 24) |
330 (addr[(info->portwidth) - 1] << 16) |
331 (addr[(4 * info->portwidth) - 1] << 8) |
332 addr[(3 * info->portwidth) - 1];
338 /*-----------------------------------------------------------------------
340 unsigned long flash_init (void)
342 unsigned long size = 0;
345 #ifdef CFG_FLASH_PROTECTION
346 char *s = getenv("unlock");
349 /* Init: no FLASHes known */
350 for (i = 0; i < CFG_MAX_FLASH_BANKS; ++i) {
351 flash_info[i].flash_id = FLASH_UNKNOWN;
352 size += flash_info[i].size = flash_get_size (bank_base[i], i);
353 if (flash_info[i].flash_id == FLASH_UNKNOWN) {
354 #ifndef CFG_FLASH_QUIET_TEST
355 printf ("## Unknown FLASH on Bank %d - Size = 0x%08lx = %ld MB\n",
356 i+1, flash_info[i].size, flash_info[i].size << 20);
357 #endif /* CFG_FLASH_QUIET_TEST */
359 #ifdef CFG_FLASH_PROTECTION
360 else if ((s != NULL) && (strcmp(s, "yes") == 0)) {
362 * Only the U-Boot image and it's environment is protected,
363 * all other sectors are unprotected (unlocked) if flash
364 * hardware protection is used (CFG_FLASH_PROTECTION) and
365 * the environment variable "unlock" is set to "yes".
367 if (flash_info[i].legacy_unlock) {
371 * Disable legacy_unlock temporarily, since
372 * flash_real_protect would relock all other sectors
375 flash_info[i].legacy_unlock = 0;
378 * Legacy unlocking (e.g. Intel J3) -> unlock only one
379 * sector. This will unlock all sectors.
381 flash_real_protect (&flash_info[i], 0, 0);
383 flash_info[i].legacy_unlock = 1;
386 * Manually mark other sectors as unlocked (unprotected)
388 for (k = 1; k < flash_info[i].sector_count; k++)
389 flash_info[i].protect[k] = 0;
392 * No legancy unlocking -> unlock all sectors
394 flash_protect (FLAG_PROTECT_CLEAR,
395 flash_info[i].start[0],
396 flash_info[i].start[0] + flash_info[i].size - 1,
400 #endif /* CFG_FLASH_PROTECTION */
403 /* Monitor protection ON by default */
404 #if (CFG_MONITOR_BASE >= CFG_FLASH_BASE)
405 flash_protect (FLAG_PROTECT_SET,
407 CFG_MONITOR_BASE + monitor_flash_len - 1,
408 flash_get_info(CFG_MONITOR_BASE));
411 /* Environment protection ON by default */
412 #ifdef CFG_ENV_IS_IN_FLASH
413 flash_protect (FLAG_PROTECT_SET,
415 CFG_ENV_ADDR + CFG_ENV_SECT_SIZE - 1,
416 flash_get_info(CFG_ENV_ADDR));
419 /* Redundant environment protection ON by default */
420 #ifdef CFG_ENV_ADDR_REDUND
421 flash_protect (FLAG_PROTECT_SET,
423 CFG_ENV_ADDR_REDUND + CFG_ENV_SIZE_REDUND - 1,
424 flash_get_info(CFG_ENV_ADDR_REDUND));
429 /*-----------------------------------------------------------------------
431 #if defined(CFG_ENV_IS_IN_FLASH) || defined(CFG_ENV_ADDR_REDUND) || (CFG_MONITOR_BASE >= CFG_FLASH_BASE)
432 static flash_info_t *flash_get_info(ulong base)
435 flash_info_t * info = 0;
437 for (i = 0; i < CFG_MAX_FLASH_BANKS; i ++) {
438 info = & flash_info[i];
439 if (info->size && info->start[0] <= base &&
440 base <= info->start[0] + info->size - 1)
444 return i == CFG_MAX_FLASH_BANKS ? 0 : info;
448 /*-----------------------------------------------------------------------
450 int flash_erase (flash_info_t * info, int s_first, int s_last)
456 if (info->flash_id != FLASH_MAN_CFI) {
457 puts ("Can't erase unknown flash type - aborted\n");
460 if ((s_first < 0) || (s_first > s_last)) {
461 puts ("- no sectors to erase\n");
466 for (sect = s_first; sect <= s_last; ++sect) {
467 if (info->protect[sect]) {
472 printf ("- Warning: %d protected sectors will not be erased!\n", prot);
478 for (sect = s_first; sect <= s_last; sect++) {
479 if (info->protect[sect] == 0) { /* not protected */
480 switch (info->vendor) {
481 case CFI_CMDSET_INTEL_STANDARD:
482 case CFI_CMDSET_INTEL_EXTENDED:
483 flash_write_cmd (info, sect, 0, FLASH_CMD_CLEAR_STATUS);
484 flash_write_cmd (info, sect, 0, FLASH_CMD_BLOCK_ERASE);
485 flash_write_cmd (info, sect, 0, FLASH_CMD_ERASE_CONFIRM);
487 case CFI_CMDSET_AMD_STANDARD:
488 case CFI_CMDSET_AMD_EXTENDED:
489 flash_unlock_seq (info, sect);
490 flash_write_cmd (info, sect, AMD_ADDR_ERASE_START,
491 AMD_CMD_ERASE_START);
492 flash_unlock_seq (info, sect);
493 flash_write_cmd (info, sect, 0, AMD_CMD_ERASE_SECTOR);
496 debug ("Unkown flash vendor %d\n",
501 if (flash_full_status_check
502 (info, sect, info->erase_blk_tout, "erase")) {
512 /*-----------------------------------------------------------------------
514 void flash_print_info (flash_info_t * info)
518 if (info->flash_id != FLASH_MAN_CFI) {
519 puts ("missing or unknown FLASH type\n");
523 printf ("CFI conformant FLASH (%d x %d)",
524 (info->portwidth << 3), (info->chipwidth << 3));
525 printf (" Size: %ld MB in %d Sectors\n",
526 info->size >> 20, info->sector_count);
528 switch (info->vendor) {
529 case CFI_CMDSET_INTEL_STANDARD:
530 printf ("Intel Standard");
532 case CFI_CMDSET_INTEL_EXTENDED:
533 printf ("Intel Extended");
535 case CFI_CMDSET_AMD_STANDARD:
536 printf ("AMD Standard");
538 case CFI_CMDSET_AMD_EXTENDED:
539 printf ("AMD Extended");
542 printf ("Unknown (%d)", info->vendor);
545 printf (" command set, Manufacturer ID: 0x%02X, Device ID: 0x%02X",
546 info->manufacturer_id, info->device_id);
547 if (info->device_id == 0x7E) {
548 printf("%04X", info->device_id2);
550 printf ("\n Erase timeout: %ld ms, write timeout: %ld ms\n",
551 info->erase_blk_tout,
553 if (info->buffer_size > 1) {
554 printf (" Buffer write timeout: %ld ms, buffer size: %d bytes\n",
555 info->buffer_write_tout,
559 puts ("\n Sector Start Addresses:");
560 for (i = 0; i < info->sector_count; ++i) {
563 #ifdef CFG_FLASH_EMPTY_INFO
567 volatile unsigned long *flash;
570 * Check if whole sector is erased
572 if (i != (info->sector_count - 1))
573 size = info->start[i + 1] - info->start[i];
575 size = info->start[0] + info->size - info->start[i];
577 flash = (volatile unsigned long *) info->start[i];
578 size = size >> 2; /* divide by 4 for longword access */
579 for (k = 0; k < size; k++) {
580 if (*flash++ != 0xffffffff) {
586 /* print empty and read-only info */
587 printf (" %08lX %c %s ",
590 info->protect[i] ? "RO" : " ");
591 #else /* ! CFG_FLASH_EMPTY_INFO */
592 printf (" %08lX %s ",
594 info->protect[i] ? "RO" : " ");
601 /*-----------------------------------------------------------------------
602 * Copy memory to flash, returns:
605 * 2 - Flash not erased
607 int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
615 #ifdef CFG_FLASH_USE_BUFFER_WRITE
618 /* get lower aligned address */
619 /* get lower aligned address */
620 wp = (addr & ~(info->portwidth - 1));
622 /* handle unaligned start */
623 if ((aln = addr - wp) != 0) {
626 for (i = 0; i < aln; ++i, ++cp)
627 flash_add_byte (info, &cword, (*(uchar *) cp));
629 for (; (i < info->portwidth) && (cnt > 0); i++) {
630 flash_add_byte (info, &cword, *src++);
634 for (; (cnt == 0) && (i < info->portwidth); ++i, ++cp)
635 flash_add_byte (info, &cword, (*(uchar *) cp));
636 if ((rc = flash_write_cfiword (info, wp, cword)) != 0)
641 /* handle the aligned part */
642 #ifdef CFG_FLASH_USE_BUFFER_WRITE
643 buffered_size = (info->portwidth / info->chipwidth);
644 buffered_size *= info->buffer_size;
645 while (cnt >= info->portwidth) {
646 /* prohibit buffer write when buffer_size is 1 */
647 if (info->buffer_size == 1) {
649 for (i = 0; i < info->portwidth; i++)
650 flash_add_byte (info, &cword, *src++);
651 if ((rc = flash_write_cfiword (info, wp, cword)) != 0)
653 wp += info->portwidth;
654 cnt -= info->portwidth;
658 /* write buffer until next buffered_size aligned boundary */
659 i = buffered_size - (wp % buffered_size);
662 if ((rc = flash_write_cfibuffer (info, wp, src, i)) != ERR_OK)
664 i -= i & (info->portwidth - 1);
670 while (cnt >= info->portwidth) {
672 for (i = 0; i < info->portwidth; i++) {
673 flash_add_byte (info, &cword, *src++);
675 if ((rc = flash_write_cfiword (info, wp, cword)) != 0)
677 wp += info->portwidth;
678 cnt -= info->portwidth;
680 #endif /* CFG_FLASH_USE_BUFFER_WRITE */
686 * handle unaligned tail bytes
689 for (i = 0, cp = wp; (i < info->portwidth) && (cnt > 0); ++i, ++cp) {
690 flash_add_byte (info, &cword, *src++);
693 for (; i < info->portwidth; ++i, ++cp) {
694 flash_add_byte (info, &cword, (*(uchar *) cp));
697 return flash_write_cfiword (info, wp, cword);
700 /*-----------------------------------------------------------------------
702 #ifdef CFG_FLASH_PROTECTION
704 int flash_real_protect (flash_info_t * info, long sector, int prot)
708 flash_write_cmd (info, sector, 0, FLASH_CMD_CLEAR_STATUS);
709 flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT);
711 flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT_SET);
713 flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT_CLEAR);
716 flash_full_status_check (info, sector, info->erase_blk_tout,
717 prot ? "protect" : "unprotect")) == 0) {
719 info->protect[sector] = prot;
722 * On some of Intel's flash chips (marked via legacy_unlock)
723 * unprotect unprotects all locking.
725 if ((prot == 0) && (info->legacy_unlock)) {
728 for (i = 0; i < info->sector_count; i++) {
729 if (info->protect[i])
730 flash_real_protect (info, i, 1);
737 /*-----------------------------------------------------------------------
738 * flash_read_user_serial - read the OneTimeProgramming cells
740 void flash_read_user_serial (flash_info_t * info, void *buffer, int offset,
747 src = flash_make_addr (info, 0, FLASH_OFFSET_USER_PROTECTION);
748 flash_write_cmd (info, 0, 0, FLASH_CMD_READ_ID);
749 memcpy (dst, src + offset, len);
750 flash_write_cmd (info, 0, 0, info->cmd_reset);
754 * flash_read_factory_serial - read the device Id from the protection area
756 void flash_read_factory_serial (flash_info_t * info, void *buffer, int offset,
761 src = flash_make_addr (info, 0, FLASH_OFFSET_INTEL_PROTECTION);
762 flash_write_cmd (info, 0, 0, FLASH_CMD_READ_ID);
763 memcpy (buffer, src + offset, len);
764 flash_write_cmd (info, 0, 0, info->cmd_reset);
767 #endif /* CFG_FLASH_PROTECTION */
770 * flash_is_busy - check to see if the flash is busy
771 * This routine checks the status of the chip and returns true if the chip is busy
773 static int flash_is_busy (flash_info_t * info, flash_sect_t sect)
777 switch (info->vendor) {
778 case CFI_CMDSET_INTEL_STANDARD:
779 case CFI_CMDSET_INTEL_EXTENDED:
780 retval = !flash_isset (info, sect, 0, FLASH_STATUS_DONE);
782 case CFI_CMDSET_AMD_STANDARD:
783 case CFI_CMDSET_AMD_EXTENDED:
784 retval = flash_toggle (info, sect, 0, AMD_STATUS_TOGGLE);
789 debug ("flash_is_busy: %d\n", retval);
793 /*-----------------------------------------------------------------------
794 * wait for XSR.7 to be set. Time out with an error if it does not.
795 * This routine does not set the flash to read-array mode.
797 static int flash_status_check (flash_info_t * info, flash_sect_t sector,
798 ulong tout, char *prompt)
806 /* Wait for command completion */
807 start = get_timer (0);
808 while (flash_is_busy (info, sector)) {
809 if (get_timer (start) > tout) {
810 printf ("Flash %s timeout at address %lx data %lx\n",
811 prompt, info->start[sector],
812 flash_read_long (info, sector, 0));
813 flash_write_cmd (info, sector, 0, info->cmd_reset);
816 udelay (1); /* also triggers watchdog */
821 /*-----------------------------------------------------------------------
822 * Wait for XSR.7 to be set, if it times out print an error, otherwise do a full status check.
823 * This routine sets the flash to read-array mode.
825 static int flash_full_status_check (flash_info_t * info, flash_sect_t sector,
826 ulong tout, char *prompt)
830 retcode = flash_status_check (info, sector, tout, prompt);
831 switch (info->vendor) {
832 case CFI_CMDSET_INTEL_EXTENDED:
833 case CFI_CMDSET_INTEL_STANDARD:
834 if ((retcode == ERR_OK)
835 && !flash_isequal (info, sector, 0, FLASH_STATUS_DONE)) {
837 printf ("Flash %s error at address %lx\n", prompt,
838 info->start[sector]);
839 if (flash_isset (info, sector, 0, FLASH_STATUS_ECLBS | FLASH_STATUS_PSLBS)) {
840 puts ("Command Sequence Error.\n");
841 } else if (flash_isset (info, sector, 0, FLASH_STATUS_ECLBS)) {
842 puts ("Block Erase Error.\n");
843 retcode = ERR_NOT_ERASED;
844 } else if (flash_isset (info, sector, 0, FLASH_STATUS_PSLBS)) {
845 puts ("Locking Error\n");
847 if (flash_isset (info, sector, 0, FLASH_STATUS_DPS)) {
848 puts ("Block locked.\n");
849 retcode = ERR_PROTECTED;
851 if (flash_isset (info, sector, 0, FLASH_STATUS_VPENS))
852 puts ("Vpp Low Error.\n");
854 flash_write_cmd (info, sector, 0, info->cmd_reset);
862 /*-----------------------------------------------------------------------
864 static void flash_add_byte (flash_info_t * info, cfiword_t * cword, uchar c)
866 #if defined(__LITTLE_ENDIAN)
869 unsigned long long ll;
872 switch (info->portwidth) {
876 case FLASH_CFI_16BIT:
877 #if defined(__LITTLE_ENDIAN)
880 cword->w = (cword->w >> 8) | w;
882 cword->w = (cword->w << 8) | c;
885 case FLASH_CFI_32BIT:
886 #if defined(__LITTLE_ENDIAN)
889 cword->l = (cword->l >> 8) | l;
891 cword->l = (cword->l << 8) | c;
894 case FLASH_CFI_64BIT:
895 #if defined(__LITTLE_ENDIAN)
898 cword->ll = (cword->ll >> 8) | ll;
900 cword->ll = (cword->ll << 8) | c;
907 /*-----------------------------------------------------------------------
908 * make a proper sized command based on the port and chip widths
910 static void flash_make_cmd (flash_info_t * info, uchar cmd, void *cmdbuf)
913 uchar *cp = (uchar *) cmdbuf;
915 #if defined(CFG_FLASH_CFI_SWAP)
916 for (i = info->portwidth; i > 0; i--)
918 for (i = 1; i <= info->portwidth; i++)
920 *cp++ = (i & (info->chipwidth - 1)) ? '\0' : cmd;
921 #ifdef CFG_FLASH_CFI_2x16
922 if ((info->portwidth == FLASH_CFI_32BIT) && (info->chipwidth == FLASH_CFI_BY16))
925 cp = (uchar *) cmdbuf;
930 #endif /* CFG_FLASH_CFI_2x16 */
934 * Write a proper sized command to the correct address
936 static void flash_write_cmd (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd)
939 volatile cfiptr_t addr;
942 addr.cp = flash_make_addr (info, sect, offset);
943 flash_make_cmd (info, cmd, &cword);
944 switch (info->portwidth) {
946 debug ("fwc addr %p cmd %x %x 8bit x %d bit\n", addr.cp, cmd,
947 cword.c, info->chipwidth << CFI_FLASH_SHIFT_WIDTH);
949 #ifdef CONFIG_BLACKFIN
953 case FLASH_CFI_16BIT:
954 debug ("fwc addr %p cmd %x %4.4x 16bit x %d bit\n", addr.wp,
956 info->chipwidth << CFI_FLASH_SHIFT_WIDTH);
958 #ifdef CONFIG_BLACKFIN
962 case FLASH_CFI_32BIT:
963 debug ("fwc addr %p cmd %x %8.8lx 32bit x %d bit\n", addr.lp,
965 info->chipwidth << CFI_FLASH_SHIFT_WIDTH);
967 #ifdef CONFIG_BLACKFIN
971 case FLASH_CFI_64BIT:
976 print_longlong (str, cword.ll);
978 debug ("fwrite addr %p cmd %x %s 64 bit x %d bit\n",
980 info->chipwidth << CFI_FLASH_SHIFT_WIDTH);
983 *addr.llp = cword.ll;
984 #ifdef CONFIG_BLACKFIN
991 static void flash_unlock_seq (flash_info_t * info, flash_sect_t sect)
993 flash_write_cmd (info, sect, AMD_ADDR_START, AMD_CMD_UNLOCK_START);
994 flash_write_cmd (info, sect, AMD_ADDR_ACK, AMD_CMD_UNLOCK_ACK);
997 /*-----------------------------------------------------------------------
999 static int flash_isequal (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd)
1005 cptr.cp = flash_make_addr (info, sect, offset);
1006 flash_make_cmd (info, cmd, &cword);
1008 debug ("is= cmd %x(%c) addr %p ", cmd, cmd, cptr.cp);
1009 switch (info->portwidth) {
1010 case FLASH_CFI_8BIT:
1011 debug ("is= %x %x\n", cptr.cp[0], cword.c);
1012 retval = (cptr.cp[0] == cword.c);
1014 case FLASH_CFI_16BIT:
1015 debug ("is= %4.4x %4.4x\n", cptr.wp[0], cword.w);
1016 retval = (cptr.wp[0] == cword.w);
1018 case FLASH_CFI_32BIT:
1019 debug ("is= %8.8lx %8.8lx\n", cptr.lp[0], cword.l);
1020 retval = (cptr.lp[0] == cword.l);
1022 case FLASH_CFI_64BIT:
1028 print_longlong (str1, cptr.llp[0]);
1029 print_longlong (str2, cword.ll);
1030 debug ("is= %s %s\n", str1, str2);
1033 retval = (cptr.llp[0] == cword.ll);
1042 /*-----------------------------------------------------------------------
1044 static int flash_isset (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd)
1050 cptr.cp = flash_make_addr (info, sect, offset);
1051 flash_make_cmd (info, cmd, &cword);
1052 switch (info->portwidth) {
1053 case FLASH_CFI_8BIT:
1054 retval = ((cptr.cp[0] & cword.c) == cword.c);
1056 case FLASH_CFI_16BIT:
1057 retval = ((cptr.wp[0] & cword.w) == cword.w);
1059 case FLASH_CFI_32BIT:
1060 retval = ((cptr.lp[0] & cword.l) == cword.l);
1062 case FLASH_CFI_64BIT:
1063 retval = ((cptr.llp[0] & cword.ll) == cword.ll);
1072 /*-----------------------------------------------------------------------
1074 static int flash_toggle (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd)
1080 cptr.cp = flash_make_addr (info, sect, offset);
1081 flash_make_cmd (info, cmd, &cword);
1082 switch (info->portwidth) {
1083 case FLASH_CFI_8BIT:
1084 retval = ((cptr.cp[0] & cword.c) != (cptr.cp[0] & cword.c));
1086 case FLASH_CFI_16BIT:
1087 retval = ((cptr.wp[0] & cword.w) != (cptr.wp[0] & cword.w));
1089 case FLASH_CFI_32BIT:
1090 retval = ((cptr.lp[0] & cword.l) != (cptr.lp[0] & cword.l));
1092 case FLASH_CFI_64BIT:
1093 retval = ((cptr.llp[0] & cword.ll) !=
1094 (cptr.llp[0] & cword.ll));
1103 /*-----------------------------------------------------------------------
1104 * read jedec ids from device and set corresponding fields in info struct
1106 * Note: assume cfi->vendor, cfi->portwidth and cfi->chipwidth are correct
1109 static void flash_read_jedec_ids (flash_info_t * info)
1111 info->manufacturer_id = 0;
1112 info->device_id = 0;
1113 info->device_id2 = 0;
1115 switch (info->vendor) {
1116 case CFI_CMDSET_INTEL_STANDARD:
1117 case CFI_CMDSET_INTEL_EXTENDED:
1118 flash_write_cmd(info, 0, 0, FLASH_CMD_RESET);
1119 flash_write_cmd(info, 0, 0, FLASH_CMD_READ_ID);
1120 udelay(1000); /* some flash are slow to respond */
1121 info->manufacturer_id = flash_read_uchar (info,
1122 FLASH_OFFSET_MANUFACTURER_ID);
1123 info->device_id = flash_read_uchar (info,
1124 FLASH_OFFSET_DEVICE_ID);
1125 flash_write_cmd(info, 0, 0, FLASH_CMD_RESET);
1127 case CFI_CMDSET_AMD_STANDARD:
1128 case CFI_CMDSET_AMD_EXTENDED:
1129 flash_write_cmd(info, 0, 0, AMD_CMD_RESET);
1130 flash_unlock_seq(info, 0);
1131 flash_write_cmd(info, 0, AMD_ADDR_START, FLASH_CMD_READ_ID);
1132 udelay(1000); /* some flash are slow to respond */
1133 info->manufacturer_id = flash_read_uchar (info,
1134 FLASH_OFFSET_MANUFACTURER_ID);
1135 info->device_id = flash_read_uchar (info,
1136 FLASH_OFFSET_DEVICE_ID);
1137 if (info->device_id == 0x7E) {
1138 /* AMD 3-byte (expanded) device ids */
1139 info->device_id2 = flash_read_uchar (info,
1140 FLASH_OFFSET_DEVICE_ID2);
1141 info->device_id2 <<= 8;
1142 info->device_id2 |= flash_read_uchar (info,
1143 FLASH_OFFSET_DEVICE_ID3);
1145 flash_write_cmd(info, 0, 0, AMD_CMD_RESET);
1152 /*-----------------------------------------------------------------------
1153 * detect if flash is compatible with the Common Flash Interface (CFI)
1154 * http://www.jedec.org/download/search/jesd68.pdf
1157 static int flash_detect_cfi (flash_info_t * info)
1160 debug ("flash detect cfi\n");
1162 for (info->portwidth = CFG_FLASH_CFI_WIDTH;
1163 info->portwidth <= FLASH_CFI_64BIT; info->portwidth <<= 1) {
1164 for (info->chipwidth = FLASH_CFI_BY8;
1165 info->chipwidth <= info->portwidth;
1166 info->chipwidth <<= 1) {
1167 flash_write_cmd (info, 0, 0, info->cmd_reset);
1168 for (cfi_offset=0; cfi_offset < sizeof(flash_offset_cfi)/sizeof(uint); cfi_offset++) {
1169 flash_write_cmd (info, 0, flash_offset_cfi[cfi_offset], FLASH_CMD_CFI);
1170 if (flash_isequal (info, 0, FLASH_OFFSET_CFI_RESP, 'Q')
1171 && flash_isequal (info, 0, FLASH_OFFSET_CFI_RESP + 1, 'R')
1172 && flash_isequal (info, 0, FLASH_OFFSET_CFI_RESP + 2, 'Y')) {
1173 info->interface = flash_read_ushort (info, 0, FLASH_OFFSET_INTERFACE);
1174 info->cfi_offset=flash_offset_cfi[cfi_offset];
1175 debug ("device interface is %d\n",
1177 debug ("found port %d chip %d ",
1178 info->portwidth, info->chipwidth);
1179 debug ("port %d bits chip %d bits\n",
1180 info->portwidth << CFI_FLASH_SHIFT_WIDTH,
1181 info->chipwidth << CFI_FLASH_SHIFT_WIDTH);
1187 debug ("not found\n");
1192 * The following code cannot be run from FLASH!
1195 ulong flash_get_size (ulong base, int banknum)
1197 flash_info_t *info = &flash_info[banknum];
1199 flash_sect_t sect_cnt;
1200 unsigned long sector;
1203 uchar num_erase_regions;
1204 int erase_region_size;
1205 int erase_region_count;
1206 int geometry_reversed = 0;
1209 info->cfi_version = 0;
1210 #ifdef CFG_FLASH_PROTECTION
1211 info->legacy_unlock = 0;
1214 info->start[0] = base;
1216 if (flash_detect_cfi (info)) {
1217 info->vendor = flash_read_ushort (info, 0,
1218 FLASH_OFFSET_PRIMARY_VENDOR);
1219 flash_read_jedec_ids (info);
1220 flash_write_cmd (info, 0, info->cfi_offset, FLASH_CMD_CFI);
1221 num_erase_regions = flash_read_uchar (info,
1222 FLASH_OFFSET_NUM_ERASE_REGIONS);
1223 info->ext_addr = flash_read_ushort (info, 0,
1224 FLASH_OFFSET_EXT_QUERY_T_P_ADDR);
1225 if (info->ext_addr) {
1226 info->cfi_version = (ushort) flash_read_uchar (info,
1227 info->ext_addr + 3) << 8;
1228 info->cfi_version |= (ushort) flash_read_uchar (info,
1229 info->ext_addr + 4);
1232 flash_printqry (info, 0);
1234 switch (info->vendor) {
1235 case CFI_CMDSET_INTEL_STANDARD:
1236 case CFI_CMDSET_INTEL_EXTENDED:
1238 info->cmd_reset = FLASH_CMD_RESET;
1239 #ifdef CFG_FLASH_PROTECTION
1240 /* read legacy lock/unlock bit from intel flash */
1241 if (info->ext_addr) {
1242 info->legacy_unlock = flash_read_uchar (info,
1243 info->ext_addr + 5) & 0x08;
1247 case CFI_CMDSET_AMD_STANDARD:
1248 case CFI_CMDSET_AMD_EXTENDED:
1249 info->cmd_reset = AMD_CMD_RESET;
1250 /* check if flash geometry needs reversal */
1251 if (num_erase_regions <= 1)
1253 /* reverse geometry if top boot part */
1254 if (info->cfi_version < 0x3131) {
1255 /* CFI < 1.1, try to guess from device id */
1256 if ((info->device_id & 0x80) != 0) {
1257 geometry_reversed = 1;
1261 /* CFI >= 1.1, deduct from top/bottom flag */
1262 /* note: ext_addr is valid since cfi_version > 0 */
1263 if (flash_read_uchar(info, info->ext_addr + 0xf) == 3) {
1264 geometry_reversed = 1;
1269 debug ("manufacturer is %d\n", info->vendor);
1270 debug ("manufacturer id is 0x%x\n", info->manufacturer_id);
1271 debug ("device id is 0x%x\n", info->device_id);
1272 debug ("device id2 is 0x%x\n", info->device_id2);
1273 debug ("cfi version is 0x%04x\n", info->cfi_version);
1275 size_ratio = info->portwidth / info->chipwidth;
1276 /* if the chip is x8/x16 reduce the ratio by half */
1277 if ((info->interface == FLASH_CFI_X8X16)
1278 && (info->chipwidth == FLASH_CFI_BY8)) {
1281 debug ("size_ratio %d port %d bits chip %d bits\n",
1282 size_ratio, info->portwidth << CFI_FLASH_SHIFT_WIDTH,
1283 info->chipwidth << CFI_FLASH_SHIFT_WIDTH);
1284 debug ("found %d erase regions\n", num_erase_regions);
1287 for (i = 0; i < num_erase_regions; i++) {
1288 if (i > NUM_ERASE_REGIONS) {
1289 printf ("%d erase regions found, only %d used\n",
1290 num_erase_regions, NUM_ERASE_REGIONS);
1293 if (geometry_reversed)
1294 tmp = flash_read_long (info, 0,
1295 FLASH_OFFSET_ERASE_REGIONS +
1296 (num_erase_regions - 1 - i) * 4);
1298 tmp = flash_read_long (info, 0,
1299 FLASH_OFFSET_ERASE_REGIONS +
1302 (tmp & 0xffff) ? ((tmp & 0xffff) * 256) : 128;
1304 erase_region_count = (tmp & 0xffff) + 1;
1305 debug ("erase_region_count = %d erase_region_size = %d\n",
1306 erase_region_count, erase_region_size);
1307 for (j = 0; j < erase_region_count; j++) {
1308 info->start[sect_cnt] = sector;
1309 sector += (erase_region_size * size_ratio);
1312 * Only read protection status from supported devices (intel...)
1314 switch (info->vendor) {
1315 case CFI_CMDSET_INTEL_EXTENDED:
1316 case CFI_CMDSET_INTEL_STANDARD:
1317 info->protect[sect_cnt] =
1318 flash_isset (info, sect_cnt,
1319 FLASH_OFFSET_PROTECT,
1320 FLASH_STATUS_PROTECT);
1323 info->protect[sect_cnt] = 0; /* default: not protected */
1330 info->sector_count = sect_cnt;
1331 /* multiply the size by the number of chips */
1332 info->size = (1 << flash_read_uchar (info, FLASH_OFFSET_SIZE)) * size_ratio;
1333 info->buffer_size = (1 << flash_read_ushort (info, 0, FLASH_OFFSET_BUFFER_SIZE));
1334 tmp = 1 << flash_read_uchar (info, FLASH_OFFSET_ETOUT);
1335 info->erase_blk_tout = (tmp * (1 << flash_read_uchar (info, FLASH_OFFSET_EMAX_TOUT)));
1336 tmp = (1 << flash_read_uchar (info, FLASH_OFFSET_WBTOUT)) *
1337 (1 << flash_read_uchar (info, FLASH_OFFSET_WBMAX_TOUT));
1338 info->buffer_write_tout = tmp / 1000 + (tmp % 1000 ? 1 : 0); /* round up when converting to ms */
1339 tmp = (1 << flash_read_uchar (info, FLASH_OFFSET_WTOUT)) *
1340 (1 << flash_read_uchar (info, FLASH_OFFSET_WMAX_TOUT));
1341 info->write_tout = tmp / 1000 + (tmp % 1000 ? 1 : 0); /* round up when converting to ms */
1342 info->flash_id = FLASH_MAN_CFI;
1343 if ((info->interface == FLASH_CFI_X8X16) && (info->chipwidth == FLASH_CFI_BY8)) {
1344 info->portwidth >>= 1; /* XXX - Need to test on x8/x16 in parallel. */
1348 flash_write_cmd (info, 0, 0, info->cmd_reset);
1349 return (info->size);
1352 /* loop through the sectors from the highest address
1353 * when the passed address is greater or equal to the sector address
1356 static flash_sect_t find_sector (flash_info_t * info, ulong addr)
1358 flash_sect_t sector;
1360 for (sector = info->sector_count - 1; sector >= 0; sector--) {
1361 if (addr >= info->start[sector])
1367 /*-----------------------------------------------------------------------
1369 static int flash_write_cfiword (flash_info_t * info, ulong dest,
1376 ctladdr.cp = flash_make_addr (info, 0, 0);
1377 cptr.cp = (uchar *) dest;
1380 /* Check if Flash is (sufficiently) erased */
1381 switch (info->portwidth) {
1382 case FLASH_CFI_8BIT:
1383 flag = ((cptr.cp[0] & cword.c) == cword.c);
1385 case FLASH_CFI_16BIT:
1386 flag = ((cptr.wp[0] & cword.w) == cword.w);
1388 case FLASH_CFI_32BIT:
1389 flag = ((cptr.lp[0] & cword.l) == cword.l);
1391 case FLASH_CFI_64BIT:
1392 flag = ((cptr.llp[0] & cword.ll) == cword.ll);
1400 /* Disable interrupts which might cause a timeout here */
1401 flag = disable_interrupts ();
1403 switch (info->vendor) {
1404 case CFI_CMDSET_INTEL_EXTENDED:
1405 case CFI_CMDSET_INTEL_STANDARD:
1406 flash_write_cmd (info, 0, 0, FLASH_CMD_CLEAR_STATUS);
1407 flash_write_cmd (info, 0, 0, FLASH_CMD_WRITE);
1409 case CFI_CMDSET_AMD_EXTENDED:
1410 case CFI_CMDSET_AMD_STANDARD:
1411 flash_unlock_seq (info, 0);
1412 flash_write_cmd (info, 0, AMD_ADDR_START, AMD_CMD_WRITE);
1416 switch (info->portwidth) {
1417 case FLASH_CFI_8BIT:
1418 cptr.cp[0] = cword.c;
1420 case FLASH_CFI_16BIT:
1421 cptr.wp[0] = cword.w;
1423 case FLASH_CFI_32BIT:
1424 cptr.lp[0] = cword.l;
1426 case FLASH_CFI_64BIT:
1427 cptr.llp[0] = cword.ll;
1431 /* re-enable interrupts if necessary */
1433 enable_interrupts ();
1435 return flash_full_status_check (info, find_sector (info, dest),
1436 info->write_tout, "write");
1439 #ifdef CFG_FLASH_USE_BUFFER_WRITE
1441 static int flash_write_cfibuffer (flash_info_t * info, ulong dest, uchar * cp,
1444 flash_sect_t sector;
1447 volatile cfiptr_t src;
1448 volatile cfiptr_t dst;
1450 switch (info->vendor) {
1451 case CFI_CMDSET_INTEL_STANDARD:
1452 case CFI_CMDSET_INTEL_EXTENDED:
1454 dst.cp = (uchar *) dest;
1455 sector = find_sector (info, dest);
1456 flash_write_cmd (info, sector, 0, FLASH_CMD_CLEAR_STATUS);
1457 flash_write_cmd (info, sector, 0, FLASH_CMD_WRITE_TO_BUFFER);
1458 if ((retcode = flash_status_check (info, sector, info->buffer_write_tout,
1459 "write to buffer")) == ERR_OK) {
1460 /* reduce the number of loops by the width of the port */
1461 switch (info->portwidth) {
1462 case FLASH_CFI_8BIT:
1465 case FLASH_CFI_16BIT:
1468 case FLASH_CFI_32BIT:
1471 case FLASH_CFI_64BIT:
1478 flash_write_cmd (info, sector, 0, (uchar) cnt - 1);
1480 switch (info->portwidth) {
1481 case FLASH_CFI_8BIT:
1482 *dst.cp++ = *src.cp++;
1484 case FLASH_CFI_16BIT:
1485 *dst.wp++ = *src.wp++;
1487 case FLASH_CFI_32BIT:
1488 *dst.lp++ = *src.lp++;
1490 case FLASH_CFI_64BIT:
1491 *dst.llp++ = *src.llp++;
1498 flash_write_cmd (info, sector, 0,
1499 FLASH_CMD_WRITE_BUFFER_CONFIRM);
1500 retcode = flash_full_status_check (info, sector,
1501 info->buffer_write_tout,
1506 case CFI_CMDSET_AMD_STANDARD:
1507 case CFI_CMDSET_AMD_EXTENDED:
1509 dst.cp = (uchar *) dest;
1510 sector = find_sector (info, dest);
1512 flash_unlock_seq(info,0);
1513 flash_write_cmd (info, sector, 0, AMD_CMD_WRITE_TO_BUFFER);
1515 switch (info->portwidth) {
1516 case FLASH_CFI_8BIT:
1518 flash_write_cmd (info, sector, 0, (uchar) cnt - 1);
1519 while (cnt-- > 0) *dst.cp++ = *src.cp++;
1521 case FLASH_CFI_16BIT:
1523 flash_write_cmd (info, sector, 0, (uchar) cnt - 1);
1524 while (cnt-- > 0) *dst.wp++ = *src.wp++;
1526 case FLASH_CFI_32BIT:
1528 flash_write_cmd (info, sector, 0, (uchar) cnt - 1);
1529 while (cnt-- > 0) *dst.lp++ = *src.lp++;
1531 case FLASH_CFI_64BIT:
1533 flash_write_cmd (info, sector, 0, (uchar) cnt - 1);
1534 while (cnt-- > 0) *dst.llp++ = *src.llp++;
1540 flash_write_cmd (info, sector, 0, AMD_CMD_WRITE_BUFFER_CONFIRM);
1541 retcode = flash_full_status_check (info, sector, info->buffer_write_tout,
1546 debug ("Unknown Command Set\n");
1550 #endif /* CFG_FLASH_USE_BUFFER_WRITE */
1551 #endif /* CFG_FLASH_CFI */