This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / drivers / mtd / chips / cfi_probe.c
index 071be42..fba4ddf 100644 (file)
@@ -1,7 +1,7 @@
 /* 
    Common Flash Interface probe code.
    (C) 2000 Red Hat. GPL'd.
-   $Id: cfi_probe.c,v 1.77 2004/07/14 08:38:44 dwmw2 Exp $
+   $Id: cfi_probe.c,v 1.71 2003/05/28 12:51:48 dwmw2 Exp $
 */
 
 #include <linux/config.h>
@@ -26,7 +26,7 @@ static void print_cfi_ident(struct cfi_ident *);
 #endif
 
 static int cfi_probe_chip(struct map_info *map, __u32 base,
-                         unsigned long *chip_map, struct cfi_private *cfi);
+                         struct flchip *chips, struct cfi_private *cfi);
 static int cfi_chip_setup(struct map_info *map, struct cfi_private *cfi);
 
 struct mtd_info *cfi_probe(struct map_info *map);
@@ -35,36 +35,21 @@ struct mtd_info *cfi_probe(struct map_info *map);
    in: interleave,type,mode
    ret: table index, <0 for error
  */
-static int qry_present(struct map_info *map, __u32 base,
+static inline int qry_present(struct map_info *map, __u32 base,
                                struct cfi_private *cfi)
 {
        int osf = cfi->interleave * cfi->device_type;   // scale factor
-       map_word val;
-       map_word qry;
 
-       qry =  cfi_build_cmd('Q', map, cfi);
-       val = map_read(map, base + osf*0x10);
+       if (cfi_read(map,base+osf*0x10)==cfi_build_cmd('Q',map,cfi) &&
+           cfi_read(map,base+osf*0x11)==cfi_build_cmd('R',map,cfi) &&
+           cfi_read(map,base+osf*0x12)==cfi_build_cmd('Y',map,cfi))
+               return 1;       // ok !
 
-       if (!map_word_equal(map, qry, val))
-               return 0;
-
-       qry =  cfi_build_cmd('R', map, cfi);
-       val = map_read(map, base + osf*0x11);
-
-       if (!map_word_equal(map, qry, val))
-               return 0;
-
-       qry =  cfi_build_cmd('Y', map, cfi);
-       val = map_read(map, base + osf*0x12);
-
-       if (!map_word_equal(map, qry, val))
-               return 0;
-
-       return 1;       // nothing found
+       return 0;       // nothing found
 }
 
 static int cfi_probe_chip(struct map_info *map, __u32 base,
-                         unsigned long *chip_map, struct cfi_private *cfi)
+                         struct flchip *chips, struct cfi_private *cfi)
 {
        int i;
        
@@ -81,7 +66,6 @@ static int cfi_probe_chip(struct map_info *map, __u32 base,
                return 0;
        }
        cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL);
-       cfi_send_gen_cmd(0xFF, 0, base, map, cfi, cfi->device_type, NULL);
        cfi_send_gen_cmd(0x98, 0x55, base, map, cfi, cfi->device_type, NULL);
 
        if (!qry_present(map,base,cfi))
@@ -94,25 +78,18 @@ static int cfi_probe_chip(struct map_info *map, __u32 base,
        }
 
        /* Check each previous chip to see if it's an alias */
-       for (i=0; i < (base >> cfi->chipshift); i++) {
-               unsigned long start;
-               if(!test_bit(i, chip_map)) {
-                       /* Skip location; no valid chip at this address */
-                       continue; 
-               }
-               start = i << cfi->chipshift;
+       for (i=0; i<cfi->numchips; i++) {
                /* This chip should be in read mode if it's one
                   we've already touched. */
-               if (qry_present(map, start, cfi)) {
+               if (qry_present(map,chips[i].start,cfi)) {
                        /* Eep. This chip also had the QRY marker. 
                         * Is it an alias for the new one? */
-                       cfi_send_gen_cmd(0xF0, 0, start, map, cfi, cfi->device_type, NULL);
-                       cfi_send_gen_cmd(0xFF, 0, start, map, cfi, cfi->device_type, NULL);
+                       cfi_send_gen_cmd(0xF0, 0, chips[i].start, map, cfi, cfi->device_type, NULL);
 
                        /* If the QRY marker goes away, it's an alias */
-                       if (!qry_present(map, start, cfi)) {
+                       if (!qry_present(map, chips[i].start, cfi)) {
                                printk(KERN_DEBUG "%s: Found an alias at 0x%x for the chip at 0x%lx\n",
-                                      map->name, base, start);
+                                      map->name, base, chips[i].start);
                                return 0;
                        }
                        /* Yes, it's actually got QRY for data. Most 
@@ -120,11 +97,10 @@ static int cfi_probe_chip(struct map_info *map, __u32 base,
                         * too and if it's the same, assume it's an alias. */
                        /* FIXME: Use other modes to do a proper check */
                        cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL);
-                       cfi_send_gen_cmd(0xFF, 0, start, map, cfi, cfi->device_type, NULL);
                        
                        if (qry_present(map, base, cfi)) {
                                printk(KERN_DEBUG "%s: Found an alias at 0x%x for the chip at 0x%lx\n",
-                                      map->name, base, start);
+                                      map->name, base, chips[i].start);
                                return 0;
                        }
                }
@@ -132,16 +108,21 @@ static int cfi_probe_chip(struct map_info *map, __u32 base,
        
        /* OK, if we got to here, then none of the previous chips appear to
           be aliases for the current one. */
-       set_bit((base >> cfi->chipshift), chip_map); /* Update chip map */
+       if (cfi->numchips == MAX_CFI_CHIPS) {
+               printk(KERN_WARNING"%s: Too many flash chips detected. Increase MAX_CFI_CHIPS from %d.\n", map->name, MAX_CFI_CHIPS);
+               /* Doesn't matter about resetting it to Read Mode - we're not going to talk to it anyway */
+               return -1;
+       }
+       chips[cfi->numchips].start = base;
+       chips[cfi->numchips].state = FL_READY;
        cfi->numchips++;
        
        /* Put it back into Read Mode */
        cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL);
-       cfi_send_gen_cmd(0xFF, 0, base, map, cfi, cfi->device_type, NULL);
 
-       printk(KERN_INFO "%s: Found %d x%d devices at 0x%x in %d-bit bank\n",
+       printk(KERN_INFO "%s: Found %d x%d devices at 0x%x in %d-bit mode\n",
               map->name, cfi->interleave, cfi->device_type*8, base,
-              map->bankwidth*8);
+              map->buswidth*8);
        
        return 1;
 }
