[PATCH] mtd: support for bit-reversed CFI cmd/query
Nikita V. Youshchenko
yoush at cs.msu.su
Wed Feb 27 15:48:07 EST 2008
commit 049aa6336a85de3143a3dc9cb3f4c87ecc8896b3
Author: Nikita Youshchenko <yoush at cs.msu.su>
Date: Wed Feb 27 20:25:22 2008 +0000
mtd: support for bit-reversed CFI cmd/query
Some embedded boards have flash chips connected with reversed bit order.
Example for 16-bit width:
chip D0 is bus D15
chip D1 is bus D14
...
chip D15 is bus D0
It works perfectly for data access, however probing and issuing CFI commands
for such chips require bit reversing. This patch adds support for this.
Signed-off-by: Nikita Youshchenko <yoush at cs.msu.su>
diff --git a/drivers/mtd/chips/Kconfig b/drivers/mtd/chips/Kconfig
index 6d8f30d..0471cd0 100644
--- a/drivers/mtd/chips/Kconfig
+++ b/drivers/mtd/chips/Kconfig
@@ -57,7 +57,8 @@ config MTD_CFI_NOSWAP
enabled, means that the CPU will not do any swapping; the chips
are expected to be wired to the CPU in 'host-endian' form.
Specific arrangements are possible with the BIG_ENDIAN_BYTE and
- LITTLE_ENDIAN_BYTE, if the bytes are reversed.
+ LITTLE_ENDIAN_BYTE, if the bytes are reversed. Also it is possible
+ to revert bit order in 'magic commands'.
If you have a LART, on which the data (and address) lines were
connected in a fashion which ensured that the nets were as short
@@ -72,6 +73,10 @@ config MTD_CFI_BE_BYTE_SWAP
config MTD_CFI_LE_BYTE_SWAP
bool "LITTLE_ENDIAN_BYTE"
+config MTD_CFI_BIT_SWAP
+ bool "Reverse bit order"
+ select BITREVERSE
+
endchoice
config MTD_CFI_GEOMETRY
diff --git a/include/linux/mtd/cfi_endian.h b/include/linux/mtd/cfi_endian.h
index 25724f7..195edae 100644
--- a/include/linux/mtd/cfi_endian.h
+++ b/include/linux/mtd/cfi_endian.h
@@ -52,6 +52,24 @@
#define cfi16_to_cpu(x) (x)
#define cfi32_to_cpu(x) (x)
#define cfi64_to_cpu(x) (x)
+#elif defined(CONFIG_MTD_CFI_BIT_SWAP)
+#include <linux/bitrev.h>
+#define cpu_to_cfi8(x) (x)
+#define cfi8_to_cpu(x) (x)
+#define cpu_to_cfi16(x) ({ u16 y = (x); \
+ (bitrev8(y & 255) << 8) | bitrev8(y >> 8); \
+ })
+#define cfi16_to_cpu(x) ({ u16 y = (x); \
+ (bitrev8(y & 255) << 8) | bitrev8(y >> 8); \
+ })
+#define cpu_to_cfi32(x) (x)
+#define cfi32_to_cpu(x) (x)
+#define cpu_to_cfi64(x) ({ u64 y = (x); \
+ (bitrev32(y & 0xffffffff) << 32) | bitrev32(y >> 32); \
+ })
+#define cfi64_to_cpu(x) ({ u64 y = (x); \
+ (bitrev32(y & 0xffffffff) << 32) | bitrev32(y >> 32); \
+ })
#else
#error No CFI endianness defined
#endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.infradead.org/pipermail/linux-mtd/attachments/20080227/7a5f591d/attachment.bin
More information about the linux-mtd
mailing list