Skip to content

Commit 39cefd8

Browse files
covanambroonie
authored andcommitted
spi: introduce SPI_TRANS_FAIL_IO for error reporting
The default message transfer implementation - spi_transfer_one_message - invokes the specific device driver's transfer_one(), then waits for completion. However, there is no mechanism for the device driver to report failure in the middle of the transfer. Introduce SPI_TRANS_FAIL_IO for drivers to report transfer failure. Signed-off-by: Nam Cao <namcao@linutronix.de> Acked-by: Linus Walleij <linus.walleij@linaro.org> Link: https://lore.kernel.org/r/4b420dac528e60f122adde16851da88e4798c1ea.1701274975.git.namcao@linutronix.de Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 2cc14f5 commit 39cefd8

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

drivers/spi/spi.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,9 @@ static int spi_transfer_wait(struct spi_controller *ctlr,
13611361
"SPI transfer timed out\n");
13621362
return -ETIMEDOUT;
13631363
}
1364+
1365+
if (xfer->error & SPI_TRANS_FAIL_IO)
1366+
return -EIO;
13641367
}
13651368

13661369
return 0;

include/linux/spi/spi.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,13 @@ extern struct spi_device *spi_new_ancillary_device(struct spi_device *spi, u8 ch
461461
* - return 1 if the transfer is still in progress. When
462462
* the driver is finished with this transfer it must
463463
* call spi_finalize_current_transfer() so the subsystem
464-
* can issue the next transfer. Note: transfer_one and
465-
* transfer_one_message are mutually exclusive; when both
466-
* are set, the generic subsystem does not call your
467-
* transfer_one callback.
464+
* can issue the next transfer. If the transfer fails, the
465+
* driver must set the flag SPI_TRANS_FAIL_IO to
466+
* spi_transfer->error first, before calling
467+
* spi_finalize_current_transfer().
468+
* Note: transfer_one and transfer_one_message are mutually
469+
* exclusive; when both are set, the generic subsystem does
470+
* not call your transfer_one callback.
468471
* @handle_err: the subsystem calls the driver to handle an error that occurs
469472
* in the generic implementation of transfer_one_message().
470473
* @mem_ops: optimized/dedicated operations for interactions with SPI memory.
@@ -1040,6 +1043,7 @@ struct spi_transfer {
10401043
unsigned len;
10411044

10421045
#define SPI_TRANS_FAIL_NO_START BIT(0)
1046+
#define SPI_TRANS_FAIL_IO BIT(1)
10431047
u16 error;
10441048

10451049
dma_addr_t tx_dma;

0 commit comments

Comments
 (0)