[PATCH V2 4/5] spi: core add spi_master.translate_message

kernel at martin.sperl.org kernel at martin.sperl.org
Mon Dec 7 07:21:47 PST 2015


From: Martin Sperl <kernel at martin.sperl.org>

Add translate_message to spi_master structure to allow
translations of spi_messages to happen independently of
prepare messages.

This "translations" are supposed to be using spi_res to handle the
reverse transformation (see spi_replace_transfers), so no explicit
code is necessary to revert any changes.

dma_mapping of spi_messages could also become part of this processing.

The long-term view is that this translation as well as the
dma_mapping of the messages may happen in a separate thread
when we are queueing those spi_messages - this would allows
for better use of cpu resources as well as reduction of latency
in the case of queuing.

Signed-off-by: Martin Sperl <kernel at martin.sperl.org>
---
 drivers/spi/spi.c       |   15 +++++++++++++++
 include/linux/spi/spi.h |    4 ++++
 2 files changed, 19 insertions(+)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 507dff0..40fb4cf 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1143,6 +1143,21 @@ static void __spi_pump_messages(struct spi_master *master, bool in_kthread)

 	trace_spi_message_start(master->cur_msg);

+	/* under some circumstances (i.e: when queuing a message) this
+	 * could get moved to a separate thread to reduce latencies
+	 * this could also handle the mapping of spi_transfers
+	 */
+	if (master->translate_message) {
+		ret = master->translate_message(master, master->cur_msg);
+		if (ret) {
+			dev_err(&master->dev,
+				"failed to translate message: %d\n", ret);
+			master->cur_msg->status = ret;
+			spi_finalize_current_message(master);
+			return;
+		}
+	}
+
 	if (master->prepare_message) {
 		ret = master->prepare_message(master, master->cur_msg);
 		if (ret) {
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index f5c9296..55e5864 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -363,6 +363,8 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
  * @handle_err: the subsystem calls the driver to handle an error that occurs
  *		in the generic implementation of transfer_one_message().
  * @unprepare_message: undo any work done by prepare_message().
+ * @translate_message: apply some message translations to optimize for the
+ *                     spi_master
  * @cs_gpios: Array of GPIOs to use as chip select lines; one per CS
  *	number. Any individual value may be -ENOENT for CS lines that
  *	are not GPIOs (driven by the SPI controller itself).
@@ -509,6 +511,8 @@ struct spi_master {
 			       struct spi_message *message);
 	int (*unprepare_message)(struct spi_master *master,
 				 struct spi_message *message);
+	int (*translate_message)(struct spi_master *master,
+				 struct spi_message *message);

 	/*
 	 * These hooks are for drivers that use a generic implementation
--
1.7.10.4




More information about the linux-rpi-kernel mailing list