.. | .. |
---|
49 | 49 | #define SST49LF008A 0x005a |
---|
50 | 50 | #define AT49BV6416 0x00d6 |
---|
51 | 51 | |
---|
| 52 | +/* |
---|
| 53 | + * Status Register bit description. Used by flash devices that don't |
---|
| 54 | + * support DQ polling (e.g. HyperFlash) |
---|
| 55 | + */ |
---|
| 56 | +#define CFI_SR_DRB BIT(7) |
---|
| 57 | +#define CFI_SR_ESB BIT(5) |
---|
| 58 | +#define CFI_SR_PSB BIT(4) |
---|
| 59 | +#define CFI_SR_WBASB BIT(3) |
---|
| 60 | +#define CFI_SR_SLSB BIT(1) |
---|
| 61 | + |
---|
| 62 | +enum cfi_quirks { |
---|
| 63 | + CFI_QUIRK_DQ_TRUE_DATA = BIT(0), |
---|
| 64 | +}; |
---|
| 65 | + |
---|
52 | 66 | static int cfi_amdstd_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *); |
---|
53 | 67 | static int cfi_amdstd_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *); |
---|
| 68 | +#if !FORCE_WORD_WRITE |
---|
54 | 69 | static int cfi_amdstd_write_buffers(struct mtd_info *, loff_t, size_t, size_t *, const u_char *); |
---|
| 70 | +#endif |
---|
55 | 71 | static int cfi_amdstd_erase_chip(struct mtd_info *, struct erase_info *); |
---|
56 | 72 | static int cfi_amdstd_erase_varsize(struct mtd_info *, struct erase_info *); |
---|
57 | 73 | static void cfi_amdstd_sync (struct mtd_info *); |
---|
.. | .. |
---|
97 | 113 | .module = THIS_MODULE |
---|
98 | 114 | }; |
---|
99 | 115 | |
---|
| 116 | +/* |
---|
| 117 | + * Use status register to poll for Erase/write completion when DQ is not |
---|
| 118 | + * supported. This is indicated by Bit[1:0] of SoftwareFeatures field in |
---|
| 119 | + * CFI Primary Vendor-Specific Extended Query table 1.5 |
---|
| 120 | + */ |
---|
| 121 | +static int cfi_use_status_reg(struct cfi_private *cfi) |
---|
| 122 | +{ |
---|
| 123 | + struct cfi_pri_amdstd *extp = cfi->cmdset_priv; |
---|
| 124 | + u8 poll_mask = CFI_POLL_STATUS_REG | CFI_POLL_DQ; |
---|
| 125 | + |
---|
| 126 | + return extp && extp->MinorVersion >= '5' && |
---|
| 127 | + (extp->SoftwareFeatures & poll_mask) == CFI_POLL_STATUS_REG; |
---|
| 128 | +} |
---|
| 129 | + |
---|
| 130 | +static int cfi_check_err_status(struct map_info *map, struct flchip *chip, |
---|
| 131 | + unsigned long adr) |
---|
| 132 | +{ |
---|
| 133 | + struct cfi_private *cfi = map->fldrv_priv; |
---|
| 134 | + map_word status; |
---|
| 135 | + |
---|
| 136 | + if (!cfi_use_status_reg(cfi)) |
---|
| 137 | + return 0; |
---|
| 138 | + |
---|
| 139 | + cfi_send_gen_cmd(0x70, cfi->addr_unlock1, chip->start, map, cfi, |
---|
| 140 | + cfi->device_type, NULL); |
---|
| 141 | + status = map_read(map, adr); |
---|
| 142 | + |
---|
| 143 | + /* The error bits are invalid while the chip's busy */ |
---|
| 144 | + if (!map_word_bitsset(map, status, CMD(CFI_SR_DRB))) |
---|
| 145 | + return 0; |
---|
| 146 | + |
---|
| 147 | + if (map_word_bitsset(map, status, CMD(0x3a))) { |
---|
| 148 | + unsigned long chipstatus = MERGESTATUS(status); |
---|
| 149 | + |
---|
| 150 | + if (chipstatus & CFI_SR_ESB) |
---|
| 151 | + pr_err("%s erase operation failed, status %lx\n", |
---|
| 152 | + map->name, chipstatus); |
---|
| 153 | + if (chipstatus & CFI_SR_PSB) |
---|
| 154 | + pr_err("%s program operation failed, status %lx\n", |
---|
| 155 | + map->name, chipstatus); |
---|
| 156 | + if (chipstatus & CFI_SR_WBASB) |
---|
| 157 | + pr_err("%s buffer program command aborted, status %lx\n", |
---|
| 158 | + map->name, chipstatus); |
---|
| 159 | + if (chipstatus & CFI_SR_SLSB) |
---|
| 160 | + pr_err("%s sector write protected, status %lx\n", |
---|
| 161 | + map->name, chipstatus); |
---|
| 162 | + |
---|
| 163 | + /* Erase/Program status bits are set on the operation failure */ |
---|
| 164 | + if (chipstatus & (CFI_SR_ESB | CFI_SR_PSB)) |
---|
| 165 | + return 1; |
---|
| 166 | + } |
---|
| 167 | + return 0; |
---|
| 168 | +} |
---|
100 | 169 | |
---|
101 | 170 | /* #define DEBUG_CFI_FEATURES */ |
---|
102 | 171 | |
---|
.. | .. |
---|
202 | 271 | } |
---|
203 | 272 | #endif |
---|
204 | 273 | |
---|
| 274 | +#if !FORCE_WORD_WRITE |
---|
205 | 275 | static void fixup_use_write_buffers(struct mtd_info *mtd) |
---|
206 | 276 | { |
---|
207 | 277 | struct map_info *map = mtd->priv; |
---|
.. | .. |
---|
211 | 281 | mtd->_write = cfi_amdstd_write_buffers; |
---|
212 | 282 | } |
---|
213 | 283 | } |
---|
| 284 | +#endif /* !FORCE_WORD_WRITE */ |
---|
214 | 285 | |
---|
215 | 286 | /* Atmel chips don't use the same PRI format as AMD chips */ |
---|
216 | 287 | static void fixup_convert_atmel_pri(struct mtd_info *mtd) |
---|
.. | .. |
---|
365 | 436 | mtd->name); |
---|
366 | 437 | } |
---|
367 | 438 | |
---|
| 439 | +static void fixup_quirks(struct mtd_info *mtd) |
---|
| 440 | +{ |
---|
| 441 | + struct map_info *map = mtd->priv; |
---|
| 442 | + struct cfi_private *cfi = map->fldrv_priv; |
---|
| 443 | + |
---|
| 444 | + if (cfi->mfr == CFI_MFR_AMD && cfi->id == 0x0c01) |
---|
| 445 | + cfi->quirks |= CFI_QUIRK_DQ_TRUE_DATA; |
---|
| 446 | +} |
---|
| 447 | + |
---|
368 | 448 | /* Used to fix CFI-Tables of chips without Extended Query Tables */ |
---|
369 | 449 | static struct cfi_fixup cfi_nopri_fixup_table[] = { |
---|
370 | 450 | { CFI_MFR_SST, 0x234a, fixup_sst39vf }, /* SST39VF1602 */ |
---|
.. | .. |
---|
403 | 483 | #if !FORCE_WORD_WRITE |
---|
404 | 484 | { CFI_MFR_ANY, CFI_ID_ANY, fixup_use_write_buffers }, |
---|
405 | 485 | #endif |
---|
| 486 | + { CFI_MFR_ANY, CFI_ID_ANY, fixup_quirks }, |
---|
406 | 487 | { 0, 0, NULL } |
---|
407 | 488 | }; |
---|
408 | 489 | static struct cfi_fixup jedec_fixup_table[] = { |
---|
.. | .. |
---|
731 | 812 | } |
---|
732 | 813 | |
---|
733 | 814 | /* |
---|
734 | | - * Return true if the chip is ready. |
---|
735 | | - * |
---|
736 | | - * Ready is one of: read mode, query mode, erase-suspend-read mode (in any |
---|
737 | | - * non-suspended sector) and is indicated by no toggle bits toggling. |
---|
738 | | - * |
---|
739 | | - * Note that anything more complicated than checking if no bits are toggling |
---|
740 | | - * (including checking DQ5 for an error status) is tricky to get working |
---|
741 | | - * correctly and is therefore not done (particularly with interleaved chips |
---|
742 | | - * as each chip must be checked independently of the others). |
---|
743 | | - */ |
---|
744 | | -static int __xipram chip_ready(struct map_info *map, unsigned long addr) |
---|
745 | | -{ |
---|
746 | | - map_word d, t; |
---|
747 | | - |
---|
748 | | - d = map_read(map, addr); |
---|
749 | | - t = map_read(map, addr); |
---|
750 | | - |
---|
751 | | - return map_word_equal(map, d, t); |
---|
752 | | -} |
---|
753 | | - |
---|
754 | | -/* |
---|
755 | 815 | * Return true if the chip is ready and has the correct value. |
---|
756 | 816 | * |
---|
757 | 817 | * Ready is one of: read mode, query mode, erase-suspend-read mode (in any |
---|
758 | | - * non-suspended sector) and it is indicated by no bits toggling. |
---|
| 818 | + * non-suspended sector) and is indicated by no toggle bits toggling. |
---|
759 | 819 | * |
---|
760 | 820 | * Error are indicated by toggling bits or bits held with the wrong value, |
---|
761 | 821 | * or with bits toggling. |
---|
.. | .. |
---|
764 | 824 | * (including checking DQ5 for an error status) is tricky to get working |
---|
765 | 825 | * correctly and is therefore not done (particularly with interleaved chips |
---|
766 | 826 | * as each chip must be checked independently of the others). |
---|
767 | | - * |
---|
768 | 827 | */ |
---|
769 | | -static int __xipram chip_good(struct map_info *map, unsigned long addr, map_word expected) |
---|
| 828 | +static int __xipram chip_ready(struct map_info *map, struct flchip *chip, |
---|
| 829 | + unsigned long addr, map_word *expected) |
---|
770 | 830 | { |
---|
771 | | - map_word oldd, curd; |
---|
| 831 | + struct cfi_private *cfi = map->fldrv_priv; |
---|
| 832 | + map_word d, t; |
---|
| 833 | + int ret; |
---|
772 | 834 | |
---|
773 | | - oldd = map_read(map, addr); |
---|
774 | | - curd = map_read(map, addr); |
---|
| 835 | + if (cfi_use_status_reg(cfi)) { |
---|
| 836 | + map_word ready = CMD(CFI_SR_DRB); |
---|
| 837 | + /* |
---|
| 838 | + * For chips that support status register, check device |
---|
| 839 | + * ready bit |
---|
| 840 | + */ |
---|
| 841 | + cfi_send_gen_cmd(0x70, cfi->addr_unlock1, chip->start, map, cfi, |
---|
| 842 | + cfi->device_type, NULL); |
---|
| 843 | + t = map_read(map, addr); |
---|
775 | 844 | |
---|
776 | | - return map_word_equal(map, oldd, curd) && |
---|
777 | | - map_word_equal(map, curd, expected); |
---|
| 845 | + return map_word_andequal(map, t, ready, ready); |
---|
| 846 | + } |
---|
| 847 | + |
---|
| 848 | + d = map_read(map, addr); |
---|
| 849 | + t = map_read(map, addr); |
---|
| 850 | + |
---|
| 851 | + ret = map_word_equal(map, d, t); |
---|
| 852 | + |
---|
| 853 | + if (!ret || !expected) |
---|
| 854 | + return ret; |
---|
| 855 | + |
---|
| 856 | + return map_word_equal(map, t, *expected); |
---|
| 857 | +} |
---|
| 858 | + |
---|
| 859 | +static int __xipram chip_good(struct map_info *map, struct flchip *chip, |
---|
| 860 | + unsigned long addr, map_word *expected) |
---|
| 861 | +{ |
---|
| 862 | + struct cfi_private *cfi = map->fldrv_priv; |
---|
| 863 | + map_word *datum = expected; |
---|
| 864 | + |
---|
| 865 | + if (cfi->quirks & CFI_QUIRK_DQ_TRUE_DATA) |
---|
| 866 | + datum = NULL; |
---|
| 867 | + |
---|
| 868 | + return chip_ready(map, chip, addr, datum); |
---|
778 | 869 | } |
---|
779 | 870 | |
---|
780 | 871 | static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr, int mode) |
---|
.. | .. |
---|
791 | 882 | |
---|
792 | 883 | case FL_STATUS: |
---|
793 | 884 | for (;;) { |
---|
794 | | - if (chip_ready(map, adr)) |
---|
| 885 | + if (chip_ready(map, chip, adr, NULL)) |
---|
795 | 886 | break; |
---|
796 | 887 | |
---|
797 | 888 | if (time_after(jiffies, timeo)) { |
---|
.. | .. |
---|
829 | 920 | chip->state = FL_ERASE_SUSPENDING; |
---|
830 | 921 | chip->erase_suspended = 1; |
---|
831 | 922 | for (;;) { |
---|
832 | | - if (chip_ready(map, adr)) |
---|
| 923 | + if (chip_ready(map, chip, adr, NULL)) |
---|
833 | 924 | break; |
---|
834 | 925 | |
---|
835 | 926 | if (time_after(jiffies, timeo)) { |
---|
.. | .. |
---|
868 | 959 | /* Only if there's no operation suspended... */ |
---|
869 | 960 | if (mode == FL_READY && chip->oldstate == FL_READY) |
---|
870 | 961 | return 0; |
---|
871 | | - |
---|
| 962 | + fallthrough; |
---|
872 | 963 | default: |
---|
873 | 964 | sleep: |
---|
874 | 965 | set_current_state(TASK_UNINTERRUPTIBLE); |
---|
.. | .. |
---|
1360 | 1451 | /* wait for chip to become ready */ |
---|
1361 | 1452 | timeo = jiffies + msecs_to_jiffies(2); |
---|
1362 | 1453 | for (;;) { |
---|
1363 | | - if (chip_ready(map, adr)) |
---|
| 1454 | + if (chip_ready(map, chip, adr, NULL)) |
---|
1364 | 1455 | break; |
---|
1365 | 1456 | |
---|
1366 | 1457 | if (time_after(jiffies, timeo)) { |
---|
.. | .. |
---|
1546 | 1637 | do_otp_lock, 1); |
---|
1547 | 1638 | } |
---|
1548 | 1639 | |
---|
1549 | | -static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip, |
---|
1550 | | - unsigned long adr, map_word datum, |
---|
1551 | | - int mode) |
---|
| 1640 | +static int __xipram do_write_oneword_once(struct map_info *map, |
---|
| 1641 | + struct flchip *chip, |
---|
| 1642 | + unsigned long adr, map_word datum, |
---|
| 1643 | + int mode, struct cfi_private *cfi) |
---|
1552 | 1644 | { |
---|
1553 | | - struct cfi_private *cfi = map->fldrv_priv; |
---|
1554 | 1645 | unsigned long timeo = jiffies + HZ; |
---|
1555 | 1646 | /* |
---|
1556 | 1647 | * We use a 1ms + 1 jiffies generic timeout for writes (most devices |
---|
.. | .. |
---|
1563 | 1654 | */ |
---|
1564 | 1655 | unsigned long uWriteTimeout = (HZ / 1000) + 1; |
---|
1565 | 1656 | int ret = 0; |
---|
1566 | | - map_word oldd; |
---|
1567 | | - int retry_cnt = 0; |
---|
1568 | 1657 | |
---|
1569 | | - adr += chip->start; |
---|
1570 | | - |
---|
1571 | | - mutex_lock(&chip->mutex); |
---|
1572 | | - ret = get_chip(map, chip, adr, mode); |
---|
1573 | | - if (ret) { |
---|
1574 | | - mutex_unlock(&chip->mutex); |
---|
1575 | | - return ret; |
---|
1576 | | - } |
---|
1577 | | - |
---|
1578 | | - pr_debug("MTD %s(): WRITE 0x%.8lx(0x%.8lx)\n", |
---|
1579 | | - __func__, adr, datum.x[0]); |
---|
1580 | | - |
---|
1581 | | - if (mode == FL_OTP_WRITE) |
---|
1582 | | - otp_enter(map, chip, adr, map_bankwidth(map)); |
---|
1583 | | - |
---|
1584 | | - /* |
---|
1585 | | - * Check for a NOP for the case when the datum to write is already |
---|
1586 | | - * present - it saves time and works around buggy chips that corrupt |
---|
1587 | | - * data at other locations when 0xff is written to a location that |
---|
1588 | | - * already contains 0xff. |
---|
1589 | | - */ |
---|
1590 | | - oldd = map_read(map, adr); |
---|
1591 | | - if (map_word_equal(map, oldd, datum)) { |
---|
1592 | | - pr_debug("MTD %s(): NOP\n", |
---|
1593 | | - __func__); |
---|
1594 | | - goto op_done; |
---|
1595 | | - } |
---|
1596 | | - |
---|
1597 | | - XIP_INVAL_CACHED_RANGE(map, adr, map_bankwidth(map)); |
---|
1598 | | - ENABLE_VPP(map); |
---|
1599 | | - xip_disable(map, chip, adr); |
---|
1600 | | - |
---|
1601 | | - retry: |
---|
1602 | 1658 | cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); |
---|
1603 | 1659 | cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, cfi->device_type, NULL); |
---|
1604 | 1660 | cfi_send_gen_cmd(0xA0, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); |
---|
.. | .. |
---|
1630 | 1686 | * We check "time_after" and "!chip_good" before checking |
---|
1631 | 1687 | * "chip_good" to avoid the failure due to scheduling. |
---|
1632 | 1688 | */ |
---|
1633 | | - if (time_after(jiffies, timeo) && !chip_good(map, adr, datum)) { |
---|
| 1689 | + if (time_after(jiffies, timeo) && |
---|
| 1690 | + !chip_good(map, chip, adr, &datum)) { |
---|
1634 | 1691 | xip_enable(map, chip, adr); |
---|
1635 | 1692 | printk(KERN_WARNING "MTD %s(): software timeout\n", __func__); |
---|
1636 | 1693 | xip_disable(map, chip, adr); |
---|
.. | .. |
---|
1638 | 1695 | break; |
---|
1639 | 1696 | } |
---|
1640 | 1697 | |
---|
1641 | | - if (chip_good(map, adr, datum)) |
---|
| 1698 | + if (chip_good(map, chip, adr, &datum)) { |
---|
| 1699 | + if (cfi_check_err_status(map, chip, adr)) |
---|
| 1700 | + ret = -EIO; |
---|
1642 | 1701 | break; |
---|
| 1702 | + } |
---|
1643 | 1703 | |
---|
1644 | 1704 | /* Latency issues. Drop the lock, wait a while and retry */ |
---|
1645 | 1705 | UDELAY(map, chip, adr, 1); |
---|
1646 | 1706 | } |
---|
1647 | 1707 | |
---|
1648 | | - /* Did we succeed? */ |
---|
| 1708 | + return ret; |
---|
| 1709 | +} |
---|
| 1710 | + |
---|
| 1711 | +static int __xipram do_write_oneword_start(struct map_info *map, |
---|
| 1712 | + struct flchip *chip, |
---|
| 1713 | + unsigned long adr, int mode) |
---|
| 1714 | +{ |
---|
| 1715 | + int ret; |
---|
| 1716 | + |
---|
| 1717 | + mutex_lock(&chip->mutex); |
---|
| 1718 | + |
---|
| 1719 | + ret = get_chip(map, chip, adr, mode); |
---|
| 1720 | + if (ret) { |
---|
| 1721 | + mutex_unlock(&chip->mutex); |
---|
| 1722 | + return ret; |
---|
| 1723 | + } |
---|
| 1724 | + |
---|
| 1725 | + if (mode == FL_OTP_WRITE) |
---|
| 1726 | + otp_enter(map, chip, adr, map_bankwidth(map)); |
---|
| 1727 | + |
---|
| 1728 | + return ret; |
---|
| 1729 | +} |
---|
| 1730 | + |
---|
| 1731 | +static void __xipram do_write_oneword_done(struct map_info *map, |
---|
| 1732 | + struct flchip *chip, |
---|
| 1733 | + unsigned long adr, int mode) |
---|
| 1734 | +{ |
---|
| 1735 | + if (mode == FL_OTP_WRITE) |
---|
| 1736 | + otp_exit(map, chip, adr, map_bankwidth(map)); |
---|
| 1737 | + |
---|
| 1738 | + chip->state = FL_READY; |
---|
| 1739 | + DISABLE_VPP(map); |
---|
| 1740 | + put_chip(map, chip, adr); |
---|
| 1741 | + |
---|
| 1742 | + mutex_unlock(&chip->mutex); |
---|
| 1743 | +} |
---|
| 1744 | + |
---|
| 1745 | +static int __xipram do_write_oneword_retry(struct map_info *map, |
---|
| 1746 | + struct flchip *chip, |
---|
| 1747 | + unsigned long adr, map_word datum, |
---|
| 1748 | + int mode) |
---|
| 1749 | +{ |
---|
| 1750 | + struct cfi_private *cfi = map->fldrv_priv; |
---|
| 1751 | + int ret = 0; |
---|
| 1752 | + map_word oldd; |
---|
| 1753 | + int retry_cnt = 0; |
---|
| 1754 | + |
---|
| 1755 | + /* |
---|
| 1756 | + * Check for a NOP for the case when the datum to write is already |
---|
| 1757 | + * present - it saves time and works around buggy chips that corrupt |
---|
| 1758 | + * data at other locations when 0xff is written to a location that |
---|
| 1759 | + * already contains 0xff. |
---|
| 1760 | + */ |
---|
| 1761 | + oldd = map_read(map, adr); |
---|
| 1762 | + if (map_word_equal(map, oldd, datum)) { |
---|
| 1763 | + pr_debug("MTD %s(): NOP\n", __func__); |
---|
| 1764 | + return ret; |
---|
| 1765 | + } |
---|
| 1766 | + |
---|
| 1767 | + XIP_INVAL_CACHED_RANGE(map, adr, map_bankwidth(map)); |
---|
| 1768 | + ENABLE_VPP(map); |
---|
| 1769 | + xip_disable(map, chip, adr); |
---|
| 1770 | + |
---|
| 1771 | + retry: |
---|
| 1772 | + ret = do_write_oneword_once(map, chip, adr, datum, mode, cfi); |
---|
1649 | 1773 | if (ret) { |
---|
1650 | 1774 | /* reset on all failures. */ |
---|
1651 | 1775 | map_write(map, CMD(0xF0), chip->start); |
---|
.. | .. |
---|
1657 | 1781 | } |
---|
1658 | 1782 | } |
---|
1659 | 1783 | xip_enable(map, chip, adr); |
---|
1660 | | - op_done: |
---|
1661 | | - if (mode == FL_OTP_WRITE) |
---|
1662 | | - otp_exit(map, chip, adr, map_bankwidth(map)); |
---|
1663 | | - chip->state = FL_READY; |
---|
1664 | | - DISABLE_VPP(map); |
---|
1665 | | - put_chip(map, chip, adr); |
---|
1666 | | - mutex_unlock(&chip->mutex); |
---|
| 1784 | + |
---|
| 1785 | + return ret; |
---|
| 1786 | +} |
---|
| 1787 | + |
---|
| 1788 | +static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip, |
---|
| 1789 | + unsigned long adr, map_word datum, |
---|
| 1790 | + int mode) |
---|
| 1791 | +{ |
---|
| 1792 | + int ret; |
---|
| 1793 | + |
---|
| 1794 | + adr += chip->start; |
---|
| 1795 | + |
---|
| 1796 | + pr_debug("MTD %s(): WRITE 0x%.8lx(0x%.8lx)\n", __func__, adr, |
---|
| 1797 | + datum.x[0]); |
---|
| 1798 | + |
---|
| 1799 | + ret = do_write_oneword_start(map, chip, adr, mode); |
---|
| 1800 | + if (ret) |
---|
| 1801 | + return ret; |
---|
| 1802 | + |
---|
| 1803 | + ret = do_write_oneword_retry(map, chip, adr, datum, mode); |
---|
| 1804 | + |
---|
| 1805 | + do_write_oneword_done(map, chip, adr, mode); |
---|
1667 | 1806 | |
---|
1668 | 1807 | return ret; |
---|
1669 | 1808 | } |
---|
.. | .. |
---|
1674 | 1813 | { |
---|
1675 | 1814 | struct map_info *map = mtd->priv; |
---|
1676 | 1815 | struct cfi_private *cfi = map->fldrv_priv; |
---|
1677 | | - int ret = 0; |
---|
| 1816 | + int ret; |
---|
1678 | 1817 | int chipnum; |
---|
1679 | 1818 | unsigned long ofs, chipstart; |
---|
1680 | 1819 | DECLARE_WAITQUEUE(wait, current); |
---|
.. | .. |
---|
1792 | 1931 | return 0; |
---|
1793 | 1932 | } |
---|
1794 | 1933 | |
---|
| 1934 | +#if !FORCE_WORD_WRITE |
---|
| 1935 | +static int __xipram do_write_buffer_wait(struct map_info *map, |
---|
| 1936 | + struct flchip *chip, unsigned long adr, |
---|
| 1937 | + map_word datum) |
---|
| 1938 | +{ |
---|
| 1939 | + unsigned long timeo; |
---|
| 1940 | + unsigned long u_write_timeout; |
---|
| 1941 | + int ret = 0; |
---|
| 1942 | + |
---|
| 1943 | + /* |
---|
| 1944 | + * Timeout is calculated according to CFI data, if available. |
---|
| 1945 | + * See more comments in cfi_cmdset_0002(). |
---|
| 1946 | + */ |
---|
| 1947 | + u_write_timeout = usecs_to_jiffies(chip->buffer_write_time_max); |
---|
| 1948 | + timeo = jiffies + u_write_timeout; |
---|
| 1949 | + |
---|
| 1950 | + for (;;) { |
---|
| 1951 | + if (chip->state != FL_WRITING) { |
---|
| 1952 | + /* Someone's suspended the write. Sleep */ |
---|
| 1953 | + DECLARE_WAITQUEUE(wait, current); |
---|
| 1954 | + |
---|
| 1955 | + set_current_state(TASK_UNINTERRUPTIBLE); |
---|
| 1956 | + add_wait_queue(&chip->wq, &wait); |
---|
| 1957 | + mutex_unlock(&chip->mutex); |
---|
| 1958 | + schedule(); |
---|
| 1959 | + remove_wait_queue(&chip->wq, &wait); |
---|
| 1960 | + timeo = jiffies + (HZ / 2); /* FIXME */ |
---|
| 1961 | + mutex_lock(&chip->mutex); |
---|
| 1962 | + continue; |
---|
| 1963 | + } |
---|
| 1964 | + |
---|
| 1965 | + /* |
---|
| 1966 | + * We check "time_after" and "!chip_good" before checking |
---|
| 1967 | + * "chip_good" to avoid the failure due to scheduling. |
---|
| 1968 | + */ |
---|
| 1969 | + if (time_after(jiffies, timeo) && |
---|
| 1970 | + !chip_good(map, chip, adr, &datum)) { |
---|
| 1971 | + pr_err("MTD %s(): software timeout, address:0x%.8lx.\n", |
---|
| 1972 | + __func__, adr); |
---|
| 1973 | + ret = -EIO; |
---|
| 1974 | + break; |
---|
| 1975 | + } |
---|
| 1976 | + |
---|
| 1977 | + if (chip_good(map, chip, adr, &datum)) { |
---|
| 1978 | + if (cfi_check_err_status(map, chip, adr)) |
---|
| 1979 | + ret = -EIO; |
---|
| 1980 | + break; |
---|
| 1981 | + } |
---|
| 1982 | + |
---|
| 1983 | + /* Latency issues. Drop the lock, wait a while and retry */ |
---|
| 1984 | + UDELAY(map, chip, adr, 1); |
---|
| 1985 | + } |
---|
| 1986 | + |
---|
| 1987 | + return ret; |
---|
| 1988 | +} |
---|
| 1989 | + |
---|
| 1990 | +static void __xipram do_write_buffer_reset(struct map_info *map, |
---|
| 1991 | + struct flchip *chip, |
---|
| 1992 | + struct cfi_private *cfi) |
---|
| 1993 | +{ |
---|
| 1994 | + /* |
---|
| 1995 | + * Recovery from write-buffer programming failures requires |
---|
| 1996 | + * the write-to-buffer-reset sequence. Since the last part |
---|
| 1997 | + * of the sequence also works as a normal reset, we can run |
---|
| 1998 | + * the same commands regardless of why we are here. |
---|
| 1999 | + * See e.g. |
---|
| 2000 | + * http://www.spansion.com/Support/Application%20Notes/MirrorBit_Write_Buffer_Prog_Page_Buffer_Read_AN.pdf |
---|
| 2001 | + */ |
---|
| 2002 | + cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, |
---|
| 2003 | + cfi->device_type, NULL); |
---|
| 2004 | + cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, |
---|
| 2005 | + cfi->device_type, NULL); |
---|
| 2006 | + cfi_send_gen_cmd(0xF0, cfi->addr_unlock1, chip->start, map, cfi, |
---|
| 2007 | + cfi->device_type, NULL); |
---|
| 2008 | + |
---|
| 2009 | + /* FIXME - should have reset delay before continuing */ |
---|
| 2010 | +} |
---|
1795 | 2011 | |
---|
1796 | 2012 | /* |
---|
1797 | 2013 | * FIXME: interleaved mode not tested, and probably not supported! |
---|
.. | .. |
---|
1801 | 2017 | int len) |
---|
1802 | 2018 | { |
---|
1803 | 2019 | struct cfi_private *cfi = map->fldrv_priv; |
---|
1804 | | - unsigned long timeo = jiffies + HZ; |
---|
1805 | | - /* |
---|
1806 | | - * Timeout is calculated according to CFI data, if available. |
---|
1807 | | - * See more comments in cfi_cmdset_0002(). |
---|
1808 | | - */ |
---|
1809 | | - unsigned long uWriteTimeout = |
---|
1810 | | - usecs_to_jiffies(chip->buffer_write_time_max); |
---|
1811 | | - int ret = -EIO; |
---|
| 2020 | + int ret; |
---|
1812 | 2021 | unsigned long cmd_adr; |
---|
1813 | 2022 | int z, words; |
---|
1814 | 2023 | map_word datum; |
---|
.. | .. |
---|
1864 | 2073 | adr, map_bankwidth(map), |
---|
1865 | 2074 | chip->word_write_time); |
---|
1866 | 2075 | |
---|
1867 | | - timeo = jiffies + uWriteTimeout; |
---|
| 2076 | + ret = do_write_buffer_wait(map, chip, adr, datum); |
---|
| 2077 | + if (ret) |
---|
| 2078 | + do_write_buffer_reset(map, chip, cfi); |
---|
1868 | 2079 | |
---|
1869 | | - for (;;) { |
---|
1870 | | - if (chip->state != FL_WRITING) { |
---|
1871 | | - /* Someone's suspended the write. Sleep */ |
---|
1872 | | - DECLARE_WAITQUEUE(wait, current); |
---|
1873 | | - |
---|
1874 | | - set_current_state(TASK_UNINTERRUPTIBLE); |
---|
1875 | | - add_wait_queue(&chip->wq, &wait); |
---|
1876 | | - mutex_unlock(&chip->mutex); |
---|
1877 | | - schedule(); |
---|
1878 | | - remove_wait_queue(&chip->wq, &wait); |
---|
1879 | | - timeo = jiffies + (HZ / 2); /* FIXME */ |
---|
1880 | | - mutex_lock(&chip->mutex); |
---|
1881 | | - continue; |
---|
1882 | | - } |
---|
1883 | | - |
---|
1884 | | - /* |
---|
1885 | | - * We check "time_after" and "!chip_good" before checking "chip_good" to avoid |
---|
1886 | | - * the failure due to scheduling. |
---|
1887 | | - */ |
---|
1888 | | - if (time_after(jiffies, timeo) && !chip_good(map, adr, datum)) |
---|
1889 | | - break; |
---|
1890 | | - |
---|
1891 | | - if (chip_good(map, adr, datum)) { |
---|
1892 | | - xip_enable(map, chip, adr); |
---|
1893 | | - goto op_done; |
---|
1894 | | - } |
---|
1895 | | - |
---|
1896 | | - /* Latency issues. Drop the lock, wait a while and retry */ |
---|
1897 | | - UDELAY(map, chip, adr, 1); |
---|
1898 | | - } |
---|
1899 | | - |
---|
1900 | | - /* |
---|
1901 | | - * Recovery from write-buffer programming failures requires |
---|
1902 | | - * the write-to-buffer-reset sequence. Since the last part |
---|
1903 | | - * of the sequence also works as a normal reset, we can run |
---|
1904 | | - * the same commands regardless of why we are here. |
---|
1905 | | - * See e.g. |
---|
1906 | | - * http://www.spansion.com/Support/Application%20Notes/MirrorBit_Write_Buffer_Prog_Page_Buffer_Read_AN.pdf |
---|
1907 | | - */ |
---|
1908 | | - cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, |
---|
1909 | | - cfi->device_type, NULL); |
---|
1910 | | - cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, |
---|
1911 | | - cfi->device_type, NULL); |
---|
1912 | | - cfi_send_gen_cmd(0xF0, cfi->addr_unlock1, chip->start, map, cfi, |
---|
1913 | | - cfi->device_type, NULL); |
---|
1914 | 2080 | xip_enable(map, chip, adr); |
---|
1915 | | - /* FIXME - should have reset delay before continuing */ |
---|
1916 | 2081 | |
---|
1917 | | - printk(KERN_WARNING "MTD %s(): software timeout, address:0x%.8lx.\n", |
---|
1918 | | - __func__, adr); |
---|
1919 | | - |
---|
1920 | | - ret = -EIO; |
---|
1921 | | - op_done: |
---|
1922 | 2082 | chip->state = FL_READY; |
---|
1923 | 2083 | DISABLE_VPP(map); |
---|
1924 | 2084 | put_chip(map, chip, adr); |
---|
.. | .. |
---|
1934 | 2094 | struct map_info *map = mtd->priv; |
---|
1935 | 2095 | struct cfi_private *cfi = map->fldrv_priv; |
---|
1936 | 2096 | int wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize; |
---|
1937 | | - int ret = 0; |
---|
| 2097 | + int ret; |
---|
1938 | 2098 | int chipnum; |
---|
1939 | 2099 | unsigned long ofs; |
---|
1940 | 2100 | |
---|
.. | .. |
---|
2002 | 2162 | |
---|
2003 | 2163 | return 0; |
---|
2004 | 2164 | } |
---|
| 2165 | +#endif /* !FORCE_WORD_WRITE */ |
---|
2005 | 2166 | |
---|
2006 | 2167 | /* |
---|
2007 | 2168 | * Wait for the flash chip to become ready to write data |
---|
.. | .. |
---|
2022 | 2183 | * If the driver thinks the chip is idle, and no toggle bits |
---|
2023 | 2184 | * are changing, then the chip is actually idle for sure. |
---|
2024 | 2185 | */ |
---|
2025 | | - if (chip->state == FL_READY && chip_ready(map, adr)) |
---|
| 2186 | + if (chip->state == FL_READY && chip_ready(map, chip, adr, NULL)) |
---|
2026 | 2187 | return 0; |
---|
2027 | 2188 | |
---|
2028 | 2189 | /* |
---|
.. | .. |
---|
2039 | 2200 | |
---|
2040 | 2201 | /* wait for the chip to become ready */ |
---|
2041 | 2202 | for (i = 0; i < jiffies_to_usecs(timeo); i++) { |
---|
2042 | | - if (chip_ready(map, adr)) |
---|
| 2203 | + if (chip_ready(map, chip, adr, NULL)) |
---|
2043 | 2204 | return 0; |
---|
2044 | 2205 | |
---|
2045 | 2206 | udelay(1); |
---|
.. | .. |
---|
2070 | 2231 | struct cfi_private *cfi = map->fldrv_priv; |
---|
2071 | 2232 | int retry_cnt = 0; |
---|
2072 | 2233 | map_word oldd; |
---|
2073 | | - int ret = 0; |
---|
| 2234 | + int ret; |
---|
2074 | 2235 | int i; |
---|
2075 | 2236 | |
---|
2076 | 2237 | adr += chip->start; |
---|
.. | .. |
---|
2103 | 2264 | map_write(map, datum, adr); |
---|
2104 | 2265 | |
---|
2105 | 2266 | for (i = 0; i < jiffies_to_usecs(uWriteTimeout); i++) { |
---|
2106 | | - if (chip_ready(map, adr)) |
---|
| 2267 | + if (chip_ready(map, chip, adr, NULL)) |
---|
2107 | 2268 | break; |
---|
2108 | 2269 | |
---|
2109 | 2270 | udelay(1); |
---|
2110 | 2271 | } |
---|
2111 | 2272 | |
---|
2112 | | - if (!chip_good(map, adr, datum)) { |
---|
| 2273 | + if (!chip_ready(map, chip, adr, &datum) || |
---|
| 2274 | + cfi_check_err_status(map, chip, adr)) { |
---|
2113 | 2275 | /* reset on all failures. */ |
---|
2114 | 2276 | map_write(map, CMD(0xF0), chip->start); |
---|
2115 | 2277 | /* FIXME - should have reset delay before continuing */ |
---|
.. | .. |
---|
2144 | 2306 | struct map_info *map = mtd->priv; |
---|
2145 | 2307 | struct cfi_private *cfi = map->fldrv_priv; |
---|
2146 | 2308 | unsigned long ofs, chipstart; |
---|
2147 | | - int ret = 0; |
---|
| 2309 | + int ret; |
---|
2148 | 2310 | int chipnum; |
---|
2149 | 2311 | |
---|
2150 | 2312 | chipnum = to >> cfi->chipshift; |
---|
.. | .. |
---|
2248 | 2410 | unsigned long timeo = jiffies + HZ; |
---|
2249 | 2411 | unsigned long int adr; |
---|
2250 | 2412 | DECLARE_WAITQUEUE(wait, current); |
---|
2251 | | - int ret = 0; |
---|
| 2413 | + int ret; |
---|
2252 | 2414 | int retry_cnt = 0; |
---|
| 2415 | + map_word datum = map_word_ff(map); |
---|
2253 | 2416 | |
---|
2254 | 2417 | adr = cfi->addr_unlock1; |
---|
2255 | 2418 | |
---|
2256 | 2419 | mutex_lock(&chip->mutex); |
---|
2257 | | - ret = get_chip(map, chip, adr, FL_WRITING); |
---|
| 2420 | + ret = get_chip(map, chip, adr, FL_ERASING); |
---|
2258 | 2421 | if (ret) { |
---|
2259 | 2422 | mutex_unlock(&chip->mutex); |
---|
2260 | 2423 | return ret; |
---|
.. | .. |
---|
2304 | 2467 | chip->erase_suspended = 0; |
---|
2305 | 2468 | } |
---|
2306 | 2469 | |
---|
2307 | | - if (chip_good(map, adr, map_word_ff(map))) |
---|
| 2470 | + if (chip_ready(map, chip, adr, &datum)) { |
---|
| 2471 | + if (cfi_check_err_status(map, chip, adr)) |
---|
| 2472 | + ret = -EIO; |
---|
2308 | 2473 | break; |
---|
| 2474 | + } |
---|
2309 | 2475 | |
---|
2310 | 2476 | if (time_after(jiffies, timeo)) { |
---|
2311 | 2477 | printk(KERN_WARNING "MTD %s(): software timeout\n", |
---|
.. | .. |
---|
2344 | 2510 | struct cfi_private *cfi = map->fldrv_priv; |
---|
2345 | 2511 | unsigned long timeo = jiffies + HZ; |
---|
2346 | 2512 | DECLARE_WAITQUEUE(wait, current); |
---|
2347 | | - int ret = 0; |
---|
| 2513 | + int ret; |
---|
2348 | 2514 | int retry_cnt = 0; |
---|
| 2515 | + map_word datum = map_word_ff(map); |
---|
2349 | 2516 | |
---|
2350 | 2517 | adr += chip->start; |
---|
2351 | 2518 | |
---|
.. | .. |
---|
2400 | 2567 | chip->erase_suspended = 0; |
---|
2401 | 2568 | } |
---|
2402 | 2569 | |
---|
2403 | | - if (chip_good(map, adr, map_word_ff(map))) |
---|
| 2570 | + if (chip_ready(map, chip, adr, &datum)) { |
---|
| 2571 | + if (cfi_check_err_status(map, chip, adr)) |
---|
| 2572 | + ret = -EIO; |
---|
2404 | 2573 | break; |
---|
| 2574 | + } |
---|
2405 | 2575 | |
---|
2406 | 2576 | if (time_after(jiffies, timeo)) { |
---|
2407 | 2577 | printk(KERN_WARNING "MTD %s(): software timeout\n", |
---|
.. | .. |
---|
2537 | 2707 | int locked; |
---|
2538 | 2708 | }; |
---|
2539 | 2709 | |
---|
2540 | | -#define MAX_SECTORS 512 |
---|
2541 | | - |
---|
2542 | 2710 | #define DO_XXLOCK_ONEBLOCK_LOCK ((void *)1) |
---|
2543 | 2711 | #define DO_XXLOCK_ONEBLOCK_UNLOCK ((void *)2) |
---|
2544 | 2712 | #define DO_XXLOCK_ONEBLOCK_GETLOCK ((void *)3) |
---|
.. | .. |
---|
2593 | 2761 | */ |
---|
2594 | 2762 | timeo = jiffies + msecs_to_jiffies(2000); /* 2s max (un)locking */ |
---|
2595 | 2763 | for (;;) { |
---|
2596 | | - if (chip_ready(map, adr)) |
---|
| 2764 | + if (chip_ready(map, chip, adr, NULL)) |
---|
2597 | 2765 | break; |
---|
2598 | 2766 | |
---|
2599 | 2767 | if (time_after(jiffies, timeo)) { |
---|
.. | .. |
---|
2637 | 2805 | int i; |
---|
2638 | 2806 | int sectors; |
---|
2639 | 2807 | int ret; |
---|
| 2808 | + int max_sectors; |
---|
2640 | 2809 | |
---|
2641 | 2810 | /* |
---|
2642 | 2811 | * PPB unlocking always unlocks all sectors of the flash chip. |
---|
.. | .. |
---|
2644 | 2813 | * first check the locking status of all sectors and save |
---|
2645 | 2814 | * it for future use. |
---|
2646 | 2815 | */ |
---|
2647 | | - sect = kcalloc(MAX_SECTORS, sizeof(struct ppb_lock), GFP_KERNEL); |
---|
| 2816 | + max_sectors = 0; |
---|
| 2817 | + for (i = 0; i < mtd->numeraseregions; i++) |
---|
| 2818 | + max_sectors += regions[i].numblocks; |
---|
| 2819 | + |
---|
| 2820 | + sect = kcalloc(max_sectors, sizeof(struct ppb_lock), GFP_KERNEL); |
---|
2648 | 2821 | if (!sect) |
---|
2649 | 2822 | return -ENOMEM; |
---|
2650 | 2823 | |
---|
.. | .. |
---|
2693 | 2866 | } |
---|
2694 | 2867 | |
---|
2695 | 2868 | sectors++; |
---|
2696 | | - if (sectors >= MAX_SECTORS) { |
---|
| 2869 | + if (sectors >= max_sectors) { |
---|
2697 | 2870 | printk(KERN_ERR "Only %d sectors for PPB locking supported!\n", |
---|
2698 | | - MAX_SECTORS); |
---|
| 2871 | + max_sectors); |
---|
2699 | 2872 | kfree(sect); |
---|
2700 | 2873 | return -EINVAL; |
---|
2701 | 2874 | } |
---|
.. | .. |
---|
2756 | 2929 | * as the whole point is that nobody can do anything |
---|
2757 | 2930 | * with the chip now anyway. |
---|
2758 | 2931 | */ |
---|
| 2932 | + fallthrough; |
---|
2759 | 2933 | case FL_SYNCING: |
---|
2760 | 2934 | mutex_unlock(&chip->mutex); |
---|
2761 | 2935 | break; |
---|