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

Vasiliy Leoenenko
2008-04-29T14:40:06Z

cfi_flash: support of long cmd in U-boot.

Some NOR flash chips needs support of commands with length grether than max value size of uchar.
For example all M18 family chips use 0x1ff command in buffered write mode as value of program loops count.

Signed-off-by: Alexey Korolev <akorolev@infradead.org>
Signed-off-by: Vasiliy Leonenko <vasiliy.leonenko@mail.ru>
======================================================
diff -aupNr a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c
--- a/drivers/mtd/cfi_flash.c 2008-04-21 02:39:38.000000000 +0400
+++ b/drivers/mtd/cfi_flash.c 2008-04-29 17:29:07.000000000 +0400
@@ -298,17 +298,32 @@ static inline void flash_unmap(flash_inf
/*-----------------------------------------------------------------------
* 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;
+ int cword_offset;
+ int perchip_offset;
uchar *cp = (uchar *) cmdbuf;
+ uchar val;

#if defined(__LITTLE_ENDIAN) || defined(CFG_WRITE_SWAPPED_DATA)
- for (i = info->portwidth; i > 0; i--)
+ for (i = sizeof(cfiword_t); i > 0; i--){
+ cword_offset = i - 1;
#else
- for (i = 1; i <= info->portwidth; i++)
+ for (i = 1; i <= sizeof(cfiword_t); i++){
+ cword_offset = sizeof(cfiword_t) - i;
#endif
- *cp++ = (i & (info->chipwidth - 1)) ? '\0' : cmd;
+ perchip_offset = cword_offset % info->chipwidth;
+
+ /* If current offset inside one chip is over command size or
+ current offset is over portwidth fill data by 0x00 */
+ if(perchip_offset >= sizeof(ulong) || cword_offset >= info->portwidth)
+ val = 0x00;
+ else
+ val = *((uchar*)&cmd + perchip_offset);
+
+ cp[i - 1] = val;
+ }
}

#ifdef DEBUG
@@ -422,7 +437,7 @@ static ulong flash_read_long (flash_info
* 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)
+ uint offset, ulong cmd)
{

void *addr;
@@ -911,7 +926,7 @@ static int flash_write_cfibuffer (flash_
/* reduce the number of loops by the width of
* the port */
cnt = len >> shift;
- 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: