Lines Matching +full:offset +full:- +full:x
3 * MTD driver for the 28F160F3 Flash Memory (non-CFI) on LART.
16 * - Order Number: 290644-005
17 * - January 2000
20 * - http://www.linux-mtd.infradead.org/
73 #define BUSWIDTH 4 /* don't change this - a lot of the code _will_ break if you change this */
74 #define FLASH_OFFSET 0xe8000000 /* see linux/arch/arm/mach-sa1100/lart.c */
120 * -------------------
139 /* Mangle data (x) */
140 #define DATA_TO_FLASH(x) \ argument
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) \
158 /* Unmangle data (x) */
159 #define FLASH_TO_DATA(x) \ argument
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) \
181 * -------------------
215 /* Mangle address (x) on chip U2 */
216 #define ADDR_TO_FLASH_U2(x) \ argument
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) \
228 /* Unmangle address (x) on chip U2 */
229 #define FLASH_U2_TO_ADDR(x) \ argument
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) \
241 /* Mangle address (x) on chip U3 */
242 #define ADDR_TO_FLASH_U3(x) \ argument
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) \
253 /* Unmangle address (x) on chip U3 */
254 #define FLASH_U3_TO_ADDR(x) \ argument
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) \
267 static __u8 read8 (__u32 offset) in read8() argument
269 volatile __u8 *data = (__u8 *) (FLASH_OFFSET + offset); in read8()
271 printk (KERN_DEBUG "%s(): 0x%.8x -> 0x%.2x\n", __func__, offset, *data); in read8()
276 static __u32 read32 (__u32 offset) in read32() argument
278 volatile __u32 *data = (__u32 *) (FLASH_OFFSET + offset); in read32()
280 printk (KERN_DEBUG "%s(): 0x%.8x -> 0x%.8x\n", __func__, offset, *data); in read32()
285 static void write32 (__u32 x,__u32 offset) in write32() argument
287 volatile __u32 *data = (__u32 *) (FLASH_OFFSET + offset); in write32()
288 *data = x; in write32()
290 printk (KERN_DEBUG "%s(): 0x%.8x <- 0x%.8x\n", __func__, offset, *data); in write32()
323 * Erase one block of flash memory at offset ``offset'' which is any
328 static inline int erase_block (__u32 offset) in erase_block() argument
333 printk (KERN_DEBUG "%s(): 0x%.8x\n", __func__, offset); in erase_block()
337 write32 (DATA_TO_FLASH (ERASE_SETUP),offset); in erase_block()
338 write32 (DATA_TO_FLASH (ERASE_CONFIRM),offset); in erase_block()
343 write32 (DATA_TO_FLASH (STATUS_READ),offset); in erase_block()
344 status = FLASH_TO_DATA (read32 (offset)); in erase_block()
349 write32 (DATA_TO_FLASH (READ_ARRAY),offset); in erase_block()
354 printk (KERN_WARNING "%s: erase error at address 0x%.8x.\n",module_name,offset); in erase_block()
367 printk (KERN_DEBUG "%s(addr = 0x%.8x, len = %d)\n", __func__, instr->addr, instr->len); in flash_erase()
379 for (i = 0; i < mtd->numeraseregions && instr->addr >= mtd->eraseregions[i].offset; i++) ; in flash_erase()
380 i--; in flash_erase()
388 if (i < 0 || (instr->addr & (mtd->eraseregions[i].erasesize - 1))) in flash_erase()
389 return -EINVAL; in flash_erase()
401 … for (; i < mtd->numeraseregions && instr->addr + instr->len >= mtd->eraseregions[i].offset; i++) ; in flash_erase()
402 i--; in flash_erase()
405 if (i < 0 || ((instr->addr + instr->len) & (mtd->eraseregions[i].erasesize - 1))) in flash_erase()
406 return -EINVAL; in flash_erase()
408 addr = instr->addr; in flash_erase()
409 len = instr->len; in flash_erase()
417 return (-EIO); in flash_erase()
419 addr += mtd->eraseregions[i].erasesize; in flash_erase()
420 len -= mtd->eraseregions[i].erasesize; in flash_erase()
422 …if (addr == mtd->eraseregions[i].offset + (mtd->eraseregions[i].erasesize * mtd->eraseregions[i].n… in flash_erase()
431 printk (KERN_DEBUG "%s(from = 0x%.8x, len = %d)\n", __func__, (__u32)from, len); in flash_read()
438 if (from & (BUSWIDTH - 1)) in flash_read()
440 int gap = BUSWIDTH - (from & (BUSWIDTH - 1)); in flash_read()
442 while (len && gap--) *buf++ = read8 (from++), len--; in flash_read()
445 /* now we read dwords until we reach a non-dword boundary */ in flash_read()
452 len -= BUSWIDTH; in flash_read()
456 if (len & (BUSWIDTH - 1)) in flash_read()
457 while (len--) *buf++ = read8 (from++); in flash_read()
463 * Write one dword ``x'' to flash memory at offset ``offset''. ``offset''
468 static inline int write_dword (__u32 offset,__u32 x) in write_dword() argument
473 printk (KERN_DEBUG "%s(): 0x%.8x <- 0x%.8x\n", __func__, offset, x); in write_dword()
477 write32 (DATA_TO_FLASH (PGM_SETUP),offset); in write_dword()
480 write32 (x,offset); in write_dword()
485 write32 (DATA_TO_FLASH (STATUS_READ),offset); in write_dword()
486 status = FLASH_TO_DATA (read32 (offset)); in write_dword()
491 write32 (DATA_TO_FLASH (READ_ARRAY),offset); in write_dword()
494 if ((status & STATUS_PGM_ERR) || read32 (offset) != x) in write_dword()
496 printk (KERN_WARNING "%s: write error at address 0x%.8x.\n",module_name,offset); in write_dword()
509 printk (KERN_DEBUG "%s(to = 0x%.8x, len = %d)\n", __func__, (__u32)to, len); in flash_write()
516 if (to & (BUSWIDTH - 1)) in flash_write()
518 __u32 aligned = to & ~(BUSWIDTH - 1); in flash_write()
519 int gap = to - aligned; in flash_write()
523 while (gap--) tmp[i++] = 0xFF; in flash_write()
524 while (len && i < BUSWIDTH) tmp[i++] = buf[n++], len--; in flash_write()
527 if (!write_dword (aligned,*((__u32 *) tmp))) return (-EIO); in flash_write()
534 /* now we write dwords until we reach a non-dword boundary */ in flash_write()
537 if (!write_dword (to,*((__u32 *) buf))) return (-EIO); in flash_write()
542 len -= BUSWIDTH; in flash_write()
546 if (len & (BUSWIDTH - 1)) in flash_write()
550 while (len--) tmp[i++] = buf[n++]; in flash_write()
553 if (!write_dword (to,*((__u32 *) tmp))) return (-EIO); in flash_write()
568 .offset = 0x00000000,
574 .offset = FLASH_BLOCKSIZE_PARAM * FLASH_NUMBLOCKS_16m_PARAM,
584 .offset = PART_BLOB_START,
590 .offset = PART_KERNEL_START, /* MTDPART_OFS_APPEND */
596 .offset = PART_INITRD_START, /* MTDPART_OFS_APPEND */
611 return (-ENXIO); in lart_flash_init()
631 "mtd.size = 0x%.8x (%uM)\n" in lart_flash_init()
632 "mtd.erasesize = 0x%.8x (%uK)\n" in lart_flash_init()
643 "mtd.eraseregions[%d].offset = 0x%.8x\n" in lart_flash_init()
644 "mtd.eraseregions[%d].erasesize = 0x%.8x (%uK)\n" in lart_flash_init()
646 result,mtd.eraseregions[result].offset, in lart_flash_init()
656 "lart_partitions[%d].offset = 0x%.8x\n" in lart_flash_init()
657 "lart_partitions[%d].size = 0x%.8x (%uK)\n", in lart_flash_init()
659 result,lart_partitions[result].offset, in lart_flash_init()