spi: Add an helper to flush the message queue
authorBoris Brezillon <boris.brezillon@bootlin.com>
Sun, 22 Apr 2018 18:35:15 +0000 (20:35 +0200)
committerMark Brown <broonie@kernel.org>
Mon, 23 Apr 2018 14:48:18 +0000 (15:48 +0100)
This is needed by the spi-mem logic to force all messages that have been
queued before a memory operation to be sent before we start the memory
operation. We do that in order to guarantee that spi-mem operations do
not preempt regular SPI transfers.

Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/internals.h
drivers/spi/spi.c

index dbe56c77b464253b7b6748bd01c59aa15f12929f..4a28a8395552d29d2ac2200b82346752ad07d4b8 100644 (file)
@@ -17,6 +17,8 @@
 #include <linux/scatterlist.h>
 #include <linux/spi/spi.h>
 
+void spi_flush_queue(struct spi_controller *ctrl);
+
 #ifdef CONFIG_HAS_DMA
 int spi_map_buf(struct spi_controller *ctlr, struct device *dev,
                struct sg_table *sgt, void *buf, size_t len,
index 86b778d8563ed7f1fb5f0fe94994cb7aab09350c..3f46663656789823b8e769edbb440fa7c9d1dc04 100644 (file)
@@ -1522,6 +1522,22 @@ err_init_queue:
        return ret;
 }
 
+/**
+ * spi_flush_queue - Send all pending messages in the queue from the callers'
+ *                  context
+ * @ctlr: controller to process queue for
+ *
+ * This should be used when one wants to ensure all pending messages have been
+ * sent before doing something. Is used by the spi-mem code to make sure SPI
+ * memory operations do not preempt regular SPI transfers that have been queued
+ * before the spi-mem operation.
+ */
+void spi_flush_queue(struct spi_controller *ctlr)
+{
+       if (ctlr->transfer == spi_queued_transfer)
+               __spi_pump_messages(ctlr, false);
+}
+
 /*-------------------------------------------------------------------------*/
 
 #if defined(CONFIG_OF)