aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Brownell <david-b@pacbell.net>2006-01-08 16:34:23 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2006-01-13 19:29:54 -0500
commitb885244eb2628e0b8206e7edaaa6a314da78e9a4 (patch)
treee548fb3a94603c4a5406920c97246a78fe16b64a
parent1d6432fe10c3e724e307dd7137cd293a0edcae80 (diff)
[PATCH] spi: add spi_driver to SPI framework
This is a refresh of the "Simple SPI Framework" found in 2.6.15-rc3-mm1 which makes the following changes: * There's now a "struct spi_driver". This increase the footprint of the core a bit, since it now includes code to do what the driver core was previously handling directly. Documentation and comments were updated to match. * spi_alloc_master() now does class_device_initialize(), so it can at least be refcounted before spi_register_master(). To match, spi_register_master() switched over to class_device_add(). * States explicitly that after transfer errors, spi_devices will be deselected. We want fault recovery procedures to work the same for all controller drivers. * Minor tweaks: controller_data no longer points to readonly data; prevent some potential cast-from-null bugs with container_of calls; clarifies some existing kerneldoc, And a few small cleanups. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--Documentation/spi/spi-summary52
-rw-r--r--drivers/spi/spi.c118
-rw-r--r--include/linux/spi/spi.h75
3 files changed, 170 insertions, 75 deletions
diff --git a/Documentation/spi/spi-summary b/Documentation/spi/spi-summary
index 00497f95ca4b..c6152d1ff2b0 100644
--- a/Documentation/spi/spi-summary
+++ b/Documentation/spi/spi-summary
@@ -1,18 +1,19 @@
1Overview of Linux kernel SPI support 1Overview of Linux kernel SPI support
2==================================== 2====================================
3 3
422-Nov-2005 402-Dec-2005
5 5
6What is SPI? 6What is SPI?
7------------ 7------------
8The "Serial Peripheral Interface" (SPI) is a four-wire point-to-point 8The "Serial Peripheral Interface" (SPI) is a synchronous four wire serial
9serial link used to connect microcontrollers to sensors and memory. 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 (SCLK, 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
15commonly used. 15commonly used. Each clock cycle shifts data out and data in; the clock
16doesn't cycle except when there is data to shift.
16 17
17SPI masters may use a "chip select" line to activate a given SPI slave 18SPI masters may use a "chip select" line to activate a given SPI slave
18device, so those three signal wires may be connected to several chips 19device, so those three signal wires may be connected to several chips
@@ -79,11 +80,18 @@ The <linux/spi/spi.h> header file includes kerneldoc, as does the
79main source code, and you should certainly read that. This is just 80main source code, and you should certainly read that. This is just
80an overview, so you get the big picture before the details. 81an overview, so you get the big picture before the details.
81 82
83SPI requests always go into I/O queues. Requests for a given SPI device
84are always executed in FIFO order, and complete asynchronously through
85completion callbacks. There are also some simple synchronous wrappers
86for those calls, including ones for common transaction types like writing
87a command and then reading its response.
88
82There are two types of SPI driver, here called: 89There are two types of SPI driver, here called:
83 90
84 Controller drivers ... these are often built in to System-On-Chip 91 Controller drivers ... these are often built in to System-On-Chip
85 processors, and often support both Master and Slave roles. 92 processors, and often support both Master and Slave roles.
86 These drivers touch hardware registers and may use DMA. 93 These drivers touch hardware registers and may use DMA.
94 Or they can be PIO bitbangers, needing just GPIO pins.
87 95
88 Protocol drivers ... these pass messages through the controller 96 Protocol drivers ... these pass messages through the controller
89 driver to communicate with a Slave or Master device on the 97 driver to communicate with a Slave or Master device on the
@@ -116,11 +124,6 @@ shows up in sysfs in several locations:
116 managing bus "B". All the spiB.* devices share the same 124 managing bus "B". All the spiB.* devices share the same
117 physical SPI bus segment, with SCLK, MOSI, and MISO. 125 physical SPI bus segment, with SCLK, MOSI, and MISO.
118 126
119The basic I/O primitive submits an asynchronous message to an I/O queue
120maintained by the controller driver. A completion callback is issued
121asynchronously when the data transfer(s) in that message completes.
122There are also some simple synchronous wrappers for those calls.
123
124 127
125How does board-specific init code declare SPI devices? 128How does board-specific init code declare SPI devices?
126------------------------------------------------------ 129------------------------------------------------------
@@ -263,33 +266,40 @@ would just be another kernel driver, probably offering some lowlevel
263access through aio_read(), aio_write(), and ioctl() calls and using the 266access through aio_read(), aio_write(), and ioctl() calls and using the
264standard userspace sysfs mechanisms to bind to a given SPI device. 267standard userspace sysfs mechanisms to bind to a given SPI device.
265 268
266SPI protocol drivers are normal device drivers, with no more wrapper 269SPI protocol drivers somewhat resemble platform device drivers:
267than needed by platform devices: 270
271 static struct spi_driver CHIP_driver = {
272 .driver = {
273 .name = "CHIP",
274 .bus = &spi_bus_type,
275 .owner = THIS_MODULE,
276 },
268 277
269 static struct device_driver CHIP_driver = {
270 .name = "CHIP",
271 .bus = &spi_bus_type,
272 .probe = CHIP_probe, 278 .probe = CHIP_probe,
273 .remove = __exit_p(CHIP_remove), 279 .remove = __devexit_p(CHIP_remove),
274 .suspend = CHIP_suspend, 280 .suspend = CHIP_suspend,
275 .resume = CHIP_resume, 281 .resume = CHIP_resume,
276 }; 282 };
277 283
278The SPI core will autmatically attempt to bind this driver to any SPI 284The driver core will autmatically attempt to bind this driver to any SPI
279device whose board_info gave a modalias of "CHIP". Your probe() code 285device whose board_info gave a modalias of "CHIP". Your probe() code
280might look like this unless you're creating a class_device: 286might look like this unless you're creating a class_device:
281 287
282 static int __init CHIP_probe(struct device *dev) 288 static int __devinit CHIP_probe(struct spi_device *spi)
283 { 289 {
284 struct spi_device *spi = to_spi_device(dev);
285 struct CHIP *chip; 290 struct CHIP *chip;
286 struct CHIP_platform_data *pdata = dev->platform_data; 291 struct CHIP_platform_data *pdata;
292
293 /* assuming the driver requires board-specific data: */
294 pdata = &spi->dev.platform_data;
295 if (!pdata)
296 return -ENODEV;
287 297
288 /* get memory for driver's per-chip state */ 298 /* get memory for driver's per-chip state */
289 chip = kzalloc(sizeof *chip, GFP_KERNEL); 299 chip = kzalloc(sizeof *chip, GFP_KERNEL);
290 if (!chip) 300 if (!chip)
291 return -ENOMEM; 301 return -ENOMEM;
292 dev_set_drvdata(dev, chip); 302 dev_set_drvdata(&spi->dev, chip);
293 303
294 ... etc 304 ... etc
295 return 0; 305 return 0;
@@ -328,6 +338,8 @@ the driver guarantees that it won't submit any more such messages.
328 - The basic I/O primitive is spi_async(). Async requests may be 338 - The basic I/O primitive is spi_async(). Async requests may be
329 issued in any context (irq handler, task, etc) and completion 339 issued in any context (irq handler, task, etc) and completion
330 is reported using a callback provided with the message. 340 is reported using a callback provided with the message.
341 After any detected error, the chip is deselected and processing
342 of that spi_message is aborted.
331 343
332 - There are also synchronous wrappers like spi_sync(), and wrappers 344 - There are also synchronous wrappers like spi_sync(), and wrappers
333 like spi_read(), spi_write(), and spi_write_then_read(). These 345 like spi_read(), spi_write(), and spi_write_then_read(). These
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 7cd356b17644..2ecb86cb3689 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -26,13 +26,9 @@
26#include <linux/spi/spi.h> 26#include <linux/spi/spi.h>
27 27
28 28
29/* SPI bustype and spi_master class are registered during early boot, 29/* SPI bustype and spi_master class are registered after board init code
30 * usually before board init code provides the SPI device tables, and 30 * provides the SPI device tables, ensuring that both are present by the
31 * are available later when driver init code needs them. 31 * time controller driver registration causes spi_devices to "enumerate".
32 *
33 * Drivers for SPI devices started out like those for platform bus
34 * devices. But both have changed in 2.6.15; maybe this should get
35 * an "spi_driver" structure at some point (not currently needed)
36 */ 32 */
37static void spidev_release(struct device *dev) 33static void spidev_release(struct device *dev)
38{ 34{
@@ -83,10 +79,7 @@ static int spi_uevent(struct device *dev, char **envp, int num_envp,
83 79
84#ifdef CONFIG_PM 80#ifdef CONFIG_PM
85 81
86/* Suspend/resume in "struct device_driver" don't really need that 82/*
87 * strange third parameter, so we just make it a constant and expect
88 * SPI drivers to ignore it just like most platform drivers do.
89 *
90 * NOTE: the suspend() method for an spi_master controller driver 83 * NOTE: the suspend() method for an spi_master controller driver
91 * should verify that all its child devices are marked as suspended; 84 * should verify that all its child devices are marked as suspended;
92 * suspend requests delivered through sysfs power/state files don't 85 * suspend requests delivered through sysfs power/state files don't
@@ -94,13 +87,14 @@ static int spi_uevent(struct device *dev, char **envp, int num_envp,
94 */ 87 */
95static int spi_suspend(struct device *dev, pm_message_t message) 88static int spi_suspend(struct device *dev, pm_message_t message)
96{ 89{
97 int value; 90 int value;
91 struct spi_driver *drv = to_spi_driver(dev->driver);
98 92
99 if (!dev->driver || !dev->driver->suspend) 93 if (!drv || !drv->suspend)
100 return 0; 94 return 0;
101 95
102 /* suspend will stop irqs and dma; no more i/o */ 96 /* suspend will stop irqs and dma; no more i/o */
103 value = dev->driver->suspend(dev, message); 97 value = drv->suspend(to_spi_device(dev), message);
104 if (value == 0) 98 if (value == 0)
105 dev->power.power_state = message; 99 dev->power.power_state = message;
106 return value; 100 return value;
@@ -108,13 +102,14 @@ static int spi_suspend(struct device *dev, pm_message_t message)
108 102
109static int spi_resume(struct device *dev) 103static int spi_resume(struct device *dev)
110{ 104{
111 int value; 105 int value;
106 struct spi_driver *drv = to_spi_driver(dev->driver);
112 107
113 if (!dev->driver || !dev->driver->resume) 108 if (!drv || !drv->resume)
114 return 0; 109 return 0;
115 110
116 /* resume may restart the i/o queue */ 111 /* resume may restart the i/o queue */
117 value = dev->driver->resume(dev); 112 value = drv->resume(to_spi_device(dev));
118 if (value == 0) 113 if (value == 0)
119 dev->power.power_state = PMSG_ON; 114 dev->power.power_state = PMSG_ON;
120 return value; 115 return value;
@@ -135,6 +130,41 @@ struct bus_type spi_bus_type = {
135}; 130};
136EXPORT_SYMBOL_GPL(spi_bus_type); 131EXPORT_SYMBOL_GPL(spi_bus_type);
137 132
133
134static int spi_drv_probe(struct device *dev)
135{
136 const struct spi_driver *sdrv = to_spi_driver(dev->driver);
137
138 return sdrv->probe(to_spi_device(dev));
139}
140
141static int spi_drv_remove(struct device *dev)
142{
143 const struct spi_driver *sdrv = to_spi_driver(dev->driver);
144
145 return sdrv->remove(to_spi_device(dev));
146}
147
148static void spi_drv_shutdown(struct device *dev)
149{
150 const struct spi_driver *sdrv = to_spi_driver(dev->driver);
151
152 sdrv->shutdown(to_spi_device(dev));
153}
154
155int spi_register_driver(struct spi_driver *sdrv)
156{
157 sdrv->driver.bus = &spi_bus_type;
158 if (sdrv->probe)
159 sdrv->driver.probe = spi_drv_probe;
160 if (sdrv->remove)
161 sdrv->driver.remove = spi_drv_remove;
162 if (sdrv->shutdown)
163 sdrv->driver.shutdown = spi_drv_shutdown;
164 return driver_register(&sdrv->driver);
165}
166EXPORT_SYMBOL_GPL(spi_register_driver);
167
138/*-------------------------------------------------------------------------*/ 168/*-------------------------------------------------------------------------*/
139 169
140/* SPI devices should normally not be created by SPI device drivers; that 170/* SPI devices should normally not be created by SPI device drivers; that
@@ -208,13 +238,15 @@ spi_new_device(struct spi_master *master, struct spi_board_info *chip)
208 if (status < 0) { 238 if (status < 0) {
209 dev_dbg(dev, "can't %s %s, status %d\n", 239 dev_dbg(dev, "can't %s %s, status %d\n",
210 "add", proxy->dev.bus_id, status); 240 "add", proxy->dev.bus_id, status);
211fail: 241 goto fail;
212 class_device_put(&master->cdev);
213 kfree(proxy);
214 return NULL;
215 } 242 }
216 dev_dbg(dev, "registered child %s\n", proxy->dev.bus_id); 243 dev_dbg(dev, "registered child %s\n", proxy->dev.bus_id);
217 return proxy; 244 return proxy;
245
246fail:
247 class_device_put(&master->cdev);
248 kfree(proxy);
249 return NULL;
218} 250}
219EXPORT_SYMBOL_GPL(spi_new_device); 251EXPORT_SYMBOL_GPL(spi_new_device);
220 252
@@ -237,11 +269,11 @@ spi_register_board_info(struct spi_board_info const *info, unsigned n)
237{ 269{
238 struct boardinfo *bi; 270 struct boardinfo *bi;
239 271
240 bi = kmalloc (sizeof (*bi) + n * sizeof (*info), GFP_KERNEL); 272 bi = kmalloc(sizeof(*bi) + n * sizeof *info, GFP_KERNEL);
241 if (!bi) 273 if (!bi)
242 return -ENOMEM; 274 return -ENOMEM;
243 bi->n_board_info = n; 275 bi->n_board_info = n;
244 memcpy(bi->board_info, info, n * sizeof (*info)); 276 memcpy(bi->board_info, info, n * sizeof *info);
245 277
246 down(&board_lock); 278 down(&board_lock);
247 list_add_tail(&bi->list, &board_list); 279 list_add_tail(&bi->list, &board_list);
@@ -330,6 +362,7 @@ spi_alloc_master(struct device *dev, unsigned size)
330 if (!master) 362 if (!master)
331 return NULL; 363 return NULL;
332 364
365 class_device_initialize(&master->cdev);
333 master->cdev.class = &spi_master_class; 366 master->cdev.class = &spi_master_class;
334 master->cdev.dev = get_device(dev); 367 master->cdev.dev = get_device(dev);
335 class_set_devdata(&master->cdev, &master[1]); 368 class_set_devdata(&master->cdev, &master[1]);
@@ -366,7 +399,7 @@ spi_register_master(struct spi_master *master)
366 /* convention: dynamically assigned bus IDs count down from the max */ 399 /* convention: dynamically assigned bus IDs count down from the max */
367 if (master->bus_num == 0) { 400 if (master->bus_num == 0) {
368 master->bus_num = atomic_dec_return(&dyn_bus_id); 401 master->bus_num = atomic_dec_return(&dyn_bus_id);
369 dynamic = 0; 402 dynamic = 1;
370 } 403 }
371 404
372 /* register the device, then userspace will see it. 405 /* register the device, then userspace will see it.
@@ -374,11 +407,9 @@ spi_register_master(struct spi_master *master)
374 */ 407 */
375 snprintf(master->cdev.class_id, sizeof master->cdev.class_id, 408 snprintf(master->cdev.class_id, sizeof master->cdev.class_id,
376 "spi%u", master->bus_num); 409 "spi%u", master->bus_num);
377 status = class_device_register(&master->cdev); 410 status = class_device_add(&master->cdev);
378 if (status < 0) { 411 if (status < 0)
379 class_device_put(&master->cdev);
380 goto done; 412 goto done;
381 }
382 dev_dbg(dev, "registered master %s%s\n", master->cdev.class_id, 413 dev_dbg(dev, "registered master %s%s\n", master->cdev.class_id,
383 dynamic ? " (dynamic)" : ""); 414 dynamic ? " (dynamic)" : "");
384 415
@@ -491,6 +522,7 @@ static u8 *buf;
491 * This performs a half duplex MicroWire style transaction with the 522 * This performs a half duplex MicroWire style transaction with the
492 * device, sending txbuf and then reading rxbuf. The return value 523 * device, sending txbuf and then reading rxbuf. The return value
493 * is zero for success, else a negative errno status code. 524 * is zero for success, else a negative errno status code.
525 * This call may only be used from a context that may sleep.
494 * 526 *
495 * Parameters to this routine are always copied using a small buffer, 527 * Parameters to this routine are always copied using a small buffer,
496 * large transfers should use use spi_{async,sync}() calls with 528 * large transfers should use use spi_{async,sync}() calls with
@@ -553,16 +585,38 @@ EXPORT_SYMBOL_GPL(spi_write_then_read);
553 585
554static int __init spi_init(void) 586static int __init spi_init(void)
555{ 587{
588 int status;
589
556 buf = kmalloc(SPI_BUFSIZ, SLAB_KERNEL); 590 buf = kmalloc(SPI_BUFSIZ, SLAB_KERNEL);
557 if (!buf) 591 if (!buf) {
558 return -ENOMEM; 592 status = -ENOMEM;
593 goto err0;
594 }
595
596 status = bus_register(&spi_bus_type);
597 if (status < 0)
598 goto err1;
559 599
560 bus_register(&spi_bus_type); 600 status = class_register(&spi_master_class);
561 class_register(&spi_master_class); 601 if (status < 0)
602 goto err2;
562 return 0; 603 return 0;
604
605err2:
606 bus_unregister(&spi_bus_type);
607err1:
608 kfree(buf);
609 buf = NULL;
610err0:
611 return status;
563} 612}
613
564/* board_info is normally registered in arch_initcall(), 614/* board_info is normally registered in arch_initcall(),
565 * but even essential drivers wait till later 615 * but even essential drivers wait till later
616 *
617 * REVISIT only boardinfo really needs static linking. the rest (device and
618 * driver registration) _could_ be dynamically linked (modular) ... costs
619 * include needing to have boardinfo data structures be much more public.
566 */ 620 */
567subsys_initcall(spi_init); 621subsys_initcall(spi_init);
568 622
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 51a6769114df..c851b3d13208 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -20,13 +20,8 @@
20#define __LINUX_SPI_H 20#define __LINUX_SPI_H
21 21
22/* 22/*
23 * INTERFACES between SPI master drivers and infrastructure 23 * INTERFACES between SPI master-side drivers and SPI infrastructure.
24 * (There's no SPI slave support for Linux yet...) 24 * (There's no SPI slave support for Linux yet...)
25 *
26 * A "struct device_driver" for an spi_device uses "spi_bus_type" and
27 * needs no special API wrappers (much like platform_bus). These drivers
28 * are bound to devices based on their names (much like platform_bus),
29 * and are available in dev->driver.
30 */ 25 */
31extern struct bus_type spi_bus_type; 26extern struct bus_type spi_bus_type;
32 27
@@ -46,8 +41,8 @@ extern struct bus_type spi_bus_type;
46 * @irq: Negative, or the number passed to request_irq() to receive 41 * @irq: Negative, or the number passed to request_irq() to receive
47 * interrupts from this device. 42 * interrupts from this device.
48 * @controller_state: Controller's runtime state 43 * @controller_state: Controller's runtime state
49 * @controller_data: Static board-specific definitions for controller, such 44 * @controller_data: Board-specific definitions for controller, such as
50 * as FIFO initialization parameters; from board_info.controller_data 45 * FIFO initialization parameters; from board_info.controller_data
51 * 46 *
52 * An spi_device is used to interchange data between an SPI slave 47 * An spi_device is used to interchange data between an SPI slave
53 * (usually a discrete chip) and CPU memory. 48 * (usually a discrete chip) and CPU memory.
@@ -63,31 +58,32 @@ struct spi_device {
63 u32 max_speed_hz; 58 u32 max_speed_hz;
64 u8 chip_select; 59 u8 chip_select;
65 u8 mode; 60 u8 mode;
66#define SPI_CPHA 0x01 /* clock phase */ 61#define SPI_CPHA 0x01 /* clock phase */
67#define SPI_CPOL 0x02 /* clock polarity */ 62#define SPI_CPOL 0x02 /* clock polarity */
68#define SPI_MODE_0 (0|0) 63#define SPI_MODE_0 (0|0)
69#define SPI_MODE_1 (0|SPI_CPHA) 64#define SPI_MODE_1 (0|SPI_CPHA) /* (original MicroWire) */
70#define SPI_MODE_2 (SPI_CPOL|0) 65#define SPI_MODE_2 (SPI_CPOL|0)
71#define SPI_MODE_3 (SPI_CPOL|SPI_CPHA) 66#define SPI_MODE_3 (SPI_CPOL|SPI_CPHA)
72#define SPI_CS_HIGH 0x04 /* chipselect active high? */ 67#define SPI_CS_HIGH 0x04 /* chipselect active high? */
73 u8 bits_per_word; 68 u8 bits_per_word;
74 int irq; 69 int irq;
75 void *controller_state; 70 void *controller_state;
76 const void *controller_data; 71 void *controller_data;
77 const char *modalias; 72 const char *modalias;
78 73
79 // likely need more hooks for more protocol options affecting how 74 // likely need more hooks for more protocol options affecting how
80 // the controller talks to its chips, like: 75 // the controller talks to each chip, like:
81 // - bit order (default is wordwise msb-first) 76 // - bit order (default is wordwise msb-first)
82 // - memory packing (12 bit samples into low bits, others zeroed) 77 // - memory packing (12 bit samples into low bits, others zeroed)
83 // - priority 78 // - priority
79 // - drop chipselect after each word
84 // - chipselect delays 80 // - chipselect delays
85 // - ... 81 // - ...
86}; 82};
87 83
88static inline struct spi_device *to_spi_device(struct device *dev) 84static inline struct spi_device *to_spi_device(struct device *dev)
89{ 85{
90 return container_of(dev, struct spi_device, dev); 86 return dev ? container_of(dev, struct spi_device, dev) : NULL;
91} 87}
92 88
93/* most drivers won't need to care about device refcounting */ 89/* most drivers won't need to care about device refcounting */
@@ -117,12 +113,38 @@ static inline void spi_set_ctldata(struct spi_device *spi, void *state)
117struct spi_message; 113struct spi_message;
118 114
119 115
116
117struct spi_driver {
118 int (*probe)(struct spi_device *spi);
119 int (*remove)(struct spi_device *spi);
120 void (*shutdown)(struct spi_device *spi);
121 int (*suspend)(struct spi_device *spi, pm_message_t mesg);
122 int (*resume)(struct spi_device *spi);
123 struct device_driver driver;
124};
125
126static inline struct spi_driver *to_spi_driver(struct device_driver *drv)
127{
128 return drv ? container_of(drv, struct spi_driver, driver) : NULL;
129}
130
131extern int spi_register_driver(struct spi_driver *sdrv);
132
133static inline void spi_unregister_driver(struct spi_driver *sdrv)
134{
135 if (!sdrv)
136 return;
137 driver_unregister(&sdrv->driver);
138}
139
140
141
120/** 142/**
121 * struct spi_master - interface to SPI master controller 143 * struct spi_master - interface to SPI master controller
122 * @cdev: class interface to this driver 144 * @cdev: class interface to this driver
123 * @bus_num: board-specific (and often SOC-specific) identifier for a 145 * @bus_num: board-specific (and often SOC-specific) identifier for a
124 * given SPI controller. 146 * given SPI controller.
125 * @num_chipselects: chipselects are used to distinguish individual 147 * @num_chipselect: chipselects are used to distinguish individual
126 * SPI slaves, and are numbered from zero to num_chipselects. 148 * SPI slaves, and are numbered from zero to num_chipselects.
127 * each slave has a chipselect signal, but it's common that not 149 * each slave has a chipselect signal, but it's common that not
128 * every chipselect is connected to a slave. 150 * every chipselect is connected to a slave.
@@ -275,7 +297,8 @@ struct spi_transfer {
275 * addresses for each transfer buffer 297 * addresses for each transfer buffer
276 * @complete: called to report transaction completions 298 * @complete: called to report transaction completions
277 * @context: the argument to complete() when it's called 299 * @context: the argument to complete() when it's called
278 * @actual_length: how many bytes were transferd 300 * @actual_length: the total number of bytes that were transferred in all
301 * successful segments
279 * @status: zero for success, else negative errno 302 * @status: zero for success, else negative errno
280 * @queue: for use by whichever driver currently owns the message 303 * @queue: for use by whichever driver currently owns the message
281 * @state: for use by whichever driver currently owns the message 304 * @state: for use by whichever driver currently owns the message
@@ -295,7 +318,7 @@ struct spi_message {
295 * 318 *
296 * Some controller drivers (message-at-a-time queue processing) 319 * Some controller drivers (message-at-a-time queue processing)
297 * could provide that as their default scheduling algorithm. But 320 * could provide that as their default scheduling algorithm. But
298 * others (with multi-message pipelines) would need a flag to 321 * others (with multi-message pipelines) could need a flag to
299 * tell them about such special cases. 322 * tell them about such special cases.
300 */ 323 */
301 324
@@ -346,6 +369,13 @@ spi_setup(struct spi_device *spi)
346 * FIFO order, messages may go to different devices in other orders. 369 * FIFO order, messages may go to different devices in other orders.
347 * Some device might be higher priority, or have various "hard" access 370 * Some device might be higher priority, or have various "hard" access
348 * time requirements, for example. 371 * time requirements, for example.
372 *
373 * On detection of any fault during the transfer, processing of
374 * the entire message is aborted, and the device is deselected.
375 * Until returning from the associated message completion callback,
376 * no other spi_message queued to that device will be processed.
377 * (This rule applies equally to all the synchronous transfer calls,
378 * which are wrappers around this core asynchronous primitive.)
349 */ 379 */
350static inline int 380static inline int
351spi_async(struct spi_device *spi, struct spi_message *message) 381spi_async(struct spi_device *spi, struct spi_message *message)
@@ -484,12 +514,12 @@ struct spi_board_info {
484 * "modalias" is normally the driver name. 514 * "modalias" is normally the driver name.
485 * 515 *
486 * platform_data goes to spi_device.dev.platform_data, 516 * platform_data goes to spi_device.dev.platform_data,
487 * controller_data goes to spi_device.platform_data, 517 * controller_data goes to spi_device.controller_data,
488 * irq is copied too 518 * irq is copied too
489 */ 519 */
490 char modalias[KOBJ_NAME_LEN]; 520 char modalias[KOBJ_NAME_LEN];
491 const void *platform_data; 521 const void *platform_data;
492 const void *controller_data; 522 void *controller_data;
493 int irq; 523 int irq;
494 524
495 /* slower signaling on noisy or low voltage boards */ 525 /* slower signaling on noisy or low voltage boards */
@@ -525,9 +555,8 @@ spi_register_board_info(struct spi_board_info const *info, unsigned n)
525 555
526 556
527/* If you're hotplugging an adapter with devices (parport, usb, etc) 557/* If you're hotplugging an adapter with devices (parport, usb, etc)
528 * use spi_new_device() to describe each device. You can also call 558 * use spi_new_device() to describe each device. You would then call
529 * spi_unregister_device() to get start making that device vanish, 559 * spi_unregister_device() to start making that device vanish.
530 * but normally that would be handled by spi_unregister_master().
531 */ 560 */
532extern struct spi_device * 561extern struct spi_device *
533spi_new_device(struct spi_master *, struct spi_board_info *); 562spi_new_device(struct spi_master *, struct spi_board_info *);