0044-mtd-add-chunked-read-io-to-m25p80.patch 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. --- a/drivers/mtd/devices/m25p80.c
  2. +++ b/drivers/mtd/devices/m25p80.c
  3. @@ -19,6 +19,7 @@
  4. #include <linux/errno.h>
  5. #include <linux/module.h>
  6. #include <linux/device.h>
  7. +#include <linux/of.h>
  8. #include <linux/mtd/mtd.h>
  9. #include <linux/mtd/partitions.h>
  10. @@ -32,6 +33,7 @@ struct m25p {
  11. struct spi_device *spi;
  12. struct spi_nor spi_nor;
  13. struct mtd_info mtd;
  14. + u16 chunk_size;
  15. u8 command[MAX_CMD_SIZE];
  16. };
  17. @@ -157,6 +159,61 @@ static int m25p80_read(struct spi_nor *n
  18. return 0;
  19. }
  20. +static void m25p80_chunked_write(struct spi_nor *nor, loff_t _from, size_t _len,
  21. + size_t *_retlen, const u_char *_buf)
  22. +{
  23. + struct m25p *flash = nor->priv;
  24. + int chunk_size;
  25. + int retlen = 0;
  26. +
  27. + chunk_size = flash->chunk_size;
  28. + if (!chunk_size)
  29. + chunk_size = _len;
  30. +
  31. + if (nor->addr_width > 3)
  32. + chunk_size -= nor->addr_width - 3;
  33. +
  34. + while (retlen < _len) {
  35. + size_t len = min_t(int, chunk_size, _len - retlen);
  36. + const u_char *buf = _buf + retlen;
  37. + loff_t from = _from + retlen;
  38. +
  39. + nor->wait_till_ready(nor);
  40. + nor->write_reg(nor, SPINOR_OP_WREN, NULL, 0, 0);
  41. +
  42. + m25p80_write(nor, from, len, &retlen, buf);
  43. + }
  44. + *_retlen += retlen;
  45. +}
  46. +
  47. +static int m25p80_chunked_read(struct spi_nor *nor, loff_t _from, size_t _len,
  48. + size_t *_retlen, u_char *_buf)
  49. +{
  50. + struct m25p *flash = nor->priv;
  51. + int chunk_size;
  52. +
  53. + chunk_size = flash->chunk_size;
  54. + if (!chunk_size)
  55. + chunk_size = _len;
  56. +
  57. + *_retlen = 0;
  58. +
  59. + while (*_retlen < _len) {
  60. + size_t len = min_t(int, chunk_size, _len - *_retlen);
  61. + u_char *buf = _buf + *_retlen;
  62. + loff_t from = _from + *_retlen;
  63. + int retlen = 0;
  64. + int ret = m25p80_read(nor, from, len, &retlen, buf);
  65. +
  66. + if (ret)
  67. + return ret;
  68. +
  69. + *_retlen += retlen;
  70. + }
  71. +
  72. + return 0;
  73. +}
  74. +
  75. static int m25p80_erase(struct spi_nor *nor, loff_t offset)
  76. {
  77. struct m25p *flash = nor->priv;
  78. @@ -197,6 +254,7 @@ static int m25p_probe(struct spi_device
  79. struct spi_nor *nor;
  80. enum read_mode mode = SPI_NOR_NORMAL;
  81. char *flash_name = NULL;
  82. + u32 val;
  83. int ret;
  84. data = dev_get_platdata(&spi->dev);
  85. @@ -244,6 +302,14 @@ static int m25p_probe(struct spi_device
  86. if (ret)
  87. return ret;
  88. + if (spi->dev.of_node &&
  89. + !of_property_read_u32(spi->dev.of_node, "m25p,chunked-io", &val)) {
  90. + dev_warn(&spi->dev, "using chunked io\n");
  91. + nor->read = m25p80_chunked_read;
  92. + nor->write = m25p80_chunked_write;
  93. + flash->chunk_size = val;
  94. + }
  95. +
  96. ppdata.of_node = spi->dev.of_node;
  97. return mtd_device_parse_register(&flash->mtd, NULL, &ppdata,