summaryrefslogtreecommitdiff
path: root/drivers/spi
diff options
context:
space:
mode:
authorJagan Teki <jagan@amarulasolutions.com>2019-07-22 17:22:56 +0530
committerJagan Teki <jagan@amarulasolutions.com>2019-09-16 08:09:22 +0530
commit8473b32127232d8b602d905a2ed26ed48d352f6e (patch)
tree82042e052a45f86951a769e161eb0eac6a6671fa /drivers/spi
parent6bd6c21693547f1887b516bee11481e95e239ecb (diff)
downloadu-boot-8473b32127232d8b602d905a2ed26ed48d352f6e.tar.gz
u-boot-8473b32127232d8b602d905a2ed26ed48d352f6e.tar.bz2
u-boot-8473b32127232d8b602d905a2ed26ed48d352f6e.zip
spi: Add spi_write_then_read
Add support for SPI synchronous write followed by read, this is common interface call from spi-nor to spi drivers. Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Jagan Teki <jagan@amarulasolutions.com> Tested-by: Adam Ford <aford173@gmail.com> #da850-evm
Diffstat (limited to 'drivers/spi')
-rw-r--r--drivers/spi/spi-uclass.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
index 88cb2a1262..76c4b53c16 100644
--- a/drivers/spi/spi-uclass.c
+++ b/drivers/spi/spi-uclass.c
@@ -108,6 +108,30 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen,
return dm_spi_xfer(slave->dev, bitlen, dout, din, flags);
}
+int spi_write_then_read(struct spi_slave *slave, const u8 *opcode,
+ size_t n_opcode, const u8 *txbuf, u8 *rxbuf,
+ size_t n_buf)
+{
+ unsigned long flags = SPI_XFER_BEGIN;
+ int ret;
+
+ if (n_buf == 0)
+ flags |= SPI_XFER_END;
+
+ ret = spi_xfer(slave, n_opcode * 8, opcode, NULL, flags);
+ if (ret) {
+ debug("spi: failed to send command (%zu bytes): %d\n",
+ n_opcode, ret);
+ } else if (n_buf != 0) {
+ ret = spi_xfer(slave, n_buf * 8, txbuf, rxbuf, SPI_XFER_END);
+ if (ret)
+ debug("spi: failed to transfer %zu bytes of data: %d\n",
+ n_buf, ret);
+ }
+
+ return ret;
+}
+
#if !CONFIG_IS_ENABLED(OF_PLATDATA)
static int spi_child_post_bind(struct udevice *dev)
{