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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
--- linux-2.6.14/drivers/mtd/maps/ixp4xx.c 2005-10-27 17:02:08.000000000 -0700
+++ linux-2.6.14/drivers/mtd/maps/ixp4xx.c 2005-10-29 23:11:24.990820968 -0700
@@ -22,6 +22,7 @@
#include <linux/string.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/map.h>
+#include <linux/mtd/cfi_endian.h>
#include <linux/mtd/partitions.h>
#include <linux/ioport.h>
#include <linux/device.h>
@@ -30,18 +31,45 @@
#include <linux/reboot.h>
+/* On a little-endian IXP4XX system (tested on NSLU2) an LDRH or STRH
+ * will flip the second address bit - i.e. XOR the address with 10b.
+ * This causes the cfi commands (sent to the command address, 0xAA for
+ * 16 bit flash) to fail. This is fixed here by XOR'ing the address
+ * before use with 10b. The cost of this is that the flash layout ends
+ * up with pdp-endiannes (on an LE system), however this is not a problem
+ * as the access code consistently only accesses half words - so the
+ * endianness is not determinable on stuff which is written and read
+ * consistently in the little endian world.
+ *
+ * For flash data from the big-endian world, however, the results are
+ * weird - the pdp-endianness results in the data apparently being
+ * 2-byte swapped (as in dd conv=swab). To work round this the 16
+ * bit values are written and read using cpu_to_cfi16 and cfi16_to_cpu,
+ * by default these are no-ops, but if the MTD driver is configed with
+ * CONFIG_MTD_CFI_BE_BYTE_SWAP the macros will byte swap the data,
+ * resulting in a consistently BE view of the flash on both BE (no
+ * op) and LE systems. This config setting also causes the command
+ * data from the CFI implementation to get swapped - as is required
+ * so that this code will *unswap* it and give the correct command
+ * data to the flash.
+ */
#ifndef __ARMEB__
#define BYTE0(h) ((h) & 0xFF)
#define BYTE1(h) (((h) >> 8) & 0xFF)
+#define FLASHWORD(a) (*(__u16*)((u32)(a) ^ 2))
#else
#define BYTE0(h) (((h) >> 8) & 0xFF)
#define BYTE1(h) ((h) & 0xFF)
+#define FLASHWORD(a) (*(__u16*)(a))
#endif
+#define FLASHW(a) cfi16_to_cpu(FLASHWORD(a))
+#define FLASHSET(a,v) (FLASHWORD(a) = cpu_to_cfi16(v))
+
static map_word ixp4xx_read16(struct map_info *map, unsigned long ofs)
{
map_word val;
- val.x[0] = *(__u16 *) (map->map_priv_1 + ofs);
+ val.x[0] = FLASHW(map->map_priv_1 + ofs);
return val;
}
@@ -53,19 +81,25 @@ static map_word ixp4xx_read16(struct map
static void ixp4xx_copy_from(struct map_info *map, void *to,
unsigned long from, ssize_t len)
{
- int i;
- u8 *dest = (u8 *) to;
- u16 *src = (u16 *) (map->map_priv_1 + from);
- u16 data;
-
- for (i = 0; i < (len / 2); i++) {
- data = src[i];
- dest[i * 2] = BYTE0(data);
- dest[i * 2 + 1] = BYTE1(data);
+ u8 *dest, *src;
+
+ if (len <= 0)
+ return;
+
+ dest = (u8 *) to;
+ src = (u8 *) (map->map_priv_1 + from);
+ if (from & 1)
+ *dest++ = BYTE1(FLASHW(src-1)), ++src, --len;
+
+ while (len >= 2) {
+ u16 data = FLASHW(src); src += 2;
+ *dest++ = BYTE0(data);
+ *dest++ = BYTE1(data);
+ len -= 2;
}
- if (len & 1)
- dest[len - 1] = BYTE0(src[i]);
+ if (len > 0)
+ *dest++ = BYTE0(FLASHW(src));
}
/*
@@ -75,7 +109,7 @@ static void ixp4xx_copy_from(struct map_
static void ixp4xx_probe_write16(struct map_info *map, map_word d, unsigned long adr)
{
if (!(adr & 1))
- *(__u16 *) (map->map_priv_1 + adr) = d.x[0];
+ FLASHSET(map->map_priv_1 + adr, d.x[0]);
}
/*
@@ -83,7 +117,7 @@ static void ixp4xx_probe_write16(struct
*/
static void ixp4xx_write16(struct map_info *map, map_word d, unsigned long adr)
{
- *(__u16 *) (map->map_priv_1 + adr) = d.x[0];
+ FLASHSET(map->map_priv_1 + adr, d.x[0]);
}
struct ixp4xx_flash_info {
|