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.1.1.1 2005/04/11 02:50:25 jack 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 {0x014F,"AMD Am29LV040B",512*1024,64*1024,MTD_CAP_NORFLASH},
42 {0x20E3,"AMD Am29W040B",512*1024,64*1024,MTD_CAP_NORFLASH},
43 {0xC2AD,"Macronix MX29F016",2*1024*1024,64*1024,MTD_CAP_NORFLASH},
46 static const struct JEDECTable *jedec_idtoinf(__u8 mfr,__u8 id);
47 static void jedec_sync(struct mtd_info *mtd) {};
48 static int jedec_read(struct mtd_info *mtd, loff_t from, size_t len,
49 size_t *retlen, u_char *buf);
50 static int jedec_read_banked(struct mtd_info *mtd, loff_t from, size_t len,
51 size_t *retlen, u_char *buf);
53 static struct mtd_info *jedec_probe(struct map_info *map);
57 static struct mtd_chip_driver jedec_chipdrv = {
63 /* Probe entry point */
65 static struct mtd_info *jedec_probe(struct map_info *map)
68 struct jedec_private *priv;
70 unsigned long SectorSize;
74 memset(&priv,0,sizeof(priv));
76 MTD = kmalloc(sizeof(struct mtd_info) + sizeof(struct jedec_private), GFP_KERNEL);
80 memset(MTD, 0, sizeof(struct mtd_info) + sizeof(struct jedec_private));
81 priv = (struct jedec_private *)&MTD[1];
83 my_bank_size = map->size;
85 if (map->size/my_bank_size > MAX_JEDEC_CHIPS)
87 printk("mtd: Increase MAX_JEDEC_CHIPS, too many banks.\n");
92 for (Base = 0; Base < map->size; Base += my_bank_size)
94 // Perhaps zero could designate all tests?
95 if (map->buswidth == 0)
98 if (map->buswidth == 1){
99 if (jedec_probe8(map,Base,priv) == 0) {
100 printk("did recognize jedec chip\n");
105 if (map->buswidth == 2)
106 jedec_probe16(map,Base,priv);
107 if (map->buswidth == 4)
108 jedec_probe32(map,Base,priv);
111 // Get the biggest sector size
113 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++)
115 // printk("priv->chips[%d].jedec is %x\n",I,priv->chips[I].jedec);
116 // printk("priv->chips[%d].sectorsize is %lx\n",I,priv->chips[I].sectorsize);
117 if (priv->chips[I].sectorsize > SectorSize)
118 SectorSize = priv->chips[I].sectorsize;
121 // Quickly ensure that the other sector sizes are factors of the largest
122 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++)
124 if ((SectorSize/priv->chips[I].sectorsize)*priv->chips[I].sectorsize != SectorSize)
126 printk("mtd: Failed. Device has incompatible mixed sector sizes\n");
132 /* Generate a part name that includes the number of different chips and
133 other configuration information */
135 strncpy(Part,map->name,sizeof(Part)-10);
136 Part[sizeof(Part)-11] = 0;
139 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++)
141 const struct JEDECTable *JEDEC;
143 if (priv->chips[I+1].jedec == priv->chips[I].jedec)
149 // Locate the chip in the jedec table
150 JEDEC = jedec_idtoinf(priv->chips[I].jedec >> 8,priv->chips[I].jedec);
153 printk("mtd: Internal Error, JEDEC not set\n");
163 sprintf(Part+strlen(Part),"%x*[%s]",count,JEDEC->name);
165 sprintf(Part+strlen(Part),"%s",JEDEC->name);
166 if (strlen(Part) > sizeof(Part)*2/3)
171 /* Determine if the chips are organized in a linear fashion, or if there
172 are empty banks. Note, the last bank does not count here, only the
173 first banks are important. Holes on non-bank boundaries can not exist
174 due to the way the detection algorithm works. */
175 if (priv->size < my_bank_size)
176 my_bank_size = priv->size;
178 //printk("priv->size is %x, my_bank_size is %x\n",priv->size,my_bank_size);
179 //printk("priv->bank_fill[0] is %x\n",priv->bank_fill[0]);
181 printk("priv->size is zero\n");
185 if (priv->size/my_bank_size) {
186 if (priv->size/my_bank_size == 1) {
187 priv->size = my_bank_size;
190 for (I = 0; I != priv->size/my_bank_size - 1; I++)
192 if (priv->bank_fill[I] != my_bank_size)
195 /* This even could be eliminated, but new de-optimized read/write
196 functions have to be written */
197 printk("priv->bank_fill[%d] is %lx, priv->bank_fill[0] is %lx\n",I,priv->bank_fill[I],priv->bank_fill[0]);
198 if (priv->bank_fill[I] != priv->bank_fill[0])
200 printk("mtd: Failed. Cannot handle unsymmetric banking\n");
207 if (priv->is_banked == 1)
208 strcat(Part,", banked");
210 // printk("Part: '%s'\n",Part);
212 memset(MTD,0,sizeof(*MTD));
213 // strncpy(MTD->name,Part,sizeof(MTD->name));
214 // MTD->name[sizeof(MTD->name)-1] = 0;
215 MTD->name = map->name;
216 MTD->type = MTD_NORFLASH;
217 MTD->flags = MTD_CAP_NORFLASH;
218 MTD->erasesize = SectorSize*(map->buswidth);
219 // printk("MTD->erasesize is %x\n",(unsigned int)MTD->erasesize);
220 MTD->size = priv->size;
221 // printk("MTD->size is %x\n",(unsigned int)MTD->size);
222 //MTD->module = THIS_MODULE; // ? Maybe this should be the low level module?
223 MTD->erase = flash_erase;
224 if (priv->is_banked == 1)
225 MTD->read = jedec_read_banked;
227 MTD->read = jedec_read;
228 MTD->write = flash_write;
229 MTD->sync = jedec_sync;
231 map->fldrv_priv = priv;
232 map->fldrv = &jedec_chipdrv;
237 /* Helper for the JEDEC function, JEDEC numbers all have odd parity */
238 static int checkparity(u_char C)
251 /* Take an array of JEDEC numbers that represent interleved flash chips
252 and process them. Check to make sure they are good JEDEC numbers, look
253 them up and then add them to the chip list */
254 static int handle_jedecs(struct map_info *map,__u8 *Mfg,__u8 *Id,unsigned Count,
255 unsigned long base,struct jedec_private *priv)
259 unsigned long SectorSize;
260 const struct JEDECTable *JEDEC;
262 // Test #2 JEDEC numbers exhibit odd parity
263 for (I = 0; I != Count; I++)
265 if (checkparity(Mfg[I]) == 0 || checkparity(Id[I]) == 0)
269 // Finally, just make sure all the chip sizes are the same
270 JEDEC = jedec_idtoinf(Mfg[0],Id[0]);
274 printk("mtd: Found JEDEC flash chip, but do not have a table entry for %x:%x\n",Mfg[0],Mfg[1]);
279 SectorSize = JEDEC->sectorsize;
280 for (I = 0; I != Count; I++)
282 JEDEC = jedec_idtoinf(Mfg[0],Id[0]);
285 printk("mtd: Found JEDEC flash chip, but do not have a table entry for %x:%x\n",Mfg[0],Mfg[1]);
289 if (Size != JEDEC->size || SectorSize != JEDEC->sectorsize)
291 printk("mtd: Failed. Interleved flash does not have matching characteristics\n");
297 for (I = 0; I != MAX_JEDEC_CHIPS; I++)
299 if (priv->chips[I].jedec == 0)
303 if (I + Count > MAX_JEDEC_CHIPS)
305 printk("mtd: Device has too many chips. Increase MAX_JEDEC_CHIPS\n");
309 // Add them to the table
310 for (J = 0; J != Count; J++)
314 JEDEC = jedec_idtoinf(Mfg[J],Id[J]);
315 priv->chips[I].jedec = (Mfg[J] << 8) | Id[J];
316 priv->chips[I].size = JEDEC->size;
317 priv->chips[I].sectorsize = JEDEC->sectorsize;
318 priv->chips[I].base = base + J;
319 priv->chips[I].datashift = J*8;
320 priv->chips[I].capabilities = JEDEC->capabilities;
321 priv->chips[I].offset = priv->size + J;
324 priv->chips[I].addrshift = 0;
325 for (Bank = Count; Bank != 1; Bank >>= 1, priv->chips[I].addrshift++);
327 // Determine how filled this bank is.
328 Bank = base & (~(my_bank_size-1));
329 if (priv->bank_fill[Bank/my_bank_size] < base +
330 (JEDEC->size << priv->chips[I].addrshift) - Bank)
331 priv->bank_fill[Bank/my_bank_size] = base + (JEDEC->size << priv->chips[I].addrshift) - Bank;
335 priv->size += priv->chips[I-1].size*Count;
337 return priv->chips[I-1].size;
340 /* Lookup the chip information from the JEDEC ID table. */
341 static const struct JEDECTable *jedec_idtoinf(__u8 mfr,__u8 id)
343 __u16 Id = (mfr << 8) | id;
345 for (I = 0; JEDEC_table[I].jedec != 0; I++)
346 if (JEDEC_table[I].jedec == Id)
347 return JEDEC_table + I;
351 // Look for flash using an 8 bit bus interface
352 static int jedec_probe8(struct map_info *map,unsigned long base,
353 struct jedec_private *priv)
355 #define flread(x) map->read8(map,base+x)
356 #define flwrite(v,x) map->write8(map,v,base+x)
358 const unsigned long AutoSel1 = 0xAA;
359 const unsigned long AutoSel2 = 0x55;
360 const unsigned long AutoSel3 = 0x90;
361 const unsigned long Reset = 0xF0;
368 // Wait for any write/erase operation to settle
369 OldVal = flread(base);
370 for (I = 0; OldVal != flread(base) && I < 10000; I++)
371 OldVal = flread(base);
374 flwrite(Reset,0x555);
377 flwrite(AutoSel1,0x555);
378 flwrite(AutoSel2,0x2AA);
379 flwrite(AutoSel3,0x555);
381 // Get the JEDEC numbers
384 // printk("Mfg is %x, Id is %x\n",Mfg[0],Id[0]);
386 Size = handle_jedecs(map,Mfg,Id,1,base,priv);
387 // printk("handle_jedecs Size is %x\n",(unsigned int)Size);
390 flwrite(Reset,0x555);
396 flwrite(Reset,0x555);
404 // Look for flash using a 16 bit bus interface (ie 2 8-bit chips)
405 static int jedec_probe16(struct map_info *map,unsigned long base,
406 struct jedec_private *priv)
411 // Look for flash using a 32 bit bus interface (ie 4 8-bit chips)
412 static int jedec_probe32(struct map_info *map,unsigned long base,
413 struct jedec_private *priv)
415 #define flread(x) map->read32(map,base+((x)<<2))
416 #define flwrite(v,x) map->write32(map,v,base+((x)<<2))
418 const unsigned long AutoSel1 = 0xAAAAAAAA;
419 const unsigned long AutoSel2 = 0x55555555;
420 const unsigned long AutoSel3 = 0x90909090;
421 const unsigned long Reset = 0xF0F0F0F0;
428 // Wait for any write/erase operation to settle
429 OldVal = flread(base);
430 for (I = 0; OldVal != flread(base) && I < 10000; I++)
431 OldVal = flread(base);
434 flwrite(Reset,0x555);
437 flwrite(AutoSel1,0x555);
438 flwrite(AutoSel2,0x2AA);
439 flwrite(AutoSel3,0x555);
441 // Test #1, JEDEC numbers are readable from 0x??00/0x??01
442 if (flread(0) != flread(0x100) ||
443 flread(1) != flread(0x101))
445 flwrite(Reset,0x555);
449 // Split up the JEDEC numbers
451 for (I = 0; I != 4; I++)
452 Mfg[I] = (OldVal >> (I*8));
454 for (I = 0; I != 4; I++)
455 Id[I] = (OldVal >> (I*8));
457 Size = handle_jedecs(map,Mfg,Id,4,base,priv);
460 flwrite(Reset,0x555);
464 /* Check if there is address wrap around within a single bank, if this
465 returns JEDEC numbers then we assume that it is wrap around. Notice
466 we call this routine with the JEDEC return still enabled, if two or
467 more flashes have a truncated address space the probe test will still
469 if (base + (Size<<2)+0x555 < map->size &&
470 base + (Size<<2)+0x555 < (base & (~(my_bank_size-1))) + my_bank_size)
472 if (flread(base+Size) != flread(base+Size + 0x100) ||
473 flread(base+Size + 1) != flread(base+Size + 0x101))
475 jedec_probe32(map,base+Size,priv);
480 flwrite(0xF0F0F0F0,0x555);
489 static int jedec_read(struct mtd_info *mtd, loff_t from, size_t len,
490 size_t *retlen, u_char *buf)
492 struct map_info *map = (struct map_info *)mtd->priv;
494 map->copy_from(map, buf, from, len);
499 /* Banked read. Take special care to jump past the holes in the bank
500 mapping. This version assumes symetry in the holes.. */
501 static int jedec_read_banked(struct mtd_info *mtd, loff_t from, size_t len,
502 size_t *retlen, u_char *buf)
504 struct map_info *map = (struct map_info *)mtd->priv;
505 struct jedec_private *priv = (struct jedec_private *)map->fldrv_priv;
510 // Determine what bank and offset into that bank the first byte is
511 unsigned long bank = from & (~(priv->bank_fill[0]-1));
512 unsigned long offset = from & (priv->bank_fill[0]-1);
513 unsigned long get = len;
514 if (priv->bank_fill[0] - offset < len)
515 get = priv->bank_fill[0] - offset;
517 bank /= priv->bank_fill[0];
518 map->copy_from(map,buf + *retlen,bank*my_bank_size + offset,get);
527 /* Pass the flags value that the flash return before it re-entered read
529 static void jedec_flash_failed(unsigned char code)
531 /* Bit 5 being high indicates that there was an internal device
532 failure, erasure time limits exceeded or something */
533 if ((code & (1 << 5)) != 0)
535 printk("mtd: Internal Flash failure\n");
538 printk("mtd: Programming didn't take\n");
541 /* This uses the erasure function described in the AMD Flash Handbook,
542 it will work for flashes with a fixed sector size only. Flashes with
543 a selection of sector sizes (ie the AMD Am29F800B) will need a different
544 routine. This routine tries to parallize erasing multiple chips/sectors
546 static int flash_erase(struct mtd_info *mtd, struct erase_info *instr)
548 // Does IO to the currently selected chip
549 #define flread(x) map->read8(map,chip->base+((x)<<chip->addrshift))
550 #define flwrite(v,x) map->write8(map,v,chip->base+((x)<<chip->addrshift))
552 unsigned long Time = 0;
553 unsigned long NoTime = 0;
554 unsigned long start = instr->addr, len = instr->len;
556 struct map_info *map = (struct map_info *)mtd->priv;
557 struct jedec_private *priv = (struct jedec_private *)map->fldrv_priv;
559 // Verify the arguments..
560 if (start + len > mtd->size ||
561 (start % mtd->erasesize) != 0 ||
562 (len % mtd->erasesize) != 0 ||
563 (len/mtd->erasesize) == 0)
566 jedec_flash_chip_scan(priv,start,len);
568 // Start the erase sequence on each chip
569 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++)
572 struct jedec_flash_chip *chip = priv->chips + I;
574 if (chip->length == 0)
577 if (chip->start + chip->length > chip->size)
583 flwrite(0xF0,chip->start + 0x555);
584 flwrite(0xAA,chip->start + 0x555);
585 flwrite(0x55,chip->start + 0x2AA);
586 flwrite(0x80,chip->start + 0x555);
587 flwrite(0xAA,chip->start + 0x555);
588 flwrite(0x55,chip->start + 0x2AA);
590 /* Once we start selecting the erase sectors the delay between each
591 command must not exceed 50us or it will immediately start erasing
592 and ignore the other sectors */
593 for (off = 0; off < len; off += chip->sectorsize)
595 // Check to make sure we didn't timeout
596 flwrite(0x30,chip->start + off);
599 if ((flread(chip->start + off) & (1 << 3)) != 0)
601 printk("mtd: Ack! We timed out the erase timer!\n");
607 /* We could split this into a timer routine and return early, performing
608 background erasure.. Maybe later if the need warrents */
610 /* Poll the flash for erasure completion, specs say this can take as long
611 as 480 seconds to do all the sectors (for a 2 meg flash).
612 Erasure time is dependant on chip age, temp and wear.. */
614 /* This being a generic routine assumes a 32 bit bus. It does read32s
615 and bundles interleved chips into the same grouping. This will work
616 for all bus widths */
619 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++)
621 struct jedec_flash_chip *chip = priv->chips + I;
622 unsigned long off = 0;
623 unsigned todo[4] = {0,0,0,0};
624 unsigned todo_left = 0;
627 if (chip->length == 0)
630 /* Find all chips in this data line, realistically this is all
631 or nothing up to the interleve count */
632 for (J = 0; priv->chips[J].jedec != 0 && J < MAX_JEDEC_CHIPS; J++)
634 if ((priv->chips[J].base & (~((1<<chip->addrshift)-1))) ==
635 (chip->base & (~((1<<chip->addrshift)-1))))
638 todo[priv->chips[J].base & ((1<<chip->addrshift)-1)] = 1;
642 /* printk("todo: %x %x %x %x\n",(short)todo[0],(short)todo[1],
643 (short)todo[2],(short)todo[3]);
648 unsigned long Count = 0;
650 /* During erase bit 7 is held low and bit 6 toggles, we watch this,
651 should it stop toggling or go high then the erase is completed,
652 or this is not really flash ;> */
653 switch (map->buswidth) {
655 Last[0] = map->read8(map,(chip->base >> chip->addrshift) + chip->start + off);
656 Last[1] = map->read8(map,(chip->base >> chip->addrshift) + chip->start + off);
657 Last[2] = map->read8(map,(chip->base >> chip->addrshift) + chip->start + off);
660 Last[0] = map->read16(map,(chip->base >> chip->addrshift) + chip->start + off);
661 Last[1] = map->read16(map,(chip->base >> chip->addrshift) + chip->start + off);
662 Last[2] = map->read16(map,(chip->base >> chip->addrshift) + chip->start + off);
665 Last[0] = map->read32(map,(chip->base >> chip->addrshift) + chip->start + off);
666 Last[1] = map->read32(map,(chip->base >> chip->addrshift) + chip->start + off);
667 Last[2] = map->read32(map,(chip->base >> chip->addrshift) + chip->start + off);
671 while (todo_left != 0)
673 for (J = 0; J != 4; J++)
675 __u8 Byte1 = (Last[(Count-1)%4] >> (J*8)) & 0xFF;
676 __u8 Byte2 = (Last[(Count-2)%4] >> (J*8)) & 0xFF;
677 __u8 Byte3 = (Last[(Count-3)%4] >> (J*8)) & 0xFF;
681 if ((Byte1 & (1 << 7)) == 0 && Byte1 != Byte2)
683 // printk("Check %x %x %x\n",(short)J,(short)Byte1,(short)Byte2);
689 jedec_flash_failed(Byte3);
698 Time += HZ/10 - schedule_timeout(HZ/10);*/
701 switch (map->buswidth) {
703 Last[Count % 4] = map->read8(map,(chip->base >> chip->addrshift) + chip->start + off);
706 Last[Count % 4] = map->read16(map,(chip->base >> chip->addrshift) + chip->start + off);
709 Last[Count % 4] = map->read32(map,(chip->base >> chip->addrshift) + chip->start + off);
714 /* // Count time, max of 15s per sector (according to AMD)
715 if (Time > 15*len/mtd->erasesize*HZ)
717 printk("mtd: Flash Erase Timed out\n");
722 // Skip to the next chip if we used chip erase
723 if (chip->length == chip->size)
726 off += chip->sectorsize;
728 if (off >= chip->length)
733 for (J = 0; priv->chips[J].jedec != 0 && J < MAX_JEDEC_CHIPS; J++)
735 if ((priv->chips[J].base & (~((1<<chip->addrshift)-1))) ==
736 (chip->base & (~((1<<chip->addrshift)-1))))
737 priv->chips[J].length = 0;
742 instr->state = MTD_ERASE_DONE;
744 instr->callback(instr);
751 /* This is the simple flash writing function. It writes to every byte, in
752 sequence. It takes care of how to properly address the flash if
753 the flash is interleved. It can only be used if all the chips in the
754 array are identical!*/
755 static int flash_write(struct mtd_info *mtd, loff_t start, size_t len,
756 size_t *retlen, const u_char *buf)
758 /* Does IO to the currently selected chip. It takes the bank addressing
759 base (which is divisable by the chip size) adds the necesary lower bits
760 of addrshift (interleve index) and then adds the control register index. */
761 #define flread(x) map->read8(map,base+(off&((1<<chip->addrshift)-1))+((x)<<chip->addrshift))
762 #define flwrite(v,x) map->write8(map,v,base+(off&((1<<chip->addrshift)-1))+((x)<<chip->addrshift))
764 struct map_info *map = (struct map_info *)mtd->priv;
765 struct jedec_private *priv = (struct jedec_private *)map->fldrv_priv;
768 size_t save_len = len;
770 if (start + len > mtd->size)
775 //printk("flash_write: start is %x, len is %x\n",start,(unsigned long)len);
778 struct jedec_flash_chip *chip = priv->chips;
780 unsigned long boffset;
782 // Compute the base of the flash.
783 off = ((unsigned long)start) % (chip->size << chip->addrshift);
786 // Perform banked addressing translation.
787 bank = base & (~(priv->bank_fill[0]-1));
788 boffset = base & (priv->bank_fill[0]-1);
789 bank = (bank/priv->bank_fill[0])*my_bank_size;
790 base = bank + boffset;
792 // printk("Flasing %X %X %X\n",base,chip->size,len);
793 // printk("off is %x, compare with %x\n",off,chip->size << chip->addrshift);
795 // Loop over this page
796 for (; off != (chip->size << chip->addrshift) && len != 0; start++, len--, off++,buf++)
798 unsigned char oldbyte = map->read8(map,base+off);
799 unsigned char Last[4];
800 unsigned long Count = 0;
802 if (oldbyte == *buf) {
803 // printk("oldbyte and *buf is %x,len is %x\n",oldbyte,len);
806 if (((~oldbyte) & *buf) != 0)
807 printk("mtd: warn: Trying to set a 0 to a 1\n");
813 map->write8(map,*buf,base + off);
814 Last[0] = map->read8(map,base + off);
815 Last[1] = map->read8(map,base + off);
816 Last[2] = map->read8(map,base + off);
818 /* Wait for the flash to finish the operation. We store the last 4
819 status bytes that have been retrieved so we can determine why
820 it failed. The toggle bits keep toggling when there is a
822 for (Count = 3; Last[(Count - 1) % 4] != Last[(Count - 2) % 4] &&
823 Count < 10000; Count++)
824 Last[Count % 4] = map->read8(map,base + off);
825 if (Last[(Count - 1) % 4] != *buf)
827 jedec_flash_failed(Last[(Count - 3) % 4]);
836 /* This is used to enhance the speed of the erase routine,
837 when things are being done to multiple chips it is possible to
838 parallize the operations, particularly full memory erases of multi
839 chip memories benifit */
840 static void jedec_flash_chip_scan(struct jedec_private *priv,unsigned long start,
846 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++)
847 priv->chips[I].start = priv->chips[I].length = 0;
849 // Intersect the region with each chip
850 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++)
852 struct jedec_flash_chip *chip = priv->chips + I;
853 unsigned long ByteStart;
854 unsigned long ChipEndByte = chip->offset + (chip->size << chip->addrshift);
856 // End is before this chip or the start is after it
857 if (start+len < chip->offset ||
858 ChipEndByte - (1 << chip->addrshift) < start)
861 if (start < chip->offset)
863 ByteStart = chip->offset;
868 chip->start = (start - chip->offset + (1 << chip->addrshift)-1) >> chip->addrshift;
872 if (start + len >= ChipEndByte)
873 chip->length = (ChipEndByte - ByteStart) >> chip->addrshift;
875 chip->length = (start + len - ByteStart + (1 << chip->addrshift)-1) >> chip->addrshift;
879 int __init jedec_init(void)
881 register_mtd_chip_driver(&jedec_chipdrv);
885 static void __exit jedec_exit(void)
887 unregister_mtd_chip_driver(&jedec_chipdrv);
890 module_init(jedec_init);
891 module_exit(jedec_exit);
893 MODULE_LICENSE("GPL");
894 MODULE_AUTHOR("Jason Gunthorpe <jgg@deltatee.com> et al.");
895 MODULE_DESCRIPTION("Old MTD chip driver for JEDEC-compliant flash chips");