Skip to content

Commit c927cd3

Browse files
KAGA-KOKOThomas Gleixner
authored andcommitted
[MTD] Add the reverse operation of cfi_build_cmd()
This is necessary to fix the broken status check in cfi_cmdset_0001 Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent fb6bb52 commit c927cd3

1 file changed

Lines changed: 64 additions & 1 deletion

File tree

‎include/linux/mtd/cfi.h‎

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
/* Common Flash Interface structures
33
* See http://support.intel.com/design/flash/technote/index.htm
4-
* $Id: cfi.h,v 1.52 2005/02/08 17:11:15 nico Exp $
4+
* $Id: cfi.h,v 1.53 2005/03/15 19:03:13 gleixner Exp $
55
*/
66

77
#ifndef __MTD_CFI_H__
@@ -315,6 +315,69 @@ static inline map_word cfi_build_cmd(u_long cmd, struct map_info *map, struct cf
315315
}
316316
#define CMD(x) cfi_build_cmd((x), map, cfi)
317317

318+
319+
static inline unsigned char cfi_merge_status(map_word val, struct map_info *map,
320+
struct cfi_private *cfi)
321+
{
322+
int wordwidth, words_per_bus, chip_mode, chips_per_word;
323+
unsigned long onestat, res = 0;
324+
int i;
325+
326+
/* We do it this way to give the compiler a fighting chance
327+
of optimising away all the crap for 'bankwidth' larger than
328+
an unsigned long, in the common case where that support is
329+
disabled */
330+
if (map_bankwidth_is_large(map)) {
331+
wordwidth = sizeof(unsigned long);
332+
words_per_bus = (map_bankwidth(map)) / wordwidth; // i.e. normally 1
333+
} else {
334+
wordwidth = map_bankwidth(map);
335+
words_per_bus = 1;
336+
}
337+
338+
chip_mode = map_bankwidth(map) / cfi_interleave(cfi);
339+
chips_per_word = wordwidth * cfi_interleave(cfi) / map_bankwidth(map);
340+
341+
onestat = val.x[0];
342+
/* Or all status words together */
343+
for (i=1; i < words_per_bus; i++) {
344+
onestat |= val.x[i];
345+
}
346+
347+
res = onestat;
348+
switch(chips_per_word) {
349+
default: BUG();
350+
#if BITS_PER_LONG >= 64
351+
case 8:
352+
res |= (onestat >> (chip_mode * 32));
353+
#endif
354+
case 4:
355+
res |= (onestat >> (chip_mode * 16));
356+
case 2:
357+
res |= (onestat >> (chip_mode * 8));
358+
case 1:
359+
;
360+
}
361+
362+
/* Last, determine what the bit-pattern should be for a single
363+
device, according to chip mode and endianness... */
364+
switch (chip_mode) {
365+
case 1:
366+
break;
367+
case 2:
368+
res = cfi16_to_cpu(res);
369+
break;
370+
case 4:
371+
res = cfi32_to_cpu(res);
372+
break;
373+
default: BUG();
374+
}
375+
return res;
376+
}
377+
378+
#define MERGESTATUS(x) cfi_merge_status((x), map, cfi)
379+
380+
318381
/*
319382
* Sends a CFI command to a bank of flash for the given geometry.
320383
*

0 commit comments

Comments
 (0)