Skip to content

Commit

Permalink
can: mcp251x: convert driver to half-duplex SPI
Browse files Browse the repository at this point in the history
Some SPI host controllers such as the Cavium Thunder TX 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@gateworks.com>
  • Loading branch information
Gateworks committed Jun 18, 2020
1 parent 3511588 commit f284504
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions drivers/net/can/spi/mcp251x.c
Expand Up @@ -291,23 +291,23 @@ static u8 mcp251x_read_reg(struct spi_device *spi, u8 reg)
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;
}

static void mcp251x_read_2regs(struct spi_device *spi, u8 reg, u8 *v1, u8 *v2)
{
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];
}

static void mcp251x_write_reg(struct spi_device *spi, u8 reg, u8 val)
Expand Down Expand Up @@ -398,8 +398,9 @@ static void mcp251x_hw_rx_frame(struct spi_device *spi, u8 *buf,
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);
}
}

Expand Down

0 comments on commit f284504

Please sign in to comment.