2 /* JEDEC Flash Interface.
3 * This is an older type of interface for self programming flash. It is
4 * commonly use in older AMD chips and is obsolete compared with CFI.
5 * It is called JEDEC because the JEDEC association distributes the ID codes
8 * See the AMD flash databook for information on how to operate the interface.
10 * This code does not support anything wider than 8 bit flash chips, I am
11 * not going to guess how to send commands to them, plus I expect they will
14 * $Id: jedec.c,v 1.14 2002/06/27 02:19:12 dwmw2 Exp $
17 #include <linux/mtd/jedec.h>
19 static struct mtd_info *jedec_probe(struct map_info *);
20 static int jedec_probe8(struct map_info *map,unsigned long base,
21 struct jedec_private *priv);
22 static int jedec_probe16(struct map_info *map,unsigned long base,
23 struct jedec_private *priv);
24 static int jedec_probe32(struct map_info *map,unsigned long base,
25 struct jedec_private *priv);
26 static void jedec_flash_chip_scan(struct jedec_private *priv,unsigned long start,
28 static int flash_erase(struct mtd_info *mtd, struct erase_info *instr);
29 static int flash_write(struct mtd_info *mtd, loff_t start, size_t len,
30 size_t *retlen, const u_char *buf);
32 static unsigned long my_bank_size;
34 /* Listing of parts and sizes. We need this table to learn the sector
35 size of the chip and the total length */
36 static const struct JEDECTable JEDEC_table[] =
37 {{0x013D,"AMD Am29F017D",2*1024*1024,64*1024,MTD_CAP_NORFLASH},
38 {0x01AD,"AMD Am29F016",2*1024*1024,64*1024,MTD_CAP_NORFLASH},
39 {0x01D5,"AMD Am29F080",1*1024*1024,64*1024,MTD_CAP_NORFLASH},
40 {0x01A4,"AMD Am29F040",512*1024,64*1024,MTD_CAP_NORFLASH},
41 {0x20E3,"AMD Am29W040B",512*1024,64*1024,MTD_CAP_NORFLASH},
42 {0xC2AD,"Macronix MX29F016",2*1024*1024,64*1024,MTD_CAP_NORFLASH},
45 static const struct JEDECTable *jedec_idtoinf(__u8 mfr,__u8 id);
46 static void jedec_sync(struct mtd_info *mtd) {};
47 static int jedec_read(struct mtd_info *mtd, loff_t from, size_t len,
48 size_t *retlen, u_char *buf);
49 static int jedec_read_banked(struct mtd_info *mtd, loff_t from, size_t len,
50 size_t *retlen, u_char *buf);
52 static struct mtd_info *jedec_probe(struct map_info *map);
56 static struct mtd_chip_driver jedec_chipdrv = {
62 /* Probe entry point */
64 static struct mtd_info *jedec_probe(struct map_info *map)
67 struct jedec_private *priv;
69 unsigned long SectorSize;
73 memset(&priv,0,sizeof(priv));
75 MTD = kmalloc(sizeof(struct mtd_info) + sizeof(struct jedec_private), GFP_KERNEL);
79 memset(MTD, 0, sizeof(struct mtd_info) + sizeof(struct jedec_private));
80 priv = (struct jedec_private *)&MTD[1];
82 my_bank_size = map->size;
84 if (map->size/my_bank_size > MAX_JEDEC_CHIPS)
86 printk("mtd: Increase MAX_JEDEC_CHIPS, too many banks.\n");
91 for (Base = 0; Base < map->size; Base += my_bank_size)
93 // Perhaps zero could designate all tests?
94 if (map->buswidth == 0)
97 if (map->buswidth == 1){
98 if (jedec_probe8(map,Base,priv) == 0) {
99 printk("did recognize jedec chip\n");
104 if (map->buswidth == 2)
105 jedec_probe16(map,Base,priv);
106 if (map->buswidth == 4)
107 jedec_probe32(map,Base,priv);
110 // Get the biggest sector size
112 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++)
114 // printk("priv->chips[%d].jedec is %x\n",I,priv->chips[I].jedec);
115 // printk("priv->chips[%d].sectorsize is %lx\n",I,priv->chips[I].sectorsize);
116 if (priv->chips[I].sectorsize > SectorSize)
117 SectorSize = priv->chips[I].sectorsize;
120 // Quickly ensure that the other sector sizes are factors of the largest
121 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++)
123 if ((SectorSize/priv->chips[I].sectorsize)*priv->chips[I].sectorsize != SectorSize)
125 printk("mtd: Failed. Device has incompatible mixed sector sizes\n");
131 /* Generate a part name that includes the number of different chips and
132 other configuration information */
134 strncpy(Part,map->name,sizeof(Part)-10);
135 Part[sizeof(Part)-11] = 0;
138 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++)
140 const struct JEDECTable *JEDEC;
142 if (priv->chips[I+1].jedec == priv->chips[I].jedec)
148 // Locate the chip in the jedec table
149 JEDEC = jedec_idtoinf(priv->chips[I].jedec >> 8,priv->chips[I].jedec);
152 printk("mtd: Internal Error, JEDEC not set\n");
162 sprintf(Part+strlen(Part),"%x*[%s]",count,JEDEC->name);
164 sprintf(Part+strlen(Part),"%s",JEDEC->name);
165 if (strlen(Part) > sizeof(Part)*2/3)
170 /* Determine if the chips are organized in a linear fashion, or if there
171 are empty banks. Note, the last bank does not count here, only the
172 first banks are important. Holes on non-bank boundaries can not exist
173 due to the way the detection algorithm works. */
174 if (priv->size < my_bank_size)
175 my_bank_size = priv->size;
177 //printk("priv->size is %x, my_bank_size is %x\n",priv->size,my_bank_size);
178 //printk("priv->bank_fill[0] is %x\n",priv->bank_fill[0]);
180 printk("priv->size is zero\n");
184 if (priv->size/my_bank_size) {
185 if (priv->size/my_bank_size == 1) {
186 priv->size = my_bank_size;
189 for (I = 0; I != priv->size/my_bank_size - 1; I++)
191 if (priv->bank_fill[I] != my_bank_size)
194 /* This even could be eliminated, but new de-optimized read/write
195 functions have to be written */
196 printk("priv->bank_fill[%d] is %lx, priv->bank_fill[0] is %lx\n",I,priv->bank_fill[I],priv->bank_fill[0]);
197 if (priv->bank_fill[I] != priv->bank_fill[0])
199 printk("mtd: Failed. Cannot handle unsymmetric banking\n");
206 if (priv->is_banked == 1)
207 strcat(Part,", banked");
209 // printk("Part: '%s'\n",Part);
211 memset(MTD,0,sizeof(*MTD));
212 // strncpy(MTD->name,Part,sizeof(MTD->name));
213 // MTD->name[sizeof(MTD->name)-1] = 0;
214 MTD->name = map->name;
215 MTD->type = MTD_NORFLASH;
216 MTD->flags = MTD_CAP_NORFLASH;
217 MTD->erasesize = SectorSize*(map->buswidth);
218 // printk("MTD->erasesize is %x\n",(unsigned int)MTD->erasesize);
219 MTD->size = priv->size;
220 // printk("MTD->size is %x\n",(unsigned int)MTD->size);
221 //MTD->module = THIS_MODULE; // ? Maybe this should be the low level module?
222 MTD->erase = flash_erase;
223 if (priv->is_banked == 1)
224 MTD->read = jedec_read_banked;
226 MTD->read = jedec_read;
227 MTD->write = flash_write;
228 MTD->sync = jedec_sync;
230 map->fldrv_priv = priv;
231 map->fldrv = &jedec_chipdrv;
236 /* Helper for the JEDEC function, JEDEC numbers all have odd parity */
237 static int checkparity(u_char C)
250 /* Take an array of JEDEC numbers that represent interleved flash chips
251 and process them. Check to make sure they are good JEDEC numbers, look
252 them up and then add them to the chip list */
253 static int handle_jedecs(struct map_info *map,__u8 *Mfg,__u8 *Id,unsigned Count,
254 unsigned long base,struct jedec_private *priv)
258 unsigned long SectorSize;
259 const struct JEDECTable *JEDEC;
261 // Test #2 JEDEC numbers exhibit odd parity
262 for (I = 0; I != Count; I++)
264 if (checkparity(Mfg[I]) == 0 || checkparity(Id[I]) == 0)
268 // Finally, just make sure all the chip sizes are the same
269 JEDEC = jedec_idtoinf(Mfg[0],Id[0]);
273 printk("mtd: Found JEDEC flash chip, but do not have a table entry for %x:%x\n",Mfg[0],Mfg[1]);
278 SectorSize = JEDEC->sectorsize;
279 for (I = 0; I != Count; I++)
281 JEDEC = jedec_idtoinf(Mfg[0],Id[0]);
284 printk("mtd: Found JEDEC flash chip, but do not have a table entry for %x:%x\n",Mfg[0],Mfg[1]);
288 if (Size != JEDEC->size || SectorSize != JEDEC->sectorsize)
290 printk("mtd: Failed. Interleved flash does not have matching characteristics\n");
296 for (I = 0; I != MAX_JEDEC_CHIPS; I++)
298 if (priv->chips[I].jedec == 0)
302 if (I + Count > MAX_JEDEC_CHIPS)
304 printk("mtd: Device has too many chips. Increase MAX_JEDEC_CHIPS\n");
308 // Add them to the table
309 for (J = 0; J != Count; J++)
313 JEDEC = jedec_idtoinf(Mfg[J],Id[J]);
314 priv->chips[I].jedec = (Mfg[J] << 8) | Id[J];
315 priv->chips[I].size = JEDEC->size;
316 priv->chips[I].sectorsize = JEDEC->sectorsize;
317 priv->chips[I].base = base + J;
318 priv->chips[I].datashift = J*8;
319 priv->chips[I].capabilities = JEDEC->capabilities;
320 priv->chips[I].offset = priv->size + J;
323 priv->chips[I].addrshift = 0;
324 for (Bank = Count; Bank != 1; Bank >>= 1, priv->chips[I].addrshift++);
326 // Determine how filled this bank is.
327 Bank = base & (~(my_bank_size-1));
328 if (priv->bank_fill[Bank/my_bank_size] < base +
329 (JEDEC->size << priv->chips[I].addrshift) - Bank)
330 priv->bank_fill[Bank/my_bank_size] = base + (JEDEC->size << priv->chips[I].addrshift) - Bank;
334 priv->size += priv->chips[I-1].size*Count;
336 return priv->chips[I-1].size;
339 /* Lookup the chip information from the JEDEC ID table. */
340 static const struct JEDECTable *jedec_idtoinf(__u8 mfr,__u8 id)
342 __u16 Id = (mfr << 8) | id;
344 for (I = 0; JEDEC_table[I].jedec != 0; I++)
345 if (JEDEC_table[I].jedec == Id)
346 return JEDEC_table + I;
350 // Look for flash using an 8 bit bus interface
351 static int jedec_probe8(struct map_info *map,unsigned long base,
352 struct jedec_private *priv)
354 #define flread(x) map->read8(map,base+x)
355 #define flwrite(v,x) map->write8(map,v,base+x)
357 const unsigned long AutoSel1 = 0xAA;
358 const unsigned long AutoSel2 = 0x55;
359 const unsigned long AutoSel3 = 0x90;
360 const unsigned long Reset = 0xF0;
367 // Wait for any write/erase operation to settle
368 OldVal = flread(base);
369 for (I = 0; OldVal != flread(base) && I < 10000; I++)
370 OldVal = flread(base);
373 flwrite(Reset,0x555);
376 flwrite(AutoSel1,0x555);
377 flwrite(AutoSel2,0x2AA);
378 flwrite(AutoSel3,0x555);
380 // Get the JEDEC numbers
383 // printk("Mfg is %x, Id is %x\n",Mfg[0],Id[0]);
385 Size = handle_jedecs(map,Mfg,Id,1,base,priv);
386 // printk("handle_jedecs Size is %x\n",(unsigned int)Size);
389 flwrite(Reset,0x555);
395 flwrite(Reset,0x555);
403 // Look for flash using a 16 bit bus interface (ie 2 8-bit chips)
404 static int jedec_probe16(struct map_info *map,unsigned long base,
405 struct jedec_private *priv)
410 // Look for flash using a 32 bit bus interface (ie 4 8-bit chips)
411 static int jedec_probe32(struct map_info *map,unsigned long base,
412 struct jedec_private *priv)
414 #define flread(x) map->read32(map,base+((x)<<2))
415 #define flwrite(v,x) map->write32(map,v,base+((x)<<2))
417 const unsigned long AutoSel1 = 0xAAAAAAAA;
418 const unsigned long AutoSel2 = 0x55555555;
419 const unsigned long AutoSel3 = 0x90909090;
420 const unsigned long Reset = 0xF0F0F0F0;
427 // Wait for any write/erase operation to settle
428 OldVal = flread(base);
429 for (I = 0; OldVal != flread(base) && I < 10000; I++)
430 OldVal = flread(base);
433 flwrite(Reset,0x555);
436 flwrite(AutoSel1,0x555);
437 flwrite(AutoSel2,0x2AA);
438 flwrite(AutoSel3,0x555);
440 // Test #1, JEDEC numbers are readable from 0x??00/0x??01
441 if (flread(0) != flread(0x100) ||
442 flread(1) != flread(0x101))
444 flwrite(Reset,0x555);
448 // Split up the JEDEC numbers
450 for (I = 0; I != 4; I++)
451 Mfg[I] = (OldVal >> (I*8));
453 for (I = 0; I != 4; I++)
454 Id[I] = (OldVal >> (I*8));
456 Size = handle_jedecs(map,Mfg,Id,4,base,priv);
459 flwrite(Reset,0x555);
463 /* Check if there is address wrap around within a single bank, if this
464 returns JEDEC numbers then we assume that it is wrap around. Notice
465 we call this routine with the JEDEC return still enabled, if two or
466 more flashes have a truncated address space the probe test will still
468 if (base + (Size<<2)+0x555 < map->size &&
469 base + (Size<<2)+0x555 < (base & (~(my_bank_size-1))) + my_bank_size)
471 if (flread(base+Size) != flread(base+Size + 0x100) ||
472 flread(base+Size + 1) != flread(base+Size + 0x101))
474 jedec_probe32(map,base+Size,priv);
479 flwrite(0xF0F0F0F0,0x555);
488 static int jedec_read(struct mtd_info *mtd, loff_t from, size_t len,
489 size_t *retlen, u_char *buf)
491 struct map_info *map = (struct map_info *)mtd->priv;
493 map->copy_from(map, buf, from, len);
498 /* Banked read. Take special care to jump past the holes in the bank
499 mapping. This version assumes symetry in the holes.. */
500 static int jedec_read_banked(struct mtd_info *mtd, loff_t from, size_t len,
501 size_t *retlen, u_char *buf)
503 struct map_info *map = (struct map_info *)mtd->priv;
504 struct jedec_private *priv = (struct jedec_private *)map->fldrv_priv;
509 // Determine what bank and offset into that bank the first byte is
510 unsigned long bank = from & (~(priv->bank_fill[0]-1));
511 unsigned long offset = from & (priv->bank_fill[0]-1);
512 unsigned long get = len;
513 if (priv->bank_fill[0] - offset < len)
514 get = priv->bank_fill[0] - offset;
516 bank /= priv->bank_fill[0];
517 map->copy_from(map,buf + *retlen,bank*my_bank_size + offset,get);
526 /* Pass the flags value that the flash return before it re-entered read
528 static void jedec_flash_failed(unsigned char code)
530 /* Bit 5 being high indicates that there was an internal device
531 failure, erasure time limits exceeded or something */
532 if ((code & (1 << 5)) != 0)
534 printk("mtd: Internal Flash failure\n");
537 printk("mtd: Programming didn't take\n");
540 /* This uses the erasure function described in the AMD Flash Handbook,
541 it will work for flashes with a fixed sector size only. Flashes with
542 a selection of sector sizes (ie the AMD Am29F800B) will need a different
543 routine. This routine tries to parallize erasing multiple chips/sectors
545 static int flash_erase(struct mtd_info *mtd, struct erase_info *instr)
547 // Does IO to the currently selected chip
548 #define flread(x) map->read8(map,chip->base+((x)<<chip->addrshift))
549 #define flwrite(v,x) map->write8(map,v,chip->base+((x)<<chip->addrshift))
551 unsigned long Time = 0;
552 unsigned long NoTime = 0;
553 unsigned long start = instr->addr, len = instr->len;
555 struct map_info *map = (struct map_info *)mtd->priv;
556 struct jedec_private *priv = (struct jedec_private *)map->fldrv_priv;
558 // Verify the arguments..
559 if (start + len > mtd->size ||
560 (start % mtd->erasesize) != 0 ||
561 (len % mtd->erasesize) != 0 ||
562 (len/mtd->erasesize) == 0)
565 jedec_flash_chip_scan(priv,start,len);
567 // Start the erase sequence on each chip
568 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++)
571 struct jedec_flash_chip *chip = priv->chips + I;
573 if (chip->length == 0)
576 if (chip->start + chip->length > chip->size)
582 flwrite(0xF0,chip->start + 0x555);
583 flwrite(0xAA,chip->start + 0x555);
584 flwrite(0x55,chip->start + 0x2AA);
585 flwrite(0x80,chip->start + 0x555);
586 flwrite(0xAA,chip->start + 0x555);
587 flwrite(0x55,chip->start + 0x2AA);
589 /* Once we start selecting the erase sectors the delay between each
590 command must not exceed 50us or it will immediately start erasing
591 and ignore the other sectors */
592 for (off = 0; off < len; off += chip->sectorsize)
594 // Check to make sure we didn't timeout
595 flwrite(0x30,chip->start + off);
598 if ((flread(chip->start + off) & (1 << 3)) != 0)
600 printk("mtd: Ack! We timed out the erase timer!\n");
606 /* We could split this into a timer routine and return early, performing
607 background erasure.. Maybe later if the need warrents */
609 /* Poll the flash for erasure completion, specs say this can take as long
610 as 480 seconds to do all the sectors (for a 2 meg flash).
611 Erasure time is dependant on chip age, temp and wear.. */
613 /* This being a generic routine assumes a 32 bit bus. It does read32s
614 and bundles interleved chips into the same grouping. This will work
615 for all bus widths */
618 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++)
620 struct jedec_flash_chip *chip = priv->chips + I;
621 unsigned long off = 0;
622 unsigned todo[4] = {0,0,0,0};
623 unsigned todo_left = 0;
626 if (chip->length == 0)
629 /* Find all chips in this data line, realistically this is all
630 or nothing up to the interleve count */
631 for (J = 0; priv->chips[J].jedec != 0 && J < MAX_JEDEC_CHIPS; J++)
633 if ((priv->chips[J].base & (~((1<<chip->addrshift)-1))) ==
634 (chip->base & (~((1<<chip->addrshift)-1))))
637 todo[priv->chips[J].base & ((1<<chip->addrshift)-1)] = 1;
641 /* printk("todo: %x %x %x %x\n",(short)todo[0],(short)todo[1],
642 (short)todo[2],(short)todo[3]);
647 unsigned long Count = 0;
649 /* During erase bit 7 is held low and bit 6 toggles, we watch this,
650 should it stop toggling or go high then the erase is completed,
651 or this is not really flash ;> */
652 switch (map->buswidth) {
654 Last[0] = map->read8(map,(chip->base >> chip->addrshift) + chip->start + off);
655 Last[1] = map->read8(map,(chip->base >> chip->addrshift) + chip->start + off);
656 Last[2] = map->read8(map,(chip->base >> chip->addrshift) + chip->start + off);
659 Last[0] = map->read16(map,(chip->base >> chip->addrshift) + chip->start + off);
660 Last[1] = map->read16(map,(chip->base >> chip->addrshift) + chip->start + off);
661 Last[2] = map->read16(map,(chip->base >> chip->addrshift) + chip->start + off);
664 Last[0] = map->read32(map,(chip->base >> chip->addrshift) + chip->start + off);
665 Last[1] = map->read32(map,(chip->base >> chip->addrshift) + chip->start + off);
666 Last[2] = map->read32(map,(chip->base >> chip->addrshift) + chip->start + off);
670 while (todo_left != 0)
672 for (J = 0; J != 4; J++)
674 __u8 Byte1 = (Last[(Count-1)%4] >> (J*8)) & 0xFF;
675 __u8 Byte2 = (Last[(Count-2)%4] >> (J*8)) & 0xFF;
676 __u8 Byte3 = (Last[(Count-3)%4] >> (J*8)) & 0xFF;
680 if ((Byte1 & (1 << 7)) == 0 && Byte1 != Byte2)
682 // printk("Check %x %x %x\n",(short)J,(short)Byte1,(short)Byte2);
688 jedec_flash_failed(Byte3);
697 Time += HZ/10 - schedule_timeout(HZ/10);*/
700 switch (map->buswidth) {
702 Last[Count % 4] = map->read8(map,(chip->base >> chip->addrshift) + chip->start + off);
705 Last[Count % 4] = map->read16(map,(chip->base >> chip->addrshift) + chip->start + off);
708 Last[Count % 4] = map->read32(map,(chip->base >> chip->addrshift) + chip->start + off);
713 /* // Count time, max of 15s per sector (according to AMD)
714 if (Time > 15*len/mtd->erasesize*HZ)
716 printk("mtd: Flash Erase Timed out\n");
721 // Skip to the next chip if we used chip erase
722 if (chip->length == chip->size)
725 off += chip->sectorsize;
727 if (off >= chip->length)
732 for (J = 0; priv->chips[J].jedec != 0 && J < MAX_JEDEC_CHIPS; J++)
734 if ((priv->chips[J].base & (~((1<<chip->addrshift)-1))) ==
735 (chip->base & (~((1<<chip->addrshift)-1))))
736 priv->chips[J].length = 0;
741 instr->state = MTD_ERASE_DONE;
743 instr->callback(instr);
750 /* This is the simple flash writing function. It writes to every byte, in
751 sequence. It takes care of how to properly address the flash if
752 the flash is interleved. It can only be used if all the chips in the
753 array are identical!*/
754 static int flash_write(struct mtd_info *mtd, loff_t start, size_t len,
755 size_t *retlen, const u_char *buf)
757 /* Does IO to the currently selected chip. It takes the bank addressing
758 base (which is divisable by the chip size) adds the necesary lower bits
759 of addrshift (interleve index) and then adds the control register index. */
760 #define flread(x) map->read8(map,base+(off&((1<<chip->addrshift)-1))+((x)<<chip->addrshift))
761 #define flwrite(v,x) map->write8(map,v,base+(off&((1<<chip->addrshift)-1))+((x)<<chip->addrshift))
763 struct map_info *map = (struct map_info *)mtd->priv;
764 struct jedec_private *priv = (struct jedec_private *)map->fldrv_priv;
767 size_t save_len = len;
769 if (start + len > mtd->size)
774 //printk("flash_write: start is %x, len is %x\n",start,(unsigned long)len);
777 struct jedec_flash_chip *chip = priv->chips;
779 unsigned long boffset;
781 // Compute the base of the flash.
782 off = ((unsigned long)start) % (chip->size << chip->addrshift);
785 // Perform banked addressing translation.
786 bank = base & (~(priv->bank_fill[0]-1));
787 boffset = base & (priv->bank_fill[0]-1);
788 bank = (bank/priv->bank_fill[0])*my_bank_size;
789 base = bank + boffset;
791 // printk("Flasing %X %X %X\n",base,chip->size,len);
792 // printk("off is %x, compare with %x\n",off,chip->size << chip->addrshift);
794 // Loop over this page
795 for (; off != (chip->size << chip->addrshift) && len != 0; start++, len--, off++,buf++)
797 unsigned char oldbyte = map->read8(map,base+off);
798 unsigned char Last[4];
799 unsigned long Count = 0;
801 if (oldbyte == *buf) {
802 // printk("oldbyte and *buf is %x,len is %x\n",oldbyte,len);
805 if (((~oldbyte) & *buf) != 0)
806 printk("mtd: warn: Trying to set a 0 to a 1\n");
812 map->write8(map,*buf,base + off);
813 Last[0] = map->read8(map,base + off);
814 Last[1] = map->read8(map,base + off);
815 Last[2] = map->read8(map,base + off);
817 /* Wait for the flash to finish the operation. We store the last 4
818 status bytes that have been retrieved so we can determine why
819 it failed. The toggle bits keep toggling when there is a
821 for (Count = 3; Last[(Count - 1) % 4] != Last[(Count - 2) % 4] &&
822 Count < 10000; Count++)
823 Last[Count % 4] = map->read8(map,base + off);
824 if (Last[(Count - 1) % 4] != *buf)
826 jedec_flash_failed(Last[(Count - 3) % 4]);
835 /* This is used to enhance the speed of the erase routine,
836 when things are being done to multiple chips it is possible to
837 parallize the operations, particularly full memory erases of multi
838 chip memories benifit */
839 static void jedec_flash_chip_scan(struct jedec_private *priv,unsigned long start,
845 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++)
846 priv->chips[I].start = priv->chips[I].length = 0;
848 // Intersect the region with each chip
849 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++)
851 struct jedec_flash_chip *chip = priv->chips + I;
852 unsigned long ByteStart;
853 unsigned long ChipEndByte = chip->offset + (chip->size << chip->addrshift);
855 // End is before this chip or the start is after it
856 if (start+len < chip->offset ||
857 ChipEndByte - (1 << chip->addrshift) < start)
860 if (start < chip->offset)
862 ByteStart = chip->offset;
867 chip->start = (start - chip->offset + (1 << chip->addrshift)-1) >> chip->addrshift;
871 if (start + len >= ChipEndByte)
872 chip->length = (ChipEndByte - ByteStart) >> chip->addrshift;
874 chip->length = (start + len - ByteStart + (1 << chip->addrshift)-1) >> chip->addrshift;
878 int __init jedec_init(void)
880 register_mtd_chip_driver(&jedec_chipdrv);
884 static void __exit jedec_exit(void)
886 unregister_mtd_chip_driver(&jedec_chipdrv);
889 module_init(jedec_init);
890 module_exit(jedec_exit);
892 MODULE_LICENSE("GPL");
893 MODULE_AUTHOR("Jason Gunthorpe <jgg@deltatee.com> et al.");
894 MODULE_DESCRIPTION("Old MTD chip driver for JEDEC-compliant flash chips");