diff options
author | Vladimir Oltean <olteanv@gmail.com> | 2019-10-12 01:31:14 +0300 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2019-10-15 13:16:56 -0400 |
commit | 8a559400da42abd9e1a5f6232b0f57d6dd374f64 (patch) | |
tree | 22098d59f07a110193919a7bab5dd530be7e9866 /drivers | |
parent | f58a887ebc990b4d01a5a53330be06c384e089c4 (diff) | |
download | linux-8a559400da42abd9e1a5f6232b0f57d6dd374f64.tar.bz2 |
net: dsa: sja1105: Move sja1105_spi_transfer into sja1105_xfer
This is a cosmetic patch that reduces some boilerplate in the SPI
interaction of the driver.
Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/net/dsa/sja1105/sja1105_spi.c | 48 |
1 files changed, 15 insertions, 33 deletions
diff --git a/drivers/net/dsa/sja1105/sja1105_spi.c b/drivers/net/dsa/sja1105/sja1105_spi.c index 007688440f6c..a7532fb3c162 100644 --- a/drivers/net/dsa/sja1105/sja1105_spi.c +++ b/drivers/net/dsa/sja1105/sja1105_spi.c @@ -13,36 +13,6 @@ #define SJA1105_SIZE_SPI_TRANSFER_MAX \ (SJA1105_SIZE_SPI_MSG_HEADER + SJA1105_SIZE_SPI_MSG_MAXLEN) -static int sja1105_spi_transfer(const struct sja1105_private *priv, - const void *tx, void *rx, int size) -{ - struct spi_device *spi = priv->spidev; - struct spi_transfer transfer = { - .tx_buf = tx, - .rx_buf = rx, - .len = size, - }; - struct spi_message msg; - int rc; - - if (size > SJA1105_SIZE_SPI_TRANSFER_MAX) { - dev_err(&spi->dev, "SPI message (%d) longer than max of %d\n", - size, SJA1105_SIZE_SPI_TRANSFER_MAX); - return -EMSGSIZE; - } - - spi_message_init(&msg); - spi_message_add_tail(&transfer, &msg); - - rc = spi_sync(spi, &msg); - if (rc < 0) { - dev_err(&spi->dev, "SPI transfer failed: %d\n", rc); - return rc; - } - - return rc; -} - static void sja1105_spi_message_pack(void *buf, const struct sja1105_spi_message *msg) { @@ -69,10 +39,17 @@ int sja1105_xfer_buf(const struct sja1105_private *priv, sja1105_spi_rw_mode_t rw, u64 reg_addr, void *packed_buf, size_t size_bytes) { + const int msg_len = size_bytes + SJA1105_SIZE_SPI_MSG_HEADER; u8 tx_buf[SJA1105_SIZE_SPI_TRANSFER_MAX] = {0}; u8 rx_buf[SJA1105_SIZE_SPI_TRANSFER_MAX] = {0}; - const int msg_len = size_bytes + SJA1105_SIZE_SPI_MSG_HEADER; + struct spi_device *spi = priv->spidev; struct sja1105_spi_message msg = {0}; + struct spi_transfer xfer = { + .tx_buf = tx_buf, + .rx_buf = rx_buf, + .len = msg_len, + }; + struct spi_message m; int rc; if (msg_len > SJA1105_SIZE_SPI_TRANSFER_MAX) @@ -89,9 +66,14 @@ int sja1105_xfer_buf(const struct sja1105_private *priv, memcpy(tx_buf + SJA1105_SIZE_SPI_MSG_HEADER, packed_buf, size_bytes); - rc = sja1105_spi_transfer(priv, tx_buf, rx_buf, msg_len); - if (rc < 0) + spi_message_init(&m); + spi_message_add_tail(&xfer, &m); + + rc = spi_sync(spi, &m); + if (rc < 0) { + dev_err(&spi->dev, "SPI transfer failed: %d\n", rc); return rc; + } if (rw == SPI_READ) memcpy(packed_buf, rx_buf + SJA1105_SIZE_SPI_MSG_HEADER, |