octeontx: fix mcp251x can controller
[openwrt/staging/rmilecki.git] / target / linux / octeontx / patches-5.4 / 0003-can-mcp251x-convert-to-half-duplex-SPI.patch
1 From 097cc81ee5c15913ad330baffff2e3dea09bdad0 Mon Sep 17 00:00:00 2001
2 From: Tim Harvey <tharvey@gateworks.com>
3 Date: Thu, 30 Aug 2018 15:16:08 -0700
4 Subject: [PATCH] can: mcp251x: convert driver to half-duplex SPI
5
6 Some SPI host controllers such as the Cavium Thunder TX do not support
7 full-duplex SPI. Using half-duplex transfers allows the driver to work
8 with those host controllers.
9
10 Signed-off-by: Tim Harvey <tharvey@gateworks.com>
11 ---
12 drivers/net/can/spi/mcp251x.c | 15 ++++++++-------
13 1 file changed, 8 insertions(+), 7 deletions(-)
14
15 diff --git a/drivers/net/can/spi/mcp251x.c b/drivers/net/can/spi/mcp251x.c
16 index bb20a9b..dc0574a 100644
17 --- a/drivers/net/can/spi/mcp251x.c
18 +++ b/drivers/net/can/spi/mcp251x.c
19 @@ -291,23 +291,23 @@ static u8 mcp251x_read_reg(struct spi_device *spi, u8 reg)
20 priv->spi_tx_buf[0] = INSTRUCTION_READ;
21 priv->spi_tx_buf[1] = reg;
22
23 - mcp251x_spi_trans(spi, 3);
24 - val = priv->spi_rx_buf[2];
25 + spi_write_then_read(spi, priv->spi_tx_buf, 2, &val, 1);
26
27 return val;
28 }
29
30 static void mcp251x_read_2regs(struct spi_device *spi, u8 reg, u8 *v1, u8 *v2)
31 {
32 + u8 val[4] = {0};
33 struct mcp251x_priv *priv = spi_get_drvdata(spi);
34
35 priv->spi_tx_buf[0] = INSTRUCTION_READ;
36 priv->spi_tx_buf[1] = reg;
37
38 - mcp251x_spi_trans(spi, 4);
39 + spi_write_then_read(spi, priv->spi_tx_buf, 2, val, 2);
40
41 - *v1 = priv->spi_rx_buf[2];
42 - *v2 = priv->spi_rx_buf[3];
43 + *v1 = val[0];
44 + *v2 = val[1];
45 }
46
47 static void mcp251x_write_reg(struct spi_device *spi, u8 reg, u8 val)
48 @@ -398,8 +398,9 @@ static void mcp251x_hw_rx_frame(struct spi_device *spi, u8 *buf,
49 buf[i] = mcp251x_read_reg(spi, RXBCTRL(buf_idx) + i);
50 } else {
51 priv->spi_tx_buf[RXBCTRL_OFF] = INSTRUCTION_READ_RXB(buf_idx);
52 - mcp251x_spi_trans(spi, SPI_TRANSFER_BUF_LEN);
53 - memcpy(buf, priv->spi_rx_buf, SPI_TRANSFER_BUF_LEN);
54 + spi_write_then_read(spi, priv->spi_tx_buf, 1, priv->spi_rx_buf,
55 + SPI_TRANSFER_BUF_LEN);
56 + memcpy(buf + 1, priv->spi_rx_buf, SPI_TRANSFER_BUF_LEN - 1);
57 }
58 }
59
60 --
61 2.7.4
62