diff options
Diffstat (limited to 'include/linux')
| -rw-r--r-- | include/linux/spi/spi.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index f62918946d86..7dbe58642525 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h | |||
| @@ -591,6 +591,26 @@ spi_transfer_del(struct spi_transfer *t) | |||
| 591 | list_del(&t->transfer_list); | 591 | list_del(&t->transfer_list); |
| 592 | } | 592 | } |
| 593 | 593 | ||
| 594 | /** | ||
| 595 | * spi_message_init_with_transfers - Initialize spi_message and append transfers | ||
| 596 | * @m: spi_message to be initialized | ||
| 597 | * @xfers: An array of spi transfers | ||
| 598 | * @num_xfers: Number of items in the xfer array | ||
| 599 | * | ||
| 600 | * This function initializes the given spi_message and adds each spi_transfer in | ||
| 601 | * the given array to the message. | ||
| 602 | */ | ||
| 603 | static inline void | ||
| 604 | spi_message_init_with_transfers(struct spi_message *m, | ||
| 605 | struct spi_transfer *xfers, unsigned int num_xfers) | ||
| 606 | { | ||
| 607 | unsigned int i; | ||
| 608 | |||
| 609 | spi_message_init(m); | ||
| 610 | for (i = 0; i < num_xfers; ++i) | ||
| 611 | spi_message_add_tail(&xfers[i], m); | ||
| 612 | } | ||
| 613 | |||
| 594 | /* It's fine to embed message and transaction structures in other data | 614 | /* It's fine to embed message and transaction structures in other data |
| 595 | * structures so long as you don't free them while they're in use. | 615 | * structures so long as you don't free them while they're in use. |
| 596 | */ | 616 | */ |
| @@ -683,6 +703,30 @@ spi_read(struct spi_device *spi, void *buf, size_t len) | |||
| 683 | return spi_sync(spi, &m); | 703 | return spi_sync(spi, &m); |
| 684 | } | 704 | } |
| 685 | 705 | ||
| 706 | /** | ||
| 707 | * spi_sync_transfer - synchronous SPI data transfer | ||
| 708 | * @spi: device with which data will be exchanged | ||
| 709 | * @xfers: An array of spi_transfers | ||
| 710 | * @num_xfers: Number of items in the xfer array | ||
| 711 | * Context: can sleep | ||
| 712 | * | ||
| 713 | * Does a synchronous SPI data transfer of the given spi_transfer array. | ||
| 714 | * | ||
| 715 | * For more specific semantics see spi_sync(). | ||
| 716 | * | ||
| 717 | * It returns zero on success, else a negative error code. | ||
| 718 | */ | ||
| 719 | static inline int | ||
| 720 | spi_sync_transfer(struct spi_device *spi, struct spi_transfer *xfers, | ||
| 721 | unsigned int num_xfers) | ||
| 722 | { | ||
| 723 | struct spi_message msg; | ||
| 724 | |||
| 725 | spi_message_init_with_transfers(&msg, xfers, num_xfers); | ||
| 726 | |||
| 727 | return spi_sync(spi, &msg); | ||
| 728 | } | ||
| 729 | |||
| 686 | /* this copies txbuf and rxbuf data; for small transfers only! */ | 730 | /* this copies txbuf and rxbuf data; for small transfers only! */ |
| 687 | extern int spi_write_then_read(struct spi_device *spi, | 731 | extern int spi_write_then_read(struct spi_device *spi, |
| 688 | const void *txbuf, unsigned n_tx, | 732 | const void *txbuf, unsigned n_tx, |
