2020-05-28 14:58:49 +00:00
|
|
|
From 097cc81ee5c15913ad330baffff2e3dea09bdad0 Mon Sep 17 00:00:00 2001
|
2020-02-26 20:40:11 +00:00
|
|
|
From: Tim Harvey <tharvey@gateworks.com>
|
2020-05-28 14:58:49 +00:00
|
|
|
Date: Thu, 30 Aug 2018 15:16:08 -0700
|
|
|
|
Subject: [PATCH] can: mcp251x: convert driver to half-duplex SPI
|
2020-02-26 20:40:11 +00:00
|
|
|
|
2020-05-28 14:58:49 +00:00
|
|
|
Some SPI host controllers such as the Cavium Thunder TX do not support
|
2020-02-26 20:40:11 +00:00
|
|
|
full-duplex SPI. Using half-duplex transfers allows the driver to work
|
|
|
|
with those host controllers.
|
|
|
|
|
|
|
|
Signed-off-by: Tim Harvey <tharvey@gateworks.com>
|
|
|
|
---
|
2020-05-28 14:58:49 +00:00
|
|
|
drivers/net/can/spi/mcp251x.c | 15 ++++++++-------
|
|
|
|
1 file changed, 8 insertions(+), 7 deletions(-)
|
2020-02-26 20:40:11 +00:00
|
|
|
|
|
|
|
--- a/drivers/net/can/spi/mcp251x.c
|
|
|
|
+++ b/drivers/net/can/spi/mcp251x.c
|
2020-06-09 12:18:25 +00:00
|
|
|
@@ -291,23 +291,23 @@ static u8 mcp251x_read_reg(struct spi_de
|
2020-02-26 20:40:11 +00:00
|
|
|
priv->spi_tx_buf[0] = INSTRUCTION_READ;
|
|
|
|
priv->spi_tx_buf[1] = reg;
|
|
|
|
|
|
|
|
- mcp251x_spi_trans(spi, 3);
|
|
|
|
- val = priv->spi_rx_buf[2];
|
|
|
|
+ spi_write_then_read(spi, priv->spi_tx_buf, 2, &val, 1);
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
2020-03-26 14:19:42 +00:00
|
|
|
|
|
|
|
static void mcp251x_read_2regs(struct spi_device *spi, u8 reg, u8 *v1, u8 *v2)
|
2020-02-26 20:40:11 +00:00
|
|
|
{
|
|
|
|
+ u8 val[4] = {0};
|
|
|
|
struct mcp251x_priv *priv = spi_get_drvdata(spi);
|
|
|
|
|
|
|
|
priv->spi_tx_buf[0] = INSTRUCTION_READ;
|
|
|
|
priv->spi_tx_buf[1] = reg;
|
|
|
|
|
|
|
|
- mcp251x_spi_trans(spi, 4);
|
|
|
|
+ spi_write_then_read(spi, priv->spi_tx_buf, 2, val, 2);
|
|
|
|
|
|
|
|
- *v1 = priv->spi_rx_buf[2];
|
|
|
|
- *v2 = priv->spi_rx_buf[3];
|
|
|
|
+ *v1 = val[0];
|
|
|
|
+ *v2 = val[1];
|
|
|
|
}
|
|
|
|
|
2020-03-26 14:19:42 +00:00
|
|
|
static void mcp251x_write_reg(struct spi_device *spi, u8 reg, u8 val)
|
2020-06-09 12:18:25 +00:00
|
|
|
@@ -398,8 +398,9 @@ static void mcp251x_hw_rx_frame(struct s
|
2020-05-28 14:58:49 +00:00
|
|
|
buf[i] = mcp251x_read_reg(spi, RXBCTRL(buf_idx) + i);
|
|
|
|
} else {
|
|
|
|
priv->spi_tx_buf[RXBCTRL_OFF] = INSTRUCTION_READ_RXB(buf_idx);
|
|
|
|
- mcp251x_spi_trans(spi, SPI_TRANSFER_BUF_LEN);
|
|
|
|
- memcpy(buf, priv->spi_rx_buf, SPI_TRANSFER_BUF_LEN);
|
|
|
|
+ spi_write_then_read(spi, priv->spi_tx_buf, 1, priv->spi_rx_buf,
|
|
|
|
+ SPI_TRANSFER_BUF_LEN);
|
|
|
|
+ memcpy(buf + 1, priv->spi_rx_buf, SPI_TRANSFER_BUF_LEN - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|