File: /usr/src/linux/drivers/mtd/chips/cfi_probe.c
1 /*
2 Common Flash Interface probe code.
3 (C) 2000 Red Hat. GPL'd.
4 $Id: cfi_probe.c,v 1.60 2001/06/03 01:32:57 nico Exp $
5 */
6
7 #include <linux/config.h>
8 #include <linux/module.h>
9 #include <linux/types.h>
10 #include <linux/kernel.h>
11 #include <asm/io.h>
12 #include <asm/byteorder.h>
13 #include <linux/errno.h>
14 #include <linux/slab.h>
15
16 #include <linux/mtd/map.h>
17 #include <linux/mtd/cfi.h>
18
19 /* #define DEBUG_CFI */
20
21 #ifdef DEBUG_CFI
22 static void print_cfi_ident(struct cfi_ident *);
23 #endif
24
25 int cfi_jedec_setup(struct cfi_private *p_cfi, int index);
26 int cfi_jedec_lookup(int index, int mfr_id, int dev_id);
27
28 static void check_cmd_set(struct map_info *, int, unsigned long);
29 static struct cfi_private *cfi_cfi_probe(struct map_info *);
30 struct mtd_info *cfi_probe(struct map_info *map);
31
32
33 static struct mtd_chip_driver cfi_chipdrv = {
34 probe: cfi_probe,
35 name: "cfi",
36 module: THIS_MODULE
37 };
38
39
40 struct mtd_info *cfi_probe(struct map_info *map)
41 {
42 struct mtd_info *mtd = NULL;
43 struct cfi_private *cfi;
44
45 /* First probe the map to see if we have CFI stuff there. */
46 cfi = cfi_cfi_probe(map);
47
48 if (!cfi)
49 return NULL;
50
51 map->fldrv_priv = cfi;
52 /* OK we liked it. Now find a driver for the command set it talks */
53
54 check_cmd_set(map, 1, cfi->chips[0].start); /* First the primary cmdset */
55 if (!map->fldrv)
56 check_cmd_set(map, 0, cfi->chips[0].start); /* Then the secondary */
57
58 /* check_cmd_set() will have used inter_module_get to increase
59 the use count of the module which provides the command set
60 driver. If we're quitting, we have to decrease it again.
61 */
62
63 if(map->fldrv) {
64 mtd = map->fldrv->probe(map);
65 /* Undo the use count we held onto from inter_module_get */
66 #ifdef MODULE
67 if(map->fldrv->module)
68 __MOD_DEC_USE_COUNT(map->fldrv->module);
69 #endif
70 if (mtd)
71 return mtd;
72 }
73 printk(KERN_WARNING"cfi_probe: No supported Vendor Command Set found\n");
74
75 kfree(cfi->cfiq);
76 kfree(cfi);
77 map->fldrv_priv = NULL;
78 return NULL;
79 }
80
81 static __u32 cfi_send_cmd(u_char cmd, __u32 base, struct map_info *map, struct cfi_private *cfi)
82 {
83 return cfi_send_gen_cmd(cmd, 0x55, base, map, cfi, cfi->device_type, NULL);
84 }
85
86 /* check for QRY, or search for jedec id.
87 in: interleave,type,mode
88 ret: table index, <0 for error
89 */
90 static int cfi_check_qry_or_id(struct map_info *map, __u32 base, int index,
91 struct cfi_private *cfi)
92 {
93 __u32 manufacturer_id, device_id;
94 int osf = cfi->interleave * cfi->device_type; // scale factor
95
96 //printk("cfi_check_qry_or_id: base=0x%08lx interl=%d type=%d index=%d\n",base,cfi->interleave,cfi->device_type,index);
97
98 switch(cfi->cfi_mode){
99 case 0:
100 if (cfi_read(map,base+osf*0x10)==cfi_build_cmd('Q',map,cfi) &&
101 cfi_read(map,base+osf*0x11)==cfi_build_cmd('R',map,cfi) &&
102 cfi_read(map,base+osf*0x12)==cfi_build_cmd('Y',map,cfi))
103 return 0; // ok !
104 break;
105
106 case 1:
107 manufacturer_id = cfi_read(map,base+0*osf);
108 device_id = cfi_read(map,base+1*osf);
109 //printk("cfi_check_qry_or_id: man=0x%lx,id=0x%lx\n",manufacturer_id, device_id);
110
111 return cfi_jedec_lookup(index,manufacturer_id,device_id);
112 }
113
114 return -1; // nothing found
115 }
116
117 static void cfi_qry_mode(struct map_info *map, __u32 base, struct cfi_private *cfi)
118 {
119 switch(cfi->cfi_mode){
120 case 0:
121 /* Query */
122 cfi_send_cmd(0x98, base, map, cfi);
123 break;
124
125 case 1:
126
127 /* Autoselect */
128 cfi_send_gen_cmd(0xaa, cfi->addr_unlock1, base, map, cfi, CFI_DEVICETYPE_X8, NULL);
129 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, base, map, cfi, CFI_DEVICETYPE_X8, NULL);
130 cfi_send_gen_cmd(0x90, cfi->addr_unlock1, base, map, cfi, CFI_DEVICETYPE_X8, NULL);
131 break;
132 }
133 }
134
135 static int cfi_probe_chip_1(struct map_info *map, __u32 base,
136 struct flchip *chips, struct cfi_private *cfi)
137 {
138 int index;
139 __u32 tmp,ofs;
140
141 ofs = cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, &tmp);
142
143 cfi_qry_mode(map,base,cfi);
144
145 index=cfi_check_qry_or_id(map,base,-1,cfi);
146 if (index<0) return -1;
147
148 if (chips){
149 int i;
150
151 for (i=0; i<cfi->numchips; i++){
152 /* This chip should be in read mode if it's one
153 we've already touched. */
154 if (cfi_check_qry_or_id(map,chips[i].start,index,cfi) >= 0){
155 cfi_send_gen_cmd(0xF0, 0, chips[i].start, map, cfi, cfi->device_type, NULL);
156 if (cfi_check_qry_or_id(map,chips[i].start,index,cfi) >= 0){
157 /* Yes it's got QRY for data. Most unfortunate.
158 Stick the old one in read mode too. */
159 cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL);
160 if (cfi_check_qry_or_id(map,base,index,cfi) >= 0){
161 /* OK, so has the new one. Assume it's an alias */
162 printk(KERN_DEBUG "%s: Found an alias at 0x%x for the chip at 0x%lx\n",
163 map->name, base, chips[i].start);
164 return -1;
165 }
166 } else {
167 /*
168 * FIXME: Is this supposed to work?
169 * The third argument is already
170 * multiplied as this within the
171 * function definition. (Nicolas Pitre)
172 */
173 cfi_send_gen_cmd(0xF0, 0, base+0xaa*cfi->interleave * cfi->device_type, map, cfi, cfi->device_type, NULL);
174 cfi_send_gen_cmd(0xF0, 0, chips[i].start+0xaa*cfi->interleave * cfi->device_type, map, cfi, cfi->device_type, NULL);
175 return -1;
176 }
177 }
178 } /* for i */
179
180 /* OK, if we got to here, then none of the previous chips appear to
181 be aliases for the current one. */
182 if (cfi->numchips == MAX_CFI_CHIPS) {
183 printk(KERN_WARNING"%s: Too many flash chips detected. Increase MAX_CFI_CHIPS from %d.\n", map->name, MAX_CFI_CHIPS);
184 /* Doesn't matter about resetting it to Read Mode - we're not going to talk to it anyway */
185 return -1;
186 }
187 chips[cfi->numchips].start = base;
188 chips[cfi->numchips].state = FL_READY;
189 chips[cfi->numchips].mutex = &chips[cfi->numchips]._spinlock;
190 cfi->numchips++;
191
192 /* Put it back into Read Mode */
193 cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL);
194 }
195 printk(KERN_INFO "%s: Found %d x%d devices at 0x%x in %d-bit mode\n", map->name,
196 cfi->interleave, cfi->device_type*8, base, map->buswidth*8);
197
198 return index;
199 }
200
201 /* put dev into qry mode, and try cfi and jedec modes for the given type/interleave
202 */
203 static int cfi_probe_chip(struct map_info *map, __u32 base,
204 struct flchip *chips, struct cfi_private *cfi)
205 {
206 int index;
207 cfi->cfi_mode=0; /* cfi mode */
208
209 switch (cfi->device_type) {
210 case CFI_DEVICETYPE_X8:
211 cfi->addr_unlock1 = 0x555;
212 cfi->addr_unlock2 = 0x2aa;
213 break;
214 case CFI_DEVICETYPE_X16:
215 cfi->addr_unlock1 = 0xaaa;
216 if (map->buswidth == cfi->interleave) {
217 /* X16 chip(s) in X8 mode */
218 cfi->addr_unlock2 = 0x555;
219 } else {
220 cfi->addr_unlock2 = 0x554;
221 }
222 break;
223 case CFI_DEVICETYPE_X32:
224 cfi->addr_unlock1 = 0x1555;
225 cfi->addr_unlock2 = 0xaaa;
226 break;
227 default:
228 return 0;
229 }
230 index = cfi_probe_chip_1(map,base,chips,cfi);
231 if (index>=0) return index;
232
233 cfi->cfi_mode=1; /* jedec mode */
234 index = cfi_probe_chip_1(map,base,chips,cfi);
235 if (index>=0) return index;
236
237 cfi->addr_unlock1 = 0x5555;
238 cfi->addr_unlock2 = 0x2aaa;
239 index = cfi_probe_chip_1(map,base,chips,cfi);
240
241 return index;
242 }
243
244 /*
245 * Since probeing for CFI chips requires writing to the device problems may
246 * occur if the flash is not present and RAM is accessed instead. For now we
247 * assume that the flash is present so we don't check for RAM or replace
248 * possibly overwritten data.
249 */
250 static int cfi_probe_new_chip(struct map_info *map, unsigned long base,
251 struct flchip *chips, struct cfi_private *cfi)
252 {
253 int index;
254 switch (map->buswidth) {
255 #ifdef CFIDEV_BUSWIDTH_1
256 case CFIDEV_BUSWIDTH_1:
257 cfi->interleave = CFIDEV_INTERLEAVE_1;
258 cfi->device_type = CFI_DEVICETYPE_X8;
259 index = cfi_probe_chip(map,base,chips,cfi);
260 if (index>=0) return index;
261
262 cfi->device_type = CFI_DEVICETYPE_X16;
263 index = cfi_probe_chip(map,base,chips,cfi);
264 if (index>=0) return index;
265 break;
266 #endif
267
268 #ifdef CFIDEV_BUSWIDTH_2
269 case CFIDEV_BUSWIDTH_2:
270 #ifdef CFIDEV_INTERLEAVE_1
271 cfi->interleave = CFIDEV_INTERLEAVE_1;
272 cfi->device_type = CFI_DEVICETYPE_X16;
273 index = cfi_probe_chip(map,base,chips,cfi);
274 if (index>=0) return index;
275 #endif
276 #ifdef CFIDEV_INTERLEAVE_2
277 cfi->interleave = CFIDEV_INTERLEAVE_2;
278 cfi->device_type = CFI_DEVICETYPE_X8;
279 index = cfi_probe_chip(map,base,chips,cfi);
280 if (index>=0) return index;
281
282 cfi->device_type = CFI_DEVICETYPE_X16;
283 index = cfi_probe_chip(map,base,chips,cfi);
284 if (index>=0) return index;
285
286 #endif
287 break;
288 #endif
289
290 #ifdef CFIDEV_BUSWIDTH_4
291 case CFIDEV_BUSWIDTH_4:
292 #ifdef CFIDEV_INTERLEAVE_4
293 cfi->interleave = CFIDEV_INTERLEAVE_4;
294 cfi->device_type = CFI_DEVICETYPE_X16;
295 index = cfi_probe_chip(map,base,chips,cfi);
296 if (index>=0) return index;
297
298 cfi->device_type = CFI_DEVICETYPE_X32;
299 index = cfi_probe_chip(map,base,chips,cfi);
300 if (index>=0) return index;
301
302 cfi->device_type = CFI_DEVICETYPE_X8;
303 index = cfi_probe_chip(map,base,chips,cfi);
304 if (index>=0) return index;
305 #endif
306 #ifdef CFIDEV_INTERLEAVE_2
307 cfi->interleave = CFIDEV_INTERLEAVE_2;
308 cfi->device_type = CFI_DEVICETYPE_X16;
309 index = cfi_probe_chip(map,base,chips,cfi);
310 if (index>=0) return index;
311 #endif
312 #ifdef CFIDEV_INTERLEAVE_1
313 cfi->interleave = CFIDEV_INTERLEAVE_1;
314 cfi->device_type = CFI_DEVICETYPE_X32;
315 index = cfi_probe_chip(map,base,chips,cfi);
316 if (index>=0) return index;
317 #endif
318 break;
319 #endif
320 default:
321 printk(KERN_WARNING "cfi_probe called with unsupported buswidth %d\n", map->buswidth);
322 return -1;
323 } // switch
324 return -1;
325 }
326
327 static struct cfi_private *cfi_cfi_probe(struct map_info *map)
328 {
329 unsigned long base=0;
330 struct cfi_private cfi;
331 struct cfi_private *retcfi;
332 struct flchip chip[MAX_CFI_CHIPS];
333 int i,index;
334 char num_erase_regions;
335 int ofs_factor;
336
337 memset(&cfi, 0, sizeof(cfi));
338
339 /* The first invocation (with chips == NULL) leaves the device in Query Mode */
340 index = cfi_probe_new_chip(map, 0, NULL, &cfi);
341
342 if (index<0) {
343 printk(KERN_WARNING"%s: Found no CFI device at location zero\n", map->name);
344 /* Doesn't appear to be CFI-compliant at all */
345 return NULL;
346 }
347
348 /* Read the Basic Query Structure from the device */
349
350 ofs_factor = cfi.interleave*cfi.device_type;
351
352 /* First, work out the amount of space to allocate */
353 if (cfi.cfi_mode==0){
354 num_erase_regions = cfi_read_query(map, base + (0x10 + 28)*ofs_factor);
355
356 #ifdef DEBUG_CFI
357 printk("Number of erase regions: %d\n", num_erase_regions);
358 #endif
359
360 cfi.cfiq = kmalloc(sizeof(struct cfi_ident) + num_erase_regions * 4, GFP_KERNEL);
361 if (!cfi.cfiq) {
362 printk(KERN_WARNING "%s: kmalloc failed for CFI ident structure\n", map->name);
363 return NULL;
364 }
365
366 memset(cfi.cfiq,0,sizeof(struct cfi_ident));
367
368 cfi.fast_prog=1; /* CFI supports fast programming */
369
370 /* CFI flash */
371 for (i=0; i<(sizeof(struct cfi_ident) + num_erase_regions * 4); i++) {
372 ((unsigned char *)cfi.cfiq)[i] = cfi_read_query(map,base + (0x10 + i)*ofs_factor);
373 }
374
375 /* Do any necessary byteswapping */
376 cfi.cfiq->P_ID = le16_to_cpu(cfi.cfiq->P_ID);
377
378 cfi.cfiq->P_ADR = le16_to_cpu(cfi.cfiq->P_ADR);
379 cfi.cfiq->A_ID = le16_to_cpu(cfi.cfiq->A_ID);
380 cfi.cfiq->A_ADR = le16_to_cpu(cfi.cfiq->A_ADR);
381 cfi.cfiq->InterfaceDesc = le16_to_cpu(cfi.cfiq->InterfaceDesc);
382 cfi.cfiq->MaxBufWriteSize = le16_to_cpu(cfi.cfiq->MaxBufWriteSize);
383
384 for (i=0; i<cfi.cfiq->NumEraseRegions; i++) {
385 cfi.cfiq->EraseRegionInfo[i] = le32_to_cpu(cfi.cfiq->EraseRegionInfo[i]);
386
387 #ifdef DEBUG_CFI
388 printk(" Erase Region #%d: BlockSize 0x%4.4X bytes, %d blocks\n",
389 i, (cfi.cfiq->EraseRegionInfo[i] >> 8) & ~0xff,
390 (cfi.cfiq->EraseRegionInfo[i] & 0xffff) + 1);
391 #endif
392 }
393 }
394 else{
395 /* JEDEC flash */
396 if (cfi_jedec_setup(&cfi,index)<0){
397 printk(KERN_WARNING "cfi_jedec_setup failed\n");
398 return NULL;
399 }
400 }
401
402 if (cfi.cfiq->NumEraseRegions == 0) {
403 printk(KERN_WARNING "Number of erase regions is zero\n");
404 kfree(cfi.cfiq);
405 return NULL;
406 }
407
408 #ifdef DEBUG_CFI
409 /* Dump the information therein */
410 print_cfi_ident(cfi.cfiq);
411 #endif
412
413 cfi_send_cmd(0xFF, base, map, &cfi);
414
415 /* OK. We've worked out what it is and we're happy with it. Now see if there are others */
416
417 chip[0].start = 0;
418 chip[0].state = FL_READY;
419 chip[0].mutex = &chip[0]._spinlock;
420
421 cfi.chipshift = cfi.cfiq->DevSize;
422 cfi.numchips = 1;
423
424 if (!cfi.chipshift) {
425 printk(KERN_ERR"cfi.chipsize is zero. This is bad. cfi.cfiq->DevSize is %d\n", cfi.cfiq->DevSize);
426 kfree(cfi.cfiq);
427 return NULL;
428 }
429 switch (cfi.interleave) {
430 case 2: cfi.chipshift += 1; break;
431 case 4: cfi.chipshift += 2; break;
432 }
433
434 for (base = (1<<cfi.chipshift); base < map->size; base += (1<<cfi.chipshift))
435 cfi_probe_chip_1(map, base, &chip[0], &cfi);
436
437 retcfi = kmalloc(sizeof(struct cfi_private) + cfi.numchips * sizeof(struct flchip), GFP_KERNEL);
438
439 if (!retcfi) {
440 printk(KERN_WARNING "%s: kmalloc failed for CFI private structure\n", map->name);
441 kfree(cfi.cfiq);
442 return NULL;
443 }
444 memcpy(retcfi, &cfi, sizeof(cfi));
445 memcpy(&retcfi->chips[0], chip, sizeof(struct flchip) * cfi.numchips);
446 for (i=0; i< retcfi->numchips; i++) {
447 init_waitqueue_head(&retcfi->chips[i].wq);
448 spin_lock_init(&retcfi->chips[i]._spinlock);
449 retcfi->chips[i].mutex = &retcfi->chips[i]._spinlock;
450 }
451 return retcfi;
452 }
453
454 #ifdef DEBUG_CFI
455 static char *vendorname(__u16 vendor)
456 {
457 switch (vendor) {
458 case P_ID_NONE:
459 return "None";
460
461 case P_ID_INTEL_EXT:
462 return "Intel/Sharp Extended";
463
464 case P_ID_AMD_STD:
465 return "AMD/Fujitsu Standard";
466
467 case P_ID_INTEL_STD:
468 return "Intel/Sharp Standard";
469
470 case P_ID_AMD_EXT:
471 return "AMD/Fujitsu Extended";
472
473 case P_ID_MITSUBISHI_STD:
474 return "Mitsubishi Standard";
475
476 case P_ID_MITSUBISHI_EXT:
477 return "Mitsubishi Extended";
478
479 case P_ID_RESERVED:
480 return "Not Allowed / Reserved for Future Use";
481
482 default:
483 return "Unknown";
484 }
485 }
486
487
488 static void print_cfi_ident(struct cfi_ident *cfip)
489 {
490 #if 0
491 if (cfip->qry[0] != 'Q' || cfip->qry[1] != 'R' || cfip->qry[2] != 'Y') {
492 printk("Invalid CFI ident structure.\n");
493 return;
494 }
495 #endif
496 printk("Primary Vendor Command Set: %4.4X (%s)\n", cfip->P_ID, vendorname(cfip->P_ID));
497 if (cfip->P_ADR)
498 printk("Primary Algorithm Table at %4.4X\n", cfip->P_ADR);
499 else
500 printk("No Primary Algorithm Table\n");
501
502 printk("Alternative Vendor Command Set: %4.4X (%s)\n", cfip->A_ID, vendorname(cfip->A_ID));
503 if (cfip->A_ADR)
504 printk("Alternate Algorithm Table at %4.4X\n", cfip->A_ADR);
505 else
506 printk("No Alternate Algorithm Table\n");
507
508
509 printk("Vcc Minimum: %x.%x V\n", cfip->VccMin >> 4, cfip->VccMin & 0xf);
510 printk("Vcc Maximum: %x.%x V\n", cfip->VccMax >> 4, cfip->VccMax & 0xf);
511 if (cfip->VppMin) {
512 printk("Vpp Minimum: %x.%x V\n", cfip->VppMin >> 4, cfip->VppMin & 0xf);
513 printk("Vpp Maximum: %x.%x V\n", cfip->VppMax >> 4, cfip->VppMax & 0xf);
514 }
515 else
516 printk("No Vpp line\n");
517
518 printk("Typical byte/word write timeout: %d µs\n", 1<<cfip->WordWriteTimeoutTyp);
519 printk("Maximum byte/word write timeout: %d µs\n", (1<<cfip->WordWriteTimeoutMax) * (1<<cfip->WordWriteTimeoutTyp));
520
521 if (cfip->BufWriteTimeoutTyp || cfip->BufWriteTimeoutMax) {
522 printk("Typical full buffer write timeout: %d µs\n", 1<<cfip->BufWriteTimeoutTyp);
523 printk("Maximum full buffer write timeout: %d µs\n", (1<<cfip->BufWriteTimeoutMax) * (1<<cfip->BufWriteTimeoutTyp));
524 }
525 else
526 printk("Full buffer write not supported\n");
527
528 printk("Typical block erase timeout: %d µs\n", 1<<cfip->BlockEraseTimeoutTyp);
529 printk("Maximum block erase timeout: %d µs\n", (1<<cfip->BlockEraseTimeoutMax) * (1<<cfip->BlockEraseTimeoutTyp));
530 if (cfip->ChipEraseTimeoutTyp || cfip->ChipEraseTimeoutMax) {
531 printk("Typical chip erase timeout: %d µs\n", 1<<cfip->ChipEraseTimeoutTyp);
532 printk("Maximum chip erase timeout: %d µs\n", (1<<cfip->ChipEraseTimeoutMax) * (1<<cfip->ChipEraseTimeoutTyp));
533 }
534 else
535 printk("Chip erase not supported\n");
536
537 printk("Device size: 0x%X bytes (%d MiB)\n", 1 << cfip->DevSize, 1<< (cfip->DevSize - 20));
538 printk("Flash Device Interface description: 0x%4.4X\n", cfip->InterfaceDesc);
539 switch(cfip->InterfaceDesc) {
540 case 0:
541 printk(" - x8-only asynchronous interface\n");
542 break;
543
544 case 1:
545 printk(" - x16-only asynchronous interface\n");
546 break;
547
548 case 2:
549 printk(" - supports x8 and x16 via BYTE# with asynchronous interface\n");
550 break;
551
552 case 3:
553 printk(" - x32-only asynchronous interface\n");
554 break;
555
556 case 65535:
557 printk(" - Not Allowed / Reserved\n");
558 break;
559
560 default:
561 printk(" - Unknown\n");
562 break;
563 }
564
565 printk("Max. bytes in buffer write: 0x%x\n", 1<< cfip->MaxBufWriteSize);
566 printk("Number of Erase Block Regions: %d\n", cfip->NumEraseRegions);
567
568 }
569 #endif /* DEBUG_CFI */
570
571 typedef void cfi_cmdset_fn_t(struct map_info *, int, unsigned long);
572
573 extern cfi_cmdset_fn_t cfi_cmdset_0001;
574 extern cfi_cmdset_fn_t cfi_cmdset_0002;
575
576 static void cfi_cmdset_unknown(struct map_info *map, int primary, unsigned long base)
577 {
578 __u16 adr;
579 struct cfi_private *cfi = map->fldrv_priv;
580 __u16 type = primary?cfi->cfiq->P_ID:cfi->cfiq->A_ID;
581 #ifdef HAVE_INTER_MODULE
582 char probename[32];
583 cfi_cmdset_fn_t *probe_function;
584
585 sprintf(probename, "cfi_cmdset_%4.4X", type);
586
587 probe_function = inter_module_get_request(probename, probename);
588
589 if (probe_function) {
590 (*probe_function)(map, primary, base);
591 return;
592 }
593 #endif
594 printk(KERN_NOTICE "Support for command set %04X not present\n", type);
595 /* This was a command set we don't know about. Print only the basic info */
596 adr = primary?cfi->cfiq->P_ADR:cfi->cfiq->A_ADR;
597
598 if (!adr) {
599 printk(" No Extended Query Table\n");
600 }
601 else {
602 int ofs_factor = cfi->interleave * cfi->device_type;
603
604 if (cfi_read_query(map,base + adr*ofs_factor) != (primary?'P':'A') ||
605 cfi_read_query(map,base + (adr+1)*ofs_factor) != (primary?'R':'L') ||
606 cfi_read_query(map,base + (adr+2)*ofs_factor) != (primary?'I':'T')) {
607 printk ("Invalid Extended Query Table at %4.4X: %2.2X %2.2X %2.2X\n",
608 adr,
609 cfi_read_query(map,base + adr*ofs_factor),
610 cfi_read_query(map,base + (adr+1)*ofs_factor),
611 cfi_read_query(map,base + (adr+2)*ofs_factor));
612 }
613 else {
614 printk(" Extended Query Table version %c.%c\n",
615 cfi_read_query(map,base + (adr+3)*ofs_factor),
616 cfi_read_query(map,base + (adr+4)*ofs_factor));
617 }
618 }
619 cfi_send_cmd(0xff, base, map, cfi);
620 }
621
622 static void check_cmd_set(struct map_info *map, int primary, unsigned long base)
623 {
624 struct cfi_private *cfi = map->fldrv_priv;
625 __u16 type = primary?cfi->cfiq->P_ID:cfi->cfiq->A_ID;
626
627 if (type == P_ID_NONE || type == P_ID_RESERVED)
628 return;
629 /* Put it in query mode */
630 cfi_qry_mode(map,base,cfi);
631
632 switch(type){
633 /* Urgh. Ifdefs. The version with weak symbols was
634 * _much_ nicer. Shame it didn't seem to work on
635 * anything but x86, really.
636 * But we can't rely in inter_module_get() because
637 * that'd mean we depend on link order.
638 */
639 #ifdef CONFIG_MTD_CFI_INTELEXT
640 case 0x0001:
641 case 0x0003:
642 return cfi_cmdset_0001(map, primary, base);
643 #endif
644 #ifdef CONFIG_MTD_CFI_AMDSTD
645 case 0x0002:
646 return cfi_cmdset_0002(map, primary, base);
647 #endif
648 }
649
650 return cfi_cmdset_unknown(map, primary, base);
651 }
652
653
654 #if LINUX_VERSION_CODE < 0x20212 && defined(MODULE)
655 #define cfi_probe_init init_module
656 #define cfi_probe_exit cleanup_module
657 #endif
658
659 mod_init_t cfi_probe_init(void)
660 {
661 register_mtd_chip_driver(&cfi_chipdrv);
662 return 0;
663 }
664
665 mod_exit_t cfi_probe_exit(void)
666 {
667 unregister_mtd_chip_driver(&cfi_chipdrv);
668 }
669
670 module_init(cfi_probe_init);
671 module_exit(cfi_probe_exit);
672