37 #include <linux/kernel.h>
38 #include <linux/module.h>
39 #include <linux/types.h>
41 #include <linux/errno.h>
42 #include <linux/string.h>
46 #ifndef CONFIG_SA1100_LART
47 #error This is for LART architecture only
56 #define FLASH_BLOCKSIZE_PARAM (4096 * BUSWIDTH)
57 #define FLASH_NUMBLOCKS_16m_PARAM 8
58 #define FLASH_NUMBLOCKS_8m_PARAM 8
64 #define FLASH_BLOCKSIZE_MAIN (32768 * BUSWIDTH)
65 #define FLASH_NUMBLOCKS_16m_MAIN 31
66 #define FLASH_NUMBLOCKS_8m_MAIN 15
74 #define FLASH_OFFSET 0xe8000000
77 #define NUM_BLOB_BLOCKS FLASH_NUMBLOCKS_16m_PARAM
78 #define BLOB_START 0x00000000
79 #define BLOB_LEN (NUM_BLOB_BLOCKS * FLASH_BLOCKSIZE_PARAM)
82 #define NUM_KERNEL_BLOCKS 7
83 #define KERNEL_START (BLOB_START + BLOB_LEN)
84 #define KERNEL_LEN (NUM_KERNEL_BLOCKS * FLASH_BLOCKSIZE_MAIN)
87 #define NUM_INITRD_BLOCKS 24
88 #define INITRD_START (KERNEL_START + KERNEL_LEN)
89 #define INITRD_LEN (NUM_INITRD_BLOCKS * FLASH_BLOCKSIZE_MAIN)
94 #define READ_ARRAY 0x00FF00FF
95 #define READ_ID_CODES 0x00900090
96 #define ERASE_SETUP 0x00200020
97 #define ERASE_CONFIRM 0x00D000D0
98 #define PGM_SETUP 0x00400040
99 #define STATUS_READ 0x00700070
100 #define STATUS_CLEAR 0x00500050
101 #define STATUS_BUSY 0x00800080
102 #define STATUS_ERASE_ERR 0x00200020
103 #define STATUS_PGM_ERR 0x00100010
108 #define FLASH_MANUFACTURER 0x00890089
109 #define FLASH_DEVICE_8mbit_TOP 0x88f188f1
110 #define FLASH_DEVICE_8mbit_BOTTOM 0x88f288f2
111 #define FLASH_DEVICE_16mbit_TOP 0x88f388f3
112 #define FLASH_DEVICE_16mbit_BOTTOM 0x88f488f4
140 #define DATA_TO_FLASH(x) \
142 (((x) & 0x08009000) >> 11) + \
143 (((x) & 0x00002000) >> 10) + \
144 (((x) & 0x04004000) >> 8) + \
145 (((x) & 0x00000010) >> 4) + \
146 (((x) & 0x91000820) >> 3) + \
147 (((x) & 0x22080080) >> 2) + \
148 ((x) & 0x40000400) + \
149 (((x) & 0x00040040) << 1) + \
150 (((x) & 0x00110000) << 4) + \
151 (((x) & 0x00220100) << 5) + \
152 (((x) & 0x00800208) << 6) + \
153 (((x) & 0x00400004) << 9) + \
154 (((x) & 0x00000001) << 12) + \
155 (((x) & 0x00000002) << 13) \
159 #define FLASH_TO_DATA(x) \
161 (((x) & 0x00010012) << 11) + \
162 (((x) & 0x00000008) << 10) + \
163 (((x) & 0x00040040) << 8) + \
164 (((x) & 0x00000001) << 4) + \
165 (((x) & 0x12200104) << 3) + \
166 (((x) & 0x08820020) << 2) + \
167 ((x) & 0x40000400) + \
168 (((x) & 0x00080080) >> 1) + \
169 (((x) & 0x01100000) >> 4) + \
170 (((x) & 0x04402000) >> 5) + \
171 (((x) & 0x20008200) >> 6) + \
172 (((x) & 0x80000800) >> 9) + \
173 (((x) & 0x00001000) >> 12) + \
174 (((x) & 0x00004000) >> 13) \
216 #define ADDR_TO_FLASH_U2(x) \
218 (((x) & 0x00000f00) >> 4) + \
219 (((x) & 0x00042000) << 1) + \
220 (((x) & 0x0009c003) << 2) + \
221 (((x) & 0x00021080) << 3) + \
222 (((x) & 0x00000010) << 4) + \
223 (((x) & 0x00000040) << 5) + \
224 (((x) & 0x00000024) << 7) + \
225 (((x) & 0x00000008) << 10) \
229 #define FLASH_U2_TO_ADDR(x) \
231 (((x) << 4) & 0x00000f00) + \
232 (((x) >> 1) & 0x00042000) + \
233 (((x) >> 2) & 0x0009c003) + \
234 (((x) >> 3) & 0x00021080) + \
235 (((x) >> 4) & 0x00000010) + \
236 (((x) >> 5) & 0x00000040) + \
237 (((x) >> 7) & 0x00000024) + \
238 (((x) >> 10) & 0x00000008) \
242 #define ADDR_TO_FLASH_U3(x) \
244 (((x) & 0x00000080) >> 3) + \
245 (((x) & 0x00000040) >> 1) + \
246 (((x) & 0x00052020) << 1) + \
247 (((x) & 0x00084f03) << 2) + \
248 (((x) & 0x00029010) << 3) + \
249 (((x) & 0x00000008) << 5) + \
250 (((x) & 0x00000004) << 7) \
254 #define FLASH_U3_TO_ADDR(x) \
256 (((x) << 3) & 0x00000080) + \
257 (((x) << 1) & 0x00000040) + \
258 (((x) >> 1) & 0x00052020) + \
259 (((x) >> 2) & 0x00084f03) + \
260 (((x) >> 3) & 0x00029010) + \
261 (((x) >> 5) & 0x00000008) + \
262 (((x) >> 7) & 0x00000004) \
304 static int flash_probe (
void)
328 static inline int erase_block (
__u32 offset)
416 if (!erase_block (addr))
448 while (len && gap--) *buf++ = read8 (from++), len--;
454 *((
__u32 *) buf) = read32 (from);
463 while (len--) *buf++ = read8 (from++);
474 static inline int write_dword (
__u32 offset,
__u32 x)
494 while ((~status & STATUS_BUSY) != 0);
519 if (!len)
return (0);
529 while (gap--) tmp[i++] = 0xFF;
530 while (len && i <
BUSWIDTH) tmp[i++] = buf[n++], len--;
531 while (i <
BUSWIDTH) tmp[i++] = 0xFF;
533 if (!write_dword (aligned,*((
__u32 *) tmp)))
return (-
EIO);
543 if (!write_dword (to,*((
__u32 *) buf)))
return (-
EIO);
556 while (len--) tmp[i++] = buf[n++];
557 while (i <
BUSWIDTH) tmp[i++] = 0xFF;
559 if (!write_dword (to,*((
__u32 *) tmp)))
return (-
EIO);
574 .offset = 0x00000000,
601 .name =
"file system",
606 #define NUM_PARTITIONS ARRAY_SIZE(lart_partitions)
608 static int __init lart_flash_init (
void)
611 memset (&mtd,0,
sizeof (mtd));
630 mtd.
_read = flash_read;
637 "mtd.size = 0x%.8x (%uM)\n"
638 "mtd.erasesize = 0x%.8x (%uK)\n"
639 "mtd.numeraseregions = %d\n",
649 "mtd.eraseregions[%d].offset = 0x%.8x\n"
650 "mtd.eraseregions[%d].erasesize = 0x%.8x (%uK)\n"
651 "mtd.eraseregions[%d].numblocks = %d\n",
658 for (result = 0; result <
ARRAY_SIZE(lart_partitions); result++)
661 "lart_partitions[%d].name = %s\n"
662 "lart_partitions[%d].offset = 0x%.8x\n"
663 "lart_partitions[%d].size = 0x%.8x (%uK)\n",
664 result,lart_partitions[result].
name,
665 result,lart_partitions[result].offset,
666 result,lart_partitions[result].
size,lart_partitions[result].size / 1024);
675 static void __exit lart_flash_exit (
void)