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