Lines Matching +full:offset +full:- +full:x

1 // SPDX-License-Identifier: GPL-2.0-only
4 * MTD driver for the 28F160F3 Flash Memory (non-CFI) on LART.
13 * - Order Number: 290644-005
14 * - January 2000
17 * - http://www.linux-mtd.infradead.org/
70 #define BUSWIDTH 4 /* don't change this - a lot of the code _will_ break if you change this */
71 #define FLASH_OFFSET 0xe8000000 /* see linux/arch/arm/mach-sa1100/lart.c */
117 * -------------------
136 /* Mangle data (x) */
137 #define DATA_TO_FLASH(x) \ argument
139 (((x) & 0x08009000) >> 11) + \
140 (((x) & 0x00002000) >> 10) + \
141 (((x) & 0x04004000) >> 8) + \
142 (((x) & 0x00000010) >> 4) + \
143 (((x) & 0x91000820) >> 3) + \
144 (((x) & 0x22080080) >> 2) + \
145 ((x) & 0x40000400) + \
146 (((x) & 0x00040040) << 1) + \
147 (((x) & 0x00110000) << 4) + \
148 (((x) & 0x00220100) << 5) + \
149 (((x) & 0x00800208) << 6) + \
150 (((x) & 0x00400004) << 9) + \
151 (((x) & 0x00000001) << 12) + \
152 (((x) & 0x00000002) << 13) \
155 /* Unmangle data (x) */
156 #define FLASH_TO_DATA(x) \ argument
158 (((x) & 0x00010012) << 11) + \
159 (((x) & 0x00000008) << 10) + \
160 (((x) & 0x00040040) << 8) + \
161 (((x) & 0x00000001) << 4) + \
162 (((x) & 0x12200104) << 3) + \
163 (((x) & 0x08820020) << 2) + \
164 ((x) & 0x40000400) + \
165 (((x) & 0x00080080) >> 1) + \
166 (((x) & 0x01100000) >> 4) + \
167 (((x) & 0x04402000) >> 5) + \
168 (((x) & 0x20008200) >> 6) + \
169 (((x) & 0x80000800) >> 9) + \
170 (((x) & 0x00001000) >> 12) + \
171 (((x) & 0x00004000) >> 13) \
178 * -------------------
212 /* Mangle address (x) on chip U2 */
213 #define ADDR_TO_FLASH_U2(x) \ argument
215 (((x) & 0x00000f00) >> 4) + \
216 (((x) & 0x00042000) << 1) + \
217 (((x) & 0x0009c003) << 2) + \
218 (((x) & 0x00021080) << 3) + \
219 (((x) & 0x00000010) << 4) + \
220 (((x) & 0x00000040) << 5) + \
221 (((x) & 0x00000024) << 7) + \
222 (((x) & 0x00000008) << 10) \
225 /* Unmangle address (x) on chip U2 */
226 #define FLASH_U2_TO_ADDR(x) \ argument
228 (((x) << 4) & 0x00000f00) + \
229 (((x) >> 1) & 0x00042000) + \
230 (((x) >> 2) & 0x0009c003) + \
231 (((x) >> 3) & 0x00021080) + \
232 (((x) >> 4) & 0x00000010) + \
233 (((x) >> 5) & 0x00000040) + \
234 (((x) >> 7) & 0x00000024) + \
235 (((x) >> 10) & 0x00000008) \
238 /* Mangle address (x) on chip U3 */
239 #define ADDR_TO_FLASH_U3(x) \ argument
241 (((x) & 0x00000080) >> 3) + \
242 (((x) & 0x00000040) >> 1) + \
243 (((x) & 0x00052020) << 1) + \
244 (((x) & 0x00084f03) << 2) + \
245 (((x) & 0x00029010) << 3) + \
246 (((x) & 0x00000008) << 5) + \
247 (((x) & 0x00000004) << 7) \
250 /* Unmangle address (x) on chip U3 */
251 #define FLASH_U3_TO_ADDR(x) \ argument
253 (((x) << 3) & 0x00000080) + \
254 (((x) << 1) & 0x00000040) + \
255 (((x) >> 1) & 0x00052020) + \
256 (((x) >> 2) & 0x00084f03) + \
257 (((x) >> 3) & 0x00029010) + \
258 (((x) >> 5) & 0x00000008) + \
259 (((x) >> 7) & 0x00000004) \
264 static __u8 read8 (__u32 offset) in read8() argument
266 volatile __u8 *data = (__u8 *) (FLASH_OFFSET + offset); in read8()
268 printk (KERN_DEBUG "%s(): 0x%.8x -> 0x%.2x\n", __func__, offset, *data); in read8()
273 static __u32 read32 (__u32 offset) in read32() argument
275 volatile __u32 *data = (__u32 *) (FLASH_OFFSET + offset); in read32()
277 printk (KERN_DEBUG "%s(): 0x%.8x -> 0x%.8x\n", __func__, offset, *data); in read32()
282 static void write32 (__u32 x,__u32 offset) in write32() argument
284 volatile __u32 *data = (__u32 *) (FLASH_OFFSET + offset); in write32()
285 *data = x; in write32()
287 printk (KERN_DEBUG "%s(): 0x%.8x <- 0x%.8x\n", __func__, offset, *data); in write32()
320 * Erase one block of flash memory at offset ``offset'' which is any
325 static inline int erase_block (__u32 offset) in erase_block() argument
330 printk (KERN_DEBUG "%s(): 0x%.8x\n", __func__, offset); in erase_block()
334 write32 (DATA_TO_FLASH (ERASE_SETUP),offset); in erase_block()
335 write32 (DATA_TO_FLASH (ERASE_CONFIRM),offset); in erase_block()
340 write32 (DATA_TO_FLASH (STATUS_READ),offset); in erase_block()
341 status = FLASH_TO_DATA (read32 (offset)); in erase_block()
346 write32 (DATA_TO_FLASH (READ_ARRAY),offset); in erase_block()
351 printk (KERN_WARNING "%s: erase error at address 0x%.8x.\n",module_name,offset); in erase_block()
364 printk (KERN_DEBUG "%s(addr = 0x%.8x, len = %d)\n", __func__, instr->addr, instr->len); in flash_erase()
376 for (i = 0; i < mtd->numeraseregions && instr->addr >= mtd->eraseregions[i].offset; i++) ; in flash_erase()
377 i--; in flash_erase()
385 if (i < 0 || (instr->addr & (mtd->eraseregions[i].erasesize - 1))) in flash_erase()
386 return -EINVAL; in flash_erase()
398 … for (; i < mtd->numeraseregions && instr->addr + instr->len >= mtd->eraseregions[i].offset; i++) ; in flash_erase()
399 i--; in flash_erase()
402 if (i < 0 || ((instr->addr + instr->len) & (mtd->eraseregions[i].erasesize - 1))) in flash_erase()
403 return -EINVAL; in flash_erase()
405 addr = instr->addr; in flash_erase()
406 len = instr->len; in flash_erase()
414 return (-EIO); in flash_erase()
416 addr += mtd->eraseregions[i].erasesize; in flash_erase()
417 len -= mtd->eraseregions[i].erasesize; in flash_erase()
419 …if (addr == mtd->eraseregions[i].offset + (mtd->eraseregions[i].erasesize * mtd->eraseregions[i].n… in flash_erase()
428 printk (KERN_DEBUG "%s(from = 0x%.8x, len = %d)\n", __func__, (__u32)from, len); in flash_read()
435 if (from & (BUSWIDTH - 1)) in flash_read()
437 int gap = BUSWIDTH - (from & (BUSWIDTH - 1)); in flash_read()
439 while (len && gap--) { in flash_read()
441 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()
526 len--; in flash_write()
530 if (!write_dword (aligned,*((__u32 *) tmp))) return (-EIO); in flash_write()
537 /* now we write dwords until we reach a non-dword boundary */ in flash_write()
540 if (!write_dword (to,*((__u32 *) buf))) return (-EIO); in flash_write()
545 len -= BUSWIDTH; in flash_write()
549 if (len & (BUSWIDTH - 1)) in flash_write()
553 while (len--) tmp[i++] = buf[n++]; in flash_write()
556 if (!write_dword (to,*((__u32 *) tmp))) return (-EIO); in flash_write()
571 .offset = 0x00000000,
577 .offset = FLASH_BLOCKSIZE_PARAM * FLASH_NUMBLOCKS_16m_PARAM,
587 .offset = PART_BLOB_START,
593 .offset = PART_KERNEL_START, /* MTDPART_OFS_APPEND */
599 .offset = PART_INITRD_START, /* MTDPART_OFS_APPEND */
614 return (-ENXIO); in lart_flash_init()
634 "mtd.size = 0x%.8x (%uM)\n" in lart_flash_init()
635 "mtd.erasesize = 0x%.8x (%uK)\n" in lart_flash_init()
646 "mtd.eraseregions[%d].offset = 0x%.8x\n" in lart_flash_init()
647 "mtd.eraseregions[%d].erasesize = 0x%.8x (%uK)\n" in lart_flash_init()
649 result,mtd.eraseregions[result].offset, in lart_flash_init()
659 "lart_partitions[%d].offset = 0x%.8x\n" in lart_flash_init()
660 "lart_partitions[%d].size = 0x%.8x (%uK)\n", in lart_flash_init()
662 result,lart_partitions[result].offset, in lart_flash_init()