@@ -570,25 +570,25 @@ static int __spi_map_msg(struct spi_master *master, struct spi_message *msg)
if (!master->can_dma(master, msg->spi, xfer))
continue;
- /* potentially add a flag to spi_master
- * (SPI_MASTER_MUST_TX_SG) to avoid unnecessary mapping
- */
- ret = spi_map_buf(master, tx_dev, &xfer->tx_sg,
- (void *)xfer->tx_buf, xfer->len,
- DMA_TO_DEVICE);
- if (ret != 0)
- return ret;
-
- /* potentially add a flag to spi_master
- * (SPI_MASTER_MUST_RX_SG) to avoid unnecessary mapping
- */
- ret = spi_map_buf(master, rx_dev, &xfer->rx_sg,
- xfer->rx_buf, xfer->len,
- DMA_FROM_DEVICE);
- if (ret != 0) {
- spi_unmap_buf(master, tx_dev, &xfer->tx_sg,
- DMA_TO_DEVICE);
- return ret;
+ if (xfer->tx_buf ||
+ (master->flags & SPI_MASTER_MUST_TX_SG)) {
+ ret = spi_map_buf(master, tx_dev, &xfer->tx_sg,
+ (void *)xfer->tx_buf, xfer->len,
+ DMA_TO_DEVICE);
+ if (ret != 0)
+ return ret;
+ }
+
+ if (xfer->rx_buf ||
+ (master->flags & SPI_MASTER_MUST_RX_SG)) {
+ ret = spi_map_buf(master, rx_dev, &xfer->rx_sg,
+ xfer->rx_buf, xfer->len,
+ DMA_FROM_DEVICE);
+ if (ret != 0) {
+ spi_unmap_buf(master, tx_dev, &xfer->tx_sg,
+ DMA_TO_DEVICE);
+ return ret;
+ }
}
}
@@ -357,6 +357,8 @@ struct spi_master {
#define SPI_MASTER_NO_TX BIT(2) /* can't do buffer write */
#define SPI_MASTER_MUST_RX BIT(3) /* requires rx */
#define SPI_MASTER_MUST_TX BIT(4) /* requires tx */
+#define SPI_MASTER_MUST_RX_SG BIT(5) /* requires rx sg_list */
+#define SPI_MASTER_MUST_TX_SG BIT(6) /* requires tx sg_list */
/* lock and mutex for SPI bus locking */
spinlock_t bus_lock_spinlock;