@@ -169,6 +150,7 @@ static int cfi_chip_setup(struct map_info *map,
        memset(cfi->cfiq,0,sizeof(struct cfi_ident));   
        
        cfi->cfi_mode = CFI_MODE_CFI;
+       cfi->fast_prog=1;               /* CFI supports fast programming */
        
        /* Read the CFI info structure */
        for (i=0; i<(sizeof(struct cfi_ident) + num_erase_regions * 4); i++) {
@@ -198,29 +180,8 @@ static int cfi_chip_setup(struct map_info *map,
                       (cfi->cfiq->EraseRegionInfo[i] & 0xffff) + 1);
 #endif
        }
-
-       /* Note we put the device back into Read Mode BEFORE going into Auto
-        * Select Mode, as some devices support nesting of modes, others
-        * don't. This way should always work.
-        * On cmdset 0001 the writes of 0xaa and 0x55 are not needed, and
-        * so should be treated as nops or illegal (and so put the device
-        * back into Read Mode, which is a nop in this case).
-        */
-       cfi_send_gen_cmd(0xf0,     0, base, map, cfi, cfi->device_type, NULL);
-       cfi_send_gen_cmd(0xaa, 0x555, base, map, cfi, cfi->device_type, NULL);
-       cfi_send_gen_cmd(0x55, 0x2aa, base, map, cfi, cfi->device_type, NULL);
-       cfi_send_gen_cmd(0x90, 0x555, base, map, cfi, cfi->device_type, NULL);
-       cfi->mfr = cfi_read_query(map, base);
-       cfi->id = cfi_read_query(map, base + ofs_factor);    
-
        /* Put it back into Read Mode */
        cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL);
-       /* ... even if it's an Intel chip */
-       cfi_send_gen_cmd(0xFF, 0, base, map, cfi, cfi->device_type, NULL);
-
-       printk(KERN_INFO "%s: Found %d x%d devices at 0x%x in %d-bit bank\n",
-              map->name, cfi->interleave, cfi->device_type*8, base,
-              map->bankwidth*8);
 
        return 1;
 }
@@ -280,11 +241,11 @@ static void print_cfi_ident(struct cfi_ident *cfip)
                printk("No Alternate Algorithm Table\n");
                
                
-       printk("Vcc Minimum: %2d.%d V\n", cfip->VccMin >> 4, cfip->VccMin & 0xf);
-       printk("Vcc Maximum: %2d.%d V\n", cfip->VccMax >> 4, cfip->VccMax & 0xf);
+       printk("Vcc Minimum: %x.%x V\n", cfip->VccMin >> 4, cfip->VccMin & 0xf);
+       printk("Vcc Maximum: %x.%x V\n", cfip->VccMax >> 4, cfip->VccMax & 0xf);
        if (cfip->VppMin) {
-               printk("Vpp Minimum: %2d.%d V\n", cfip->VppMin >> 4, cfip->VppMin & 0xf);
-               printk("Vpp Maximum: %2d.%d V\n", cfip->VppMax >> 4, cfip->VppMax & 0xf);
+               printk("Vpp Minimum: %x.%x V\n", cfip->VppMin >> 4, cfip->VppMin & 0xf);
+               printk("Vpp Maximum: %x.%x V\n", cfip->VppMax >> 4, cfip->VppMax & 0xf);
        }
        else
                printk("No Vpp line\n");