diff options
Diffstat (limited to 'include/linux/spi')
-rw-r--r-- | include/linux/spi/spi.h | 75 |
1 files changed, 52 insertions, 23 deletions
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 | */ |
31 | extern struct bus_type spi_bus_type; | 26 | extern 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 | ||
88 | static inline struct spi_device *to_spi_device(struct device *dev) | 84 | static 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) | |||
117 | struct spi_message; | 113 | struct spi_message; |
118 | 114 | ||
119 | 115 | ||
116 | |||
117 | struct 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 | |||
126 | static 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 | |||
131 | extern int spi_register_driver(struct spi_driver *sdrv); | ||
132 | |||
133 | static 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 | */ |
350 | static inline int | 380 | static inline int |
351 | spi_async(struct spi_device *spi, struct spi_message *message) | 381 | spi_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 | */ |
532 | extern struct spi_device * | 561 | extern struct spi_device * |
533 | spi_new_device(struct spi_master *, struct spi_board_info *); | 562 | spi_new_device(struct spi_master *, struct spi_board_info *); |