0023-mtd-spi-nor-configure-the-number-of-dummy-clock-cycl.patch 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. From 16410a33d6655d6c85c8c522bc6f2cfebf7c06a4 Mon Sep 17 00:00:00 2001
  2. From: Cyrille Pitchen <cyrille.pitchen@atmel.com>
  3. Date: Fri, 8 Jan 2016 17:02:20 +0100
  4. Subject: [PATCH 23/33] mtd: spi-nor: configure the number of dummy clock
  5. cycles by manufacturer
  6. This is a transitional patch which let us set the number of dummy clock
  7. cycles by manufacturer.
  8. More patches will follow by manufacturer to actually configure the
  9. relevant number of dummy clock cycles following the dedicated procedure.
  10. For instance, some manufacturers like Spansion configure the number of
  11. dummy clock cycles to be used by Fast Read command through some
  12. non-volatile register. In such a case, we should avoid updating its value
  13. but instead read it then set the nor->read_dummy accordingly.
  14. On the other hand, some manufacturers like Micron use some volatile
  15. register. In this case, we'd rather update this register to use a number
  16. of dummy clock cycles, which is a multiple of 8.
  17. Indeed some drivers, like m25p80, only support writing bytes, hence
  18. multiples of 8 bits.
  19. Signed-off-by: Cyrille Pitchen <cyrille.pitchen@atmel.com>
  20. ---
  21. drivers/mtd/spi-nor/spi-nor.c | 99 ++++++++++++++++++++++++++++++++-----------
  22. 1 file changed, 74 insertions(+), 25 deletions(-)
  23. diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
  24. index 8a042ab..ae3e9d8 100644
  25. --- a/drivers/mtd/spi-nor/spi-nor.c
  26. +++ b/drivers/mtd/spi-nor/spi-nor.c
  27. @@ -139,24 +139,6 @@ static int read_cr(struct spi_nor *nor)
  28. }
  29. /*
  30. - * Dummy Cycle calculation for different type of read.
  31. - * It can be used to support more commands with
  32. - * different dummy cycle requirements.
  33. - */
  34. -static inline int spi_nor_read_dummy_cycles(struct spi_nor *nor)
  35. -{
  36. - switch (nor->flash_read) {
  37. - case SPI_NOR_FAST:
  38. - case SPI_NOR_DUAL:
  39. - case SPI_NOR_QUAD:
  40. - return 8;
  41. - case SPI_NOR_NORMAL:
  42. - return 0;
  43. - }
  44. - return 0;
  45. -}
  46. -
  47. -/*
  48. * Write status register 1 byte
  49. * Returns negative if error occurred.
  50. */
  51. @@ -1217,6 +1199,7 @@ static int macronix_set_quad_mode(struct spi_nor *nor)
  52. * read (performance enhance) mode by mistake!
  53. */
  54. nor->read_opcode = SPINOR_OP_READ_1_4_4;
  55. + nor->read_dummy = 8;
  56. return 0;
  57. }
  58. @@ -1238,6 +1221,7 @@ static int macronix_set_quad_mode(struct spi_nor *nor)
  59. }
  60. nor->read_proto = SNOR_PROTO_1_1_4;
  61. nor->read_opcode = SPINOR_OP_READ_1_1_4;
  62. + nor->read_dummy = 8;
  63. return 0;
  64. }
  65. @@ -1251,12 +1235,27 @@ static int macronix_set_dual_mode(struct spi_nor *nor)
  66. {
  67. nor->read_proto = SNOR_PROTO_1_1_2;
  68. nor->read_opcode = SPINOR_OP_READ_1_1_2;
  69. + nor->read_dummy = 8;
  70. return 0;
  71. }
  72. static int macronix_set_single_mode(struct spi_nor *nor)
  73. {
  74. + u8 read_dummy;
  75. +
  76. + switch (nor->read_opcode) {
  77. + case SPINOR_OP_READ:
  78. + case SPINOR_OP_READ4:
  79. + read_dummy = 0;
  80. + break;
  81. +
  82. + default:
  83. + read_dummy = 8;
  84. + break;
  85. + }
  86. +
  87. nor->read_proto = SNOR_PROTO_1_1_1;
  88. + nor->read_dummy = read_dummy;
  89. return 0;
  90. }
  91. @@ -1277,6 +1276,7 @@ static int winbond_set_quad_mode(struct spi_nor *nor)
  92. * Hence the Fast Read 1-1-1 (0x0b) op code is chosen.
  93. */
  94. nor->read_opcode = SPINOR_OP_READ_FAST;
  95. + nor->read_dummy = 8;
  96. return 0;
  97. }
  98. @@ -1295,6 +1295,7 @@ static int winbond_set_quad_mode(struct spi_nor *nor)
  99. }
  100. nor->read_proto = SNOR_PROTO_1_1_4;
  101. nor->read_opcode = SPINOR_OP_READ_1_1_4;
  102. + nor->read_dummy = 8;
  103. return 0;
  104. }
  105. @@ -1308,12 +1309,27 @@ static int winbond_set_dual_mode(struct spi_nor *nor)
  106. {
  107. nor->read_proto = SNOR_PROTO_1_1_2;
  108. nor->read_opcode = SPINOR_OP_READ_1_1_2;
  109. + nor->read_dummy = 8;
  110. return 0;
  111. }
  112. static int winbond_set_single_mode(struct spi_nor *nor)
  113. {
  114. + u8 read_dummy;
  115. +
  116. + switch (nor->read_opcode) {
  117. + case SPINOR_OP_READ:
  118. + case SPINOR_OP_READ4:
  119. + read_dummy = 0;
  120. + break;
  121. +
  122. + default:
  123. + read_dummy = 8;
  124. + break;
  125. + }
  126. +
  127. nor->read_proto = SNOR_PROTO_1_1_1;
  128. + nor->read_dummy = read_dummy;
  129. return 0;
  130. }
  131. @@ -1405,6 +1421,7 @@ static int micron_set_quad_mode(struct spi_nor *nor)
  132. if (nor->read_proto != SNOR_PROTO_4_4_4)
  133. nor->read_proto = SNOR_PROTO_1_1_4;
  134. nor->read_opcode = SPINOR_OP_READ_1_1_4;
  135. + nor->read_dummy = 8;
  136. return 0;
  137. }
  138. @@ -1434,11 +1451,14 @@ static int micron_set_dual_mode(struct spi_nor *nor)
  139. if (nor->read_proto != SNOR_PROTO_2_2_2)
  140. nor->read_proto = SNOR_PROTO_1_1_2;
  141. nor->read_opcode = SPINOR_OP_READ_1_1_2;
  142. + nor->read_dummy = 8;
  143. return 0;
  144. }
  145. static int micron_set_single_mode(struct spi_nor *nor)
  146. {
  147. + u8 read_dummy;
  148. +
  149. /* Check whether either the Dual or Quad mode is enabled. */
  150. if (unlikely(nor->read_proto != SNOR_PROTO_1_1_1)) {
  151. int ret;
  152. @@ -1455,6 +1475,18 @@ static int micron_set_single_mode(struct spi_nor *nor)
  153. nor->read_proto = SNOR_PROTO_1_1_1;
  154. }
  155. + /* Force the number of dummy cycles to 8 for Fast Read, 0 for Read. */
  156. + switch (nor->read_opcode) {
  157. + case SPINOR_OP_READ:
  158. + case SPINOR_OP_READ4:
  159. + read_dummy = 0;
  160. + break;
  161. +
  162. + default:
  163. + read_dummy = 8;
  164. + break;
  165. + }
  166. + nor->read_dummy = read_dummy;
  167. return 0;
  168. }
  169. @@ -1469,6 +1501,7 @@ static int spansion_set_quad_mode(struct spi_nor *nor)
  170. }
  171. nor->read_proto = SNOR_PROTO_1_1_4;
  172. nor->read_opcode = SPINOR_OP_READ_1_1_4;
  173. + nor->read_dummy = 8;
  174. return 0;
  175. }
  176. @@ -1476,12 +1509,27 @@ static int spansion_set_dual_mode(struct spi_nor *nor)
  177. {
  178. nor->read_proto = SNOR_PROTO_1_1_2;
  179. nor->read_opcode = SPINOR_OP_READ_1_1_2;
  180. + nor->read_dummy = 8;
  181. return 0;
  182. }
  183. static int spansion_set_single_mode(struct spi_nor *nor)
  184. {
  185. + u8 read_dummy;
  186. +
  187. + switch (nor->read_opcode) {
  188. + case SPINOR_OP_READ:
  189. + case SPINOR_OP_READ4:
  190. + read_dummy = 0;
  191. + break;
  192. +
  193. + default:
  194. + read_dummy = 8;
  195. + break;
  196. + }
  197. +
  198. nor->read_proto = SNOR_PROTO_1_1_1;
  199. + nor->read_dummy = read_dummy;
  200. return 0;
  201. }
  202. @@ -1696,11 +1744,14 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
  203. if (info->flags & SPI_NOR_NO_FR)
  204. nor->flash_read = SPI_NOR_NORMAL;
  205. - /* Default commands */
  206. - if (nor->flash_read == SPI_NOR_NORMAL)
  207. + /* Default commands and number of dummy cycles */
  208. + if (nor->flash_read == SPI_NOR_NORMAL) {
  209. nor->read_opcode = SPINOR_OP_READ;
  210. - else
  211. + nor->read_dummy = 0;
  212. + } else {
  213. nor->read_opcode = SPINOR_OP_READ_FAST;
  214. + nor->read_dummy = 8;
  215. + }
  216. nor->program_opcode = SPINOR_OP_PP;
  217. @@ -1715,8 +1766,8 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
  218. * - SNOR_PROTO_2_2_2 is either:
  219. * + Micron Dual mode enabled
  220. *
  221. - * The opcodes and the protocols are updated depending on the
  222. - * manufacturer.
  223. + * The opcodes, the protocols and the number of dummy cycles are updated
  224. + * depending on the manufacturer.
  225. * The read opcode and protocol should be updated by the relevant
  226. * function when entering Quad or Dual mode.
  227. */
  228. @@ -1780,8 +1831,6 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
  229. return -EINVAL;
  230. }
  231. - nor->read_dummy = spi_nor_read_dummy_cycles(nor);
  232. -
  233. dev_info(dev, "%s (%lld Kbytes)\n", info->name,
  234. (long long)mtd->size >> 10);
  235. --
  236. 2.8.1