1090-mtd-spi-nor-Add-SPI-NOR-layer-PM-support.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. From 2c5a3db21926e9ebfd7a32e3c36a3256ed84903c Mon Sep 17 00:00:00 2001
  2. From: Hou Zhiqiang <Zhiqiang.Hou@freescale.com>
  3. Date: Thu, 19 Nov 2015 20:25:24 +0800
  4. Subject: [PATCH 090/113] mtd: spi-nor: Add SPI NOR layer PM support
  5. [context adjustment]
  6. Add the Power Management API in SPI NOR framework.
  7. The Power Management system will turn off power supply to SPI flash
  8. when system suspending, and then the SPI flash will be in the reset
  9. state after system resuming. As a result, the status&configurations
  10. of SPI flash driver will mismatch with its current hardware state.
  11. So reinitialize SPI flash to make sure it is resumed to the correct
  12. state.
  13. And the SPI NOR layer just do common configuration depending on the
  14. records in structure spi_nor.
  15. Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@freescale.com>
  16. Integrated-by: Jiang Yutang <yutang.jiang@nxp.com>
  17. ---
  18. drivers/mtd/spi-nor/spi-nor.c | 74 ++++++++++++++++++++++++++++++++++-------
  19. include/linux/mtd/spi-nor.h | 9 +++++
  20. 2 files changed, 71 insertions(+), 12 deletions(-)
  21. --- a/drivers/mtd/spi-nor/spi-nor.c
  22. +++ b/drivers/mtd/spi-nor/spi-nor.c
  23. @@ -1154,6 +1154,26 @@ static int spi_nor_check(struct spi_nor
  24. return 0;
  25. }
  26. +/*
  27. + * Atmel, SST, Intel/Numonyx, and others serial NOR tend to power up
  28. + * with the software protection bits set
  29. + */
  30. +static int spi_nor_unprotect_on_powerup(struct spi_nor *nor)
  31. +{
  32. + const struct flash_info *info = NULL;
  33. + int ret = 0;
  34. +
  35. + info = spi_nor_read_id(nor);
  36. + if (JEDEC_MFR(info) == SNOR_MFR_ATMEL ||
  37. + JEDEC_MFR(info) == SNOR_MFR_INTEL ||
  38. + JEDEC_MFR(info) == SNOR_MFR_SST) {
  39. + write_enable(nor);
  40. + ret = write_sr(nor, 0);
  41. + }
  42. +
  43. + return ret;
  44. +}
  45. +
  46. int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
  47. {
  48. const struct flash_info *info = NULL;
  49. @@ -1201,19 +1221,9 @@ int spi_nor_scan(struct spi_nor *nor, co
  50. mutex_init(&nor->lock);
  51. - /*
  52. - * Atmel, SST, Intel/Numonyx, and others serial NOR tend to power up
  53. - * with the software protection bits set
  54. - */
  55. -
  56. - if (JEDEC_MFR(info) == SNOR_MFR_ATMEL ||
  57. - JEDEC_MFR(info) == SNOR_MFR_INTEL ||
  58. - JEDEC_MFR(info) == SNOR_MFR_MACRONIX ||
  59. - JEDEC_MFR(info) == SNOR_MFR_SST ||
  60. - info->flags & SPI_NOR_HAS_LOCK) {
  61. - write_enable(nor);
  62. - write_sr(nor, 0);
  63. - }
  64. + ret = spi_nor_unprotect_on_powerup(nor);
  65. + if (ret)
  66. + return ret;
  67. if (!mtd->name)
  68. mtd->name = dev_name(dev);
  69. @@ -1380,6 +1390,45 @@ int spi_nor_scan(struct spi_nor *nor, co
  70. }
  71. EXPORT_SYMBOL_GPL(spi_nor_scan);
  72. +static int spi_nor_hw_reinit(struct spi_nor *nor)
  73. +{
  74. + const struct flash_info *info = NULL;
  75. + struct device *dev = nor->dev;
  76. + int ret;
  77. +
  78. + info = spi_nor_read_id(nor);
  79. +
  80. + ret = spi_nor_unprotect_on_powerup(nor);
  81. + if (ret)
  82. + return ret;
  83. +
  84. + if (nor->flash_read == SPI_NOR_QUAD) {
  85. + ret = set_quad_mode(nor, info);
  86. + if (ret) {
  87. + dev_err(dev, "quad mode not supported\n");
  88. + return ret;
  89. + }
  90. + }
  91. +
  92. + if (nor->addr_width == 4 &&
  93. + JEDEC_MFR(info) != SNOR_MFR_SPANSION)
  94. + set_4byte(nor, info, 1);
  95. +
  96. + return 0;
  97. +}
  98. +
  99. +int spi_nor_suspend(struct spi_nor *nor)
  100. +{
  101. + return 0;
  102. +}
  103. +EXPORT_SYMBOL_GPL(spi_nor_suspend);
  104. +
  105. +int spi_nor_resume(struct spi_nor *nor)
  106. +{
  107. + return spi_nor_hw_reinit(nor);
  108. +}
  109. +EXPORT_SYMBOL_GPL(spi_nor_resume);
  110. +
  111. static const struct flash_info *spi_nor_match_id(const char *name)
  112. {
  113. const struct flash_info *id = spi_nor_ids;
  114. --- a/include/linux/mtd/spi-nor.h
  115. +++ b/include/linux/mtd/spi-nor.h
  116. @@ -210,4 +210,13 @@ static inline struct device_node *spi_no
  117. */
  118. int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode);
  119. +/**
  120. + * spi_nor_suspend/resume() - the SPI NOR layer PM API
  121. + * @nor: the spi_nor structure
  122. + *
  123. + * Return: 0 for success, others for failure.
  124. + */
  125. +int spi_nor_suspend(struct spi_nor *nor);
  126. +int spi_nor_resume(struct spi_nor *nor);
  127. +
  128. #endif