406-mtd-m25p80-allow-to-specify-max-read-size.patch 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. --- a/drivers/mtd/devices/m25p80.c
  2. +++ b/drivers/mtd/devices/m25p80.c
  3. @@ -93,6 +93,7 @@ struct m25p {
  4. u8 erase_opcode;
  5. u8 *command;
  6. bool fast_read;
  7. + size_t max_read_len;
  8. };
  9. static inline struct m25p *mtd_to_m25p(struct mtd_info *mtd)
  10. @@ -344,6 +345,7 @@ static int m25p80_read(struct mtd_info *
  11. struct spi_transfer t[2];
  12. struct spi_message m;
  13. uint8_t opcode;
  14. + loff_t ofs;
  15. pr_debug("%s: %s from 0x%08x, len %zd\n", dev_name(&flash->spi->dev),
  16. __func__, (u32)from, len);
  17. @@ -359,19 +361,10 @@ static int m25p80_read(struct mtd_info *
  18. t[0].len = m25p_cmdsz(flash) + (flash->fast_read ? 1 : 0);
  19. spi_message_add_tail(&t[0], &m);
  20. - t[1].rx_buf = buf;
  21. - t[1].len = len;
  22. spi_message_add_tail(&t[1], &m);
  23. mutex_lock(&flash->lock);
  24. - /* Wait till previous write/erase is done. */
  25. - if (wait_till_ready(flash)) {
  26. - /* REVISIT status return?? */
  27. - mutex_unlock(&flash->lock);
  28. - return 1;
  29. - }
  30. -
  31. /* FIXME switch to OPCODE_FAST_READ. It's required for higher
  32. * clocks; and at this writing, every chip this driver handles
  33. * supports that opcode.
  34. @@ -380,13 +373,43 @@ static int m25p80_read(struct mtd_info *
  35. /* Set up the write data buffer. */
  36. opcode = flash->fast_read ? OPCODE_FAST_READ : OPCODE_NORM_READ;
  37. flash->command[0] = opcode;
  38. - m25p_addr2cmd(flash, from, flash->command);
  39. + ofs = 0;
  40. + while (len) {
  41. + size_t readlen;
  42. + size_t done;
  43. + int ret;
  44. +
  45. + ret = wait_till_ready(flash);
  46. + if (ret) {
  47. + mutex_unlock(&flash->lock);
  48. + return 1;
  49. + }
  50. +
  51. + if (flash->max_read_len > 0 &&
  52. + flash->max_read_len < len)
  53. + readlen = flash->max_read_len;
  54. + else
  55. + readlen = len;
  56. +
  57. + t[1].rx_buf = buf + ofs;
  58. + t[1].len = readlen;
  59. +
  60. + m25p_addr2cmd(flash, from + ofs, flash->command);
  61. +
  62. + spi_sync(flash->spi, &m);
  63. - spi_sync(flash->spi, &m);
  64. + done = m.actual_length - m25p_cmdsz(flash) -
  65. + (flash->fast_read ? 1 : 0);
  66. + if (done != readlen) {
  67. + mutex_unlock(&flash->lock);
  68. + return 1;
  69. + }
  70. - *retlen = m.actual_length - m25p_cmdsz(flash) -
  71. - (flash->fast_read ? 1 : 0);
  72. + ofs += done;
  73. + len -= done;
  74. + }
  75. + *retlen = ofs;
  76. mutex_unlock(&flash->lock);
  77. return 0;
  78. @@ -1022,6 +1045,12 @@ static int m25p_probe(struct spi_device
  79. flash->mtd._unlock = m25p80_unlock;
  80. }
  81. + if (data && data->max_read_len) {
  82. + flash->max_read_len = data->max_read_len;
  83. + dev_warn(&spi->dev, "max_read_len set to %d bytes\n",
  84. + flash->max_read_len);
  85. + }
  86. +
  87. /* sst flash chips use AAI word program */
  88. if (info->flags & SST_WRITE)
  89. flash->mtd._write = sst_write;
  90. --- a/include/linux/spi/flash.h
  91. +++ b/include/linux/spi/flash.h
  92. @@ -25,6 +25,7 @@ struct flash_platform_data {
  93. char *type;
  94. + size_t max_read_len;
  95. /* we'll likely add more ... use JEDEC IDs, etc */
  96. };