0027-kernel-mtd-spi-nor-wait-until-status-register-writes-are-ready.patch 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. From: Matthias Schiffer <mschiffer@universe-factory.net>
  2. Date: Sat, 7 May 2016 00:17:55 +0200
  3. Subject: kernel: mtd: spi-nor: wait until status register writes are ready
  4. diff --git a/target/linux/generic/patches-3.18/094-0001-mtd-spi-nor-wait-until-lock-unlock-operations-are-re.patch b/target/linux/generic/patches-3.18/094-0001-mtd-spi-nor-wait-until-lock-unlock-operations-are-re.patch
  5. new file mode 100644
  6. index 0000000..2c2e5f3
  7. --- /dev/null
  8. +++ b/target/linux/generic/patches-3.18/094-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. +@@ -462,6 +462,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. +@@ -498,7 +499,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. +@@ -512,6 +516,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. +@@ -546,7 +551,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-3.18/094-0002-mtd-spi-nor-wait-for-SR_WIP-to-clear-on-initial-unlo.patch b/target/linux/generic/patches-3.18/094-0002-mtd-spi-nor-wait-for-SR_WIP-to-clear-on-initial-unlo.patch
  77. new file mode 100644
  78. index 0000000..a0573d5
  79. --- /dev/null
  80. +++ b/target/linux/generic/patches-3.18/094-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. +@@ -1167,6 +1167,7 @@ int spi_nor_scan(struct spi_nor *nor, co
  108. + JEDEC_MFR(info) == SNOR_MFR_SST) {
  109. + write_enable(nor);
  110. + write_sr(nor, 0);
  111. ++ spi_nor_wait_till_ready(nor);
  112. + }
  113. +
  114. + if (!mtd->name)