182-spi-bcm53xx-simplify-reading-SPI-data.patch 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <[email protected]>
  2. Date: Fri, 29 Dec 2017 14:44:09 +0100
  3. Subject: [PATCH] spi: bcm53xx: simplify reading SPI data
  4. MIME-Version: 1.0
  5. Content-Type: text/plain; charset=UTF-8
  6. Content-Transfer-Encoding: 8bit
  7. This commit makes transfer function use spi_transfer_is_last to
  8. determine if currently processed transfer is the last one. Thanks to
  9. that we finally set hardware registers properly and it makes controller
  10. behave the way it's expected to.
  11. This allows simplifying read function which can now simply start reading
  12. from the slot 0 instead of the last saved offset. It has been
  13. successfully tested using spi_write_then_read.
  14. Moreover this change fixes handling messages with two writing transfers.
  15. It's important for SPI flash devices as their drivers commonly use one
  16. transfer for a command and another one for data.
  17. Signed-off-by: Rafał Miłecki <[email protected]>
  18. ---
  19. drivers/spi/spi-bcm53xx.c | 26 ++++++++++----------------
  20. 1 file changed, 10 insertions(+), 16 deletions(-)
  21. --- a/drivers/spi/spi-bcm53xx.c
  22. +++ b/drivers/spi/spi-bcm53xx.c
  23. @@ -27,8 +27,6 @@ struct bcm53xxspi {
  24. struct bcma_device *core;
  25. struct spi_master *master;
  26. void __iomem *mmio_base;
  27. -
  28. - size_t read_offset;
  29. bool bspi; /* Boot SPI mode with memory mapping */
  30. };
  31. @@ -172,8 +170,6 @@ static void bcm53xxspi_buf_write(struct
  32. if (!cont)
  33. bcm53xxspi_write(b53spi, B53SPI_MSPI_WRITE_LOCK, 0);
  34. -
  35. - b53spi->read_offset = len;
  36. }
  37. static void bcm53xxspi_buf_read(struct bcm53xxspi *b53spi, u8 *r_buf,
  38. @@ -182,10 +178,10 @@ static void bcm53xxspi_buf_read(struct b
  39. u32 tmp;
  40. int i;
  41. - for (i = 0; i < b53spi->read_offset + len; i++) {
  42. + for (i = 0; i < len; i++) {
  43. tmp = B53SPI_CDRAM_CONT | B53SPI_CDRAM_PCS_DISABLE_ALL |
  44. B53SPI_CDRAM_PCS_DSCK;
  45. - if (!cont && i == b53spi->read_offset + len - 1)
  46. + if (!cont && i == len - 1)
  47. tmp &= ~B53SPI_CDRAM_CONT;
  48. tmp &= ~0x1;
  49. /* Command Register File */
  50. @@ -194,8 +190,7 @@ static void bcm53xxspi_buf_read(struct b
  51. /* Set queue pointers */
  52. bcm53xxspi_write(b53spi, B53SPI_MSPI_NEWQP, 0);
  53. - bcm53xxspi_write(b53spi, B53SPI_MSPI_ENDQP,
  54. - b53spi->read_offset + len - 1);
  55. + bcm53xxspi_write(b53spi, B53SPI_MSPI_ENDQP, len - 1);
  56. if (cont)
  57. bcm53xxspi_write(b53spi, B53SPI_MSPI_WRITE_LOCK, 1);
  58. @@ -214,13 +209,11 @@ static void bcm53xxspi_buf_read(struct b
  59. bcm53xxspi_write(b53spi, B53SPI_MSPI_WRITE_LOCK, 0);
  60. for (i = 0; i < len; ++i) {
  61. - int offset = b53spi->read_offset + i;
  62. + u16 reg = B53SPI_MSPI_RXRAM + 4 * (1 + i * 2);
  63. /* Data stored in the transmit register file LSB */
  64. - r_buf[i] = (u8)bcm53xxspi_read(b53spi, B53SPI_MSPI_RXRAM + 4 * (1 + offset * 2));
  65. + r_buf[i] = (u8)bcm53xxspi_read(b53spi, reg);
  66. }
  67. -
  68. - b53spi->read_offset = 0;
  69. }
  70. static int bcm53xxspi_transfer_one(struct spi_master *master,
  71. @@ -238,7 +231,8 @@ static int bcm53xxspi_transfer_one(struc
  72. left = t->len;
  73. while (left) {
  74. size_t to_write = min_t(size_t, 16, left);
  75. - bool cont = left - to_write > 0;
  76. + bool cont = !spi_transfer_is_last(master, t) ||
  77. + left - to_write > 0;
  78. bcm53xxspi_buf_write(b53spi, buf, to_write, cont);
  79. left -= to_write;
  80. @@ -250,9 +244,9 @@ static int bcm53xxspi_transfer_one(struc
  81. buf = (u8 *)t->rx_buf;
  82. left = t->len;
  83. while (left) {
  84. - size_t to_read = min_t(size_t, 16 - b53spi->read_offset,
  85. - left);
  86. - bool cont = left - to_read > 0;
  87. + size_t to_read = min_t(size_t, 16, left);
  88. + bool cont = !spi_transfer_is_last(master, t) ||
  89. + left - to_read > 0;
  90. bcm53xxspi_buf_read(b53spi, buf, to_read, cont);
  91. left -= to_read;