aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Brownell <david-b@pacbell.net>2007-05-08 03:32:21 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-05-08 14:15:16 -0400
commit33e34dc6ee2cb2cf2d50e65c5b825d9ebb8b9e66 (patch)
tree965e5feaaa7c7802129205bff03ec5e0982a75ba
parent814a8d50eb1d88cedcef97567be53ee0d4512631 (diff)
SPI kerneldoc
Various documentation updates for the SPI infrastructure, to clarify things that may not have been clear, to cope with lack of editing, and fix omissions. Also, plug SPI into the kernel-api DocBook template, and fix all the resulting glitches in document generation. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Cc: "Randy.Dunlap" <rdunlap@xenotime.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--Documentation/DocBook/kernel-api.tmpl63
-rw-r--r--Documentation/spi/spi-summary43
-rw-r--r--drivers/spi/spi.c33
-rw-r--r--include/linux/spi/spi.h82
4 files changed, 166 insertions, 55 deletions
diff --git a/Documentation/DocBook/kernel-api.tmpl b/Documentation/DocBook/kernel-api.tmpl
index b61dfc79e1b8..a2b2b4d187c5 100644
--- a/Documentation/DocBook/kernel-api.tmpl
+++ b/Documentation/DocBook/kernel-api.tmpl
@@ -576,4 +576,67 @@ X!Idrivers/video/console/fonts.c
576!Edrivers/input/ff-core.c 576!Edrivers/input/ff-core.c
577!Edrivers/input/ff-memless.c 577!Edrivers/input/ff-memless.c
578 </chapter> 578 </chapter>
579
580 <chapter id="spi">
581 <title>Serial Peripheral Interface (SPI)</title>
582 <para>
583 SPI is the "Serial Peripheral Interface", widely used with
584 embedded systems because it is a simple and efficient
585 interface: basically a multiplexed shift register.
586 Its three signal wires hold a clock (SCK, often in the range
587 of 1-20 MHz), a "Master Out, Slave In" (MOSI) data line, and
588 a "Master In, Slave Out" (MISO) data line.
589 SPI is a full duplex protocol; for each bit shifted out the
590 MOSI line (one per clock) another is shifted in on the MISO line.
591 Those bits are assembled into words of various sizes on the
592 way to and from system memory.
593 An additional chipselect line is usually active-low (nCS);
594 four signals are normally used for each peripheral, plus
595 sometimes an interrupt.
596 </para>
597 <para>
598 The SPI bus facilities listed here provide a generalized
599 interface to declare SPI busses and devices, manage them
600 according to the standard Linux driver model, and perform
601 input/output operations.
602 At this time, only "master" side interfaces are supported,
603 where Linux talks to SPI peripherals and does not implement
604 such a peripheral itself.
605 (Interfaces to support implementing SPI slaves would
606 necessarily look different.)
607 </para>
608 <para>
609 The programming interface is structured around two kinds of driver,
610 and two kinds of device.
611 A "Controller Driver" abstracts the controller hardware, which may
612 be as simple as a set of GPIO pins or as complex as a pair of FIFOs
613 connected to dual DMA engines on the other side of the SPI shift
614 register (maximizing throughput). Such drivers bridge between
615 whatever bus they sit on (often the platform bus) and SPI, and
616 expose the SPI side of their device as a
617 <structname>struct spi_master</structname>.
618 SPI devices are children of that master, represented as a
619 <structname>struct spi_device</structname> and manufactured from
620 <structname>struct spi_board_info</structname> descriptors which
621 are usually provided by board-specific initialization code.
622 A <structname>struct spi_driver</structname> is called a
623 "Protocol Driver", and is bound to a spi_device using normal
624 driver model calls.
625 </para>
626 <para>
627 The I/O model is a set of queued messages. Protocol drivers
628 submit one or more <structname>struct spi_message</structname>
629 objects, which are processed and completed asynchronously.
630 (There are synchronous wrappers, however.) Messages are
631 built from one or more <structname>struct spi_transfer</structname>
632 objects, each of which wraps a full duplex SPI transfer.
633 A variety of protocol tweaking options are needed, because
634 different chips adopt very different policies for how they
635 use the bits transferred with SPI.
636 </para>
637!Iinclude/linux/spi/spi.h
638!Fdrivers/spi/spi.c spi_register_board_info
639!Edrivers/spi/spi.c
640 </chapter>
641
579</book> 642</book>
diff --git a/Documentation/spi/spi-summary b/Documentation/spi/spi-summary
index ecc7c9eb9f29..795fbb48ffa7 100644
--- a/Documentation/spi/spi-summary
+++ b/Documentation/spi/spi-summary
@@ -8,7 +8,7 @@ What is SPI?
8The "Serial Peripheral Interface" (SPI) is a synchronous four wire serial 8The "Serial Peripheral Interface" (SPI) is a synchronous four wire serial
9link used to connect microcontrollers to sensors, memory, and peripherals. 9link used to connect microcontrollers to sensors, memory, and peripherals.
10 10
11The three signal wires hold a clock (SCLK, often on the order of 10 MHz), 11The three signal wires hold a clock (SCK, often on the order of 10 MHz),
12and parallel data lines with "Master Out, Slave In" (MOSI) or "Master In, 12and parallel data lines with "Master Out, Slave In" (MOSI) or "Master In,
13Slave Out" (MISO) signals. (Other names are also used.) There are four 13Slave Out" (MISO) signals. (Other names are also used.) There are four
14clocking modes through which data is exchanged; mode-0 and mode-3 are most 14clocking modes through which data is exchanged; mode-0 and mode-3 are most
@@ -22,7 +22,7 @@ other signals, often including an interrupt to the master.
22 22
23Unlike serial busses like USB or SMBUS, even low level protocols for 23Unlike serial busses like USB or SMBUS, even low level protocols for
24SPI slave functions are usually not interoperable between vendors 24SPI slave functions are usually not interoperable between vendors
25(except for cases like SPI memory chips). 25(except for commodities like SPI memory chips).
26 26
27 - SPI may be used for request/response style device protocols, as with 27 - SPI may be used for request/response style device protocols, as with
28 touchscreen sensors and memory chips. 28 touchscreen sensors and memory chips.
@@ -77,8 +77,9 @@ cards without needing a special purpose MMC/SD/SDIO controller.
77How do these driver programming interfaces work? 77How do these driver programming interfaces work?
78------------------------------------------------ 78------------------------------------------------
79The <linux/spi/spi.h> header file includes kerneldoc, as does the 79The <linux/spi/spi.h> header file includes kerneldoc, as does the
80main source code, and you should certainly read that. This is just 80main source code, and you should certainly read that chapter of the
81an overview, so you get the big picture before the details. 81kernel API document. This is just an overview, so you get the big
82picture before those details.
82 83
83SPI requests always go into I/O queues. Requests for a given SPI device 84SPI requests always go into I/O queues. Requests for a given SPI device
84are always executed in FIFO order, and complete asynchronously through 85are always executed in FIFO order, and complete asynchronously through
@@ -88,7 +89,7 @@ a command and then reading its response.
88 89
89There are two types of SPI driver, here called: 90There are two types of SPI driver, here called:
90 91
91 Controller drivers ... these are often built in to System-On-Chip 92 Controller drivers ... controllers may be built in to System-On-Chip
92 processors, and often support both Master and Slave roles. 93 processors, and often support both Master and Slave roles.
93 These drivers touch hardware registers and may use DMA. 94 These drivers touch hardware registers and may use DMA.
94 Or they can be PIO bitbangers, needing just GPIO pins. 95 Or they can be PIO bitbangers, needing just GPIO pins.
@@ -108,18 +109,18 @@ those two types of driver. At this writing, Linux has no slave side
108programming interface. 109programming interface.
109 110
110There is a minimal core of SPI programming interfaces, focussing on 111There is a minimal core of SPI programming interfaces, focussing on
111using driver model to connect controller and protocol drivers using 112using the driver model to connect controller and protocol drivers using
112device tables provided by board specific initialization code. SPI 113device tables provided by board specific initialization code. SPI
113shows up in sysfs in several locations: 114shows up in sysfs in several locations:
114 115
115 /sys/devices/.../CTLR/spiB.C ... spi_device for on bus "B", 116 /sys/devices/.../CTLR/spiB.C ... spi_device on bus "B",
116 chipselect C, accessed through CTLR. 117 chipselect C, accessed through CTLR.
117 118
118 /sys/devices/.../CTLR/spiB.C/modalias ... identifies the driver 119 /sys/devices/.../CTLR/spiB.C/modalias ... identifies the driver
119 that should be used with this device (for hotplug/coldplug) 120 that should be used with this device (for hotplug/coldplug)
120 121
121 /sys/bus/spi/devices/spiB.C ... symlink to the physical 122 /sys/bus/spi/devices/spiB.C ... symlink to the physical
122 spiB-C device 123 spiB.C device
123 124
124 /sys/bus/spi/drivers/D ... driver for one or more spi*.* devices 125 /sys/bus/spi/drivers/D ... driver for one or more spi*.* devices
125 126
@@ -240,7 +241,7 @@ The board_info should provide enough information to let the system work
240without the chip's driver being loaded. The most troublesome aspect of 241without the chip's driver being loaded. The most troublesome aspect of
241that is likely the SPI_CS_HIGH bit in the spi_device.mode field, since 242that is likely the SPI_CS_HIGH bit in the spi_device.mode field, since
242sharing a bus with a device that interprets chipselect "backwards" is 243sharing a bus with a device that interprets chipselect "backwards" is
243not possible. 244not possible until the infrastructure knows how to deselect it.
244 245
245Then your board initialization code would register that table with the SPI 246Then your board initialization code would register that table with the SPI
246infrastructure, so that it's available later when the SPI master controller 247infrastructure, so that it's available later when the SPI master controller
@@ -268,16 +269,14 @@ board info based on the board that was hotplugged. Of course, you'd later
268call at least spi_unregister_device() when that board is removed. 269call at least spi_unregister_device() when that board is removed.
269 270
270When Linux includes support for MMC/SD/SDIO/DataFlash cards through SPI, those 271When Linux includes support for MMC/SD/SDIO/DataFlash cards through SPI, those
271configurations will also be dynamic. Fortunately, those devices all support 272configurations will also be dynamic. Fortunately, such devices all support
272basic device identification probes, so that support should hotplug normally. 273basic device identification probes, so they should hotplug normally.
273 274
274 275
275How do I write an "SPI Protocol Driver"? 276How do I write an "SPI Protocol Driver"?
276---------------------------------------- 277----------------------------------------
277All SPI drivers are currently kernel drivers. A userspace driver API 278Most SPI drivers are currently kernel drivers, but there's also support
278would just be another kernel driver, probably offering some lowlevel 279for userspace drivers. Here we talk only about kernel drivers.
279access through aio_read(), aio_write(), and ioctl() calls and using the
280standard userspace sysfs mechanisms to bind to a given SPI device.
281 280
282SPI protocol drivers somewhat resemble platform device drivers: 281SPI protocol drivers somewhat resemble platform device drivers:
283 282
@@ -319,7 +318,8 @@ might look like this unless you're creating a class_device:
319 318
320As soon as it enters probe(), the driver may issue I/O requests to 319As soon as it enters probe(), the driver may issue I/O requests to
321the SPI device using "struct spi_message". When remove() returns, 320the SPI device using "struct spi_message". When remove() returns,
322the driver guarantees that it won't submit any more such messages. 321or after probe() fails, the driver guarantees that it won't submit
322any more such messages.
323 323
324 - An spi_message is a sequence of protocol operations, executed 324 - An spi_message is a sequence of protocol operations, executed
325 as one atomic sequence. SPI driver controls include: 325 as one atomic sequence. SPI driver controls include:
@@ -368,7 +368,8 @@ the driver guarantees that it won't submit any more such messages.
368Some drivers may need to modify spi_device characteristics like the 368Some drivers may need to modify spi_device characteristics like the
369transfer mode, wordsize, or clock rate. This is done with spi_setup(), 369transfer mode, wordsize, or clock rate. This is done with spi_setup(),
370which would normally be called from probe() before the first I/O is 370which would normally be called from probe() before the first I/O is
371done to the device. 371done to the device. However, that can also be called at any time
372that no message is pending for that device.
372 373
373While "spi_device" would be the bottom boundary of the driver, the 374While "spi_device" would be the bottom boundary of the driver, the
374upper boundaries might include sysfs (especially for sensor readings), 375upper boundaries might include sysfs (especially for sensor readings),
@@ -445,11 +446,15 @@ SPI MASTER METHODS
445 This sets up the device clock rate, SPI mode, and word sizes. 446 This sets up the device clock rate, SPI mode, and word sizes.
446 Drivers may change the defaults provided by board_info, and then 447 Drivers may change the defaults provided by board_info, and then
447 call spi_setup(spi) to invoke this routine. It may sleep. 448 call spi_setup(spi) to invoke this routine. It may sleep.
449 Unless each SPI slave has its own configuration registers, don't
450 change them right away ... otherwise drivers could corrupt I/O
451 that's in progress for other SPI devices.
448 452
449 master->transfer(struct spi_device *spi, struct spi_message *message) 453 master->transfer(struct spi_device *spi, struct spi_message *message)
450 This must not sleep. Its responsibility is arrange that the 454 This must not sleep. Its responsibility is arrange that the
451 transfer happens and its complete() callback is issued; the two 455 transfer happens and its complete() callback is issued. The two
452 will normally happen later, after other transfers complete. 456 will normally happen later, after other transfers complete, and
457 if the controller is idle it will need to be kickstarted.
453 458
454 master->cleanup(struct spi_device *spi) 459 master->cleanup(struct spi_device *spi)
455 Your controller driver may use spi_device.controller_state to hold 460 Your controller driver may use spi_device.controller_state to hold
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 6657331eed93..c3219b29b5ac 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -152,6 +152,11 @@ static void spi_drv_shutdown(struct device *dev)
152 sdrv->shutdown(to_spi_device(dev)); 152 sdrv->shutdown(to_spi_device(dev));
153} 153}
154 154
155/**
156 * spi_register_driver - register a SPI driver
157 * @sdrv: the driver to register
158 * Context: can sleep
159 */
155int spi_register_driver(struct spi_driver *sdrv) 160int spi_register_driver(struct spi_driver *sdrv)
156{ 161{
157 sdrv->driver.bus = &spi_bus_type; 162 sdrv->driver.bus = &spi_bus_type;
@@ -183,7 +188,13 @@ static LIST_HEAD(board_list);
183static DECLARE_MUTEX(board_lock); 188static DECLARE_MUTEX(board_lock);
184 189
185 190
186/* On typical mainboards, this is purely internal; and it's not needed 191/**
192 * spi_new_device - instantiate one new SPI device
193 * @master: Controller to which device is connected
194 * @chip: Describes the SPI device
195 * Context: can sleep
196 *
197 * On typical mainboards, this is purely internal; and it's not needed
187 * after board init creates the hard-wired devices. Some development 198 * after board init creates the hard-wired devices. Some development
188 * platforms may not be able to use spi_register_board_info though, and 199 * platforms may not be able to use spi_register_board_info though, and
189 * this is exported so that for example a USB or parport based adapter 200 * this is exported so that for example a USB or parport based adapter
@@ -251,7 +262,12 @@ fail:
251} 262}
252EXPORT_SYMBOL_GPL(spi_new_device); 263EXPORT_SYMBOL_GPL(spi_new_device);
253 264
254/* 265/**
266 * spi_register_board_info - register SPI devices for a given board
267 * @info: array of chip descriptors
268 * @n: how many descriptors are provided
269 * Context: can sleep
270 *
255 * Board-specific early init code calls this (probably during arch_initcall) 271 * Board-specific early init code calls this (probably during arch_initcall)
256 * with segments of the SPI device table. Any device nodes are created later, 272 * with segments of the SPI device table. Any device nodes are created later,
257 * after the relevant parent SPI controller (bus_num) is defined. We keep 273 * after the relevant parent SPI controller (bus_num) is defined. We keep
@@ -337,9 +353,10 @@ static struct class spi_master_class = {
337/** 353/**
338 * spi_alloc_master - allocate SPI master controller 354 * spi_alloc_master - allocate SPI master controller
339 * @dev: the controller, possibly using the platform_bus 355 * @dev: the controller, possibly using the platform_bus
340 * @size: how much driver-private data to preallocate; the pointer to this 356 * @size: how much zeroed driver-private data to allocate; the pointer to this
341 * memory is in the class_data field of the returned class_device, 357 * memory is in the class_data field of the returned class_device,
342 * accessible with spi_master_get_devdata(). 358 * accessible with spi_master_get_devdata().
359 * Context: can sleep
343 * 360 *
344 * This call is used only by SPI master controller drivers, which are the 361 * This call is used only by SPI master controller drivers, which are the
345 * only ones directly touching chip registers. It's how they allocate 362 * only ones directly touching chip registers. It's how they allocate
@@ -375,6 +392,7 @@ EXPORT_SYMBOL_GPL(spi_alloc_master);
375/** 392/**
376 * spi_register_master - register SPI master controller 393 * spi_register_master - register SPI master controller
377 * @master: initialized master, originally from spi_alloc_master() 394 * @master: initialized master, originally from spi_alloc_master()
395 * Context: can sleep
378 * 396 *
379 * SPI master controllers connect to their drivers using some non-SPI bus, 397 * SPI master controllers connect to their drivers using some non-SPI bus,
380 * such as the platform bus. The final stage of probe() in that code 398 * such as the platform bus. The final stage of probe() in that code
@@ -437,6 +455,7 @@ static int __unregister(struct device *dev, void *unused)
437/** 455/**
438 * spi_unregister_master - unregister SPI master controller 456 * spi_unregister_master - unregister SPI master controller
439 * @master: the master being unregistered 457 * @master: the master being unregistered
458 * Context: can sleep
440 * 459 *
441 * This call is used only by SPI master controller drivers, which are the 460 * This call is used only by SPI master controller drivers, which are the
442 * only ones directly touching chip registers. 461 * only ones directly touching chip registers.
@@ -455,6 +474,7 @@ EXPORT_SYMBOL_GPL(spi_unregister_master);
455/** 474/**
456 * spi_busnum_to_master - look up master associated with bus_num 475 * spi_busnum_to_master - look up master associated with bus_num
457 * @bus_num: the master's bus number 476 * @bus_num: the master's bus number
477 * Context: can sleep
458 * 478 *
459 * This call may be used with devices that are registered after 479 * This call may be used with devices that are registered after
460 * arch init time. It returns a refcounted pointer to the relevant 480 * arch init time. It returns a refcounted pointer to the relevant
@@ -492,6 +512,7 @@ static void spi_complete(void *arg)
492 * spi_sync - blocking/synchronous SPI data transfers 512 * spi_sync - blocking/synchronous SPI data transfers
493 * @spi: device with which data will be exchanged 513 * @spi: device with which data will be exchanged
494 * @message: describes the data transfers 514 * @message: describes the data transfers
515 * Context: can sleep
495 * 516 *
496 * This call may only be used from a context that may sleep. The sleep 517 * This call may only be used from a context that may sleep. The sleep
497 * is non-interruptible, and has no timeout. Low-overhead controller 518 * is non-interruptible, and has no timeout. Low-overhead controller
@@ -508,7 +529,7 @@ static void spi_complete(void *arg)
508 * 529 *
509 * The return value is a negative error code if the message could not be 530 * The return value is a negative error code if the message could not be
510 * submitted, else zero. When the value is zero, then message->status is 531 * submitted, else zero. When the value is zero, then message->status is
511 * also defined: it's the completion code for the transfer, either zero 532 * also defined; it's the completion code for the transfer, either zero
512 * or a negative error code from the controller driver. 533 * or a negative error code from the controller driver.
513 */ 534 */
514int spi_sync(struct spi_device *spi, struct spi_message *message) 535int spi_sync(struct spi_device *spi, struct spi_message *message)
@@ -538,6 +559,7 @@ static u8 *buf;
538 * @n_tx: size of txbuf, in bytes 559 * @n_tx: size of txbuf, in bytes
539 * @rxbuf: buffer into which data will be read 560 * @rxbuf: buffer into which data will be read
540 * @n_rx: size of rxbuf, in bytes (need not be dma-safe) 561 * @n_rx: size of rxbuf, in bytes (need not be dma-safe)
562 * Context: can sleep
541 * 563 *
542 * This performs a half duplex MicroWire style transaction with the 564 * This performs a half duplex MicroWire style transaction with the
543 * device, sending txbuf and then reading rxbuf. The return value 565 * device, sending txbuf and then reading rxbuf. The return value
@@ -545,7 +567,8 @@ static u8 *buf;
545 * This call may only be used from a context that may sleep. 567 * This call may only be used from a context that may sleep.
546 * 568 *
547 * Parameters to this routine are always copied using a small buffer; 569 * Parameters to this routine are always copied using a small buffer;
548 * performance-sensitive or bulk transfer code should instead use 570 * portable code should never use this for more than 32 bytes.
571 * Performance-sensitive or bulk transfer code should instead use
549 * spi_{async,sync}() calls with dma-safe buffers. 572 * spi_{async,sync}() calls with dma-safe buffers.
550 */ 573 */
551int spi_write_then_read(struct spi_device *spi, 574int spi_write_then_read(struct spi_device *spi,
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 4f0f8c2e58a5..b6bedc3ee95c 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -32,11 +32,12 @@ extern struct bus_type spi_bus_type;
32 * @max_speed_hz: Maximum clock rate to be used with this chip 32 * @max_speed_hz: Maximum clock rate to be used with this chip
33 * (on this board); may be changed by the device's driver. 33 * (on this board); may be changed by the device's driver.
34 * The spi_transfer.speed_hz can override this for each transfer. 34 * The spi_transfer.speed_hz can override this for each transfer.
35 * @chip-select: Chipselect, distinguishing chips handled by "master". 35 * @chip_select: Chipselect, distinguishing chips handled by @master.
36 * @mode: The spi mode defines how data is clocked out and in. 36 * @mode: The spi mode defines how data is clocked out and in.
37 * This may be changed by the device's driver. 37 * This may be changed by the device's driver.
38 * The "active low" default for chipselect mode can be overridden, 38 * The "active low" default for chipselect mode can be overridden
39 * as can the "MSB first" default for each word in a transfer. 39 * (by specifying SPI_CS_HIGH) as can the "MSB first" default for
40 * each word in a transfer (by specifying SPI_LSB_FIRST).
40 * @bits_per_word: Data transfers involve one or more words; word sizes 41 * @bits_per_word: Data transfers involve one or more words; word sizes
41 * like eight or 12 bits are common. In-memory wordsizes are 42 * like eight or 12 bits are common. In-memory wordsizes are
42 * powers of two bytes (e.g. 20 bit samples use 32 bits). 43 * powers of two bytes (e.g. 20 bit samples use 32 bits).
@@ -48,14 +49,18 @@ extern struct bus_type spi_bus_type;
48 * @controller_state: Controller's runtime state 49 * @controller_state: Controller's runtime state
49 * @controller_data: Board-specific definitions for controller, such as 50 * @controller_data: Board-specific definitions for controller, such as
50 * FIFO initialization parameters; from board_info.controller_data 51 * FIFO initialization parameters; from board_info.controller_data
52 * @modalias: Name of the driver to use with this device, or an alias
53 * for that name. This appears in the sysfs "modalias" attribute
54 * for driver coldplugging, and in uevents used for hotplugging
51 * 55 *
52 * An spi_device is used to interchange data between an SPI slave 56 * A @spi_device is used to interchange data between an SPI slave
53 * (usually a discrete chip) and CPU memory. 57 * (usually a discrete chip) and CPU memory.
54 * 58 *
55 * In "dev", the platform_data is used to hold information about this 59 * In @dev, the platform_data is used to hold information about this
56 * device that's meaningful to the device's protocol driver, but not 60 * device that's meaningful to the device's protocol driver, but not
57 * to its controller. One example might be an identifier for a chip 61 * to its controller. One example might be an identifier for a chip
58 * variant with slightly different functionality. 62 * variant with slightly different functionality; another might be
63 * information about how this particular board wires the chip's pins.
59 */ 64 */
60struct spi_device { 65struct spi_device {
61 struct device dev; 66 struct device dev;
@@ -77,13 +82,15 @@ struct spi_device {
77 void *controller_data; 82 void *controller_data;
78 const char *modalias; 83 const char *modalias;
79 84
80 // likely need more hooks for more protocol options affecting how 85 /*
81 // the controller talks to each chip, like: 86 * likely need more hooks for more protocol options affecting how
82 // - memory packing (12 bit samples into low bits, others zeroed) 87 * the controller talks to each chip, like:
83 // - priority 88 * - memory packing (12 bit samples into low bits, others zeroed)
84 // - drop chipselect after each word 89 * - priority
85 // - chipselect delays 90 * - drop chipselect after each word
86 // - ... 91 * - chipselect delays
92 * - ...
93 */
87}; 94};
88 95
89static inline struct spi_device *to_spi_device(struct device *dev) 96static inline struct spi_device *to_spi_device(struct device *dev)
@@ -146,6 +153,11 @@ static inline struct spi_driver *to_spi_driver(struct device_driver *drv)
146 153
147extern int spi_register_driver(struct spi_driver *sdrv); 154extern int spi_register_driver(struct spi_driver *sdrv);
148 155
156/**
157 * spi_unregister_driver - reverse effect of spi_register_driver
158 * @sdrv: the driver to unregister
159 * Context: can sleep
160 */
149static inline void spi_unregister_driver(struct spi_driver *sdrv) 161static inline void spi_unregister_driver(struct spi_driver *sdrv)
150{ 162{
151 if (sdrv) 163 if (sdrv)
@@ -165,18 +177,20 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
165 * @setup: updates the device mode and clocking records used by a 177 * @setup: updates the device mode and clocking records used by a
166 * device's SPI controller; protocol code may call this. This 178 * device's SPI controller; protocol code may call this. This
167 * must fail if an unrecognized or unsupported mode is requested. 179 * must fail if an unrecognized or unsupported mode is requested.
180 * It's always safe to call this unless transfers are pending on
181 * the device whose settings are being modified.
168 * @transfer: adds a message to the controller's transfer queue. 182 * @transfer: adds a message to the controller's transfer queue.
169 * @cleanup: frees controller-specific state 183 * @cleanup: frees controller-specific state
170 * 184 *
171 * Each SPI master controller can communicate with one or more spi_device 185 * Each SPI master controller can communicate with one or more @spi_device
172 * children. These make a small bus, sharing MOSI, MISO and SCK signals 186 * children. These make a small bus, sharing MOSI, MISO and SCK signals
173 * but not chip select signals. Each device may be configured to use a 187 * but not chip select signals. Each device may be configured to use a
174 * different clock rate, since those shared signals are ignored unless 188 * different clock rate, since those shared signals are ignored unless
175 * the chip is selected. 189 * the chip is selected.
176 * 190 *
177 * The driver for an SPI controller manages access to those devices through 191 * The driver for an SPI controller manages access to those devices through
178 * a queue of spi_message transactions, copyin data between CPU memory and 192 * a queue of spi_message transactions, copying data between CPU memory and
179 * an SPI slave device). For each such message it queues, it calls the 193 * an SPI slave device. For each such message it queues, it calls the
180 * message's completion function when the transaction completes. 194 * message's completion function when the transaction completes.
181 */ 195 */
182struct spi_master { 196struct spi_master {
@@ -280,27 +294,27 @@ extern struct spi_master *spi_busnum_to_master(u16 busnum);
280 * struct spi_transfer - a read/write buffer pair 294 * struct spi_transfer - a read/write buffer pair
281 * @tx_buf: data to be written (dma-safe memory), or NULL 295 * @tx_buf: data to be written (dma-safe memory), or NULL
282 * @rx_buf: data to be read (dma-safe memory), or NULL 296 * @rx_buf: data to be read (dma-safe memory), or NULL
283 * @tx_dma: DMA address of tx_buf, if spi_message.is_dma_mapped 297 * @tx_dma: DMA address of tx_buf, if @spi_message.is_dma_mapped
284 * @rx_dma: DMA address of rx_buf, if spi_message.is_dma_mapped 298 * @rx_dma: DMA address of rx_buf, if @spi_message.is_dma_mapped
285 * @len: size of rx and tx buffers (in bytes) 299 * @len: size of rx and tx buffers (in bytes)
286 * @speed_hz: Select a speed other then the device default for this 300 * @speed_hz: Select a speed other then the device default for this
287 * transfer. If 0 the default (from spi_device) is used. 301 * transfer. If 0 the default (from @spi_device) is used.
288 * @bits_per_word: select a bits_per_word other then the device default 302 * @bits_per_word: select a bits_per_word other then the device default
289 * for this transfer. If 0 the default (from spi_device) is used. 303 * for this transfer. If 0 the default (from @spi_device) is used.
290 * @cs_change: affects chipselect after this transfer completes 304 * @cs_change: affects chipselect after this transfer completes
291 * @delay_usecs: microseconds to delay after this transfer before 305 * @delay_usecs: microseconds to delay after this transfer before
292 * (optionally) changing the chipselect status, then starting 306 * (optionally) changing the chipselect status, then starting
293 * the next transfer or completing this spi_message. 307 * the next transfer or completing this @spi_message.
294 * @transfer_list: transfers are sequenced through spi_message.transfers 308 * @transfer_list: transfers are sequenced through @spi_message.transfers
295 * 309 *
296 * SPI transfers always write the same number of bytes as they read. 310 * SPI transfers always write the same number of bytes as they read.
297 * Protocol drivers should always provide rx_buf and/or tx_buf. 311 * Protocol drivers should always provide @rx_buf and/or @tx_buf.
298 * In some cases, they may also want to provide DMA addresses for 312 * In some cases, they may also want to provide DMA addresses for
299 * the data being transferred; that may reduce overhead, when the 313 * the data being transferred; that may reduce overhead, when the
300 * underlying driver uses dma. 314 * underlying driver uses dma.
301 * 315 *
302 * If the transmit buffer is null, zeroes will be shifted out 316 * If the transmit buffer is null, zeroes will be shifted out
303 * while filling rx_buf. If the receive buffer is null, the data 317 * while filling @rx_buf. If the receive buffer is null, the data
304 * shifted in will be discarded. Only "len" bytes shift out (or in). 318 * shifted in will be discarded. Only "len" bytes shift out (or in).
305 * It's an error to try to shift out a partial word. (For example, by 319 * It's an error to try to shift out a partial word. (For example, by
306 * shifting out three bytes with word size of sixteen or twenty bits; 320 * shifting out three bytes with word size of sixteen or twenty bits;
@@ -309,7 +323,7 @@ extern struct spi_master *spi_busnum_to_master(u16 busnum);
309 * In-memory data values are always in native CPU byte order, translated 323 * In-memory data values are always in native CPU byte order, translated
310 * from the wire byte order (big-endian except with SPI_LSB_FIRST). So 324 * from the wire byte order (big-endian except with SPI_LSB_FIRST). So
311 * for example when bits_per_word is sixteen, buffers are 2N bytes long 325 * for example when bits_per_word is sixteen, buffers are 2N bytes long
312 * and hold N sixteen bit words in CPU byte order. 326 * (@len = 2N) and hold N sixteen bit words in CPU byte order.
313 * 327 *
314 * When the word size of the SPI transfer is not a power-of-two multiple 328 * When the word size of the SPI transfer is not a power-of-two multiple
315 * of eight bits, those in-memory words include extra bits. In-memory 329 * of eight bits, those in-memory words include extra bits. In-memory
@@ -318,7 +332,7 @@ extern struct spi_master *spi_busnum_to_master(u16 busnum);
318 * 332 *
319 * All SPI transfers start with the relevant chipselect active. Normally 333 * All SPI transfers start with the relevant chipselect active. Normally
320 * it stays selected until after the last transfer in a message. Drivers 334 * it stays selected until after the last transfer in a message. Drivers
321 * can affect the chipselect signal using cs_change: 335 * can affect the chipselect signal using cs_change.
322 * 336 *
323 * (i) If the transfer isn't the last one in the message, this flag is 337 * (i) If the transfer isn't the last one in the message, this flag is
324 * used to make the chipselect briefly go inactive in the middle of the 338 * used to make the chipselect briefly go inactive in the middle of the
@@ -372,7 +386,7 @@ struct spi_transfer {
372 * @queue: for use by whichever driver currently owns the message 386 * @queue: for use by whichever driver currently owns the message
373 * @state: for use by whichever driver currently owns the message 387 * @state: for use by whichever driver currently owns the message
374 * 388 *
375 * An spi_message is used to execute an atomic sequence of data transfers, 389 * A @spi_message is used to execute an atomic sequence of data transfers,
376 * each represented by a struct spi_transfer. The sequence is "atomic" 390 * each represented by a struct spi_transfer. The sequence is "atomic"
377 * in the sense that no other spi_message may use that SPI bus until that 391 * in the sense that no other spi_message may use that SPI bus until that
378 * sequence completes. On some systems, many such sequences can execute as 392 * sequence completes. On some systems, many such sequences can execute as
@@ -464,8 +478,9 @@ static inline void spi_message_free(struct spi_message *m)
464} 478}
465 479
466/** 480/**
467 * spi_setup -- setup SPI mode and clock rate 481 * spi_setup - setup SPI mode and clock rate
468 * @spi: the device whose settings are being modified 482 * @spi: the device whose settings are being modified
483 * Context: can sleep
469 * 484 *
470 * SPI protocol drivers may need to update the transfer mode if the 485 * SPI protocol drivers may need to update the transfer mode if the
471 * device doesn't work with the mode 0 default. They may likewise need 486 * device doesn't work with the mode 0 default. They may likewise need
@@ -474,7 +489,7 @@ static inline void spi_message_free(struct spi_message *m)
474 * The changes take effect the next time the device is selected and data 489 * The changes take effect the next time the device is selected and data
475 * is transferred to or from it. 490 * is transferred to or from it.
476 * 491 *
477 * Note that this call wil fail if the protocol driver specifies an option 492 * Note that this call will fail if the protocol driver specifies an option
478 * that the underlying controller or its driver does not support. For 493 * that the underlying controller or its driver does not support. For
479 * example, not all hardware supports wire transfers using nine bit words, 494 * example, not all hardware supports wire transfers using nine bit words,
480 * LSB-first wire encoding, or active-high chipselects. 495 * LSB-first wire encoding, or active-high chipselects.
@@ -487,9 +502,10 @@ spi_setup(struct spi_device *spi)
487 502
488 503
489/** 504/**
490 * spi_async -- asynchronous SPI transfer 505 * spi_async - asynchronous SPI transfer
491 * @spi: device with which data will be exchanged 506 * @spi: device with which data will be exchanged
492 * @message: describes the data transfers, including completion callback 507 * @message: describes the data transfers, including completion callback
508 * Context: any (irqs may be blocked, etc)
493 * 509 *
494 * This call may be used in_irq and other contexts which can't sleep, 510 * This call may be used in_irq and other contexts which can't sleep,
495 * as well as from task contexts which can sleep. 511 * as well as from task contexts which can sleep.
@@ -535,6 +551,7 @@ extern int spi_sync(struct spi_device *spi, struct spi_message *message);
535 * @spi: device to which data will be written 551 * @spi: device to which data will be written
536 * @buf: data buffer 552 * @buf: data buffer
537 * @len: data buffer size 553 * @len: data buffer size
554 * Context: can sleep
538 * 555 *
539 * This writes the buffer and returns zero or a negative error code. 556 * This writes the buffer and returns zero or a negative error code.
540 * Callable only from contexts that can sleep. 557 * Callable only from contexts that can sleep.
@@ -558,8 +575,9 @@ spi_write(struct spi_device *spi, const u8 *buf, size_t len)
558 * @spi: device from which data will be read 575 * @spi: device from which data will be read
559 * @buf: data buffer 576 * @buf: data buffer
560 * @len: data buffer size 577 * @len: data buffer size
578 * Context: can sleep
561 * 579 *
562 * This writes the buffer and returns zero or a negative error code. 580 * This reads the buffer and returns zero or a negative error code.
563 * Callable only from contexts that can sleep. 581 * Callable only from contexts that can sleep.
564 */ 582 */
565static inline int 583static inline int
@@ -585,6 +603,7 @@ extern int spi_write_then_read(struct spi_device *spi,
585 * spi_w8r8 - SPI synchronous 8 bit write followed by 8 bit read 603 * spi_w8r8 - SPI synchronous 8 bit write followed by 8 bit read
586 * @spi: device with which data will be exchanged 604 * @spi: device with which data will be exchanged
587 * @cmd: command to be written before data is read back 605 * @cmd: command to be written before data is read back
606 * Context: can sleep
588 * 607 *
589 * This returns the (unsigned) eight bit number returned by the 608 * This returns the (unsigned) eight bit number returned by the
590 * device, or else a negative error code. Callable only from 609 * device, or else a negative error code. Callable only from
@@ -605,6 +624,7 @@ static inline ssize_t spi_w8r8(struct spi_device *spi, u8 cmd)
605 * spi_w8r16 - SPI synchronous 8 bit write followed by 16 bit read 624 * spi_w8r16 - SPI synchronous 8 bit write followed by 16 bit read
606 * @spi: device with which data will be exchanged 625 * @spi: device with which data will be exchanged
607 * @cmd: command to be written before data is read back 626 * @cmd: command to be written before data is read back
627 * Context: can sleep
608 * 628 *
609 * This returns the (unsigned) sixteen bit number returned by the 629 * This returns the (unsigned) sixteen bit number returned by the
610 * device, or else a negative error code. Callable only from 630 * device, or else a negative error code. Callable only from