1 /* SPDX-License-Identifier: GPL-2.0+ */ 2 /* 3 * Copyright (C) 2018 Exceet Electronics GmbH 4 * Copyright (C) 2018 Bootlin 5 * 6 * Author: Boris Brezillon <boris.brezillon@bootlin.com> 7 * 8 * Helpers needed by the SPI core and its tests. Should not be used outside 9 * drivers/spi/. 10 */ 11 12 #ifndef __LINUX_SPI_INTERNALS_H 13 #define __LINUX_SPI_INTERNALS_H 14 15 #include <linux/device.h> 16 #include <linux/dma-direction.h> 17 #include <linux/scatterlist.h> 18 #include <linux/spi/spi.h> 19 20 void spi_flush_queue(struct spi_controller *ctrl); 21 22 #ifdef CONFIG_HAS_DMA 23 #if IS_ENABLED(CONFIG_KUNIT) 24 int __spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg); 25 int __spi_unmap_msg(struct spi_controller *ctlr, struct spi_message *msg); 26 #endif 27 28 int spi_map_buf(struct spi_controller *ctlr, struct device *dev, 29 struct sg_table *sgt, void *buf, size_t len, 30 enum dma_data_direction dir); 31 void spi_unmap_buf(struct spi_controller *ctlr, struct device *dev, 32 struct sg_table *sgt, enum dma_data_direction dir); 33 #else /* !CONFIG_HAS_DMA */ 34 static inline int spi_map_buf(struct spi_controller *ctlr, struct device *dev, 35 struct sg_table *sgt, void *buf, size_t len, 36 enum dma_data_direction dir) 37 { 38 return -EINVAL; 39 } 40 41 static inline void spi_unmap_buf(struct spi_controller *ctlr, 42 struct device *dev, struct sg_table *sgt, 43 enum dma_data_direction dir) 44 { 45 } 46 #endif /* CONFIG_HAS_DMA */ 47 48 static inline bool spi_xfer_is_dma_mapped(struct spi_controller *ctlr, 49 struct spi_device *spi, 50 struct spi_transfer *xfer) 51 { 52 return ctlr->can_dma && ctlr->can_dma(ctlr, spi, xfer) && 53 (xfer->tx_sg_mapped || xfer->rx_sg_mapped); 54 } 55 56 #endif /* __LINUX_SPI_INTERNALS_H */ 57