The submission of zero-sized read requests in a write-only transaction fails at least for omap2_mcspi drivers and is pointless in general.
Even with this patch, zero-sized write requests might be submitted for read-only transactions, but for most SPI chips, there always is a command transferred (written) before reading data, so there is no such thing as a pure-read transaction.
Signed-off-by: Michael Karcher flashrom@mkarcher.dialup.fu-berlin.de --- linux_spi.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/linux_spi.c b/linux_spi.c index d994389..3d1ca3e 100644 --- a/linux_spi.c +++ b/linux_spi.c @@ -114,6 +114,7 @@ static int linux_spi_send_command(struct flashctx *flash, unsigned int writecnt, const unsigned char *txbuf, unsigned char *rxbuf) { + unsigned iocontrol_code; struct spi_ioc_transfer msg[2] = { { .tx_buf = (uint64_t)(ptrdiff_t)txbuf, @@ -128,7 +129,14 @@ static int linux_spi_send_command(struct flashctx *flash, unsigned int writecnt, if (fd == -1) return -1;
- if (ioctl(fd, SPI_IOC_MESSAGE(2), msg) == -1) { + /* Just submit the first (write) request in case there is nothing + to read. Otherwise submit both requests */ + if (readcnt == 0) + iocontrol_code = SPI_IOC_MESSAGE(1); + else + iocontrol_code = SPI_IOC_MESSAGE(2); + + if (ioctl(fd, iocontrol_code, msg) == -1) { msg_cerr("%s: ioctl: %s\n", __func__, strerror(errno)); return -1; }