aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorMark Brown <broonie@linaro.org>2013-10-05 06:50:40 -0400
committerMark Brown <broonie@linaro.org>2013-10-11 15:09:50 -0400
commitb158935f70b9c156903338053216dd0adf7ce31c (patch)
tree8fc35f89210cf56eb647c64f92a814c2ede84505 /include/linux
parent6bb9c0e34185717f5b0df4ad468476f64f0d73fb (diff)
spi: Provide common spi_message processing loop
The loops which SPI controller drivers use to process the list of transfers in a spi_message are typically very similar and have some error prone areas such as the handling of /CS. Help simplify drivers by factoring this code out into the core - if drivers provide a transfer_one() function instead of a transfer_one_message() function the core will handle processing at the message level. /CS can be controlled by either setting cs_gpio or providing a set_cs function. If this is not possible for hardware reasons then both can be omitted and the driver should continue to implement manual /CS handling. This is a first step in refactoring and it is expected that there will be further enhancements, for example factoring out of the mapping of transfers for DMA and the initiation and completion of interrupt driven transfers. Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/spi/spi.h21
1 files changed, 19 insertions, 2 deletions
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 000b50bee6c0..da371ab5ebeb 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -23,6 +23,7 @@
23#include <linux/mod_devicetable.h> 23#include <linux/mod_devicetable.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/kthread.h> 25#include <linux/kthread.h>
26#include <linux/completion.h>
26 27
27/* 28/*
28 * INTERFACES between SPI master-side drivers and SPI infrastructure. 29 * INTERFACES between SPI master-side drivers and SPI infrastructure.
@@ -150,8 +151,7 @@ static inline void *spi_get_drvdata(struct spi_device *spi)
150} 151}
151 152
152struct spi_message; 153struct spi_message;
153 154struct spi_transfer;
154
155 155
156/** 156/**
157 * struct spi_driver - Host side "protocol" driver 157 * struct spi_driver - Host side "protocol" driver
@@ -259,6 +259,7 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
259 * @cur_msg: the currently in-flight message 259 * @cur_msg: the currently in-flight message
260 * @cur_msg_prepared: spi_prepare_message was called for the currently 260 * @cur_msg_prepared: spi_prepare_message was called for the currently
261 * in-flight message 261 * in-flight message
262 * @xfer_completion: used by core tranfer_one_message()
262 * @busy: message pump is busy 263 * @busy: message pump is busy
263 * @running: message pump is running 264 * @running: message pump is running
264 * @rt: whether this queue is set to run as a realtime task 265 * @rt: whether this queue is set to run as a realtime task
@@ -276,9 +277,15 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
276 * @unprepare_transfer_hardware: there are currently no more messages on the 277 * @unprepare_transfer_hardware: there are currently no more messages on the
277 * queue so the subsystem notifies the driver that it may relax the 278 * queue so the subsystem notifies the driver that it may relax the
278 * hardware by issuing this call 279 * hardware by issuing this call
280 * @set_cs: assert or deassert chip select, true to assert. May be called
281 * from interrupt context.
279 * @prepare_message: set up the controller to transfer a single message, 282 * @prepare_message: set up the controller to transfer a single message,
280 * for example doing DMA mapping. Called from threaded 283 * for example doing DMA mapping. Called from threaded
281 * context. 284 * context.
285 * @transfer_one: transfer a single spi_transfer. When the
286 * driver is finished with this transfer it must call
287 * spi_finalize_current_transfer() so the subsystem can issue
288 * the next transfer
282 * @unprepare_message: undo any work done by prepare_message(). 289 * @unprepare_message: undo any work done by prepare_message().
283 * @cs_gpios: Array of GPIOs to use as chip select lines; one per CS 290 * @cs_gpios: Array of GPIOs to use as chip select lines; one per CS
284 * number. Any individual value may be -ENOENT for CS lines that 291 * number. Any individual value may be -ENOENT for CS lines that
@@ -395,6 +402,7 @@ struct spi_master {
395 bool rt; 402 bool rt;
396 bool auto_runtime_pm; 403 bool auto_runtime_pm;
397 bool cur_msg_prepared; 404 bool cur_msg_prepared;
405 struct completion xfer_completion;
398 406
399 int (*prepare_transfer_hardware)(struct spi_master *master); 407 int (*prepare_transfer_hardware)(struct spi_master *master);
400 int (*transfer_one_message)(struct spi_master *master, 408 int (*transfer_one_message)(struct spi_master *master,
@@ -405,6 +413,14 @@ struct spi_master {
405 int (*unprepare_message)(struct spi_master *master, 413 int (*unprepare_message)(struct spi_master *master,
406 struct spi_message *message); 414 struct spi_message *message);
407 415
416 /*
417 * These hooks are for drivers that use a generic implementation
418 * of transfer_one_message() provied by the core.
419 */
420 void (*set_cs)(struct spi_device *spi, bool enable);
421 int (*transfer_one)(struct spi_master *master, struct spi_device *spi,
422 struct spi_transfer *transfer);
423
408 /* gpio chip select */ 424 /* gpio chip select */
409 int *cs_gpios; 425 int *cs_gpios;
410}; 426};
@@ -439,6 +455,7 @@ extern int spi_master_resume(struct spi_master *master);
439/* Calls the driver make to interact with the message queue */ 455/* Calls the driver make to interact with the message queue */
440extern struct spi_message *spi_get_next_queued_message(struct spi_master *master); 456extern struct spi_message *spi_get_next_queued_message(struct spi_master *master);
441extern void spi_finalize_current_message(struct spi_master *master); 457extern void spi_finalize_current_message(struct spi_master *master);
458extern void spi_finalize_current_transfer(struct spi_master *master);
442 459
443/* the spi driver core manages memory for the spi_master classdev */ 460/* the spi driver core manages memory for the spi_master classdev */
444extern struct spi_master * 461extern struct spi_master *