Skip to content

Commit 4843653

Browse files
Nicolas PitreThomas Gleixner
authored andcommitted
[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>
1 parent e27a996 commit 4843653

1 file changed

Lines changed: 71 additions & 56 deletions

File tree

‎drivers/mtd/chips/cfi_cmdset_0001.c‎

Lines changed: 71 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* (C) 2000 Red Hat. GPL'd
66
*
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 $
88
*
99
*
1010
* 10/10/2000 Nicolas Pitre <nico@cam.org>
@@ -438,7 +438,7 @@ static struct mtd_info *cfi_intelext_setup(struct mtd_info *mtd)
438438
}
439439

440440
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",
442442
i,mtd->eraseregions[i].offset,
443443
mtd->eraseregions[i].erasesize,
444444
mtd->eraseregions[i].numblocks);
@@ -663,8 +663,8 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
663663
break;
664664

665665
if (time_after(jiffies, timeo)) {
666-
printk(KERN_ERR "Waiting for chip to be ready timed out. Status %lx\n",
667-
status.x[0]);
666+
printk(KERN_ERR "%s: Waiting for chip to be ready timed out. Status %lx\n",
667+
map->name, status.x[0]);
668668
return -EIO;
669669
}
670670
spin_unlock(chip->mutex);
@@ -711,8 +711,8 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
711711
map_write(map, CMD(0x70), adr);
712712
chip->state = FL_ERASING;
713713
chip->oldstate = FL_READY;
714-
printk(KERN_ERR "Chip not ready after erase "
715-
"suspended: status = 0x%lx\n", status.x[0]);
714+
printk(KERN_ERR "%s: Chip not ready after erase "
715+
"suspended: status = 0x%lx\n", map->name, status.x[0]);
716716
return -EIO;
717717
}
718718

@@ -819,7 +819,7 @@ static void put_chip(struct map_info *map, struct flchip *chip, unsigned long ad
819819
DISABLE_VPP(map);
820820
break;
821821
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);
823823
}
824824
wake_up(&chip->wq);
825825
}
@@ -1130,7 +1130,7 @@ static void cfi_intelext_unpoint (struct mtd_info *mtd, u_char *addr, loff_t fro
11301130
if(chip->ref_point_counter == 0)
11311131
chip->state = FL_READY;
11321132
} 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? */
11341134

11351135
put_chip(map, chip, chip->start);
11361136
spin_unlock(chip->mutex);
@@ -1271,9 +1271,10 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
12711271

12721272
/* OK Still waiting */
12731273
if (time_after(jiffies, timeo)) {
1274+
map_write(map, CMD(0x70), adr);
12741275
chip->state = FL_STATUS;
12751276
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);
12771278
ret = -EIO;
12781279
goto out;
12791280
}
@@ -1285,27 +1286,39 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
12851286
if (!z) {
12861287
chip->word_write_time--;
12871288
if (!chip->word_write_time)
1288-
chip->word_write_time++;
1289+
chip->word_write_time = 1;
12891290
}
12901291
if (z > 1)
12911292
chip->word_write_time++;
12921293

12931294
/* Done and happy. */
12941295
chip->state = FL_STATUS;
12951296

1296-
/* check for lock bit */
1297-
if (map_word_bitsset(map, status, CMD(0x02))) {
1298-
/* clear status */
1297+
/* check for errors */
1298+
if (map_word_bitsset(map, status, CMD(0x1a))) {
1299+
unsigned long chipstatus = MERGESTATUS(status);
1300+
1301+
/* reset status */
12991302
map_write(map, CMD(0x50), adr);
1300-
/* put back into read status register mode */
13011303
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;
13031317
}
13041318

13051319
xip_enable(map, chip, adr);
13061320
out: put_chip(map, chip, adr);
13071321
spin_unlock(chip->mutex);
1308-
13091322
return ret;
13101323
}
13111324

@@ -1456,8 +1469,8 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
14561469
map_write(map, CMD(0x50), cmd_adr);
14571470
map_write(map, CMD(0x70), cmd_adr);
14581471
xip_enable(map, chip, cmd_adr);
1459-
printk(KERN_ERR "Chip not ready for buffer write. status = %lx, Xstatus = %lx\n",
1460-
status.x[0], Xstatus.x[0]);
1472+
printk(KERN_ERR "%s: Chip not ready for buffer write. status = %lx, Xstatus = %lx\n",
1473+
map->name, status.x[0], Xstatus.x[0]);
14611474
ret = -EIO;
14621475
goto out;
14631476
}
@@ -1516,9 +1529,10 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
15161529

15171530
/* OK Still waiting */
15181531
if (time_after(jiffies, timeo)) {
1532+
map_write(map, CMD(0x70), cmd_adr);
15191533
chip->state = FL_STATUS;
15201534
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);
15221536
ret = -EIO;
15231537
goto out;
15241538
}
@@ -1530,21 +1544,34 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
15301544
if (!z) {
15311545
chip->buffer_write_time--;
15321546
if (!chip->buffer_write_time)
1533-
chip->buffer_write_time++;
1547+
chip->buffer_write_time = 1;
15341548
}
15351549
if (z > 1)
15361550
chip->buffer_write_time++;
15371551

