Patchwork [07/10] MIPS: lantiq: add NOR flash CFI address swizzle

login
register
mail settings
Submitter John Crispin
Date Jan. 5, 2011, 7:56 p.m.
Message ID <1294257379-417-8-git-send-email-blogic@openwrt.org>
Download mbox | patch
Permalink /patch/77631/
State New
Headers show

Comments

John Crispin - Jan. 5, 2011, 7:56 p.m.
This patch adds the hack mentioned in the previous patch.

It is only a hack to make the map driver work until a better solution
is discussed.

Signed-off-by: John Crispin <blogic@openwrt.org>
Signed-off-by: Ralph Hempel <ralph.hempel@lantiq.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: linux-mips@linux-mips.org
Cc: linux-mtd@lists.infradead.org
---
 drivers/mtd/chips/Kconfig           |    9 +++++++++
 drivers/mtd/chips/cfi_cmdset_0002.c |    8 ++++++++
 2 files changed, 17 insertions(+), 0 deletions(-)
John Crispin - Jan. 6, 2011, 10:06 a.m.
On 05/01/11 20:56, John Crispin wrote:
>  
>  	adr += chip->start;
> +#ifdef CONFIG_MTD_CFI_CMD_SWIZZLE
> +	adr ^= 2;
> +#endif
>  
>  	mutex_lock(&chip->mutex);
>  	ret = get_chip(map, chip, adr, FL_WRITING);
>   

Hi,

What this patch essentially does is to make sure to pass a addr with the
^=2 hack already applied, so that the complex map ends up with an un
swizzled addr as it applies the hack internally again.

I think it would be cleanest to extend the read/write callbacks of
struct map_info; with a flag indicating whether we are doing a CMD or
DATA action. as the 2 following macros are used anyway, it should not be
too hard to implement this.

#define map_read(map, ofs) (map)->read(map, ofs)
#define map_write(map, datum, ofs) (map)->write(map, datum, ofs)

I am not sure however if this is the correct fix.

Thanks,
John

Patch

diff --git a/drivers/mtd/chips/Kconfig b/drivers/mtd/chips/Kconfig
index 35c6a23..9ecb5eb 100644
--- a/drivers/mtd/chips/Kconfig
+++ b/drivers/mtd/chips/Kconfig
@@ -39,6 +39,15 @@  config MTD_CFI_ADV_OPTIONS
 
 	  If unsure, say 'N'.
 
+config MTD_CFI_CMD_SWIZZLE
+	bool "Swizzle last bit of command address"
+	default y
+	depends on LANTIQ
+	help
+	  lantiq SoCs share the external bus unit with the pci interface
+	  for MTD to work at the the same time with PCI, we need to add
+	  this quirk
+
 choice
 	prompt "Flash cmd/query data swapping"
 	depends on MTD_CFI_ADV_OPTIONS
diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
index 3b8e32d..e047af1 100644
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -39,7 +39,12 @@ 
 #include <linux/mtd/xip.h>
 
 #define AMD_BOOTLOC_BUG
+
+#ifdef CONFIG_MTD_CFI_CMD_SWIZZLE
+#define FORCE_WORD_WRITE 1
+#else
 #define FORCE_WORD_WRITE 0
+#endif
 
 #define MAX_WORD_RETRIES 3
 
@@ -1140,6 +1145,9 @@  static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
 	int retry_cnt = 0;
 
 	adr += chip->start;
+#ifdef CONFIG_MTD_CFI_CMD_SWIZZLE
+	adr ^= 2;
+#endif
 
 	mutex_lock(&chip->mutex);
 	ret = get_chip(map, chip, adr, FL_WRITING);