[U-Boot-Users] [PATCH] M18 flash (Sibley) support (attempt 2)

Vasiliy Leoenenko
2007-09-28T11:29:56Z

Hi Wolfgang,

> Your patch was corrupted by your mailer which wrapped long lines. It
> cannot be applied.
Thank you very much for your reply. Gmail wrapped long lines. So I changed mail box. This is the second attempt.

The patch was verified on different kinds of NOR using Mainstone II platform - no issues are found on u-boot (versions 1.3.0-rc1 and 1.3.0-rc2).

Any comments and suggestions are welcome.

Thanks,

Signed-off-by: Vasiliy Leonenko <vasiliy.leonenko@mail.ru>
Signed-off-by: Alexey Korolev <akorolex@gmail.com>
====================================================
--- u-boot-1.3.0-rc1.base/drivers/cfi_flash.c 2007-09-07 19:43:36.000000000 +0400
+++ u-boot-1.3.0-rc1/drivers/cfi_flash.c 2007-09-24 16:07:10.000000000 +0400
@@ -74,6 +74,7 @@
#define FLASH_CMD_PROTECT_CLEAR 0xD0
#define FLASH_CMD_CLEAR_STATUS 0x50
#define FLASH_CMD_WRITE_TO_BUFFER 0xE8
+#define FLASH_CMD_WRITE_TO_BUFFER_EXT 0xE9
#define FLASH_CMD_WRITE_BUFFER_CONFIRM 0xD0

#define FLASH_STATUS_DONE 0x80
@@ -136,6 +137,7 @@
#define CFI_CMDSET_MITSU_STANDARD 256
#define CFI_CMDSET_MITSU_EXTENDED 257
#define CFI_CMDSET_SST 258
+#define CFI_CMDSET_INTEL_PROG_REGIONS 512

#ifdef CFG_FLASH_CFI_AMD_RESET /* needed for STM_ID_29W320DB on UC100 */
# undef FLASH_CMD_RESET
@@ -184,8 +186,8 @@ flash_info_t flash_info[CFG_MAX_FLASH_BA
typedef unsigned long flash_sect_t;

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_write_cmd (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd);
+static void flash_make_cmd (flash_info_t * info, ulong cmd, void *cmdbuf);
+static void flash_write_cmd (flash_info_t * info, flash_sect_t sect, uint offset, ulong cmd);
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_isset (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd);
@@ -474,6 +476,7 @@ int flash_erase (flash_info_t * info, in
for (sect = s_first; sect <= s_last; sect++) {
if (info->protect[sect] == 0) { /* not protected */
switch (info->vendor) {
+ case CFI_CMDSET_INTEL_PROG_REGIONS:
case CFI_CMDSET_INTEL_STANDARD:
case CFI_CMDSET_INTEL_EXTENDED:
flash_write_cmd (info, sect, 0, FLASH_CMD_CLEAR_STATUS);
@@ -522,6 +525,9 @@ void flash_print_info (flash_info_t * in
info->size >> 20, info->sector_count);
printf (" ");
switch (info->vendor) {
+ case CFI_CMDSET_INTEL_PROG_REGIONS:
+ printf ("Intel Prog Regions");
+ break;
case CFI_CMDSET_INTEL_STANDARD:
printf ("Intel Standard");
break;
@@ -771,6 +777,7 @@ static int flash_is_busy (flash_info_t *
int retval;

switch (info->vendor) {
+ case CFI_CMDSET_INTEL_PROG_REGIONS:
case CFI_CMDSET_INTEL_STANDARD:
case CFI_CMDSET_INTEL_EXTENDED:
retval = !flash_isset (info, sect, 0, FLASH_STATUS_DONE);
@@ -825,6 +832,7 @@ static int flash_full_status_check (flas

retcode = flash_status_check (info, sector, tout, prompt);
switch (info->vendor) {
+ case CFI_CMDSET_INTEL_PROG_REGIONS:
case CFI_CMDSET_INTEL_EXTENDED:
case CFI_CMDSET_INTEL_STANDARD:
if ((retcode == ERR_OK)
@@ -903,7 +911,7 @@ static void flash_add_byte (flash_info_t
/*-----------------------------------------------------------------------
* make a proper sized command based on the port and chip widths
*/
-static void flash_make_cmd (flash_info_t * info, uchar cmd, void *cmdbuf)
+static void flash_make_cmd (flash_info_t * info, ulong cmd, void *cmdbuf)
{
int i;
uchar *cp = (uchar *) cmdbuf;
@@ -913,13 +921,13 @@ static void flash_make_cmd (flash_info_t
#else
for (i = 1; i <= info->portwidth; i++)
#endif
- *cp++ = (i & (info->chipwidth - 1)) ? '\0' : cmd;
+ *cp++ = (i > info->chipwidth) ? '\0' : *((uchar *)&cmd + info->portwidth - i);
}

/*
* 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, ulong cmd)
{

volatile cfiptr_t addr;
@@ -1090,6 +1098,7 @@ static void flash_read_jedec_ids (flash_
info->device_id2 = 0;

switch (info->vendor) {
+ case CFI_CMDSET_INTEL_PROG_REGIONS:
case CFI_CMDSET_INTEL_STANDARD:
case CFI_CMDSET_INTEL_EXTENDED:
flash_write_cmd(info, 0, 0, FLASH_CMD_RESET);
@@ -1209,6 +1218,7 @@ ulong flash_get_size (ulong base, int ba
flash_printqry (info, 0);
#endif
switch (info->vendor) {
+ case CFI_CMDSET_INTEL_PROG_REGIONS:
case CFI_CMDSET_INTEL_STANDARD:
case CFI_CMDSET_INTEL_EXTENDED:
default:
@@ -1289,6 +1299,7 @@ ulong flash_get_size (ulong base, int ba
* Only read protection status from supported devices (intel...)
*/
switch (info->vendor) {
+ case CFI_CMDSET_INTEL_PROG_REGIONS:
case CFI_CMDSET_INTEL_EXTENDED:
case CFI_CMDSET_INTEL_STANDARD:
info->protect[sect_cnt] =
@@ -1377,6 +1388,7 @@ static int flash_write_cfiword (flash_in
flag = disable_interrupts ();

switch (info->vendor) {
+ case CFI_CMDSET_INTEL_PROG_REGIONS:
case CFI_CMDSET_INTEL_EXTENDED:
case CFI_CMDSET_INTEL_STANDARD:
flash_write_cmd (info, 0, 0, FLASH_CMD_CLEAR_STATUS);
@@ -1422,15 +1434,19 @@ static int flash_write_cfibuffer (flash_
int retcode;
volatile cfiptr_t src;
volatile cfiptr_t dst;
+ uchar write_cmd;

switch (info->vendor) {
+ case CFI_CMDSET_INTEL_PROG_REGIONS:
case CFI_CMDSET_INTEL_STANDARD:
case CFI_CMDSET_INTEL_EXTENDED:
src.cp = cp;
dst.cp = (uchar *) dest;
sector = find_sector (info, dest);
+ write_cmd = (info->vendor == CFI_CMDSET_INTEL_PROG_REGIONS) ?
+ FLASH_CMD_WRITE_TO_BUFFER_EXT : FLASH_CMD_WRITE_TO_BUFFER;
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, write_cmd);
if ((retcode = flash_status_check (info, sector, info->buffer_write_tout,
"write to buffer")) == ERR_OK) {
/* reduce the number of loops by the width of the port */
@@ -1451,7 +1467,7 @@ static int flash_write_cfibuffer (flash_
return ERR_INVAL;
break;
}
- flash_write_cmd (info, sector, 0, (uchar) cnt - 1);
+ flash_write_cmd (info, sector, 0, cnt - 1);
while (cnt-- > 0) {
switch (info->portwidth) {
case FLASH_CFI_8BIT: