Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'cfi/for-5.4-rc1' of https://github.com/r-vignesh/linux into mtd/for-5.4

CFI core

* Kill useless initializer in mtd_do_chip_probe()
* Fix a rare write failure seen on some cfi_cmdset_0002 compliant
Parallel NORs
* Bunch of cleanups for cfi_cmdset_0002 driver's write functions by
Tokunori Ikegami <ikegami.t@gmail.com>

+187 -114
+186 -113
drivers/mtd/chips/cfi_cmdset_0002.c
··· 61 61 62 62 static int cfi_amdstd_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *); 63 63 static int cfi_amdstd_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *); 64 + #if !FORCE_WORD_WRITE 64 65 static int cfi_amdstd_write_buffers(struct mtd_info *, loff_t, size_t, size_t *, const u_char *); 66 + #endif 65 67 static int cfi_amdstd_erase_chip(struct mtd_info *, struct erase_info *); 66 68 static int cfi_amdstd_erase_varsize(struct mtd_info *, struct erase_info *); 67 69 static void cfi_amdstd_sync (struct mtd_info *); ··· 258 256 } 259 257 #endif 260 258 259 + #if !FORCE_WORD_WRITE 261 260 static void fixup_use_write_buffers(struct mtd_info *mtd) 262 261 { 263 262 struct map_info *map = mtd->priv; ··· 268 265 mtd->_write = cfi_amdstd_write_buffers; 269 266 } 270 267 } 268 + #endif /* !FORCE_WORD_WRITE */ 271 269 272 270 /* Atmel chips don't use the same PRI format as AMD chips */ 273 271 static void fixup_convert_atmel_pri(struct mtd_info *mtd) ··· 1641 1637 do_otp_lock, 1); 1642 1638 } 1643 1639 1644 - static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip, 1645 - unsigned long adr, map_word datum, 1646 - 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) 1647 1644 { 1648 - struct cfi_private *cfi = map->fldrv_priv; 1649 1645 unsigned long timeo = jiffies + HZ; 1650 1646 /* 1651 1647 * We use a 1ms + 1 jiffies generic timeout for writes (most devices ··· 1658 1654 */ 1659 1655 unsigned long uWriteTimeout = (HZ / 1000) + 1; 1660 1656 int ret = 0; 1661 - map_word oldd; 1662 - int retry_cnt = 0; 1663 1657 1664 - adr += chip->start; 1665 - 1666 - mutex_lock(&chip->mutex); 1667 - ret = get_chip(map, chip, adr, mode); 1668 - if (ret) { 1669 - mutex_unlock(&chip->mutex); 1670 - return ret; 1671 - } 1672 - 1673 - pr_debug("MTD %s(): WRITE 0x%.8lx(0x%.8lx)\n", 1674 - __func__, adr, datum.x[0]); 1675 - 1676 - if (mode == FL_OTP_WRITE) 1677 - otp_enter(map, chip, adr, map_bankwidth(map)); 1678 - 1679 - /* 1680 - * Check for a NOP for the case when the datum to write is already 1681 - * present - it saves time and works around buggy chips that corrupt 1682 - * data at other locations when 0xff is written to a location that 1683 - * already contains 0xff. 1684 - */ 1685 - oldd = map_read(map, adr); 1686 - if (map_word_equal(map, oldd, datum)) { 1687 - pr_debug("MTD %s(): NOP\n", 1688 - __func__); 1689 - goto op_done; 1690 - } 1691 - 1692 - XIP_INVAL_CACHED_RANGE(map, adr, map_bankwidth(map)); 1693 - ENABLE_VPP(map); 1694 - xip_disable(map, chip, adr); 1695 - 1696 - retry: 1697 1658 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); 1698 1659 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, cfi->device_type, NULL); 1699 1660 cfi_send_gen_cmd(0xA0, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); ··· 1686 1717 continue; 1687 1718 } 1688 1719 1720 + /* 1721 + * We check "time_after" and "!chip_good" before checking 1722 + * "chip_good" to avoid the failure due to scheduling. 1723 + */ 1689 1724 if (time_after(jiffies, timeo) && 1690 - !chip_ready(map, chip, adr)) { 1725 + !chip_good(map, chip, adr, datum)) { 1691 1726 xip_enable(map, chip, adr); 1692 1727 printk(KERN_WARNING "MTD %s(): software timeout\n", __func__); 1693 1728 xip_disable(map, chip, adr); 1729 + ret = -EIO; 1694 1730 break; 1695 1731 } 1696 1732 1697 - if (chip_ready(map, chip, adr)) 1733 + if (chip_good(map, chip, adr, datum)) 1698 1734 break; 1699 1735 1700 1736 /* Latency issues. Drop the lock, wait a while and retry */ 1701 1737 UDELAY(map, chip, adr, 1); 1702 1738 } 1703 - /* Did we succeed? */ 1704 - if (!chip_good(map, chip, adr, datum)) { 1739 + 1740 + return ret; 1741 + } 1742 + 1743 + static int __xipram do_write_oneword_start(struct map_info *map, 1744 + struct flchip *chip, 1745 + unsigned long adr, int mode) 1746 + { 1747 + int ret = 0; 1748 + 1749 + mutex_lock(&chip->mutex); 1750 + 1751 + ret = get_chip(map, chip, adr, mode); 1752 + if (ret) { 1753 + mutex_unlock(&chip->mutex); 1754 + return ret; 1755 + } 1756 + 1757 + if (mode == FL_OTP_WRITE) 1758 + otp_enter(map, chip, adr, map_bankwidth(map)); 1759 + 1760 + return ret; 1761 + } 1762 + 1763 + static void __xipram do_write_oneword_done(struct map_info *map, 1764 + struct flchip *chip, 1765 + unsigned long adr, int mode) 1766 + { 1767 + if (mode == FL_OTP_WRITE) 1768 + otp_exit(map, chip, adr, map_bankwidth(map)); 1769 + 1770 + chip->state = FL_READY; 1771 + DISABLE_VPP(map); 1772 + put_chip(map, chip, adr); 1773 + 1774 + mutex_unlock(&chip->mutex); 1775 + } 1776 + 1777 + static int __xipram do_write_oneword_retry(struct map_info *map, 1778 + struct flchip *chip, 1779 + unsigned long adr, map_word datum, 1780 + int mode) 1781 + { 1782 + struct cfi_private *cfi = map->fldrv_priv; 1783 + int ret = 0; 1784 + map_word oldd; 1785 + int retry_cnt = 0; 1786 + 1787 + /* 1788 + * Check for a NOP for the case when the datum to write is already 1789 + * present - it saves time and works around buggy chips that corrupt 1790 + * data at other locations when 0xff is written to a location that 1791 + * already contains 0xff. 1792 + */ 1793 + oldd = map_read(map, adr); 1794 + if (map_word_equal(map, oldd, datum)) { 1795 + pr_debug("MTD %s(): NOP\n", __func__); 1796 + return ret; 1797 + } 1798 + 1799 + XIP_INVAL_CACHED_RANGE(map, adr, map_bankwidth(map)); 1800 + ENABLE_VPP(map); 1801 + xip_disable(map, chip, adr); 1802 + 1803 + retry: 1804 + ret = do_write_oneword_once(map, chip, adr, datum, mode, cfi); 1805 + if (ret) { 1705 1806 /* reset on all failures. */ 1706 1807 cfi_check_err_status(map, chip, adr); 1707 1808 map_write(map, CMD(0xF0), chip->start); 1708 1809 /* FIXME - should have reset delay before continuing */ 1709 1810 1710 - if (++retry_cnt <= MAX_RETRIES) 1811 + if (++retry_cnt <= MAX_RETRIES) { 1812 + ret = 0; 1711 1813 goto retry; 1712 - 1713 - ret = -EIO; 1814 + } 1714 1815 } 1715 1816 xip_enable(map, chip, adr); 1716 - op_done: 1717 - if (mode == FL_OTP_WRITE) 1718 - otp_exit(map, chip, adr, map_bankwidth(map)); 1719 - chip->state = FL_READY; 1720 - DISABLE_VPP(map); 1721 - put_chip(map, chip, adr); 1722 - mutex_unlock(&chip->mutex); 1817 + 1818 + return ret; 1819 + } 1820 + 1821 + static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip, 1822 + unsigned long adr, map_word datum, 1823 + int mode) 1824 + { 1825 + int ret = 0; 1826 + 1827 + adr += chip->start; 1828 + 1829 + pr_debug("MTD %s(): WRITE 0x%.8lx(0x%.8lx)\n", __func__, adr, 1830 + datum.x[0]); 1831 + 1832 + ret = do_write_oneword_start(map, chip, adr, mode); 1833 + if (ret) 1834 + return ret; 1835 + 1836 + ret = do_write_oneword_retry(map, chip, adr, datum, mode); 1837 + 1838 + do_write_oneword_done(map, chip, adr, mode); 1723 1839 1724 1840 return ret; 1725 1841 } ··· 1933 1879 return 0; 1934 1880 } 1935 1881 1882 + #if !FORCE_WORD_WRITE 1883 + static int __xipram do_write_buffer_wait(struct map_info *map, 1884 + struct flchip *chip, unsigned long adr, 1885 + map_word datum) 1886 + { 1887 + unsigned long timeo; 1888 + unsigned long u_write_timeout; 1889 + int ret = 0; 1890 + 1891 + /* 1892 + * Timeout is calculated according to CFI data, if available. 1893 + * See more comments in cfi_cmdset_0002(). 1894 + */ 1895 + u_write_timeout = usecs_to_jiffies(chip->buffer_write_time_max); 1896 + timeo = jiffies + u_write_timeout; 1897 + 1898 + for (;;) { 1899 + if (chip->state != FL_WRITING) { 1900 + /* Someone's suspended the write. Sleep */ 1901 + DECLARE_WAITQUEUE(wait, current); 1902 + 1903 + set_current_state(TASK_UNINTERRUPTIBLE); 1904 + add_wait_queue(&chip->wq, &wait); 1905 + mutex_unlock(&chip->mutex); 1906 + schedule(); 1907 + remove_wait_queue(&chip->wq, &wait); 1908 + timeo = jiffies + (HZ / 2); /* FIXME */ 1909 + mutex_lock(&chip->mutex); 1910 + continue; 1911 + } 1912 + 1913 + /* 1914 + * We check "time_after" and "!chip_good" before checking 1915 + * "chip_good" to avoid the failure due to scheduling. 1916 + */ 1917 + if (time_after(jiffies, timeo) && 1918 + !chip_good(map, chip, adr, datum)) { 1919 + ret = -EIO; 1920 + break; 1921 + } 1922 + 1923 + if (chip_good(map, chip, adr, datum)) 1924 + break; 1925 + 1926 + /* Latency issues. Drop the lock, wait a while and retry */ 1927 + UDELAY(map, chip, adr, 1); 1928 + } 1929 + 1930 + return ret; 1931 + } 1932 + 1933 + static void __xipram do_write_buffer_reset(struct map_info *map, 1934 + struct flchip *chip, 1935 + struct cfi_private *cfi) 1936 + { 1937 + /* 1938 + * Recovery from write-buffer programming failures requires 1939 + * the write-to-buffer-reset sequence. Since the last part 1940 + * of the sequence also works as a normal reset, we can run 1941 + * the same commands regardless of why we are here. 1942 + * See e.g. 1943 + * http://www.spansion.com/Support/Application%20Notes/MirrorBit_Write_Buffer_Prog_Page_Buffer_Read_AN.pdf 1944 + */ 1945 + cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, 1946 + cfi->device_type, NULL); 1947 + cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, 1948 + cfi->device_type, NULL); 1949 + cfi_send_gen_cmd(0xF0, cfi->addr_unlock1, chip->start, map, cfi, 1950 + cfi->device_type, NULL); 1951 + 1952 + /* FIXME - should have reset delay before continuing */ 1953 + } 1936 1954 1937 1955 /* 1938 1956 * FIXME: interleaved mode not tested, and probably not supported! ··· 2014 1888 int len) 2015 1889 { 2016 1890 struct cfi_private *cfi = map->fldrv_priv; 2017 - unsigned long timeo = jiffies + HZ; 2018 - /* 2019 - * Timeout is calculated according to CFI data, if available. 2020 - * See more comments in cfi_cmdset_0002(). 2021 - */ 2022 - unsigned long uWriteTimeout = 2023 - usecs_to_jiffies(chip->buffer_write_time_max); 2024 1891 int ret = -EIO; 2025 1892 unsigned long cmd_adr; 2026 1893 int z, words; ··· 2070 1951 adr, map_bankwidth(map), 2071 1952 chip->word_write_time); 2072 1953 2073 - timeo = jiffies + uWriteTimeout; 2074 - 2075 - for (;;) { 2076 - if (chip->state != FL_WRITING) { 2077 - /* Someone's suspended the write. Sleep */ 2078 - DECLARE_WAITQUEUE(wait, current); 2079 - 2080 - set_current_state(TASK_UNINTERRUPTIBLE); 2081 - add_wait_queue(&chip->wq, &wait); 2082 - mutex_unlock(&chip->mutex); 2083 - schedule(); 2084 - remove_wait_queue(&chip->wq, &wait); 2085 - timeo = jiffies + (HZ / 2); /* FIXME */ 2086 - mutex_lock(&chip->mutex); 2087 - continue; 2088 - } 2089 - 2090 - /* 2091 - * We check "time_after" and "!chip_good" before checking "chip_good" to avoid 2092 - * the failure due to scheduling. 2093 - */ 2094 - if (time_after(jiffies, timeo) && 2095 - !chip_good(map, chip, adr, datum)) 2096 - break; 2097 - 2098 - if (chip_good(map, chip, adr, datum)) { 2099 - xip_enable(map, chip, adr); 2100 - goto op_done; 2101 - } 2102 - 2103 - /* Latency issues. Drop the lock, wait a while and retry */ 2104 - UDELAY(map, chip, adr, 1); 1954 + ret = do_write_buffer_wait(map, chip, adr, datum); 1955 + if (ret) { 1956 + cfi_check_err_status(map, chip, adr); 1957 + do_write_buffer_reset(map, chip, cfi); 1958 + pr_err("MTD %s(): software timeout, address:0x%.8lx.\n", 1959 + __func__, adr); 2105 1960 } 2106 1961 2107 - /* 2108 - * Recovery from write-buffer programming failures requires 2109 - * the write-to-buffer-reset sequence. Since the last part 2110 - * of the sequence also works as a normal reset, we can run 2111 - * the same commands regardless of why we are here. 2112 - * See e.g. 2113 - * http://www.spansion.com/Support/Application%20Notes/MirrorBit_Write_Buffer_Prog_Page_Buffer_Read_AN.pdf 2114 - */ 2115 - cfi_check_err_status(map, chip, adr); 2116 - cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, 2117 - cfi->device_type, NULL); 2118 - cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, 2119 - cfi->device_type, NULL); 2120 - cfi_send_gen_cmd(0xF0, cfi->addr_unlock1, chip->start, map, cfi, 2121 - cfi->device_type, NULL); 2122 1962 xip_enable(map, chip, adr); 2123 - /* FIXME - should have reset delay before continuing */ 2124 1963 2125 - printk(KERN_WARNING "MTD %s(): software timeout, address:0x%.8lx.\n", 2126 - __func__, adr); 2127 - 2128 - ret = -EIO; 2129 - op_done: 2130 1964 chip->state = FL_READY; 2131 1965 DISABLE_VPP(map); 2132 1966 put_chip(map, chip, adr); ··· 2163 2091 2164 2092 return 0; 2165 2093 } 2094 + #endif /* !FORCE_WORD_WRITE */ 2166 2095 2167 2096 /* 2168 2097 * Wait for the flash chip to become ready to write data
+1 -1
drivers/mtd/chips/gen_probe.c
··· 20 20 21 21 struct mtd_info *mtd_do_chip_probe(struct map_info *map, struct chip_probe *cp) 22 22 { 23 - struct mtd_info *mtd = NULL; 23 + struct mtd_info *mtd; 24 24 struct cfi_private *cfi; 25 25 26 26 /* First probe the map to see if we have CFI stuff there. */