diff options
Diffstat (limited to 'include/linux/spi/spi.h')
-rw-r--r-- | include/linux/spi/spi.h | 61 |
1 files changed, 59 insertions, 2 deletions
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 887116dbce2c..8c62ba74dd91 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <linux/mod_devicetable.h> | 23 | #include <linux/mod_devicetable.h> |
24 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
25 | #include <linux/kthread.h> | 25 | #include <linux/kthread.h> |
26 | #include <linux/completion.h> | ||
26 | 27 | ||
27 | /* | 28 | /* |
28 | * INTERFACES between SPI master-side drivers and SPI infrastructure. | 29 | * INTERFACES between SPI master-side drivers and SPI infrastructure. |
@@ -150,8 +151,7 @@ static inline void *spi_get_drvdata(struct spi_device *spi) | |||
150 | } | 151 | } |
151 | 152 | ||
152 | struct spi_message; | 153 | struct spi_message; |
153 | 154 | struct spi_transfer; | |
154 | |||
155 | 155 | ||
156 | /** | 156 | /** |
157 | * struct spi_driver - Host side "protocol" driver | 157 | * struct spi_driver - Host side "protocol" driver |
@@ -257,6 +257,9 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv) | |||
257 | * @queue_lock: spinlock to syncronise access to message queue | 257 | * @queue_lock: spinlock to syncronise access to message queue |
258 | * @queue: message queue | 258 | * @queue: message queue |
259 | * @cur_msg: the currently in-flight message | 259 | * @cur_msg: the currently in-flight message |
260 | * @cur_msg_prepared: spi_prepare_message was called for the currently | ||
261 | * in-flight message | ||
262 | * @xfer_completion: used by core tranfer_one_message() | ||
260 | * @busy: message pump is busy | 263 | * @busy: message pump is busy |
261 | * @running: message pump is running | 264 | * @running: message pump is running |
262 | * @rt: whether this queue is set to run as a realtime task | 265 | * @rt: whether this queue is set to run as a realtime task |
@@ -274,6 +277,16 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv) | |||
274 | * @unprepare_transfer_hardware: there are currently no more messages on the | 277 | * @unprepare_transfer_hardware: there are currently no more messages on the |
275 | * queue so the subsystem notifies the driver that it may relax the | 278 | * queue so the subsystem notifies the driver that it may relax the |
276 | * hardware by issuing this call | 279 | * hardware by issuing this call |
280 | * @set_cs: assert or deassert chip select, true to assert. May be called | ||
281 | * from interrupt context. | ||
282 | * @prepare_message: set up the controller to transfer a single message, | ||
283 | * for example doing DMA mapping. Called from threaded | ||
284 | * context. | ||
285 | * @transfer_one: transfer a single spi_transfer. When the | ||
286 | * driver is finished with this transfer it must call | ||
287 | * spi_finalize_current_transfer() so the subsystem can issue | ||
288 | * the next transfer | ||
289 | * @unprepare_message: undo any work done by prepare_message(). | ||
277 | * @cs_gpios: Array of GPIOs to use as chip select lines; one per CS | 290 | * @cs_gpios: Array of GPIOs to use as chip select lines; one per CS |
278 | * number. Any individual value may be -ENOENT for CS lines that | 291 | * number. Any individual value may be -ENOENT for CS lines that |
279 | * are not GPIOs (driven by the SPI controller itself). | 292 | * are not GPIOs (driven by the SPI controller itself). |
@@ -388,11 +401,25 @@ struct spi_master { | |||
388 | bool running; | 401 | bool running; |
389 | bool rt; | 402 | bool rt; |
390 | bool auto_runtime_pm; | 403 | bool auto_runtime_pm; |
404 | bool cur_msg_prepared; | ||
405 | struct completion xfer_completion; | ||
391 | 406 | ||
392 | int (*prepare_transfer_hardware)(struct spi_master *master); | 407 | int (*prepare_transfer_hardware)(struct spi_master *master); |
393 | int (*transfer_one_message)(struct spi_master *master, | 408 | int (*transfer_one_message)(struct spi_master *master, |
394 | struct spi_message *mesg); | 409 | struct spi_message *mesg); |
395 | int (*unprepare_transfer_hardware)(struct spi_master *master); | 410 | int (*unprepare_transfer_hardware)(struct spi_master *master); |
411 | int (*prepare_message)(struct spi_master *master, | ||
412 | struct spi_message *message); | ||
413 | int (*unprepare_message)(struct spi_master *master, | ||
414 | struct spi_message *message); | ||
415 | |||
416 | /* | ||
417 | * These hooks are for drivers that use a generic implementation | ||
418 | * of transfer_one_message() provied by the core. | ||
419 | */ | ||
420 | void (*set_cs)(struct spi_device *spi, bool enable); | ||
421 | int (*transfer_one)(struct spi_master *master, struct spi_device *spi, | ||
422 | struct spi_transfer *transfer); | ||
396 | 423 | ||
397 | /* gpio chip select */ | 424 | /* gpio chip select */ |
398 | int *cs_gpios; | 425 | int *cs_gpios; |
@@ -428,12 +455,15 @@ extern int spi_master_resume(struct spi_master *master); | |||
428 | /* Calls the driver make to interact with the message queue */ | 455 | /* Calls the driver make to interact with the message queue */ |
429 | extern struct spi_message *spi_get_next_queued_message(struct spi_master *master); | 456 | extern struct spi_message *spi_get_next_queued_message(struct spi_master *master); |
430 | extern void spi_finalize_current_message(struct spi_master *master); | 457 | extern void spi_finalize_current_message(struct spi_master *master); |
458 | extern void spi_finalize_current_transfer(struct spi_master *master); | ||
431 | 459 | ||
432 | /* the spi driver core manages memory for the spi_master classdev */ | 460 | /* the spi driver core manages memory for the spi_master classdev */ |
433 | extern struct spi_master * | 461 | extern struct spi_master * |
434 | spi_alloc_master(struct device *host, unsigned size); | 462 | spi_alloc_master(struct device *host, unsigned size); |
435 | 463 | ||
436 | extern int spi_register_master(struct spi_master *master); | 464 | extern int spi_register_master(struct spi_master *master); |
465 | extern int devm_spi_register_master(struct device *dev, | ||
466 | struct spi_master *master); | ||
437 | extern void spi_unregister_master(struct spi_master *master); | 467 | extern void spi_unregister_master(struct spi_master *master); |
438 | 468 | ||
439 | extern struct spi_master *spi_busnum_to_master(u16 busnum); | 469 | extern struct spi_master *spi_busnum_to_master(u16 busnum); |
@@ -823,6 +853,33 @@ static inline ssize_t spi_w8r16(struct spi_device *spi, u8 cmd) | |||
823 | return (status < 0) ? status : result; | 853 | return (status < 0) ? status : result; |
824 | } | 854 | } |
825 | 855 | ||
856 | /** | ||
857 | * spi_w8r16be - SPI synchronous 8 bit write followed by 16 bit big-endian read | ||
858 | * @spi: device with which data will be exchanged | ||
859 | * @cmd: command to be written before data is read back | ||
860 | * Context: can sleep | ||
861 | * | ||
862 | * This returns the (unsigned) sixteen bit number returned by the device in cpu | ||
863 | * endianness, or else a negative error code. Callable only from contexts that | ||
864 | * can sleep. | ||
865 | * | ||
866 | * This function is similar to spi_w8r16, with the exception that it will | ||
867 | * convert the read 16 bit data word from big-endian to native endianness. | ||
868 | * | ||
869 | */ | ||
870 | static inline ssize_t spi_w8r16be(struct spi_device *spi, u8 cmd) | ||
871 | |||
872 | { | ||
873 | ssize_t status; | ||
874 | __be16 result; | ||
875 | |||
876 | status = spi_write_then_read(spi, &cmd, 1, &result, 2); | ||
877 | if (status < 0) | ||
878 | return status; | ||
879 | |||
880 | return be16_to_cpu(result); | ||
881 | } | ||
882 | |||
826 | /*---------------------------------------------------------------------------*/ | 883 | /*---------------------------------------------------------------------------*/ |
827 | 884 | ||
828 | /* | 885 | /* |