0003-can-mcp251x-convert-to-half-duplex-SPI.patch 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. From 097cc81ee5c15913ad330baffff2e3dea09bdad0 Mon Sep 17 00:00:00 2001
  2. From: Tim Harvey <[email protected]>
  3. Date: Thu, 30 Aug 2018 15:16:08 -0700
  4. Subject: [PATCH] can: mcp251x: convert driver to half-duplex SPI
  5. Some SPI host controllers such as the Cavium Thunder TX do not support
  6. full-duplex SPI. Using half-duplex transfers allows the driver to work
  7. with those host controllers.
  8. Signed-off-by: Tim Harvey <[email protected]>
  9. ---
  10. drivers/net/can/spi/mcp251x.c | 15 ++++++++-------
  11. 1 file changed, 8 insertions(+), 7 deletions(-)
  12. --- a/drivers/net/can/spi/mcp251x.c
  13. +++ b/drivers/net/can/spi/mcp251x.c
  14. @@ -291,23 +291,23 @@ static u8 mcp251x_read_reg(struct spi_de
  15. priv->spi_tx_buf[0] = INSTRUCTION_READ;
  16. priv->spi_tx_buf[1] = reg;
  17. - mcp251x_spi_trans(spi, 3);
  18. - val = priv->spi_rx_buf[2];
  19. + spi_write_then_read(spi, priv->spi_tx_buf, 2, &val, 1);
  20. return val;
  21. }
  22. static void mcp251x_read_2regs(struct spi_device *spi, u8 reg, u8 *v1, u8 *v2)
  23. {
  24. + u8 val[4] = {0};
  25. struct mcp251x_priv *priv = spi_get_drvdata(spi);
  26. priv->spi_tx_buf[0] = INSTRUCTION_READ;
  27. priv->spi_tx_buf[1] = reg;
  28. - mcp251x_spi_trans(spi, 4);
  29. + spi_write_then_read(spi, priv->spi_tx_buf, 2, val, 2);
  30. - *v1 = priv->spi_rx_buf[2];
  31. - *v2 = priv->spi_rx_buf[3];
  32. + *v1 = val[0];
  33. + *v2 = val[1];
  34. }
  35. static void mcp251x_write_reg(struct spi_device *spi, u8 reg, u8 val)
  36. @@ -398,8 +398,9 @@ static void mcp251x_hw_rx_frame(struct s
  37. buf[i] = mcp251x_read_reg(spi, RXBCTRL(buf_idx) + i);
  38. } else {
  39. priv->spi_tx_buf[RXBCTRL_OFF] = INSTRUCTION_READ_RXB(buf_idx);
  40. - mcp251x_spi_trans(spi, SPI_TRANSFER_BUF_LEN);
  41. - memcpy(buf, priv->spi_rx_buf, SPI_TRANSFER_BUF_LEN);
  42. + spi_write_then_read(spi, priv->spi_tx_buf, 1, priv->spi_rx_buf,
  43. + SPI_TRANSFER_BUF_LEN);
  44. + memcpy(buf + 1, priv->spi_rx_buf, SPI_TRANSFER_BUF_LEN - 1);
  45. }
  46. }