1 --- a/drivers/mtd/cfi_flash.c
2 +++ b/drivers/mtd/cfi_flash.c
3 @@ -85,6 +85,22 @@ flash_info_t flash_info[CFI_MAX_FLASH_BA
4 #define CONFIG_SYS_FLASH_CFI_WIDTH FLASH_CFI_8BIT
8 + * Check if address fixup macros are defined, define defaults otherwise
10 +#ifndef FLASH_FIXUP_ADDR_8
11 +#define FLASH_FIXUP_ADDR_8(addr) (addr)
13 +#ifndef FLASH_FIXUP_ADDR_16
14 +#define FLASH_FIXUP_ADDR_16(addr) (addr)
16 +#ifndef FLASH_FIXUP_ADDR_32
17 +#define FLASH_FIXUP_ADDR_32(addr) (addr)
19 +#ifndef FLASH_FIXUP_ADDR_64
20 +#define FLASH_FIXUP_ADDR_64(addr) (addr)
23 static void __flash_write8(u8 value, void *addr)
25 __raw_writeb(value, addr);
26 @@ -264,9 +280,9 @@ static inline uchar flash_read_uchar (fl
28 cp = flash_map (info, 0, offset);
29 #if defined(__LITTLE_ENDIAN) || defined(CONFIG_SYS_WRITE_SWAPPED_DATA)
30 - retval = flash_read8(cp);
31 + retval = flash_read8(FLASH_FIXUP_ADDR_8(cp));
33 - retval = flash_read8(cp + info->portwidth - 1);
34 + retval = flash_read8(FLASH_FIXUP_ADDR_8(cp) + info->portwidth - 1);
36 flash_unmap (info, 0, offset, cp);
38 @@ -280,7 +296,7 @@ static inline ushort flash_read_word (fl
41 addr = flash_map (info, 0, offset);
42 - retval = flash_read16 (addr);
43 + retval = flash_read16 (FLASH_FIXUP_ADDR_16(addr));
44 flash_unmap (info, 0, offset, addr);
47 @@ -305,19 +321,28 @@ static ulong flash_read_long (flash_info
48 debug ("long addr is at %p info->portwidth = %d\n", addr,
50 for (x = 0; x < 4 * info->portwidth; x++) {
51 - debug ("addr[%x] = 0x%x\n", x, flash_read8(addr + x));
52 + debug ("addr[%x] = 0x%x\n", x,
53 + flash_read8(FLASH_FIXUP_ADDR_32(addr) + x));
56 #if defined(__LITTLE_ENDIAN) || defined(CONFIG_SYS_WRITE_SWAPPED_DATA)
57 - retval = ((flash_read8(addr) << 16) |
58 - (flash_read8(addr + info->portwidth) << 24) |
59 - (flash_read8(addr + 2 * info->portwidth)) |
60 - (flash_read8(addr + 3 * info->portwidth) << 8));
61 + retval = ((flash_read8(FLASH_FIXUP_ADDR_8
63 + (flash_read8(FLASH_FIXUP_ADDR_8
64 + (addr + info->portwidth)) << 24) |
65 + (flash_read8(FLASH_FIXUP_ADDR_8
66 + (addr + 2 * info->portwidth))) |
67 + (flash_read8(FLASH_FIXUP_ADDR_8
68 + (addr + 3 * info->portwidth)) << 8));
70 - retval = ((flash_read8(addr + 2 * info->portwidth - 1) << 24) |
71 - (flash_read8(addr + info->portwidth - 1) << 16) |
72 - (flash_read8(addr + 4 * info->portwidth - 1) << 8) |
73 - (flash_read8(addr + 3 * info->portwidth - 1)));
74 + retval = ((flash_read8(FLASH_FIXUP_ADDR_8
75 + (addr + 2 * info->portwidth - 1)) << 24) |
76 + (flash_read8(FLASH_FIXUP_ADDR_8
77 + (addr + info->portwidth - 1)) << 16) |
78 + (flash_read8(FLASH_FIXUP_ADDR_8
79 + (addr + 4 * info->portwidth - 1)) << 8) |
80 + (flash_read8(FLASH_FIXUP_ADDR_8
81 + (addr + 3 * info->portwidth - 1))));
83 flash_unmap(info, sect, offset, addr);
85 @@ -338,21 +363,22 @@ void flash_write_cmd (flash_info_t * inf
86 flash_make_cmd (info, cmd, &cword);
87 switch (info->portwidth) {
89 - debug ("fwc addr %p cmd %x %x 8bit x %d bit\n", addr, cmd,
90 - cword.c, info->chipwidth << CFI_FLASH_SHIFT_WIDTH);
91 - flash_write8(cword.c, addr);
92 + debug ("fwc addr %p cmd %x %x 8bit x %d bit\n",
93 + FLASH_FIXUP_ADDR_8(addr), cmd, cword.c,
94 + info->chipwidth << CFI_FLASH_SHIFT_WIDTH);
95 + flash_write8(cword.c, FLASH_FIXUP_ADDR_8(addr));
98 - debug ("fwc addr %p cmd %x %4.4x 16bit x %d bit\n", addr,
100 + debug ("fwc addr %p cmd %x %4.4x 16bit x %d bit\n",
101 + FLASH_FIXUP_ADDR_16(addr), cmd, cword.w,
102 info->chipwidth << CFI_FLASH_SHIFT_WIDTH);
103 - flash_write16(cword.w, addr);
104 + flash_write16(cword.w, FLASH_FIXUP_ADDR_16(addr));
106 case FLASH_CFI_32BIT:
107 - debug ("fwc addr %p cmd %x %8.8lx 32bit x %d bit\n", addr,
109 + debug ("fwc addr %p cmd %x %8.8lx 32bit x %d bit\n",
110 + FLASH_FIXUP_ADDR_32(addr), cmd, cword.l,
111 info->chipwidth << CFI_FLASH_SHIFT_WIDTH);
112 - flash_write32(cword.l, addr);
113 + flash_write32(cword.l, FLASH_FIXUP_ADDR_32(addr));
115 case FLASH_CFI_64BIT:
117 @@ -362,11 +388,11 @@ void flash_write_cmd (flash_info_t * inf
118 print_longlong (str, cword.ll);
120 debug ("fwrite addr %p cmd %x %s 64 bit x %d bit\n",
122 + FLASH_FIXUP_ADDR_64(addr), cmd, str,
123 info->chipwidth << CFI_FLASH_SHIFT_WIDTH);
126 - flash_write64(cword.ll, addr);
127 + flash_write64(cword.ll, FLASH_FIXUP_ADDR_64(addr));
131 @@ -397,16 +423,19 @@ static int flash_isequal (flash_info_t *
132 debug ("is= cmd %x(%c) addr %p ", cmd, cmd, addr);
133 switch (info->portwidth) {
135 - debug ("is= %x %x\n", flash_read8(addr), cword.c);
136 - retval = (flash_read8(addr) == cword.c);
137 + debug ("is= %x %x\n",
138 + flash_read8(FLASH_FIXUP_ADDR_8(addr)), cword.c);
139 + retval = (flash_read8(FLASH_FIXUP_ADDR_8(addr)) == cword.c);
141 case FLASH_CFI_16BIT:
142 - debug ("is= %4.4x %4.4x\n", flash_read16(addr), cword.w);
143 - retval = (flash_read16(addr) == cword.w);
144 + debug ("is= %4.4x %4.4x\n",
145 + flash_read16(FLASH_FIXUP_ADDR_16(addr)), cword.w);
146 + retval = (flash_read16(FLASH_FIXUP_ADDR_16(addr)) == cword.w);
148 case FLASH_CFI_32BIT:
149 - debug ("is= %8.8x %8.8lx\n", flash_read32(addr), cword.l);
150 - retval = (flash_read32(addr) == cword.l);
151 + debug ("is= %8.8x %8.8lx\n",
152 + flash_read32(FLASH_FIXUP_ADDR_32(addr)), cword.l);
153 + retval = (flash_read32(FLASH_FIXUP_ADDR_32(addr)) == cword.l);
155 case FLASH_CFI_64BIT:
157 @@ -414,12 +443,13 @@ static int flash_isequal (flash_info_t *
161 - print_longlong (str1, flash_read64(addr));
162 + print_longlong (str1, flash_read64(FLASH_FIXUP_ADDR_64
164 print_longlong (str2, cword.ll);
165 debug ("is= %s %s\n", str1, str2);
168 - retval = (flash_read64(addr) == cword.ll);
169 + retval = (flash_read64(FLASH_FIXUP_ADDR_64(addr)) == cword.ll);
173 @@ -443,16 +473,20 @@ static int flash_isset (flash_info_t * i
174 flash_make_cmd (info, cmd, &cword);
175 switch (info->portwidth) {
177 - retval = ((flash_read8(addr) & cword.c) == cword.c);
178 + retval = ((flash_read8(FLASH_FIXUP_ADDR_8(addr))
179 + & cword.c) == cword.c);
181 case FLASH_CFI_16BIT:
182 - retval = ((flash_read16(addr) & cword.w) == cword.w);
183 + retval = ((flash_read16(FLASH_FIXUP_ADDR_16(addr))
184 + & cword.w) == cword.w);
186 case FLASH_CFI_32BIT:
187 - retval = ((flash_read32(addr) & cword.l) == cword.l);
188 + retval = ((flash_read32(FLASH_FIXUP_ADDR_32(addr))
189 + & cword.l) == cword.l);
191 case FLASH_CFI_64BIT:
192 - retval = ((flash_read64(addr) & cword.ll) == cword.ll);
193 + retval = ((flash_read64(FLASH_FIXUP_ADDR_64(addr))
194 + & cword.ll) == cword.ll);
198 @@ -476,17 +510,22 @@ static int flash_toggle (flash_info_t *
199 flash_make_cmd (info, cmd, &cword);
200 switch (info->portwidth) {
202 - retval = flash_read8(addr) != flash_read8(addr);
203 + retval = flash_read8(FLASH_FIXUP_ADDR_8(addr)) !=
204 + flash_read8(FLASH_FIXUP_ADDR_8(addr));
206 case FLASH_CFI_16BIT:
207 - retval = flash_read16(addr) != flash_read16(addr);
208 + retval = flash_read16(FLASH_FIXUP_ADDR_16(addr)) !=
209 + flash_read16(FLASH_FIXUP_ADDR_16(addr));
211 case FLASH_CFI_32BIT:
212 - retval = flash_read32(addr) != flash_read32(addr);
213 + retval = flash_read32(FLASH_FIXUP_ADDR_32(addr)) !=
214 + flash_read32(FLASH_FIXUP_ADDR_32(addr));
216 case FLASH_CFI_64BIT:
217 - retval = ( (flash_read32( addr ) != flash_read32( addr )) ||
218 - (flash_read32(addr+4) != flash_read32(addr+4)) );
219 + retval = ( (flash_read32(FLASH_FIXUP_ADDR_64( addr )) !=
220 + flash_read32(FLASH_FIXUP_ADDR_64( addr ))) ||
221 + (flash_read32(FLASH_FIXUP_ADDR_64(addr+4)) !=
222 + flash_read32(FLASH_FIXUP_ADDR_64(addr+4))) );