1094-mtd-spi-nor-stop-passing-around-retlen.patch 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. From a99477d72b500b48cb3614aad0ce096fe4e3f437 Mon Sep 17 00:00:00 2001
  2. From: Michal Suchanek <hramrach@gmail.com>
  3. Date: Wed, 2 Dec 2015 10:38:20 +0000
  4. Subject: [PATCH 094/113] mtd: spi-nor: stop passing around retlen
  5. [context adjustment]
  6. not apply changes of drivers/mtd/devices/m25p80.c
  7. #################
  8. @@ -74,7 +74,7 @@ static int m25p80_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len)
  9. }
  10. static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len,
  11. - size_t *retlen, const u_char *buf)
  12. + const u_char *buf)
  13. {
  14. struct m25p *flash = nor->priv;
  15. struct spi_device *spi = flash->spi;
  16. @@ -106,7 +106,6 @@ static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len,
  17. ret = m.actual_length - cmd_sz;
  18. if (ret < 0)
  19. return -EIO;
  20. - *retlen += ret;
  21. return ret;
  22. }
  23. @@ -127,7 +126,7 @@ static inline unsigned int m25p80_rx_nbits(struct spi_nor *nor)
  24. * may be any size provided it is within the physical boundaries.
  25. */
  26. static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
  27. - size_t *retlen, u_char *buf)
  28. + u_char *buf)
  29. {
  30. struct m25p *flash = nor->priv;
  31. struct spi_device *spi = flash->spi;
  32. @@ -161,7 +160,6 @@ static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
  33. ret = m.actual_length - m25p_cmdsz(nor) - dummy;
  34. if (ret < 0)
  35. return -EIO;
  36. - *retlen += ret;
  37. return ret;
  38. }
  39. #################
  40. Do not pass retlen to hardware driver read/write functions. Update it in
  41. spi-nor generic driver instead.
  42. Signed-off-by: Michal Suchanek <hramrach@gmail.com>
  43. Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@freescale.com>
  44. Integrated-by: Jiang Yutang <yutang.jiang@nxp.com>
  45. ---
  46. drivers/mtd/spi-nor/fsl-quadspi.c | 16 ++++++----------
  47. drivers/mtd/spi-nor/spi-nor.c | 21 +++++++++++++--------
  48. include/linux/mtd/spi-nor.h | 4 ++--
  49. 3 files changed, 21 insertions(+), 20 deletions(-)
  50. --- a/drivers/mtd/spi-nor/fsl-quadspi.c
  51. +++ b/drivers/mtd/spi-nor/fsl-quadspi.c
  52. @@ -620,7 +620,7 @@ static inline void fsl_qspi_invalid(stru
  53. static ssize_t fsl_qspi_nor_write(struct fsl_qspi *q, struct spi_nor *nor,
  54. u8 opcode, unsigned int to, u32 *txbuf,
  55. - unsigned count, size_t *retlen)
  56. + unsigned count)
  57. {
  58. int ret, i, j;
  59. u32 tmp;
  60. @@ -647,11 +647,8 @@ static ssize_t fsl_qspi_nor_write(struct
  61. /* Trigger it */
  62. ret = fsl_qspi_runcmd(q, opcode, to, count);
  63. - if (ret == 0) {
  64. - if (retlen)
  65. - *retlen += count;
  66. + if (ret == 0)
  67. return count;
  68. - }
  69. return ret;
  70. }
  71. @@ -862,7 +859,7 @@ static int fsl_qspi_write_reg(struct spi
  72. } else if (len > 0) {
  73. ret = fsl_qspi_nor_write(q, nor, opcode, 0,
  74. - (u32 *)buf, len, NULL);
  75. + (u32 *)buf, len);
  76. if (ret > 0)
  77. return 0;
  78. } else {
  79. @@ -874,12 +871,11 @@ static int fsl_qspi_write_reg(struct spi
  80. }
  81. static ssize_t fsl_qspi_write(struct spi_nor *nor, loff_t to,
  82. - size_t len, size_t *retlen, const u_char *buf)
  83. + size_t len, const u_char *buf)
  84. {
  85. struct fsl_qspi *q = nor->priv;
  86. -
  87. ssize_t ret = fsl_qspi_nor_write(q, nor, nor->program_opcode, to,
  88. - (u32 *)buf, len, retlen);
  89. + (u32 *)buf, len);
  90. /* invalid the data in the AHB buffer. */
  91. fsl_qspi_invalid(q);
  92. @@ -887,7 +883,7 @@ static ssize_t fsl_qspi_write(struct spi
  93. }
  94. static ssize_t fsl_qspi_read(struct spi_nor *nor, loff_t from,
  95. - size_t len, size_t *retlen, u_char *buf)
  96. + size_t len, u_char *buf)
  97. {
  98. struct fsl_qspi *q = nor->priv;
  99. u8 cmd = nor->read_opcode;
  100. --- a/drivers/mtd/spi-nor/spi-nor.c
  101. +++ b/drivers/mtd/spi-nor/spi-nor.c
  102. @@ -927,12 +927,13 @@ static int spi_nor_read(struct mtd_info
  103. if (ret)
  104. return ret;
  105. - ret = nor->read(nor, from, len, retlen, buf);
  106. + ret = nor->read(nor, from, len, buf);
  107. spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_READ);
  108. if (ret < 0)
  109. return ret;
  110. + *retlen += ret;
  111. return 0;
  112. }
  113. @@ -959,7 +960,7 @@ static int sst_write(struct mtd_info *mt
  114. nor->program_opcode = SPINOR_OP_BP;
  115. /* write one byte. */
  116. - ret = nor->write(nor, to, 1, retlen, buf);
  117. + ret = nor->write(nor, to, 1, buf);
  118. if (ret < 0)
  119. goto sst_write_err;
  120. WARN(ret != 1, "While writing 1 byte written %i bytes\n",
  121. @@ -975,7 +976,7 @@ static int sst_write(struct mtd_info *mt
  122. nor->program_opcode = SPINOR_OP_AAI_WP;
  123. /* write two bytes. */
  124. - ret = nor->write(nor, to, 2, retlen, buf + actual);
  125. + ret = nor->write(nor, to, 2, buf + actual);
  126. if (ret < 0)
  127. goto sst_write_err;
  128. WARN(ret != 2, "While writing 2 bytes written %i bytes\n",
  129. @@ -998,7 +999,7 @@ static int sst_write(struct mtd_info *mt
  130. write_enable(nor);
  131. nor->program_opcode = SPINOR_OP_BP;
  132. - ret = nor->write(nor, to, 1, retlen, buf + actual);
  133. + ret = nor->write(nor, to, 1, buf + actual);
  134. if (ret < 0)
  135. goto sst_write_err;
  136. WARN(ret != 1, "While writing 1 byte written %i bytes\n",
  137. @@ -1007,8 +1008,10 @@ static int sst_write(struct mtd_info *mt
  138. if (ret)
  139. goto sst_write_err;
  140. write_disable(nor);
  141. + actual += 1;
  142. }
  143. sst_write_err:
  144. + *retlen += actual;
  145. spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_WRITE);
  146. return ret;
  147. }
  148. @@ -1037,15 +1040,17 @@ static int spi_nor_write(struct mtd_info
  149. /* do all the bytes fit onto one page? */
  150. if (page_offset + len <= nor->page_size) {
  151. - ret = nor->write(nor, to, len, retlen, buf);
  152. + ret = nor->write(nor, to, len, buf);
  153. if (ret < 0)
  154. goto write_err;
  155. + *retlen += ret;
  156. } else {
  157. /* the size of data remaining on the first page */
  158. page_size = nor->page_size - page_offset;
  159. - ret = nor->write(nor, to, page_size, retlen, buf);
  160. + ret = nor->write(nor, to, page_size, buf);
  161. if (ret < 0)
  162. goto write_err;
  163. + *retlen += ret;
  164. /* write everything in nor->page_size chunks */
  165. for (i = ret; i < len; ) {
  166. @@ -1059,10 +1064,10 @@ static int spi_nor_write(struct mtd_info
  167. write_enable(nor);
  168. - ret = nor->write(nor, to + i, page_size, retlen,
  169. - buf + i);
  170. + ret = nor->write(nor, to + i, page_size, buf + i);
  171. if (ret < 0)
  172. goto write_err;
  173. + *retlen += ret;
  174. i += ret;
  175. }
  176. }
  177. --- a/include/linux/mtd/spi-nor.h
  178. +++ b/include/linux/mtd/spi-nor.h
  179. @@ -171,9 +171,9 @@ struct spi_nor {
  180. int (*write_reg)(struct spi_nor *nor, u8 opcode, u8 *buf, int len);
  181. ssize_t (*read)(struct spi_nor *nor, loff_t from,
  182. - size_t len, size_t *retlen, u_char *read_buf);
  183. + size_t len, u_char *read_buf);
  184. ssize_t (*write)(struct spi_nor *nor, loff_t to,
  185. - size_t len, size_t *retlen, const u_char *write_buf);
  186. + size_t len, const u_char *write_buf);
  187. int (*erase)(struct spi_nor *nor, loff_t offs);
  188. int (*flash_lock)(struct spi_nor *nor, loff_t ofs, uint64_t len);