diff options
Diffstat (limited to 'include/linux/spi/spi.h')
-rw-r--r-- | include/linux/spi/spi.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index f62918946d86..38c2b925923d 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h | |||
@@ -57,6 +57,8 @@ extern struct bus_type spi_bus_type; | |||
57 | * @modalias: Name of the driver to use with this device, or an alias | 57 | * @modalias: Name of the driver to use with this device, or an alias |
58 | * for that name. This appears in the sysfs "modalias" attribute | 58 | * for that name. This appears in the sysfs "modalias" attribute |
59 | * for driver coldplugging, and in uevents used for hotplugging | 59 | * for driver coldplugging, and in uevents used for hotplugging |
60 | * @cs_gpio: gpio number of the chipselect line (optional, -EINVAL when | ||
61 | * when not using a GPIO line) | ||
60 | * | 62 | * |
61 | * A @spi_device is used to interchange data between an SPI slave | 63 | * A @spi_device is used to interchange data between an SPI slave |
62 | * (usually a discrete chip) and CPU memory. | 64 | * (usually a discrete chip) and CPU memory. |
@@ -258,6 +260,9 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv) | |||
258 | * @unprepare_transfer_hardware: there are currently no more messages on the | 260 | * @unprepare_transfer_hardware: there are currently no more messages on the |
259 | * queue so the subsystem notifies the driver that it may relax the | 261 | * queue so the subsystem notifies the driver that it may relax the |
260 | * hardware by issuing this call | 262 | * hardware by issuing this call |
263 | * @cs_gpios: Array of GPIOs to use as chip select lines; one per CS | ||
264 | * number. Any individual value may be -EINVAL for CS lines that | ||
265 | * are not GPIOs (driven by the SPI controller itself). | ||
261 | * | 266 | * |
262 | * Each SPI master controller can communicate with one or more @spi_device | 267 | * Each SPI master controller can communicate with one or more @spi_device |
263 | * children. These make a small bus, sharing MOSI, MISO and SCK signals | 268 | * children. These make a small bus, sharing MOSI, MISO and SCK signals |
@@ -591,6 +596,26 @@ spi_transfer_del(struct spi_transfer *t) | |||
591 | list_del(&t->transfer_list); | 596 | list_del(&t->transfer_list); |
592 | } | 597 | } |
593 | 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 | */ | ||
608 | static inline void | ||
609 | spi_message_init_with_transfers(struct spi_message *m, | ||
610 | struct 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 | |||
594 | /* 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 |
595 | * 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. |
596 | */ | 621 | */ |
@@ -683,6 +708,30 @@ spi_read(struct spi_device *spi, void *buf, size_t len) | |||
683 | return spi_sync(spi, &m); | 708 | return spi_sync(spi, &m); |
684 | } | 709 | } |
685 | 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 | */ | ||
724 | static inline int | ||
725 | spi_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 | |||
686 | /* this copies txbuf and rxbuf data; for small transfers only! */ | 735 | /* this copies txbuf and rxbuf data; for small transfers only! */ |
687 | extern int spi_write_then_read(struct spi_device *spi, | 736 | extern int spi_write_then_read(struct spi_device *spi, |
688 | const void *txbuf, unsigned n_tx, | 737 | const void *txbuf, unsigned n_tx, |