cfi_flash: Break long lines
This patch tries to keep all lines in the cfi_flash driver below 80 columns. There are a few lines left which don't fit this requirement because I couldn't find any trivial way to break them (i.e. it would take some restructuring, which I intend to do in a later patch.) Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
This commit is contained in:
parent
42026c9cb3
commit
7e5b9b4715
|
@ -42,9 +42,12 @@
|
||||||
#ifdef CFG_FLASH_CFI_DRIVER
|
#ifdef CFG_FLASH_CFI_DRIVER
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file implements a Common Flash Interface (CFI) driver for U-Boot.
|
* This file implements a Common Flash Interface (CFI) driver for
|
||||||
* The width of the port and the width of the chips are determined at initialization.
|
* U-Boot.
|
||||||
* These widths are used to calculate the address for access CFI data structures.
|
*
|
||||||
|
* The width of the port and the width of the chips are determined at
|
||||||
|
* initialization. These widths are used to calculate the address for
|
||||||
|
* access CFI data structures.
|
||||||
*
|
*
|
||||||
* References
|
* References
|
||||||
* JEDEC Standard JESD68 - Common Flash Interface (CFI)
|
* JEDEC Standard JESD68 - Common Flash Interface (CFI)
|
||||||
|
@ -55,7 +58,7 @@
|
||||||
* AMD/Spansion Application Note: Migration from Single-byte to Three-byte
|
* AMD/Spansion Application Note: Migration from Single-byte to Three-byte
|
||||||
* Device IDs, Publication Number 25538 Revision A, November 8, 2001
|
* Device IDs, Publication Number 25538 Revision A, November 8, 2001
|
||||||
*
|
*
|
||||||
* define CFG_WRITE_SWAPPED_DATA, if you have to swap the Bytes between
|
* Define CFG_WRITE_SWAPPED_DATA, if you have to swap the Bytes between
|
||||||
* reading and writing ... (yes there is such a Hardware).
|
* reading and writing ... (yes there is such a Hardware).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -106,7 +109,8 @@
|
||||||
#define FLASH_OFFSET_CFI_ALT 0x555
|
#define FLASH_OFFSET_CFI_ALT 0x555
|
||||||
#define FLASH_OFFSET_CFI_RESP 0x10
|
#define FLASH_OFFSET_CFI_RESP 0x10
|
||||||
#define FLASH_OFFSET_PRIMARY_VENDOR 0x13
|
#define FLASH_OFFSET_PRIMARY_VENDOR 0x13
|
||||||
#define FLASH_OFFSET_EXT_QUERY_T_P_ADDR 0x15 /* extended query table primary addr */
|
/* extended query table primary address */
|
||||||
|
#define FLASH_OFFSET_EXT_QUERY_T_P_ADDR 0x15
|
||||||
#define FLASH_OFFSET_WTOUT 0x1F
|
#define FLASH_OFFSET_WTOUT 0x1F
|
||||||
#define FLASH_OFFSET_WBTOUT 0x20
|
#define FLASH_OFFSET_WBTOUT 0x20
|
||||||
#define FLASH_OFFSET_ETOUT 0x21
|
#define FLASH_OFFSET_ETOUT 0x21
|
||||||
|
@ -181,14 +185,19 @@ typedef unsigned long flash_sect_t;
|
||||||
|
|
||||||
static void flash_add_byte (flash_info_t * info, cfiword_t * cword, uchar c);
|
static void flash_add_byte (flash_info_t * info, cfiword_t * cword, uchar c);
|
||||||
static void flash_make_cmd (flash_info_t * info, uchar cmd, void *cmdbuf);
|
static void flash_make_cmd (flash_info_t * info, uchar cmd, void *cmdbuf);
|
||||||
static void flash_write_cmd (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd);
|
static void flash_write_cmd (flash_info_t * info, flash_sect_t sect,
|
||||||
|
uint offset, uchar cmd);
|
||||||
static void flash_unlock_seq (flash_info_t * info, flash_sect_t sect);
|
static void flash_unlock_seq (flash_info_t * info, flash_sect_t sect);
|
||||||
static int flash_isequal (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd);
|
static int flash_isequal (flash_info_t * info, flash_sect_t sect,
|
||||||
static int flash_isset (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd);
|
uint offset, uchar cmd);
|
||||||
static int flash_toggle (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd);
|
static int flash_isset (flash_info_t * info, flash_sect_t sect,
|
||||||
|
uint offset, uchar cmd);
|
||||||
|
static int flash_toggle (flash_info_t * info, flash_sect_t sect,
|
||||||
|
uint offset, uchar cmd);
|
||||||
static void flash_read_jedec_ids (flash_info_t * info);
|
static void flash_read_jedec_ids (flash_info_t * info);
|
||||||
static int flash_detect_cfi (flash_info_t * info);
|
static int flash_detect_cfi (flash_info_t * info);
|
||||||
static int flash_write_cfiword (flash_info_t * info, ulong dest, cfiword_t cword);
|
static int flash_write_cfiword (flash_info_t * info, ulong dest,
|
||||||
|
cfiword_t cword);
|
||||||
static int flash_full_status_check (flash_info_t * info, flash_sect_t sector,
|
static int flash_full_status_check (flash_info_t * info, flash_sect_t sector,
|
||||||
ulong tout, char *prompt);
|
ulong tout, char *prompt);
|
||||||
ulong flash_get_size (ulong base, int banknum);
|
ulong flash_get_size (ulong base, int banknum);
|
||||||
|
@ -196,13 +205,15 @@ ulong flash_get_size (ulong base, int banknum);
|
||||||
static flash_info_t *flash_get_info(ulong base);
|
static flash_info_t *flash_get_info(ulong base);
|
||||||
#endif
|
#endif
|
||||||
#ifdef CFG_FLASH_USE_BUFFER_WRITE
|
#ifdef CFG_FLASH_USE_BUFFER_WRITE
|
||||||
static int flash_write_cfibuffer (flash_info_t * info, ulong dest, uchar * cp, int len);
|
static int flash_write_cfibuffer (flash_info_t * info, ulong dest,
|
||||||
|
uchar * cp, int len);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------
|
/*-----------------------------------------------------------------------
|
||||||
* create an address based on the offset and the port width
|
* create an address based on the offset and the port width
|
||||||
*/
|
*/
|
||||||
inline uchar *flash_make_addr (flash_info_t * info, flash_sect_t sect, uint offset)
|
inline uchar *
|
||||||
|
flash_make_addr (flash_info_t * info, flash_sect_t sect, uint offset)
|
||||||
{
|
{
|
||||||
return ((uchar *) (info->start[sect] + (offset * info->portwidth)));
|
return ((uchar *) (info->start[sect] + (offset * info->portwidth)));
|
||||||
}
|
}
|
||||||
|
@ -316,7 +327,8 @@ ulong flash_read_long (flash_info_t * info, flash_sect_t sect, uint offset)
|
||||||
#endif
|
#endif
|
||||||
#if defined(__LITTLE_ENDIAN) || defined(CFG_WRITE_SWAPPED_DATA)
|
#if defined(__LITTLE_ENDIAN) || defined(CFG_WRITE_SWAPPED_DATA)
|
||||||
retval = (addr[0] << 16) | (addr[(info->portwidth)] << 24) |
|
retval = (addr[0] << 16) | (addr[(info->portwidth)] << 24) |
|
||||||
(addr[(2 * info->portwidth)]) | (addr[(3 * info->portwidth)] << 8);
|
(addr[(2 * info->portwidth)]) |
|
||||||
|
(addr[(3 * info->portwidth)] << 8);
|
||||||
#else
|
#else
|
||||||
retval = (addr[(2 * info->portwidth) - 1] << 24) |
|
retval = (addr[(2 * info->portwidth) - 1] << 24) |
|
||||||
(addr[(info->portwidth) - 1] << 16) |
|
(addr[(info->portwidth) - 1] << 16) |
|
||||||
|
@ -336,17 +348,22 @@ ulong flash_read_long (flash_info_t * info, flash_sect_t sect, uint offset)
|
||||||
int flash_detect_legacy(ulong base, int banknum)
|
int flash_detect_legacy(ulong base, int banknum)
|
||||||
{
|
{
|
||||||
flash_info_t *info = &flash_info[banknum];
|
flash_info_t *info = &flash_info[banknum];
|
||||||
|
|
||||||
if (board_flash_get_legacy(base, banknum, info)) {
|
if (board_flash_get_legacy(base, banknum, info)) {
|
||||||
/* board code may have filled info completely. If not, we
|
/* board code may have filled info completely. If not, we
|
||||||
use JEDEC ID probing. */
|
use JEDEC ID probing. */
|
||||||
if (!info->vendor) {
|
if (!info->vendor) {
|
||||||
int modes[] = { CFI_CMDSET_AMD_STANDARD, CFI_CMDSET_INTEL_STANDARD };
|
int modes[] = {
|
||||||
|
CFI_CMDSET_AMD_STANDARD,
|
||||||
|
CFI_CMDSET_INTEL_STANDARD
|
||||||
|
};
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < sizeof(modes) / sizeof(modes[0]); i++) {
|
for (i = 0; i < sizeof(modes) / sizeof(modes[0]); i++) {
|
||||||
info->vendor = modes[i];
|
info->vendor = modes[i];
|
||||||
info->start[0] = base;
|
info->start[0] = base;
|
||||||
if (info->portwidth == FLASH_CFI_8BIT && info->interface == FLASH_CFI_X8X16) {
|
if (info->portwidth == FLASH_CFI_8BIT
|
||||||
|
&& info->interface == FLASH_CFI_X8X16) {
|
||||||
info->addr_unlock1 = 0x2AAA;
|
info->addr_unlock1 = 0x2AAA;
|
||||||
info->addr_unlock2 = 0x5555;
|
info->addr_unlock2 = 0x5555;
|
||||||
} else {
|
} else {
|
||||||
|
@ -354,11 +371,15 @@ int flash_detect_legacy(ulong base, int banknum)
|
||||||
info->addr_unlock2 = 0x2AAA;
|
info->addr_unlock2 = 0x2AAA;
|
||||||
}
|
}
|
||||||
flash_read_jedec_ids(info);
|
flash_read_jedec_ids(info);
|
||||||
debug("JEDEC PROBE: ID %x %x %x\n", info->manufacturer_id, info->device_id, info->device_id2);
|
debug("JEDEC PROBE: ID %x %x %x\n",
|
||||||
|
info->manufacturer_id,
|
||||||
|
info->device_id,
|
||||||
|
info->device_id2);
|
||||||
if (jedec_flash_match(info, base))
|
if (jedec_flash_match(info, base))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(info->vendor) {
|
switch(info->vendor) {
|
||||||
case CFI_CMDSET_INTEL_STANDARD:
|
case CFI_CMDSET_INTEL_STANDARD:
|
||||||
case CFI_CMDSET_INTEL_EXTENDED:
|
case CFI_CMDSET_INTEL_EXTENDED:
|
||||||
|
@ -403,38 +424,45 @@ unsigned long flash_init (void)
|
||||||
size += flash_info[i].size;
|
size += flash_info[i].size;
|
||||||
if (flash_info[i].flash_id == FLASH_UNKNOWN) {
|
if (flash_info[i].flash_id == FLASH_UNKNOWN) {
|
||||||
#ifndef CFG_FLASH_QUIET_TEST
|
#ifndef CFG_FLASH_QUIET_TEST
|
||||||
printf ("## Unknown FLASH on Bank %d - Size = 0x%08lx = %ld MB\n",
|
printf ("## Unknown FLASH on Bank %d "
|
||||||
i+1, flash_info[i].size, flash_info[i].size << 20);
|
"- Size = 0x%08lx = %ld MB\n",
|
||||||
|
i+1, flash_info[i].size,
|
||||||
|
flash_info[i].size << 20);
|
||||||
#endif /* CFG_FLASH_QUIET_TEST */
|
#endif /* CFG_FLASH_QUIET_TEST */
|
||||||
}
|
}
|
||||||
#ifdef CFG_FLASH_PROTECTION
|
#ifdef CFG_FLASH_PROTECTION
|
||||||
else if ((s != NULL) && (strcmp(s, "yes") == 0)) {
|
else if ((s != NULL) && (strcmp(s, "yes") == 0)) {
|
||||||
/*
|
/*
|
||||||
* Only the U-Boot image and it's environment is protected,
|
* Only the U-Boot image and it's environment
|
||||||
* all other sectors are unprotected (unlocked) if flash
|
* is protected, all other sectors are
|
||||||
* hardware protection is used (CFG_FLASH_PROTECTION) and
|
* unprotected (unlocked) if flash hardware
|
||||||
* the environment variable "unlock" is set to "yes".
|
* protection is used (CFG_FLASH_PROTECTION)
|
||||||
|
* and the environment variable "unlock" is
|
||||||
|
* set to "yes".
|
||||||
*/
|
*/
|
||||||
if (flash_info[i].legacy_unlock) {
|
if (flash_info[i].legacy_unlock) {
|
||||||
int k;
|
int k;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Disable legacy_unlock temporarily, since
|
* Disable legacy_unlock temporarily,
|
||||||
* flash_real_protect would relock all other sectors
|
* since flash_real_protect would
|
||||||
* again otherwise.
|
* relock all other sectors again
|
||||||
|
* otherwise.
|
||||||
*/
|
*/
|
||||||
flash_info[i].legacy_unlock = 0;
|
flash_info[i].legacy_unlock = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Legacy unlocking (e.g. Intel J3) -> unlock only one
|
* Legacy unlocking (e.g. Intel J3) ->
|
||||||
* sector. This will unlock all sectors.
|
* unlock only one sector. This will
|
||||||
|
* unlock all sectors.
|
||||||
*/
|
*/
|
||||||
flash_real_protect (&flash_info[i], 0, 0);
|
flash_real_protect (&flash_info[i], 0, 0);
|
||||||
|
|
||||||
flash_info[i].legacy_unlock = 1;
|
flash_info[i].legacy_unlock = 1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Manually mark other sectors as unlocked (unprotected)
|
* Manually mark other sectors as
|
||||||
|
* unlocked (unprotected)
|
||||||
*/
|
*/
|
||||||
for (k = 1; k < flash_info[i].sector_count; k++)
|
for (k = 1; k < flash_info[i].sector_count; k++)
|
||||||
flash_info[i].protect[k] = 0;
|
flash_info[i].protect[k] = 0;
|
||||||
|
@ -444,7 +472,8 @@ unsigned long flash_init (void)
|
||||||
*/
|
*/
|
||||||
flash_protect (FLAG_PROTECT_CLEAR,
|
flash_protect (FLAG_PROTECT_CLEAR,
|
||||||
flash_info[i].start[0],
|
flash_info[i].start[0],
|
||||||
flash_info[i].start[0] + flash_info[i].size - 1,
|
flash_info[i].start[0]
|
||||||
|
+ flash_info[i].size - 1,
|
||||||
&flash_info[i]);
|
&flash_info[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -520,7 +549,8 @@ int flash_erase (flash_info_t * info, int s_first, int s_last)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (prot) {
|
if (prot) {
|
||||||
printf ("- Warning: %d protected sectors will not be erased!\n", prot);
|
printf ("- Warning: %d protected sectors will not be erased!\n",
|
||||||
|
prot);
|
||||||
} else {
|
} else {
|
||||||
putc ('\n');
|
putc ('\n');
|
||||||
}
|
}
|
||||||
|
@ -531,23 +561,31 @@ int flash_erase (flash_info_t * info, int s_first, int s_last)
|
||||||
switch (info->vendor) {
|
switch (info->vendor) {
|
||||||
case CFI_CMDSET_INTEL_STANDARD:
|
case CFI_CMDSET_INTEL_STANDARD:
|
||||||
case CFI_CMDSET_INTEL_EXTENDED:
|
case CFI_CMDSET_INTEL_EXTENDED:
|
||||||
flash_write_cmd (info, sect, 0, FLASH_CMD_CLEAR_STATUS);
|
flash_write_cmd (info, sect, 0,
|
||||||
flash_write_cmd (info, sect, 0, FLASH_CMD_BLOCK_ERASE);
|
FLASH_CMD_CLEAR_STATUS);
|
||||||
flash_write_cmd (info, sect, 0, FLASH_CMD_ERASE_CONFIRM);
|
flash_write_cmd (info, sect, 0,
|
||||||
|
FLASH_CMD_BLOCK_ERASE);
|
||||||
|
flash_write_cmd (info, sect, 0,
|
||||||
|
FLASH_CMD_ERASE_CONFIRM);
|
||||||
break;
|
break;
|
||||||
case CFI_CMDSET_AMD_STANDARD:
|
case CFI_CMDSET_AMD_STANDARD:
|
||||||
case CFI_CMDSET_AMD_EXTENDED:
|
case CFI_CMDSET_AMD_EXTENDED:
|
||||||
flash_unlock_seq (info, sect);
|
flash_unlock_seq (info, sect);
|
||||||
flash_write_cmd (info, sect, info->addr_unlock1, AMD_CMD_ERASE_START);
|
flash_write_cmd (info, sect,
|
||||||
|
info->addr_unlock1,
|
||||||
|
AMD_CMD_ERASE_START);
|
||||||
flash_unlock_seq (info, sect);
|
flash_unlock_seq (info, sect);
|
||||||
flash_write_cmd (info, sect, 0, AMD_CMD_ERASE_SECTOR);
|
flash_write_cmd (info, sect, 0,
|
||||||
|
AMD_CMD_ERASE_SECTOR);
|
||||||
break;
|
break;
|
||||||
#ifdef CONFIG_FLASH_CFI_LEGACY
|
#ifdef CONFIG_FLASH_CFI_LEGACY
|
||||||
case CFI_CMDSET_AMD_LEGACY:
|
case CFI_CMDSET_AMD_LEGACY:
|
||||||
flash_unlock_seq (info, 0);
|
flash_unlock_seq (info, 0);
|
||||||
flash_write_cmd (info, 0, info->addr_unlock1, AMD_CMD_ERASE_START);
|
flash_write_cmd (info, 0, info->addr_unlock1,
|
||||||
|
AMD_CMD_ERASE_START);
|
||||||
flash_unlock_seq (info, 0);
|
flash_unlock_seq (info, 0);
|
||||||
flash_write_cmd (info, sect, 0, AMD_CMD_ERASE_SECTOR);
|
flash_write_cmd (info, sect, 0,
|
||||||
|
AMD_CMD_ERASE_SECTOR);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
|
@ -619,7 +657,8 @@ void flash_print_info (flash_info_t * info)
|
||||||
info->erase_blk_tout,
|
info->erase_blk_tout,
|
||||||
info->write_tout);
|
info->write_tout);
|
||||||
if (info->buffer_size > 1) {
|
if (info->buffer_size > 1) {
|
||||||
printf (" Buffer write timeout: %ld ms, buffer size: %d bytes\n",
|
printf (" Buffer write timeout: %ld ms, "
|
||||||
|
"buffer size: %d bytes\n",
|
||||||
info->buffer_write_tout,
|
info->buffer_write_tout,
|
||||||
info->buffer_size);
|
info->buffer_size);
|
||||||
}
|
}
|
||||||
|
@ -836,7 +875,9 @@ void flash_read_factory_serial (flash_info_t * info, void *buffer, int offset,
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* flash_is_busy - check to see if the flash is busy
|
* flash_is_busy - check to see if the flash is busy
|
||||||
* This routine checks the status of the chip and returns true if the chip is busy
|
*
|
||||||
|
* This routine checks the status of the chip and returns true if the
|
||||||
|
* chip is busy.
|
||||||
*/
|
*/
|
||||||
static int flash_is_busy (flash_info_t * info, flash_sect_t sect)
|
static int flash_is_busy (flash_info_t * info, flash_sect_t sect)
|
||||||
{
|
{
|
||||||
|
@ -890,7 +931,9 @@ static int flash_status_check (flash_info_t * info, flash_sect_t sector,
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------
|
/*-----------------------------------------------------------------------
|
||||||
* Wait for XSR.7 to be set, if it times out print an error, otherwise do a full status check.
|
* Wait for XSR.7 to be set, if it times out print an error, otherwise
|
||||||
|
* do a full status check.
|
||||||
|
*
|
||||||
* This routine sets the flash to read-array mode.
|
* This routine sets the flash to read-array mode.
|
||||||
*/
|
*/
|
||||||
static int flash_full_status_check (flash_info_t * info, flash_sect_t sector,
|
static int flash_full_status_check (flash_info_t * info, flash_sect_t sector,
|
||||||
|
@ -907,12 +950,15 @@ static int flash_full_status_check (flash_info_t * info, flash_sect_t sector,
|
||||||
retcode = ERR_INVAL;
|
retcode = ERR_INVAL;
|
||||||
printf ("Flash %s error at address %lx\n", prompt,
|
printf ("Flash %s error at address %lx\n", prompt,
|
||||||
info->start[sector]);
|
info->start[sector]);
|
||||||
if (flash_isset (info, sector, 0, FLASH_STATUS_ECLBS | FLASH_STATUS_PSLBS)) {
|
if (flash_isset (info, sector, 0, FLASH_STATUS_ECLBS |
|
||||||
|
FLASH_STATUS_PSLBS)) {
|
||||||
puts ("Command Sequence Error.\n");
|
puts ("Command Sequence Error.\n");
|
||||||
} else if (flash_isset (info, sector, 0, FLASH_STATUS_ECLBS)) {
|
} else if (flash_isset (info, sector, 0,
|
||||||
|
FLASH_STATUS_ECLBS)) {
|
||||||
puts ("Block Erase Error.\n");
|
puts ("Block Erase Error.\n");
|
||||||
retcode = ERR_NOT_ERASED;
|
retcode = ERR_NOT_ERASED;
|
||||||
} else if (flash_isset (info, sector, 0, FLASH_STATUS_PSLBS)) {
|
} else if (flash_isset (info, sector, 0,
|
||||||
|
FLASH_STATUS_PSLBS)) {
|
||||||
puts ("Locking Error\n");
|
puts ("Locking Error\n");
|
||||||
}
|
}
|
||||||
if (flash_isset (info, sector, 0, FLASH_STATUS_DPS)) {
|
if (flash_isset (info, sector, 0, FLASH_STATUS_DPS)) {
|
||||||
|
@ -994,7 +1040,8 @@ static void flash_make_cmd (flash_info_t * info, uchar cmd, void *cmdbuf)
|
||||||
/*
|
/*
|
||||||
* Write a proper sized command to the correct address
|
* Write a proper sized command to the correct address
|
||||||
*/
|
*/
|
||||||
static void flash_write_cmd (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd)
|
static void flash_write_cmd (flash_info_t * info, flash_sect_t sect,
|
||||||
|
uint offset, uchar cmd)
|
||||||
{
|
{
|
||||||
|
|
||||||
volatile cfiptr_t addr;
|
volatile cfiptr_t addr;
|
||||||
|
@ -1048,7 +1095,8 @@ static void flash_unlock_seq (flash_info_t * info, flash_sect_t sect)
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------
|
/*-----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
static int flash_isequal (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd)
|
static int flash_isequal (flash_info_t * info, flash_sect_t sect,
|
||||||
|
uint offset, uchar cmd)
|
||||||
{
|
{
|
||||||
cfiptr_t cptr;
|
cfiptr_t cptr;
|
||||||
cfiword_t cword;
|
cfiword_t cword;
|
||||||
|
@ -1093,7 +1141,8 @@ static int flash_isequal (flash_info_t * info, flash_sect_t sect, uint offset, u
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------
|
/*-----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
static int flash_isset (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd)
|
static int flash_isset (flash_info_t * info, flash_sect_t sect,
|
||||||
|
uint offset, uchar cmd)
|
||||||
{
|
{
|
||||||
cfiptr_t cptr;
|
cfiptr_t cptr;
|
||||||
cfiword_t cword;
|
cfiword_t cword;
|
||||||
|
@ -1123,7 +1172,8 @@ static int flash_isset (flash_info_t * info, flash_sect_t sect, uint offset, uch
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------
|
/*-----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
static int flash_toggle (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd)
|
static int flash_toggle (flash_info_t * info, flash_sect_t sect,
|
||||||
|
uint offset, uchar cmd)
|
||||||
{
|
{
|
||||||
cfiptr_t cptr;
|
cfiptr_t cptr;
|
||||||
cfiword_t cword;
|
cfiword_t cword;
|
||||||
|
@ -1204,25 +1254,22 @@ static void flash_read_jedec_ids (flash_info_t * info)
|
||||||
/*-----------------------------------------------------------------------
|
/*-----------------------------------------------------------------------
|
||||||
* detect if flash is compatible with the Common Flash Interface (CFI)
|
* detect if flash is compatible with the Common Flash Interface (CFI)
|
||||||
* http://www.jedec.org/download/search/jesd68.pdf
|
* http://www.jedec.org/download/search/jesd68.pdf
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
static int flash_detect_cfi (flash_info_t * info)
|
static int __flash_detect_cfi (flash_info_t * info)
|
||||||
{
|
{
|
||||||
int cfi_offset;
|
int cfi_offset;
|
||||||
debug ("flash detect cfi\n");
|
|
||||||
|
|
||||||
for (info->portwidth = CFG_FLASH_CFI_WIDTH;
|
|
||||||
info->portwidth <= FLASH_CFI_64BIT; info->portwidth <<= 1) {
|
|
||||||
for (info->chipwidth = FLASH_CFI_BY8;
|
|
||||||
info->chipwidth <= info->portwidth;
|
|
||||||
info->chipwidth <<= 1) {
|
|
||||||
flash_write_cmd (info, 0, 0, info->cmd_reset);
|
flash_write_cmd (info, 0, 0, info->cmd_reset);
|
||||||
for (cfi_offset=0; cfi_offset < sizeof(flash_offset_cfi)/sizeof(uint); cfi_offset++) {
|
for (cfi_offset=0;
|
||||||
flash_write_cmd (info, 0, flash_offset_cfi[cfi_offset], FLASH_CMD_CFI);
|
cfi_offset < sizeof(flash_offset_cfi) / sizeof(uint);
|
||||||
|
cfi_offset++) {
|
||||||
|
flash_write_cmd (info, 0, flash_offset_cfi[cfi_offset],
|
||||||
|
FLASH_CMD_CFI);
|
||||||
if (flash_isequal (info, 0, FLASH_OFFSET_CFI_RESP, 'Q')
|
if (flash_isequal (info, 0, FLASH_OFFSET_CFI_RESP, 'Q')
|
||||||
&& flash_isequal (info, 0, FLASH_OFFSET_CFI_RESP + 1, 'R')
|
&& flash_isequal (info, 0, FLASH_OFFSET_CFI_RESP + 1, 'R')
|
||||||
&& flash_isequal (info, 0, FLASH_OFFSET_CFI_RESP + 2, 'Y')) {
|
&& flash_isequal (info, 0, FLASH_OFFSET_CFI_RESP + 2, 'Y')) {
|
||||||
info->interface = flash_read_ushort (info, 0, FLASH_OFFSET_INTERFACE);
|
info->interface = flash_read_ushort (info, 0,
|
||||||
|
FLASH_OFFSET_INTERFACE);
|
||||||
info->cfi_offset = flash_offset_cfi[cfi_offset];
|
info->cfi_offset = flash_offset_cfi[cfi_offset];
|
||||||
debug ("device interface is %d\n",
|
debug ("device interface is %d\n",
|
||||||
info->interface);
|
info->interface);
|
||||||
|
@ -1255,7 +1302,21 @@ static int flash_detect_cfi (flash_info_t * info)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int flash_detect_cfi (flash_info_t * info)
|
||||||
|
{
|
||||||
|
debug ("flash detect cfi\n");
|
||||||
|
|
||||||
|
for (info->portwidth = CFG_FLASH_CFI_WIDTH;
|
||||||
|
info->portwidth <= FLASH_CFI_64BIT; info->portwidth <<= 1) {
|
||||||
|
for (info->chipwidth = FLASH_CFI_BY8;
|
||||||
|
info->chipwidth <= info->portwidth;
|
||||||
|
info->chipwidth <<= 1)
|
||||||
|
if (__flash_detect_cfi(info))
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
debug ("not found\n");
|
debug ("not found\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1386,7 +1447,8 @@ ulong flash_get_size (ulong base, int banknum)
|
||||||
sector += (erase_region_size * size_ratio);
|
sector += (erase_region_size * size_ratio);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Only read protection status from supported devices (intel...)
|
* Only read protection status from
|
||||||
|
* supported devices (intel...)
|
||||||
*/
|
*/
|
||||||
switch (info->vendor) {
|
switch (info->vendor) {
|
||||||
case CFI_CMDSET_INTEL_EXTENDED:
|
case CFI_CMDSET_INTEL_EXTENDED:
|
||||||
|
@ -1397,7 +1459,8 @@ ulong flash_get_size (ulong base, int banknum)
|
||||||
FLASH_STATUS_PROTECT);
|
FLASH_STATUS_PROTECT);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
info->protect[sect_cnt] = 0; /* default: not protected */
|
/* default: not protected */
|
||||||
|
info->protect[sect_cnt] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sect_cnt++;
|
sect_cnt++;
|
||||||
|
@ -1405,20 +1468,28 @@ ulong flash_get_size (ulong base, int banknum)
|
||||||
}
|
}
|
||||||
|
|
||||||
info->sector_count = sect_cnt;
|
info->sector_count = sect_cnt;
|
||||||
|
info->size = 1 << flash_read_uchar (info, FLASH_OFFSET_SIZE);
|
||||||
/* multiply the size by the number of chips */
|
/* multiply the size by the number of chips */
|
||||||
info->size = (1 << flash_read_uchar (info, FLASH_OFFSET_SIZE)) * size_ratio;
|
info->size *= size_ratio;
|
||||||
info->buffer_size = (1 << flash_read_ushort (info, 0, FLASH_OFFSET_BUFFER_SIZE));
|
info->buffer_size = 1 << flash_read_ushort (info, 0,
|
||||||
|
FLASH_OFFSET_BUFFER_SIZE);
|
||||||
tmp = 1 << flash_read_uchar (info, FLASH_OFFSET_ETOUT);
|
tmp = 1 << flash_read_uchar (info, FLASH_OFFSET_ETOUT);
|
||||||
info->erase_blk_tout = (tmp * (1 << flash_read_uchar (info, FLASH_OFFSET_EMAX_TOUT)));
|
info->erase_blk_tout = tmp *
|
||||||
|
(1 << flash_read_uchar (
|
||||||
|
info, FLASH_OFFSET_EMAX_TOUT));
|
||||||
tmp = (1 << flash_read_uchar (info, FLASH_OFFSET_WBTOUT)) *
|
tmp = (1 << flash_read_uchar (info, FLASH_OFFSET_WBTOUT)) *
|
||||||
(1 << flash_read_uchar (info, FLASH_OFFSET_WBMAX_TOUT));
|
(1 << flash_read_uchar (info, FLASH_OFFSET_WBMAX_TOUT));
|
||||||
info->buffer_write_tout = tmp / 1000 + (tmp % 1000 ? 1 : 0); /* round up when converting to ms */
|
/* round up when converting to ms */
|
||||||
|
info->buffer_write_tout = tmp / 1000 + (tmp % 1000 ? 1 : 0);
|
||||||
tmp = (1 << flash_read_uchar (info, FLASH_OFFSET_WTOUT)) *
|
tmp = (1 << flash_read_uchar (info, FLASH_OFFSET_WTOUT)) *
|
||||||
(1 << flash_read_uchar (info, FLASH_OFFSET_WMAX_TOUT));
|
(1 << flash_read_uchar (info, FLASH_OFFSET_WMAX_TOUT));
|
||||||
info->write_tout = tmp / 1000 + (tmp % 1000 ? 1 : 0); /* round up when converting to ms */
|
/* round up when converting to ms */
|
||||||
|
info->write_tout = tmp / 1000 + (tmp % 1000 ? 1 : 0);
|
||||||
info->flash_id = FLASH_MAN_CFI;
|
info->flash_id = FLASH_MAN_CFI;
|
||||||
if ((info->interface == FLASH_CFI_X8X16) && (info->chipwidth == FLASH_CFI_BY8)) {
|
if ((info->interface == FLASH_CFI_X8X16) &&
|
||||||
info->portwidth >>= 1; /* XXX - Need to test on x8/x16 in parallel. */
|
(info->chipwidth == FLASH_CFI_BY8)) {
|
||||||
|
/* XXX - Need to test on x8/x16 in parallel. */
|
||||||
|
info->portwidth >>= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1426,9 +1497,8 @@ ulong flash_get_size (ulong base, int banknum)
|
||||||
return (info->size);
|
return (info->size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* loop through the sectors from the highest address
|
/* loop through the sectors from the highest address when the passed
|
||||||
* when the passed address is greater or equal to the sector address
|
* address is greater or equal to the sector address we have a match
|
||||||
* we have a match
|
|
||||||
*/
|
*/
|
||||||
static flash_sect_t find_sector (flash_info_t * info, ulong addr)
|
static flash_sect_t find_sector (flash_info_t * info, ulong addr)
|
||||||
{
|
{
|
||||||
|
@ -1534,9 +1604,12 @@ static int flash_write_cfibuffer (flash_info_t * info, ulong dest, uchar * cp,
|
||||||
sector = find_sector (info, dest);
|
sector = find_sector (info, dest);
|
||||||
flash_write_cmd (info, sector, 0, FLASH_CMD_CLEAR_STATUS);
|
flash_write_cmd (info, sector, 0, FLASH_CMD_CLEAR_STATUS);
|
||||||
flash_write_cmd (info, sector, 0, FLASH_CMD_WRITE_TO_BUFFER);
|
flash_write_cmd (info, sector, 0, FLASH_CMD_WRITE_TO_BUFFER);
|
||||||
if ((retcode = flash_status_check (info, sector, info->buffer_write_tout,
|
retcode = flash_status_check (info, sector,
|
||||||
"write to buffer")) == ERR_OK) {
|
info->buffer_write_tout,
|
||||||
/* reduce the number of loops by the width of the port */
|
"write to buffer");
|
||||||
|
if (retcode == ERR_OK) {
|
||||||
|
/* reduce the number of loops by the width of
|
||||||
|
* the port */
|
||||||
switch (info->portwidth) {
|
switch (info->portwidth) {
|
||||||
case FLASH_CFI_8BIT:
|
case FLASH_CFI_8BIT:
|
||||||
cnt = len;
|
cnt = len;
|
||||||
|
@ -1576,8 +1649,8 @@ static int flash_write_cfibuffer (flash_info_t * info, ulong dest, uchar * cp,
|
||||||
}
|
}
|
||||||
flash_write_cmd (info, sector, 0,
|
flash_write_cmd (info, sector, 0,
|
||||||
FLASH_CMD_WRITE_BUFFER_CONFIRM);
|
FLASH_CMD_WRITE_BUFFER_CONFIRM);
|
||||||
retcode = flash_full_status_check (info, sector,
|
retcode = flash_full_status_check (
|
||||||
info->buffer_write_tout,
|
info, sector, info->buffer_write_tout,
|
||||||
"buffer write");
|
"buffer write");
|
||||||
}
|
}
|
||||||
return retcode;
|
return retcode;
|
||||||
|
@ -1617,7 +1690,8 @@ static int flash_write_cfibuffer (flash_info_t * info, ulong dest, uchar * cp,
|
||||||
}
|
}
|
||||||
|
|
||||||
flash_write_cmd (info, sector, 0, AMD_CMD_WRITE_BUFFER_CONFIRM);
|
flash_write_cmd (info, sector, 0, AMD_CMD_WRITE_BUFFER_CONFIRM);
|
||||||
retcode = flash_full_status_check (info, sector, info->buffer_write_tout,
|
retcode = flash_full_status_check (info, sector,
|
||||||
|
info->buffer_write_tout,
|
||||||
"buffer write");
|
"buffer write");
|
||||||
return retcode;
|
return retcode;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue