203-MTD-DEVICES-m25p80-add-support-for-limiting-reads.patch 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. From 5fb4e8d7287ac8fcb33aae8b1e9e22c5a3c392bd Mon Sep 17 00:00:00 2001
  2. From: Jonas Gorski <jonas.gorski@gmail.com>
  3. Date: Thu, 10 Nov 2011 17:33:40 +0100
  4. Subject: [PATCH 51/79] MTD: DEVICES: m25p80: add support for limiting reads
  5. Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
  6. ---
  7. drivers/mtd/devices/m25p80.c | 29 +++++++++++++++++++++++++++--
  8. include/linux/spi/flash.h | 4 ++++
  9. 2 files changed, 31 insertions(+), 2 deletions(-)
  10. --- a/drivers/mtd/devices/m25p80.c
  11. +++ b/drivers/mtd/devices/m25p80.c
  12. @@ -31,6 +31,7 @@
  13. struct m25p {
  14. struct spi_device *spi;
  15. struct spi_nor spi_nor;
  16. + int max_transfer_len;
  17. u8 command[MAX_CMD_SIZE];
  18. };
  19. @@ -119,7 +120,7 @@ static inline unsigned int m25p80_rx_nbi
  20. * Read an address range from the nor chip. The address range
  21. * may be any size provided it is within the physical boundaries.
  22. */
  23. -static int m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
  24. +static int __m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
  25. size_t *retlen, u_char *buf)
  26. {
  27. struct m25p *flash = nor->priv;
  28. @@ -174,6 +175,29 @@ static int m25p80_read(struct spi_nor *n
  29. return 0;
  30. }
  31. +static int m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
  32. + size_t *retlen, u_char *buf)
  33. +{
  34. + struct m25p *flash = nor->priv;
  35. + size_t off;
  36. + size_t read_len = flash->max_transfer_len;
  37. + size_t part_len;
  38. + int ret = 0;
  39. +
  40. + if (!read_len)
  41. + return __m25p80_read(nor, from, len, retlen, buf);
  42. +
  43. + *retlen = 0;
  44. +
  45. + for (off = 0; off < len && !ret; off += read_len) {
  46. + ret = __m25p80_read(nor, from + off, min(len - off, read_len),
  47. + &part_len, buf + off);
  48. + *retlen += part_len;
  49. + }
  50. +
  51. + return ret;
  52. +}
  53. +
  54. static int m25p80_erase(struct spi_nor *nor, loff_t offset)
  55. {
  56. struct m25p *flash = nor->priv;
  57. @@ -244,6 +268,9 @@ static int m25p_probe(struct spi_device
  58. else
  59. flash_name = spi->modalias;
  60. + if (data)
  61. + flash->max_transfer_len = data->max_transfer_len;
  62. +
  63. ret = spi_nor_scan(nor, flash_name, mode);
  64. if (ret)
  65. return ret;
  66. --- a/include/linux/spi/flash.h
  67. +++ b/include/linux/spi/flash.h
  68. @@ -13,6 +13,8 @@ struct mtd_part_parser_data;
  69. * @part_probe_types: optional list of MTD parser names to use for
  70. * partitioning
  71. *
  72. + * @max_transfer_len: option maximum read/write length limitation for
  73. + * SPI controllers not able to transfer any length commands.
  74. * Board init code (in arch/.../mach-xxx/board-yyy.c files) can
  75. * provide information about SPI flash parts (such as DataFlash) to
  76. * help set up the device and its appropriate default partitioning.
  77. @@ -28,6 +30,8 @@ struct flash_platform_data {
  78. char *type;
  79. const char **part_probe_types;
  80. +
  81. + unsigned int max_transfer_len;
  82. /* we'll likely add more ... use JEDEC IDs, etc */
  83. };