1086-mtd-spi-nor-wait-until-lock-unlock-operations-are-re.patch 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. From 3a06c61b48fbc23046928275e37a693e1055ae74 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Ezequiel=20Garc=C3=ADa?= <ezequiel@vanguardiasur.com.ar>
  3. Date: Mon, 28 Dec 2015 17:54:51 -0300
  4. Subject: [PATCH 086/113] mtd: spi-nor: wait until lock/unlock operations are
  5. ready
  6. On Micron and Numonyx devices, the status register write command
  7. (WRSR), raises a work-in-progress bit (WIP) on the status register.
  8. The datasheets for these devices specify that while the status
  9. register write is in progress, the status register WIP bit can still
  10. be read to check the end of the operation.
  11. This commit adds a wait_till_ready call on lock/unlock operations,
  12. which is required for Micron and Numonyx but should be harmless for
  13. others. This is needed to prevent applications from issuing erase or
  14. program operations before the unlock operation is completed.
  15. Reported-by: Stas Sergeev <stsp@list.ru>
  16. Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
  17. Signed-off-by: Brian Norris <computersforpeace@gmail.com>
  18. ---
  19. drivers/mtd/spi-nor/spi-nor.c | 12 ++++++++++--
  20. 1 file changed, 10 insertions(+), 2 deletions(-)
  21. --- a/drivers/mtd/spi-nor/spi-nor.c
  22. +++ b/drivers/mtd/spi-nor/spi-nor.c
  23. @@ -482,6 +482,7 @@ static int stm_lock(struct spi_nor *nor,
  24. int status_old, status_new;
  25. u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
  26. u8 shift = ffs(mask) - 1, pow, val;
  27. + int ret;
  28. status_old = read_sr(nor);
  29. if (status_old < 0)
  30. @@ -520,7 +521,10 @@ static int stm_lock(struct spi_nor *nor,
  31. return -EINVAL;
  32. write_enable(nor);
  33. - return write_sr(nor, status_new);
  34. + ret = write_sr(nor, status_new);
  35. + if (ret)
  36. + return ret;
  37. + return spi_nor_wait_till_ready(nor);
  38. }
  39. /*
  40. @@ -534,6 +538,7 @@ static int stm_unlock(struct spi_nor *no
  41. int status_old, status_new;
  42. u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
  43. u8 shift = ffs(mask) - 1, pow, val;
  44. + int ret;
  45. status_old = read_sr(nor);
  46. if (status_old < 0)
  47. @@ -570,7 +575,10 @@ static int stm_unlock(struct spi_nor *no
  48. return -EINVAL;
  49. write_enable(nor);
  50. - return write_sr(nor, status_new);
  51. + ret = write_sr(nor, status_new);
  52. + if (ret)
  53. + return ret;
  54. + return spi_nor_wait_till_ready(nor);
  55. }
  56. /*