15381552
/* Done and happy. */
15391553
chip->state = FL_STATUS;
15401554

1541-
/* check for lock bit */
1542-
if (map_word_bitsset(map, status, CMD(0x02))) {
1543-
/* clear status */
1555+
/* check for errors */
1556+
if (map_word_bitsset(map, status, CMD(0x1a))) {
1557+
unsigned long chipstatus = MERGESTATUS(status);
1558+
1559+
/* reset status */
15441560
map_write(map, CMD(0x50), cmd_adr);
1545-
/* put back into read status register mode */
1546-
map_write(map, CMD(0x70), adr);
1547-
ret = -EROFS;
1561+
map_write(map, CMD(0x70), cmd_adr);
1562+
xip_enable(map, chip, cmd_adr);
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;
15481575
}
15491576

15501577
xip_enable(map, chip, cmd_adr);
@@ -1685,16 +1712,10 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
16851712

16861713
/* OK Still waiting */
16871714
if (time_after(jiffies, timeo)) {
1688-
map_word Xstatus;
16891715
map_write(map, CMD(0x70), adr);
16901716
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);
16951717
xip_enable(map, chip, adr);
1696-
printk(KERN_ERR "waiting for erase at %08lx to complete timed out. status = %lx, Xstatus = %lx.\n",
1697-
adr, status.x[0], Xstatus.x[0]);
1718+
printk(KERN_ERR "%s: block erase error: (status timeout)\n", map->name);
16981719
ret = -EIO;
16991720
goto out;
17001721
}
@@ -1708,43 +1729,40 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
17081729
chip->state = FL_STATUS;
17091730
status = map_read(map, adr);
17101731

1711-
/* check for lock bit */
1732+
/* check for errors */
17121733
if (map_word_bitsset(map, status, CMD(0x3a))) {
1713-
unsigned long chipstatus;
1734+
unsigned long chipstatus = MERGESTATUS(status);
17141735

17151736
/* Reset the error bits */
17161737
map_write(map, CMD(0x50), adr);
17171738
map_write(map, CMD(0x70), adr);
17181739
xip_enable(map, chip, adr);
17191740

1720-
chipstatus = MERGESTATUS(status);
1721-
17221741
if ((chipstatus & 0x30) == 0x30) {
1723-
printk(KERN_NOTICE "Chip reports improper command sequence: status 0x%lx\n", chipstatus);
1724-
ret = -EIO;
1742+
printk(KERN_ERR "%s: block erase error: (bad command sequence, status 0x%lx)\n", map->name, chipstatus);
1743+
ret = -EINVAL;
17251744
} else if (chipstatus & 0x02) {
17261745
/* Protection bit set */
17271746
ret = -EROFS;
17281747
} else if (chipstatus & 0x8) {
17291748
/* 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);
17311750
ret = -EIO;
1732-
} else if (chipstatus & 0x20) {
1733-
if (retries--) {
1734-
printk(KERN_DEBUG "Chip erase failed at 0x%08lx: status 0x%lx. Retrying...\n", adr, chipstatus);
1735-
timeo = jiffies + HZ;
1736-
put_chip(map, chip, adr);
1737-
spin_unlock(chip->mutex);
1738-
goto retry;
1739-
}
1740-
printk(KERN_DEBUG "Chip erase failed at 0x%08lx: status 0x%lx\n", adr, chipstatus);
1751+
} else if (chipstatus & 0x20 && retries--) {
1752+
printk(KERN_DEBUG "block erase failed at 0x%08lx: status 0x%lx. Retrying...\n", adr, chipstatus);
1753+
timeo = jiffies + HZ;
1754+
put_chip(map, chip, adr);
1755+
spin_unlock(chip->mutex);
1756+
goto retry;
1757+
} else {
1758+
printk(KERN_ERR "%s: block erase failed at 0x%08lx (status 0x%lx)\n", map->name, adr, chipstatus);
17411759
ret = -EIO;
17421760
}
1743-
} else {
1744-
xip_enable(map, chip, adr);
1745-
ret = 0;
1761+
1762+
goto out;
17461763
}
17471764

1765+
xip_enable(map, chip, adr);
17481766
out: put_chip(map, chip, adr);
17491767
spin_unlock(chip->mutex);
17501768
return ret;
@@ -1887,13 +1905,10 @@ static int __xipram do_xxlock_oneblock(struct map_info *map, struct flchip *chip
18871905

18881906
/* OK Still waiting */
18891907
if (time_after(jiffies, timeo)) {
1890-
map_word Xstatus;
18911908
map_write(map, CMD(0x70), adr);
18921909
chip->state = FL_STATUS;
1893-
Xstatus = map_read(map, adr);
18941910
xip_enable(map, chip, adr);
1895-
printk(KERN_ERR "waiting for unlock to complete timed out. status = %lx, Xstatus = %lx.\n",
1896-
status.x[0], Xstatus.x[0]);
1911+
printk(KERN_ERR "%s: block unlock error: (status timeout)\n", map->name);
18971912
put_chip(map, chip, adr);
18981913
spin_unlock(chip->mutex);
18991914
return -EIO;

0 commit comments

Comments
 (0)