From: Tim Harvey <tharvey@xxxxxxxxxxxxx> Some SPI host controllers such as the Cavium Thunder do not support full-duplex SPI. Using half-duplex transfers allows the driver to work with those host controllers. Signed-off-by: Tim Harvey <tharvey@xxxxxxxxxxxxx> Signed-off-by: Marc Kleine-Budde <mkl@xxxxxxxxxxxxxx> --- Hello, what about setting up a proper half duplex transfer like this? Marc Changes since v1: - use spi_sync_transfer instead of spi_write_then_read() drivers/net/can/spi/mcp251x.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/drivers/net/can/spi/mcp251x.c b/drivers/net/can/spi/mcp251x.c index a3897baa359f..26b7e4cb51ed 100644 --- a/drivers/net/can/spi/mcp251x.c +++ b/drivers/net/can/spi/mcp251x.c @@ -317,13 +317,26 @@ static int mcp251x_spi_trans(struct spi_device *spi, int len) static u8 mcp251x_read_reg(struct spi_device *spi, u8 reg) { struct mcp251x_priv *priv = spi_get_drvdata(spi); + struct spi_transfer xfer[] = { + { + .tx_buf = priv->spi_tx_buf, + .len = 2, + }, { + .rx_buf = priv->spi_rx_buf, + .len = 1, + }, + }; u8 val = 0; + int err; priv->spi_tx_buf[0] = INSTRUCTION_READ; priv->spi_tx_buf[1] = reg; - mcp251x_spi_trans(spi, 3); - val = priv->spi_rx_buf[2]; + err = spi_sync_transfer(spi, xfer, ARRAY_SIZE(xfer)); + if (err) + dev_err(&spi->dev, "spi transfer failed: ret = %d\n", err); + + val = priv->spi_rx_buf[0]; return val; } @@ -331,14 +344,26 @@ static u8 mcp251x_read_reg(struct spi_device *spi, u8 reg) static void mcp251x_read_2regs(struct spi_device *spi, u8 reg, u8 *v1, u8 *v2) { struct mcp251x_priv *priv = spi_get_drvdata(spi); + struct spi_transfer xfer[] = { + { + .tx_buf = priv->spi_tx_buf, + .len = 2, + }, { + .rx_buf = priv->spi_rx_buf, + .len = 2, + }, + }; + int err; priv->spi_tx_buf[0] = INSTRUCTION_READ; priv->spi_tx_buf[1] = reg; - mcp251x_spi_trans(spi, 4); + err = spi_sync_transfer(spi, xfer, ARRAY_SIZE(xfer)); + if (err) + dev_err(&spi->dev, "spi transfer failed: ret = %d\n", err); - *v1 = priv->spi_rx_buf[2]; - *v2 = priv->spi_rx_buf[3]; + *v1 = priv->spi_rx_buf[0]; + *v2 = priv->spi_rx_buf[1]; } static void mcp251x_write_reg(struct spi_device *spi, u8 reg, u8 val) -- 2.25.0