aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/chips
diff options
context:
space:
mode:
authorNicolas Pitre <nico@cam.org>2005-08-06 00:16:52 -0400
committerThomas Gleixner <tglx@mtd.linutronix.de>2005-11-06 14:10:19 -0500
commit4843653cab0db036399f77d9355db31ce39cb8b9 (patch)
tree0c9665509f2a1c1b66cd00ca170ec7b542446f5c /drivers/mtd/chips
parente27a9960af0506d84b9ca9dd3874b7d88901f230 (diff)
[MTD] cleanups to cfi_cmdset_0001
This includes improved error handling/reporting plus some other message cleanups. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'drivers/mtd/chips')
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0001.c127
1 files changed, 71 insertions, 56 deletions
diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
index 1e99dffcc6ae..308855e80f66 100644
--- a/drivers/mtd/chips/cfi_cmdset_0001.c
+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
@@ -4,7 +4,7 @@
4 * 4 *
5 * (C) 2000 Red Hat. GPL'd 5 * (C) 2000 Red Hat. GPL'd
6 * 6 *
7 * $Id: cfi_cmdset_0001.c,v 1.180 2005/07/20 21:01:13 tpoynor Exp $ 7 * $Id: cfi_cmdset_0001.c,v 1.181 2005/08/06 04:16:48 nico Exp $
8 * 8 *
9 * 9 *
10 * 10/10/2000 Nicolas Pitre <nico@cam.org> 10 * 10/10/2000 Nicolas Pitre <nico@cam.org>
@@ -438,7 +438,7 @@ static struct mtd_info *cfi_intelext_setup(struct mtd_info *mtd)
438 } 438 }
439 439
440 for (i=0; i<mtd->numeraseregions;i++){ 440 for (i=0; i<mtd->numeraseregions;i++){
441 printk(KERN_DEBUG "%d: offset=0x%x,size=0x%x,blocks=%d\n", 441 printk(KERN_DEBUG "erase region %d: offset=0x%x,size=0x%x,blocks=%d\n",
442 i,mtd->eraseregions[i].offset, 442 i,mtd->eraseregions[i].offset,
443 mtd->eraseregions[i].erasesize, 443 mtd->eraseregions[i].erasesize,
444 mtd->eraseregions[i].numblocks); 444 mtd->eraseregions[i].numblocks);
@@ -663,8 +663,8 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
663 break; 663 break;
664 664
665 if (time_after(jiffies, timeo)) { 665 if (time_after(jiffies, timeo)) {
666 printk(KERN_ERR "Waiting for chip to be ready timed out. Status %lx\n", 666 printk(KERN_ERR "%s: Waiting for chip to be ready timed out. Status %lx\n",
667 status.x[0]); 667 map->name, status.x[0]);
668 return -EIO; 668 return -EIO;
669 } 669 }
670 spin_unlock(chip->mutex); 670 spin_unlock(chip->mutex);
@@ -711,8 +711,8 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
711 map_write(map, CMD(0x70), adr); 711 map_write(map, CMD(0x70), adr);
712 chip->state = FL_ERASING; 712 chip->state = FL_ERASING;
713 chip->oldstate = FL_READY; 713 chip->oldstate = FL_READY;
714 printk(KERN_ERR "Chip not ready after erase " 714 printk(KERN_ERR "%s: Chip not ready after erase "
715 "suspended: status = 0x%lx\n", status.x[0]); 715 "suspended: status = 0x%lx\n", map->name, status.x[0]);
716 return -EIO; 716 return -EIO;
717 } 717 }
718 718
@@ -819,7 +819,7 @@ static void put_chip(struct map_info *map, struct flchip *chip, unsigned long ad
819 DISABLE_VPP(map); 819 DISABLE_VPP(map);
820 break; 820 break;
821 default: 821 default:
822 printk(KERN_ERR "put_chip() called with oldstate %d!!\n", chip->oldstate); 822 printk(KERN_ERR "%s: put_chip() called with oldstate %d!!\n", map->name, chip->oldstate);
823 } 823 }
824 wake_up(&chip->wq); 824 wake_up(&chip->wq);
825} 825}
@@ -1130,7 +1130,7 @@ static void cfi_intelext_unpoint (struct mtd_info *mtd, u_char *addr, loff_t fro
1130 if(chip->ref_point_counter == 0) 1130 if(chip->ref_point_counter == 0)
1131 chip->state = FL_READY; 1131 chip->state = FL_READY;
1132 } else 1132 } else
1133 printk(KERN_ERR "Warning: unpoint called on non pointed region\n"); /* Should this give an error? */ 1133 printk(KERN_ERR "%s: Warning: unpoint called on non pointed region\n", map->name); /* Should this give an error? */
1134 1134
1135 put_chip(map, chip, chip->start); 1135 put_chip(map, chip, chip->start);
1136 spin_unlock(chip->mutex); 1136 spin_unlock(chip->mutex);
@@ -1271,9 +1271,10 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
1271 1271
1272 /* OK Still waiting */ 1272 /* OK Still waiting */
1273 if (time_after(jiffies, timeo)) { 1273 if (time_after(jiffies, timeo)) {
1274 map_write(map, CMD(0x70), adr);
1274 chip->state = FL_STATUS; 1275 chip->state = FL_STATUS;
1275 xip_enable(map, chip, adr); 1276 xip_enable(map, chip, adr);
1276 printk(KERN_ERR "waiting for chip to be ready timed out in word write\n"); 1277 printk(KERN_ERR "%s: word write error (status timeout)\n", map->name);
1277 ret = -EIO; 1278 ret = -EIO;
1278 goto out; 1279 goto out;
1279 } 1280 }
@@ -1285,7 +1286,7 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
1285 if (!z) { 1286 if (!z) {
1286 chip->word_write_time--; 1287 chip->word_write_time--;
1287 if (!chip->word_write_time) 1288 if (!chip->word_write_time)
1288 chip->word_write_time++; 1289 chip->word_write_time = 1;
1289 } 1290 }
1290 if (z > 1) 1291 if (z > 1)
1291 chip->word_write_time++; 1292 chip->word_write_time++;
@@ -1293,19 +1294,31 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
1293 /* Done and happy. */ 1294 /* Done and happy. */
1294 chip->state = FL_STATUS; 1295 chip->state = FL_STATUS;
1295 1296
1296 /* check for lock bit */ 1297 /* check for errors */
1297 if (map_word_bitsset(map, status, CMD(0x02))) { 1298 if (map_word_bitsset(map, status, CMD(0x1a))) {
1298 /* clear status */ 1299 unsigned long chipstatus = MERGESTATUS(status);
1300
1301 /* reset status */
1299 map_write(map, CMD(0x50), adr); 1302 map_write(map, CMD(0x50), adr);
1300 /* put back into read status register mode */
1301 map_write(map, CMD(0x70), adr); 1303 map_write(map, CMD(0x70), adr);
1302 ret = -EROFS; 1304 xip_enable(map, chip, adr);
1305
1306 if (chipstatus & 0x02) {
1307 ret = -EROFS;
1308 } else if (chipstatus & 0x08) {
1309 printk(KERN_ERR "%s: word write error (bad VPP)\n", map->name);
1310 ret = -EIO;
1311 } else {
1312 printk(KERN_ERR "%s: word write error (status 0x%lx)\n", map->name, chipstatus);
1313 ret = -EINVAL;
1314 }
1315
1316 goto out;
1303 } 1317 }
1304 1318
1305 xip_enable(map, chip, adr); 1319 xip_enable(map, chip, adr);
1306 out: put_chip(map, chip, adr); 1320 out: put_chip(map, chip, adr);
1307 spin_unlock(chip->mutex); 1321 spin_unlock(chip->mutex);
1308
1309 return ret; 1322 return ret;
1310} 1323}
1311 1324
@@ -1456,8 +1469,8 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1456 map_write(map, CMD(0x50), cmd_adr); 1469 map_write(map, CMD(0x50), cmd_adr);
1457 map_write(map, CMD(0x70), cmd_adr); 1470 map_write(map, CMD(0x70), cmd_adr);
1458 xip_enable(map, chip, cmd_adr); 1471 xip_enable(map, chip, cmd_adr);
1459 printk(KERN_ERR "Chip not ready for buffer write. status = %lx, Xstatus = %lx\n", 1472 printk(KERN_ERR "%s: Chip not ready for buffer write. status = %lx, Xstatus = %lx\n",
1460 status.x[0], Xstatus.x[0]); 1473 map->name, status.x[0], Xstatus.x[0]);
1461 ret = -EIO; 1474 ret = -EIO;
1462 goto out; 1475 goto out;
1463 } 1476 }
@@ -1516,9 +1529,10 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1516 1529
1517 /* OK Still waiting */ 1530 /* OK Still waiting */
1518 if (time_after(jiffies, timeo)) { 1531 if (time_after(jiffies, timeo)) {
1532 map_write(map, CMD(0x70), cmd_adr);
1519 chip->state = FL_STATUS; 1533 chip->state = FL_STATUS;
1520 xip_enable(map, chip, cmd_adr); 1534 xip_enable(map, chip, cmd_adr);
1521 printk(KERN_ERR "waiting for chip to be ready timed out in bufwrite\n"); 1535 printk(KERN_ERR "%s: buffer write error (status timeout)\n", map->name);
1522 ret = -EIO; 1536 ret = -EIO;
1523 goto out; 1537 goto out;
1524 } 1538 }
@@ -1530,7 +1544,7 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1530 if (!z) { 1544 if (!z) {
1531 chip->buffer_write_time--; 1545 chip->buffer_write_time--;
1532 if (!chip->buffer_write_time) 1546 if (!chip->buffer_write_time)
1533 chip->buffer_write_time++; 1547 chip->buffer_write_time = 1;
1534 } 1548 }
1535 if (z > 1) 1549 if (z > 1)
1536 chip->buffer_write_time++; 1550 chip->buffer_write_time++;
@@ -1538,13 +1552,26 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1538 /* Done and happy. */ 1552 /* Done and happy. */
1539 chip->state = FL_STATUS; 1553 chip->state = FL_STATUS;
1540 1554
1541 /* check for lock bit */ 1555 /* check for errors */
1542 if (map_word_bitsset(map, status, CMD(0x02))) { 1556 if (map_word_bitsset(map, status, CMD(0x1a))) {
1543 /* clear status */ 1557 unsigned long chipstatus = MERGESTATUS(status);
1558
1559 /* reset status */
1544 map_write(map, CMD(0x50), cmd_adr); 1560 map_write(map, CMD(0x50), cmd_adr);
1545 /* put back into read status register mode */ 1561 map_write(map, CMD(0x70), cmd_adr);
1546 map_write(map, CMD(0x70), adr); 1562 xip_enable(map, chip, cmd_adr);
1547 ret = -EROFS; 1563
1564 if (chipstatus & 0x02) {
1565 ret = -EROFS;
1566 } else if (chipstatus & 0x08) {
1567 printk(KERN_ERR "%s: buffer write error (bad VPP)\n", map->name);
1568 ret = -EIO;
1569 } else {
1570 printk(KERN_ERR "%s: buffer write error (status 0x%lx)\n", map->name, chipstatus);
1571 ret = -EINVAL;
1572 }
1573
1574 goto out;
1548 } 1575 }
1549 1576
1550 xip_enable(map, chip, cmd_adr); 1577 xip_enable(map, chip, cmd_adr);
@@ -1685,16 +1712,10 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
1685 1712
1686 /* OK Still waiting */ 1713 /* OK Still waiting */
1687 if (time_after(jiffies, timeo)) { 1714 if (time_after(jiffies, timeo)) {
1688 map_word Xstatus;
1689 map_write(map, CMD(0x70), adr); 1715 map_write(map, CMD(0x70), adr);
1690 chip->state = FL_STATUS; 1716 chip->state = FL_STATUS;
1691 Xstatus = map_read(map, adr);
1692 /* Clear status bits */
1693 map_write(map, CMD(0x50), adr);
1694 map_write(map, CMD(0x70), adr);
1695 xip_enable(map, chip, adr); 1717 xip_enable(map, chip, adr);
1696 printk(KERN_ERR "waiting for erase at %08lx to complete timed out. status = %lx, Xstatus = %lx.\n", 1718 printk(KERN_ERR "%s: block erase error: (status timeout)\n", map->name);
1697 adr, status.x[0], Xstatus.x[0]);
1698 ret = -EIO; 1719 ret = -EIO;
1699 goto out; 1720 goto out;
1700 } 1721 }
@@ -1708,43 +1729,40 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
1708 chip->state = FL_STATUS; 1729 chip->state = FL_STATUS;
1709 status = map_read(map, adr); 1730 status = map_read(map, adr);
1710 1731
1711 /* check for lock bit */ 1732 /* check for errors */
1712 if (map_word_bitsset(map, status, CMD(0x3a))) { 1733 if (map_word_bitsset(map, status, CMD(0x3a))) {
1713 unsigned long chipstatus; 1734 unsigned long chipstatus = MERGESTATUS(status);
1714 1735
1715 /* Reset the error bits */ 1736 /* Reset the error bits */
1716 map_write(map, CMD(0x50), adr); 1737 map_write(map, CMD(0x50), adr);
1717 map_write(map, CMD(0x70), adr); 1738 map_write(map, CMD(0x70), adr);
1718 xip_enable(map, chip, adr); 1739 xip_enable(map, chip, adr);
1719 1740
1720 chipstatus = MERGESTATUS(status);
1721
1722 if ((chipstatus & 0x30) == 0x30) { 1741 if ((chipstatus & 0x30) == 0x30) {
1723 printk(KERN_NOTICE "Chip reports improper command sequence: status 0x%lx\n", chipstatus); 1742 printk(KERN_ERR "%s: block erase error: (bad command sequence, status 0x%lx)\n", map->name, chipstatus);
1724 ret = -EIO; 1743 ret = -EINVAL;
1725 } else if (chipstatus & 0x02) { 1744 } else if (chipstatus & 0x02) {
1726 /* Protection bit set */ 1745 /* Protection bit set */
1727 ret = -EROFS; 1746 ret = -EROFS;
1728 } else if (chipstatus & 0x8) { 1747 } else if (chipstatus & 0x8) {
1729 /* Voltage */ 1748 /* Voltage */
1730 printk(KERN_WARNING "Chip reports voltage low on erase: status 0x%lx\n", chipstatus); 1749 printk(KERN_ERR "%s: block erase error: (bad VPP)\n", map->name);
1731 ret = -EIO; 1750 ret = -EIO;
1732 } else if (chipstatus & 0x20) { 1751 } else if (chipstatus & 0x20 && retries--) {
1733 if (retries--) { 1752 printk(KERN_DEBUG "block erase failed at 0x%08lx: status 0x%lx. Retrying...\n", adr, chipstatus);
1734 printk(KERN_DEBUG "Chip erase failed at 0x%08lx: status 0x%lx. Retrying...\n", adr, chipstatus); 1753 timeo = jiffies + HZ;
1735 timeo = jiffies + HZ; 1754 put_chip(map, chip, adr);
1736 put_chip(map, chip, adr); 1755 spin_unlock(chip->mutex);
1737 spin_unlock(chip->mutex); 1756 goto retry;
1738 goto retry; 1757 } else {
1739 } 1758 printk(KERN_ERR "%s: block erase failed at 0x%08lx (status 0x%lx)\n", map->name, adr, chipstatus);
1740 printk(KERN_DEBUG "Chip erase failed at 0x%08lx: status 0x%lx\n", adr, chipstatus);
1741 ret = -EIO; 1759 ret = -EIO;
1742 } 1760 }
1743 } else { 1761
1744 xip_enable(map, chip, adr); 1762 goto out;
1745 ret = 0;
1746 } 1763 }
1747 1764
1765 xip_enable(map, chip, adr);
1748 out: put_chip(map, chip, adr); 1766 out: put_chip(map, chip, adr);
1749 spin_unlock(chip->mutex); 1767 spin_unlock(chip->mutex);
1750 return ret; 1768 return ret;
@@ -1887,13 +1905,10 @@ static int __xipram do_xxlock_oneblock(struct map_info *map, struct flchip *chip
1887 1905
1888 /* OK Still waiting */ 1906 /* OK Still waiting */
1889 if (time_after(jiffies, timeo)) { 1907 if (time_after(jiffies, timeo)) {
1890 map_word Xstatus;
1891 map_write(map, CMD(0x70), adr); 1908 map_write(map, CMD(0x70), adr);
1892 chip->state = FL_STATUS; 1909 chip->state = FL_STATUS;
1893 Xstatus = map_read(map, adr);
1894 xip_enable(map, chip, adr); 1910 xip_enable(map, chip, adr);
1895 printk(KERN_ERR "waiting for unlock to complete timed out. status = %lx, Xstatus = %lx.\n", 1911 printk(KERN_ERR "%s: block unlock error: (status timeout)\n", map->name);
1896 status.x[0], Xstatus.x[0]);
1897 put_chip(map, chip, adr); 1912 put_chip(map, chip, adr);
1898 spin_unlock(chip->mutex); 1913 spin_unlock(chip->mutex);
1899 return -EIO; 1914 return -EIO;