[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>

authored by David Brownell and committed by Greg Kroah-Hartman b885244e 1d6432fe

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