summaryrefslogtreecommitdiff
path: root/target/linux/adm5120-2.6/patches/101-cfi-fixup-macronix-bootloc.patch
blob: 58b6dff1f2933da9cfc654ad1939d6bff5cca17f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
Index: linux-2.6.21.1/drivers/mtd/chips/cfi_cmdset_0002.c
===================================================================
--- linux-2.6.21.1.orig/drivers/mtd/chips/cfi_cmdset_0002.c
+++ linux-2.6.21.1/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -47,12 +47,17 @@
 #define MANUFACTURER_AMD	0x0001
 #define MANUFACTURER_ATMEL	0x001F
 #define MANUFACTURER_SST	0x00BF
+#define MANUFACTURER_MACRONIX	0x00C2
 #define SST49LF004B	        0x0060
 #define SST49LF040B	        0x0050
 #define SST49LF008A		0x005a
 #define AT49BV6416		0x00d6
 #define MANUFACTURER_SAMSUNG	0x00ec
 
+/* Macronix */
+#define MX29LV160B	0x2249	/* MX29LV160 Bottom-boot chip */
+#define MX29LV320B	0x22A8	/* MX29LV320 Bottom-boot chip */
+
 static int cfi_amdstd_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
 static int cfi_amdstd_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
 static int cfi_amdstd_write_buffers(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
@@ -217,6 +222,35 @@ static void fixup_use_atmel_lock(struct 
 	mtd->flags |= MTD_STUPID_LOCK;
 }
 
+#ifdef CONFIG_MTD_CFI_FIXUP_MACRONIX_BOOTLOC
+/*
+ * Some Macronix chips has bad bootblock information in the CFI table
+ */
+static void fixup_macronix_bootloc(struct mtd_info *mtd, void* param)
+{
+	struct map_info *map = mtd->priv;
+	struct cfi_private *cfi = map->fldrv_priv;
+	struct cfi_pri_amdstd *extp = cfi->cmdset_priv;
+	__u8 major = extp->MajorVersion;
+	__u8 minor = extp->MinorVersion;
+
+	switch (cfi->id) {
+	/* TODO: put affected chip ids here */
+	case MX29LV160B:
+	case MX29LV320B:
+		if (((major << 8) | minor) != 0x3131)
+			break;
+
+		if (extp->TopBottom == 2)
+			break;
+
+		extp->TopBottom = 2;	/* Bottom boot */
+		printk("%s: weird Macronix chip detected, id:0x%04X, boot location "
+			"forced to bottom\n", map->name, cfi->id);
+	}
+}
+#endif /* CONFIG_MTD_CFI_FIXUP_MACRONIX_BOOTLOC */
+
 static struct cfi_fixup cfi_fixup_table[] = {
 #ifdef AMD_BOOTLOC_BUG
 	{ CFI_MFR_AMD, CFI_ID_ANY, fixup_amd_bootblock, NULL },
@@ -231,6 +265,9 @@ static struct cfi_fixup cfi_fixup_table[
 	{ CFI_MFR_ANY, CFI_ID_ANY, fixup_use_write_buffers, NULL, },
 #endif
 	{ CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL },
+#ifdef CONFIG_MTD_CFI_FIXUP_MACRONIX_BOOTLOC
+	{ MANUFACTURER_MACRONIX, CFI_ID_ANY, fixup_macronix_bootloc, NULL, },
+#endif
 	{ 0, 0, NULL, NULL }
 };
 static struct cfi_fixup jedec_fixup_table[] = {
Index: linux-2.6.21.1/drivers/mtd/chips/Kconfig
===================================================================
--- linux-2.6.21.1.orig/drivers/mtd/chips/Kconfig
+++ linux-2.6.21.1/drivers/mtd/chips/Kconfig
@@ -199,6 +199,14 @@ config MTD_CFI_AMDSTD
 	  provides support for one of those command sets, used on chips
 	  including the AMD Am29LV320.
 
+config MTD_CFI_FIXUP_MACRONIX_BOOTLOC
+	bool "Force bottom boot for Macronix flash chips"
+	depends on MTD_CFI_AMDSTD
+	help
+	  Some Macronix flash chips have wrong boot-block location in the
+	  CFI table, and the driver may detect the type incorrectly. Select 
+	  this if your board has such chip.
+
 config MTD_CFI_STAA
 	tristate "Support for ST (Advanced Architecture) flash chips"
 	depends on MTD_GEN_PROBE