0031-generic-mtd-backport-unlock-support-and-asserted-fixes-for-certain-Winbond-Spansion-flash-chips.patch 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. From: Matthias Schiffer <mschiffer@universe-factory.net>
  2. Date: Tue, 20 Jun 2017 11:01:27 +0200
  3. Subject: generic: mtd: backport unlock support and asserted fixes for certain Winbond/Spansion flash chips
  4. diff --git a/target/linux/generic/patches-4.4/049-0001-mtd-spi-nor-wait-until-lock-unlock-operations-are-re.patch b/target/linux/generic/patches-4.4/049-0001-mtd-spi-nor-wait-until-lock-unlock-operations-are-re.patch
  5. new file mode 100644
  6. index 0000000000000000000000000000000000000000..c8aafe2ebbf7368f47e8f4d7a24dd5e45583a136
  7. --- /dev/null
  8. +++ b/target/linux/generic/patches-4.4/049-0001-mtd-spi-nor-wait-until-lock-unlock-operations-are-re.patch
  9. @@ -0,0 +1,66 @@
  10. +From 32321e950d8a237d7e8f3a9b76220007dfa87544 Mon Sep 17 00:00:00 2001
  11. +Message-Id: <32321e950d8a237d7e8f3a9b76220007dfa87544.1462572686.git.mschiffer@universe-factory.net>
  12. +From: =?UTF-8?q?Ezequiel=20Garc=C3=ADa?= <ezequiel@vanguardiasur.com.ar>
  13. +Date: Mon, 28 Dec 2015 17:54:51 -0300
  14. +Subject: [PATCH] mtd: spi-nor: wait until lock/unlock operations are ready
  15. +
  16. +On Micron and Numonyx devices, the status register write command
  17. +(WRSR), raises a work-in-progress bit (WIP) on the status register.
  18. +The datasheets for these devices specify that while the status
  19. +register write is in progress, the status register WIP bit can still
  20. +be read to check the end of the operation.
  21. +
  22. +This commit adds a wait_till_ready call on lock/unlock operations,
  23. +which is required for Micron and Numonyx but should be harmless for
  24. +others. This is needed to prevent applications from issuing erase or
  25. +program operations before the unlock operation is completed.
  26. +
  27. +Reported-by: Stas Sergeev <stsp@list.ru>
  28. +Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
  29. +Signed-off-by: Brian Norris <computersforpeace@gmail.com>
  30. +---
  31. + drivers/mtd/spi-nor/spi-nor.c | 12 ++++++++++--
  32. + 1 file changed, 10 insertions(+), 2 deletions(-)
  33. +
  34. +--- a/drivers/mtd/spi-nor/spi-nor.c
  35. ++++ b/drivers/mtd/spi-nor/spi-nor.c
  36. +@@ -463,6 +463,7 @@ static int stm_lock(struct spi_nor *nor,
  37. + u8 status_old, status_new;
  38. + u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
  39. + u8 shift = ffs(mask) - 1, pow, val;
  40. ++ int ret;
  41. +
  42. + status_old = read_sr(nor);
  43. +
  44. +@@ -499,7 +500,10 @@ static int stm_lock(struct spi_nor *nor,
  45. + return -EINVAL;
  46. +
  47. + write_enable(nor);
  48. +- return write_sr(nor, status_new);
  49. ++ ret = write_sr(nor, status_new);
  50. ++ if (ret)
  51. ++ return ret;
  52. ++ return spi_nor_wait_till_ready(nor);
  53. + }
  54. +
  55. + /*
  56. +@@ -513,6 +517,7 @@ static int stm_unlock(struct spi_nor *no
  57. + uint8_t status_old, status_new;
  58. + u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
  59. + u8 shift = ffs(mask) - 1, pow, val;
  60. ++ int ret;
  61. +
  62. + status_old = read_sr(nor);
  63. +
  64. +@@ -547,7 +552,10 @@ static int stm_unlock(struct spi_nor *no
  65. + return -EINVAL;
  66. +
  67. + write_enable(nor);
  68. +- return write_sr(nor, status_new);
  69. ++ ret = write_sr(nor, status_new);
  70. ++ if (ret)
  71. ++ return ret;
  72. ++ return spi_nor_wait_till_ready(nor);
  73. + }
  74. +
  75. + /*
  76. diff --git a/target/linux/generic/patches-4.4/049-0002-mtd-spi-nor-wait-for-SR_WIP-to-clear-on-initial-unlo.patch b/target/linux/generic/patches-4.4/049-0002-mtd-spi-nor-wait-for-SR_WIP-to-clear-on-initial-unlo.patch
  77. new file mode 100644
  78. index 0000000000000000000000000000000000000000..0541c95594ec14f62b5db787f4d52d5a42777cdc
  79. --- /dev/null
  80. +++ b/target/linux/generic/patches-4.4/049-0002-mtd-spi-nor-wait-for-SR_WIP-to-clear-on-initial-unlo.patch
  81. @@ -0,0 +1,33 @@
  82. +From edf891ef9ab773363f8e58022a26d7d31604aed6 Mon Sep 17 00:00:00 2001
  83. +Message-Id: <edf891ef9ab773363f8e58022a26d7d31604aed6.1462572703.git.mschiffer@universe-factory.net>
  84. +From: Brian Norris <computersforpeace@gmail.com>
  85. +Date: Fri, 29 Jan 2016 11:25:30 -0800
  86. +Subject: [PATCH] mtd: spi-nor: wait for SR_WIP to clear on initial unlock
  87. +
  88. +Fixup a piece leftover by commit 32321e950d8a ("mtd: spi-nor: wait until
  89. +lock/unlock operations are ready"). That commit made us wait for the WIP
  90. +bit to settle after lock/unlock operations, but it missed the open-coded
  91. +"unlock" that happens at probe() time.
  92. +
  93. +We should probably have this code utilize the unlock() routines in the
  94. +future, to avoid duplication, but unfortunately, flash which need to be
  95. +unlocked don't all have a proper ->flash_unlock() callback.
  96. +
  97. +Signed-off-by: Brian Norris <computersforpeace@gmail.com>
  98. +Cc: Stas Sergeev <stsp@users.sourceforge.net>
  99. +Reviewed-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
  100. +Tested-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
  101. +---
  102. + drivers/mtd/spi-nor/spi-nor.c | 1 +
  103. + 1 file changed, 1 insertion(+)
  104. +
  105. +--- a/drivers/mtd/spi-nor/spi-nor.c
  106. ++++ b/drivers/mtd/spi-nor/spi-nor.c
  107. +@@ -1169,6 +1169,7 @@ int spi_nor_scan(struct spi_nor *nor, co
  108. + info->flags & SPI_NOR_HAS_LOCK) {
  109. + write_enable(nor);
  110. + write_sr(nor, 0);
  111. ++ spi_nor_wait_till_ready(nor);
  112. + }
  113. +
  114. + if (!mtd->name)
  115. diff --git a/target/linux/generic/patches-4.4/466-revert-mtd-spi-nor-fix-Spansion-regressions-aliased-.patch b/target/linux/generic/patches-4.4/466-revert-mtd-spi-nor-fix-Spansion-regressions-aliased-.patch
  116. new file mode 100644
  117. index 0000000000000000000000000000000000000000..7c6530a5e0e8bc144e1d4497428e3c3691c2ef22
  118. --- /dev/null
  119. +++ b/target/linux/generic/patches-4.4/466-revert-mtd-spi-nor-fix-Spansion-regressions-aliased-.patch
  120. @@ -0,0 +1,18 @@
  121. +--- a/drivers/mtd/spi-nor/spi-nor.c
  122. ++++ b/drivers/mtd/spi-nor/spi-nor.c
  123. +@@ -1161,6 +1161,7 @@ int spi_nor_scan(struct spi_nor *nor, co
  124. + JEDEC_MFR(info) == SNOR_MFR_INTEL ||
  125. + JEDEC_MFR(info) == SNOR_MFR_MACRONIX ||
  126. + JEDEC_MFR(info) == SNOR_MFR_SST ||
  127. ++ JEDEC_MFR(info) == SNOR_MFR_WINBOND ||
  128. + info->flags & SPI_NOR_HAS_LOCK) {
  129. + write_enable(nor);
  130. + write_sr(nor, 0);
  131. +@@ -1178,6 +1179,7 @@ int spi_nor_scan(struct spi_nor *nor, co
  132. +
  133. + /* NOR protection support for STmicro/Micron chips and similar */
  134. + if (JEDEC_MFR(info) == SNOR_MFR_MICRON ||
  135. ++ JEDEC_MFR(info) == SNOR_MFR_WINBOND ||
  136. + info->flags & SPI_NOR_HAS_LOCK) {
  137. + nor->flash_lock = stm_lock;
  138. + nor->flash_unlock = stm_unlock;