0021-mtd-spi-nor-fix-support-of-Micron-memories.patch 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. From 0cd0df6b3583920ab9231035e533560b58e71a50 Mon Sep 17 00:00:00 2001
  2. From: Cyrille Pitchen <cyrille.pitchen@atmel.com>
  3. Date: Fri, 8 Jan 2016 17:02:18 +0100
  4. Subject: [PATCH 21/33] mtd: spi-nor: fix support of Micron memories
  5. This patch adds missing mode transitions. Indeed depending on both the
  6. current memory mode and the new protocol wanted by the user, we may need
  7. to perform a switch back to the Extended SPI mode.
  8. However when the current mode is the Quad mode and the user has asked for
  9. a Quad SPI protocol, we'd rather stay in Quad mode and use the Fast Read
  10. 4-4-4 command than switch to the Extended SPI mode and use the Fast Read
  11. 1-1-4 command.
  12. Also we'd rather stay in Dual mode than swith to the Extended SPI mode
  13. whenever the user has asked for Dual SPI protocol.
  14. Signed-off-by: Cyrille Pitchen <cyrille.pitchen@atmel.com>
  15. ---
  16. drivers/mtd/spi-nor/spi-nor.c | 154 +++++++++++++++++++++++++++++++++++++++---
  17. include/linux/mtd/spi-nor.h | 1 +
  18. 2 files changed, 147 insertions(+), 8 deletions(-)
  19. diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
  20. index aa7d26d..ae2cbac 100644
  21. --- a/drivers/mtd/spi-nor/spi-nor.c
  22. +++ b/drivers/mtd/spi-nor/spi-nor.c
  23. @@ -1317,6 +1317,147 @@ static int winbond_set_single_mode(struct spi_nor *nor)
  24. return 0;
  25. }
  26. +static int micron_set_protocol(struct spi_nor *nor, u8 mask, u8 val,
  27. + enum spi_nor_protocol proto)
  28. +{
  29. + u8 evcr;
  30. + int ret;
  31. +
  32. + /* Read the Enhanced Volatile Configuration Register (EVCR). */
  33. + ret = nor->read_reg(nor, SPINOR_OP_RD_EVCR, &evcr, 1);
  34. + if (ret < 0) {
  35. + dev_err(nor->dev, "error while reading EVCR register\n");
  36. + return ret;
  37. + }
  38. +
  39. + /* Check whether we need to update the protocol bits. */
  40. + if ((evcr & mask) == val)
  41. + return 0;
  42. +
  43. + /* Set EVCR protocol bits. */
  44. + write_enable(nor);
  45. + evcr = (evcr & ~mask) | val;
  46. + ret = nor->write_reg(nor, SPINOR_OP_WD_EVCR, &evcr, 1);
  47. + if (ret < 0) {
  48. + dev_err(nor->dev, "error while writing EVCR register\n");
  49. + return ret;
  50. + }
  51. +
  52. + /* Switch reg protocol now before accessing any other registers. */
  53. + nor->reg_proto = proto;
  54. +
  55. + ret = spi_nor_wait_till_ready(nor);
  56. + if (ret)
  57. + return ret;
  58. +
  59. + /* Read EVCR and check it. */
  60. + ret = nor->read_reg(nor, SPINOR_OP_RD_EVCR, &evcr, 1);
  61. + if (ret < 0 || (evcr & mask) != val) {
  62. + dev_err(nor->dev, "Micron EVCR protocol bits not updated\n");
  63. + return -EINVAL;
  64. + }
  65. +
  66. + return 0;
  67. +}
  68. +
  69. +static int micron_set_extended_spi_protocol(struct spi_nor *nor)
  70. +{
  71. + int ret;
  72. +
  73. + /* Set Quad/Dual bits to 11 to select the Extended SPI mode */
  74. + ret = micron_set_protocol(nor,
  75. + EVCR_QUAD_EN_MICRON | EVCR_DUAL_EN_MICRON,
  76. + EVCR_QUAD_EN_MICRON | EVCR_DUAL_EN_MICRON,
  77. + SNOR_PROTO_1_1_1);
  78. + if (ret) {
  79. + dev_err(nor->dev, "Failed to set Micron Extended SPI mode\n");
  80. + return ret;
  81. + }
  82. +
  83. + nor->write_proto = SNOR_PROTO_1_1_1;
  84. + nor->erase_proto = SNOR_PROTO_1_1_1;
  85. + return 0;
  86. +}
  87. +
  88. +static int micron_set_quad_mode(struct spi_nor *nor)
  89. +{
  90. + /* Check whether the Dual SPI mode is enabled. */
  91. + if (unlikely(nor->read_proto == SNOR_PROTO_2_2_2)) {
  92. + int ret;
  93. +
  94. + /*
  95. + * Exit Micron Dual mode and switch to the Extended SPI mode:
  96. + * we can change the mode safely as we write into a volatile
  97. + * register.
  98. + * Also the Quad mode is not worth it for MTD usages: it
  99. + * should only be relevant for eXecution In Place (XIP) usages,
  100. + * which are out of the scope of the spi-nor framework.
  101. + */
  102. + ret = micron_set_extended_spi_protocol(nor);
  103. + if (ret)
  104. + return ret;
  105. + }
  106. +
  107. + /*
  108. + * Whatever the Quad mode is enabled or not, the
  109. + * Fast Read Quad Output 1-1-4 (0x6b) op code is supported.
  110. + */
  111. + if (nor->read_proto != SNOR_PROTO_4_4_4)
  112. + nor->read_proto = SNOR_PROTO_1_1_4;
  113. + nor->read_opcode = SPINOR_OP_READ_1_1_4;
  114. + return 0;
  115. +}
  116. +
  117. +static int micron_set_dual_mode(struct spi_nor *nor)
  118. +{
  119. + /* Check whether Quad mode is enabled. */
  120. + if (unlikely(nor->read_proto == SNOR_PROTO_4_4_4)) {
  121. + int ret;
  122. +
  123. + /*
  124. + * Exit Micron Quad mode and switch to the Extended SPI mode:
  125. + * we can change the mode safely as we write into a volatile
  126. + * register.
  127. + * Also the Dual mode is not worth it for MTD usages: it
  128. + * should only be relevant for eXecution In Place (XIP) usages,
  129. + * which are out of the scope of the spi-nor framework.
  130. + */
  131. + ret = micron_set_extended_spi_protocol(nor);
  132. + if (ret)
  133. + return ret;
  134. + }
  135. +
  136. + /*
  137. + * Whatever the Dual mode is enabled or not, the
  138. + * Fast Read Dual Output 1-1-2 (0x3b) op code is supported.
  139. + */
  140. + if (nor->read_proto != SNOR_PROTO_2_2_2)
  141. + nor->read_proto = SNOR_PROTO_1_1_2;
  142. + nor->read_opcode = SPINOR_OP_READ_1_1_2;
  143. + return 0;
  144. +}
  145. +
  146. +static int micron_set_single_mode(struct spi_nor *nor)
  147. +{
  148. + /* Check whether either the Dual or Quad mode is enabled. */
  149. + if (unlikely(nor->read_proto != SNOR_PROTO_1_1_1)) {
  150. + int ret;
  151. +
  152. + /*
  153. + * Exit Micron Dual or Quad mode and switch to the Extended SPI
  154. + * mode: we can change the mode safely as we write into a
  155. + * volatile register.
  156. + */
  157. + ret = micron_set_extended_spi_protocol(nor);
  158. + if (ret)
  159. + return ret;
  160. +
  161. + nor->read_proto = SNOR_PROTO_1_1_1;
  162. + }
  163. +
  164. + return 0;
  165. +}
  166. +
  167. static int set_quad_mode(struct spi_nor *nor, const struct flash_info *info)
  168. {
  169. int status;
  170. @@ -1329,10 +1470,7 @@ static int set_quad_mode(struct spi_nor *nor, const struct flash_info *info)
  171. return winbond_set_quad_mode(nor);
  172. case SNOR_MFR_MICRON:
  173. - /* Check whether Micron Quad mode is enabled. */
  174. - if (nor->read_proto != SNOR_PROTO_4_4_4)
  175. - nor->read_proto = SNOR_PROTO_1_1_4;
  176. - break;
  177. + return micron_set_quad_mode(nor);
  178. case SNOR_MFR_SPANSION:
  179. status = spansion_quad_enable(nor);
  180. @@ -1361,10 +1499,7 @@ static int set_dual_mode(struct spi_nor *nor, const struct flash_info *info)
  181. return winbond_set_dual_mode(nor);
  182. case SNOR_MFR_MICRON:
  183. - /* Check whether Micron Dual mode is enabled. */
  184. - if (nor->read_proto != SNOR_PROTO_2_2_2)
  185. - nor->read_proto = SNOR_PROTO_1_1_2;
  186. - break;
  187. + return micron_set_dual_mode(nor);
  188. default:
  189. nor->read_proto = SNOR_PROTO_1_1_2;
  190. @@ -1384,6 +1519,9 @@ static int set_single_mode(struct spi_nor *nor, const struct flash_info *info)
  191. case SNOR_MFR_WINBOND:
  192. return winbond_set_single_mode(nor);
  193. + case SNOR_MFR_MICRON:
  194. + return micron_set_single_mode(nor);
  195. +
  196. default:
  197. nor->read_proto = SNOR_PROTO_1_1_1;
  198. break;
  199. diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
  200. index 46343f5..d0a6f34 100644
  201. --- a/include/linux/mtd/spi-nor.h
  202. +++ b/include/linux/mtd/spi-nor.h
  203. @@ -102,6 +102,7 @@
  204. /* Enhanced Volatile Configuration Register bits */
  205. #define EVCR_QUAD_EN_MICRON BIT(7) /* Micron Quad I/O */
  206. +#define EVCR_DUAL_EN_MICRON BIT(6) /* Micron Dual I/O */
  207. /* Flag Status Register bits */
  208. #define FSR_READY BIT(7)
  209. --
  210. 2.8.1