Skip to content

Commit ffbbdd2

Browse files
linuswglikely
authored andcommitted
spi: create a message queueing infrastructure
This rips the message queue in the PL022 driver out and pushes it into (optional) common infrastructure. Drivers that want to use the message pumping thread will need to define the new per-messags transfer methods and leave the deprecated transfer() method as NULL. Most of the design is described in the documentation changes that are included in this patch. Since there is a queue that need to be stopped when the system is suspending/resuming, two new calls are implemented for the device drivers to call in their suspend()/resume() functions: spi_master_suspend() and spi_master_resume(). ChangeLog v1->v2: - Remove Kconfig entry and do not make the queue support optional at all, instead be more agressive and have it as part of the compulsory infrastructure. - If the .transfer() method is implemented, delete print a small deprecation notice and do not start the transfer pump. - Fix a bitrotted comment. ChangeLog v2->v3: - Fix up a problematic sequence courtesy of Chris Blair. - Stop rather than destroy the queue on suspend() courtesy of Chris Blair. Signed-off-by: Chris Blair <chris.blair@stericsson.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Tested-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Reviewed-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
1 parent 0b2182d commit ffbbdd2

File tree

4 files changed

+487
-264
lines changed

4 files changed

+487
-264
lines changed

Documentation/spi/spi-summary

+46-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Overview of Linux kernel SPI support
22
====================================
33

4-
21-May-2007
4+
02-Feb-2012
55

66
What is SPI?
77
------------
@@ -483,9 +483,9 @@ also initialize its own internal state. (See below about bus numbering
483483
and those methods.)
484484

485485
After you initialize the spi_master, then use spi_register_master() to
486-
publish it to the rest of the system. At that time, device nodes for
487-
the controller and any predeclared spi devices will be made available,
488-
and the driver model core will take care of binding them to drivers.
486+
publish it to the rest of the system. At that time, device nodes for the
487+
controller and any predeclared spi devices will be made available, and
488+
the driver model core will take care of binding them to drivers.
489489

490490
If you need to remove your SPI controller driver, spi_unregister_master()
491491
will reverse the effect of spi_register_master().
@@ -521,21 +521,53 @@ SPI MASTER METHODS
521521
** When you code setup(), ASSUME that the controller
522522
** is actively processing transfers for another device.
523523

524-
master->transfer(struct spi_device *spi, struct spi_message *message)
525-
This must not sleep. Its responsibility is arrange that the
526-
transfer happens and its complete() callback is issued. The two
527-
will normally happen later, after other transfers complete, and
528-
if the controller is idle it will need to be kickstarted.
529-
530524
master->cleanup(struct spi_device *spi)
531525
Your controller driver may use spi_device.controller_state to hold
532526
state it dynamically associates with that device. If you do that,
533527
be sure to provide the cleanup() method to free that state.
534528

529+
master->prepare_transfer_hardware(struct spi_master *master)
530+
This will be called by the queue mechanism to signal to the driver
531+
that a message is coming in soon, so the subsystem requests the
532+
driver to prepare the transfer hardware by issuing this call.
533+
This may sleep.
534+
535+
master->unprepare_transfer_hardware(struct spi_master *master)
536+
This will be called by the queue mechanism to signal to the driver
537+
that there are no more messages pending in the queue and it may
538+
relax the hardware (e.g. by power management calls). This may sleep.
539+
540+
master->transfer_one_message(struct spi_master *master,
541+
struct spi_message *mesg)
542+
The subsystem calls the driver to transfer a single message while
543+
queuing transfers that arrive in the meantime. When the driver is
544+
finished with this message, it must call
545+
spi_finalize_current_message() so the subsystem can issue the next
546+
transfer. This may sleep.
547+
548+
DEPRECATED METHODS
549+
550+
master->transfer(struct spi_device *spi, struct spi_message *message)
551+
This must not sleep. Its responsibility is arrange that the
552+
transfer happens and its complete() callback is issued. The two
553+
will normally happen later, after other transfers complete, and
554+
if the controller is idle it will need to be kickstarted. This
555+
method is not used on queued controllers and must be NULL if
556+
transfer_one_message() and (un)prepare_transfer_hardware() are
557+
implemented.
558+
535559

536560
SPI MESSAGE QUEUE
537561

538-
The bulk of the driver will be managing the I/O queue fed by transfer().
562+
If you are happy with the standard queueing mechanism provided by the
563+
SPI subsystem, just implement the queued methods specified above. Using
564+
the message queue has the upside of centralizing a lot of code and
565+
providing pure process-context execution of methods. The message queue
566+
can also be elevated to realtime priority on high-priority SPI traffic.
567+
568+
Unless the queueing mechanism in the SPI subsystem is selected, the bulk
569+
of the driver will be managing the I/O queue fed by the now deprecated
570+
function transfer().
539571

540572
That queue could be purely conceptual. For example, a driver used only
541573
for low-frequency sensor access might be fine using synchronous PIO.
@@ -561,4 +593,6 @@ Stephen Street
561593
Mark Underwood
562594
Andrew Victor
563595
Vitaly Wool
564-
596+
Grant Likely
597+
Mark Brown
598+
Linus Walleij

0 commit comments

Comments
 (0)