aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/devices
diff options
context:
space:
mode:
authorMichael Hennerich <michael.hennerich@analog.com>2008-06-03 00:26:05 -0400
committerDavid Woodhouse <dwmw2@infradead.org>2008-06-04 12:39:38 -0400
commite9d42227bdc96238676bd28feca5815fcff2d6a8 (patch)
tree7d33aa53ac632066501ae91ffeba21844c5bf4ea /drivers/mtd/devices
parent856613c98c2f864994d5fb33a62b7a468f68ab9b (diff)
[MTD] DataFlash: fix bug - ATMEL AT45DF321D spi flash card fails to be copied to (v2)
- Add support for binary page size DataFlashes. - The driver now prints out pagesize and erasesize. Printout valuable information for creating flash filesystems. Signed-off-by: Michael Hennerich <michael.hennerich@analog.com> Cc: David Brownell <david-b@pacbell.net> Signed-off-by: Bryan Wu <cooloney@kernel.org> Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Diffstat (limited to 'drivers/mtd/devices')
-rw-r--r--drivers/mtd/devices/mtd_dataflash.c117
1 files changed, 112 insertions, 5 deletions
diff --git a/drivers/mtd/devices/mtd_dataflash.c b/drivers/mtd/devices/mtd_dataflash.c
index b35e4813a3a5..acc3728872e3 100644
--- a/drivers/mtd/devices/mtd_dataflash.c
+++ b/drivers/mtd/devices/mtd_dataflash.c
@@ -487,7 +487,9 @@ add_dataflash(struct spi_device *spi, char *name,
487 device->write = dataflash_write; 487 device->write = dataflash_write;
488 device->priv = priv; 488 device->priv = priv;
489 489
490 dev_info(&spi->dev, "%s (%d KBytes)\n", name, device->size/1024); 490 dev_info(&spi->dev, "%s (%d KBytes) pagesize %d bytes, "
491 "erasesize %d bytes\n", name, device->size/1024,
492 pagesize, pagesize * 8); /* 8 pages = 1 block */
491 dev_set_drvdata(&spi->dev, priv); 493 dev_set_drvdata(&spi->dev, priv);
492 494
493 if (mtd_has_partitions()) { 495 if (mtd_has_partitions()) {
@@ -521,7 +523,7 @@ add_dataflash(struct spi_device *spi, char *name,
521 * 523 *
522 * Device Density ID code #Pages PageSize Offset 524 * Device Density ID code #Pages PageSize Offset
523 * AT45DB011B 1Mbit (128K) xx0011xx (0x0c) 512 264 9 525 * AT45DB011B 1Mbit (128K) xx0011xx (0x0c) 512 264 9
524 * AT45DB021B 2Mbit (256K) xx0101xx (0x14) 1025 264 9 526 * AT45DB021B 2Mbit (256K) xx0101xx (0x14) 1024 264 9
525 * AT45DB041B 4Mbit (512K) xx0111xx (0x1c) 2048 264 9 527 * AT45DB041B 4Mbit (512K) xx0111xx (0x1c) 2048 264 9
526 * AT45DB081B 8Mbit (1M) xx1001xx (0x24) 4096 264 9 528 * AT45DB081B 8Mbit (1M) xx1001xx (0x24) 4096 264 9
527 * AT45DB0161B 16Mbit (2M) xx1011xx (0x2c) 4096 528 10 529 * AT45DB0161B 16Mbit (2M) xx1011xx (0x2c) 4096 528 10
@@ -529,9 +531,114 @@ add_dataflash(struct spi_device *spi, char *name,
529 * AT45DB0642 64Mbit (8M) xx111xxx (0x3c) 8192 1056 11 531 * AT45DB0642 64Mbit (8M) xx111xxx (0x3c) 8192 1056 11
530 * AT45DB1282 128Mbit (16M) xx0100xx (0x10) 16384 1056 11 532 * AT45DB1282 128Mbit (16M) xx0100xx (0x10) 16384 1056 11
531 */ 533 */
534
535struct flash_info {
536 char *name;
537
538 /* JEDEC id zero means "no ID" (most older chips); otherwise it has
539 * a high byte of zero plus three data bytes: the manufacturer id,
540 * then a two byte device id.
541 */
542 u32 jedec_id;
543
544 /* The size listed here is what works with OPCODE_SE, which isn't
545 * necessarily called a "sector" by the vendor.
546 */
547 unsigned nr_pages;
548 u16 pagesize;
549 u16 pageoffset;
550
551 u16 flags;
552#define SUP_POW2PS 0x02
553#define IS_POW2PS 0x01
554};
555
556static struct flash_info __devinitdata dataflash_data [] = {
557
558 { "at45db011d", 0x1f2200, 512, 264, 9, SUP_POW2PS},
559 { "at45db011d", 0x1f2200, 512, 256, 8, SUP_POW2PS | IS_POW2PS},
560
561 { "at45db021d", 0x1f2300, 1024, 264, 9, SUP_POW2PS},
562 { "at45db021d", 0x1f2300, 1024, 256, 8, SUP_POW2PS | IS_POW2PS},
563
564 { "at45db041d", 0x1f2400, 2048, 264, 9, SUP_POW2PS},
565 { "at45db041d", 0x1f2400, 2048, 256, 8, SUP_POW2PS | IS_POW2PS},
566
567 { "at45db081d", 0x1f2500, 4096, 264, 9, SUP_POW2PS},
568 { "at45db081d", 0x1f2500, 4096, 256, 8, SUP_POW2PS | IS_POW2PS},
569
570 { "at45db161d", 0x1f2600, 4096, 528, 10, SUP_POW2PS},
571 { "at45db161d", 0x1f2600, 4096, 512, 9, SUP_POW2PS | IS_POW2PS},
572
573 { "at45db321c", 0x1f2700, 8192, 528, 10, },
574
575 { "at45db321d", 0x1f2701, 8192, 528, 10, SUP_POW2PS},
576 { "at45db321d", 0x1f2701, 8192, 512, 9, SUP_POW2PS | IS_POW2PS},
577
578 { "at45db641d", 0x1f2800, 8192, 1056, 11, SUP_POW2PS},
579 { "at45db641d", 0x1f2800, 8192, 1024, 10, SUP_POW2PS | IS_POW2PS},
580};
581
582static struct flash_info *__devinit jedec_probe(struct spi_device *spi)
583{
584 int tmp;
585 u8 code = OP_READ_ID;
586 u8 id[3];
587 u32 jedec;
588 struct flash_info *info;
589 int status;
590
591
592 /* JEDEC also defines an optional "extended device information"
593 * string for after vendor-specific data, after the three bytes
594 * we use here. Supporting some chips might require using it.
595 */
596 tmp = spi_write_then_read(spi, &code, 1, id, 3);
597 if (tmp < 0) {
598 DEBUG(MTD_DEBUG_LEVEL0, "%s: error %d reading JEDEC ID\n",
599 spi->dev.bus_id, tmp);
600 return NULL;
601 }
602 jedec = id[0];
603 jedec = jedec << 8;
604 jedec |= id[1];
605 jedec = jedec << 8;
606 jedec |= id[2];
607
608 for (tmp = 0, info = dataflash_data;
609 tmp < ARRAY_SIZE(dataflash_data);
610 tmp++, info++) {
611 if (info->jedec_id == jedec) {
612 if (info->flags & SUP_POW2PS) {
613 status = dataflash_status(spi);
614 if (status & 0x1)
615 /* return power of 2 pagesize */
616 return ++info;
617 else
618 return info;
619 }
620 }
621 }
622 return NULL;
623}
624
532static int __devinit dataflash_probe(struct spi_device *spi) 625static int __devinit dataflash_probe(struct spi_device *spi)
533{ 626{
534 int status; 627 int status;
628 struct flash_info *info;
629
630 /*
631 * Try to detect dataflash by JEDEC ID.
632 * If it succeeds we know we have either a C or D part.
633 * D will support power of 2 pagesize option.
634 */
635
636 info = jedec_probe(spi);
637
638 if (info != NULL)
639 return add_dataflash(spi, info->name, info->nr_pages,
640 info->pagesize, info->pageoffset);
641
535 642
536 status = dataflash_status(spi); 643 status = dataflash_status(spi);
537 if (status <= 0 || status == 0xff) { 644 if (status <= 0 || status == 0xff) {
@@ -551,16 +658,16 @@ static int __devinit dataflash_probe(struct spi_device *spi)
551 status = add_dataflash(spi, "AT45DB011B", 512, 264, 9); 658 status = add_dataflash(spi, "AT45DB011B", 512, 264, 9);
552 break; 659 break;
553 case 0x14: /* 0 1 0 1 x x */ 660 case 0x14: /* 0 1 0 1 x x */
554 status = add_dataflash(spi, "AT45DB021B", 1025, 264, 9); 661 status = add_dataflash(spi, "AT45DB021B", 1024, 264, 9);
555 break; 662 break;
556 case 0x1c: /* 0 1 1 1 x x */ 663 case 0x1c: /* 0 1 1 1 x x */
557 status = add_dataflash(spi, "AT45DB041x", 2048, 264, 9); 664 status = add_dataflash(spi, "AT45DB041B", 2048, 264, 9);
558 break; 665 break;
559 case 0x24: /* 1 0 0 1 x x */ 666 case 0x24: /* 1 0 0 1 x x */
560 status = add_dataflash(spi, "AT45DB081B", 4096, 264, 9); 667 status = add_dataflash(spi, "AT45DB081B", 4096, 264, 9);
561 break; 668 break;
562 case 0x2c: /* 1 0 1 1 x x */ 669 case 0x2c: /* 1 0 1 1 x x */
563 status = add_dataflash(spi, "AT45DB161x", 4096, 528, 10); 670 status = add_dataflash(spi, "AT45DB161B", 4096, 528, 10);
564 break; 671 break;
565 case 0x34: /* 1 1 0 1 x x */ 672 case 0x34: /* 1 1 0 1 x x */
566 status = add_dataflash(spi, "AT45DB321x", 8192, 528, 10); 673 status = add_dataflash(spi, "AT45DB321x", 8192, 528, 10);