Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Nikita V. Youshchenko" <yoush@cs.msu.su>
To: linux-mtd@lists.infradead.org
Subject: [PATCH] mtd: support for bit-reversed CFI cmd/query
Date: Wed, 27 Feb 2008 23:48:07 +0300	[thread overview]
Message-ID: <200802272348.13180@blacky.localdomain> (raw)

[-- Attachment #1: Type: text/plain, Size: 2562 bytes --]

commit 049aa6336a85de3143a3dc9cb3f4c87ecc8896b3
Author: Nikita Youshchenko <yoush@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@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

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

             reply	other threads:[~2008-02-27 20:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-27 20:48 Nikita V. Youshchenko [this message]
2008-04-22 18:56 ` [PATCH] mtd: support for bit-reversed CFI cmd/query David Woodhouse
2008-04-22 19:08   ` Nikita V. Youshchenko
2008-04-22 19:23     ` David Woodhouse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200802272348.13180@blacky.localdomain \
    --to=yoush@cs.msu.su \
    --cc=linux-mtd@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox