aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/spi/spi.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/spi/spi.h')
-rw-r--r--include/linux/spi/spi.h38
1 files changed, 36 insertions, 2 deletions
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index a1d4ca290862..36c86ef51ff3 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -24,6 +24,9 @@
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#include <linux/completion.h>
27#include <linux/scatterlist.h>
28
29struct dma_chan;
27 30
28/* 31/*
29 * INTERFACES between SPI master-side drivers and SPI infrastructure. 32 * INTERFACES between SPI master-side drivers and SPI infrastructure.
@@ -266,6 +269,7 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
266 * @auto_runtime_pm: the core should ensure a runtime PM reference is held 269 * @auto_runtime_pm: the core should ensure a runtime PM reference is held
267 * while the hardware is prepared, using the parent 270 * while the hardware is prepared, using the parent
268 * device for the spidev 271 * device for the spidev
272 * @max_dma_len: Maximum length of a DMA transfer for the device.
269 * @prepare_transfer_hardware: a message will soon arrive from the queue 273 * @prepare_transfer_hardware: a message will soon arrive from the queue
270 * so the subsystem requests the driver to prepare the transfer hardware 274 * so the subsystem requests the driver to prepare the transfer hardware
271 * by issuing this call 275 * by issuing this call
@@ -273,7 +277,7 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
273 * message while queuing transfers that arrive in the meantime. When the 277 * message while queuing transfers that arrive in the meantime. When the
274 * driver is finished with this message, it must call 278 * driver is finished with this message, it must call
275 * spi_finalize_current_message() so the subsystem can issue the next 279 * spi_finalize_current_message() so the subsystem can issue the next
276 * transfer 280 * message
277 * @unprepare_transfer_hardware: there are currently no more messages on the 281 * @unprepare_transfer_hardware: there are currently no more messages on the
278 * queue so the subsystem notifies the driver that it may relax the 282 * queue so the subsystem notifies the driver that it may relax the
279 * hardware by issuing this call 283 * hardware by issuing this call
@@ -287,7 +291,10 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
287 * - return 1 if the transfer is still in progress. When 291 * - return 1 if the transfer is still in progress. When
288 * the driver is finished with this transfer it must 292 * the driver is finished with this transfer it must
289 * call spi_finalize_current_transfer() so the subsystem 293 * call spi_finalize_current_transfer() so the subsystem
290 * can issue the next transfer 294 * can issue the next transfer. Note: transfer_one and
295 * transfer_one_message are mutually exclusive; when both
296 * are set, the generic subsystem does not call your
297 * transfer_one callback.
291 * @unprepare_message: undo any work done by prepare_message(). 298 * @unprepare_message: undo any work done by prepare_message().
292 * @cs_gpios: Array of GPIOs to use as chip select lines; one per CS 299 * @cs_gpios: Array of GPIOs to use as chip select lines; one per CS
293 * number. Any individual value may be -ENOENT for CS lines that 300 * number. Any individual value may be -ENOENT for CS lines that
@@ -345,6 +352,8 @@ struct spi_master {
345#define SPI_MASTER_HALF_DUPLEX BIT(0) /* can't do full duplex */ 352#define SPI_MASTER_HALF_DUPLEX BIT(0) /* can't do full duplex */
346#define SPI_MASTER_NO_RX BIT(1) /* can't do buffer read */ 353#define SPI_MASTER_NO_RX BIT(1) /* can't do buffer read */
347#define SPI_MASTER_NO_TX BIT(2) /* can't do buffer write */ 354#define SPI_MASTER_NO_TX BIT(2) /* can't do buffer write */
355#define SPI_MASTER_MUST_RX BIT(3) /* requires rx */
356#define SPI_MASTER_MUST_TX BIT(4) /* requires tx */
348 357
349 /* lock and mutex for SPI bus locking */ 358 /* lock and mutex for SPI bus locking */
350 spinlock_t bus_lock_spinlock; 359 spinlock_t bus_lock_spinlock;
@@ -387,6 +396,17 @@ struct spi_master {
387 void (*cleanup)(struct spi_device *spi); 396 void (*cleanup)(struct spi_device *spi);
388 397
389 /* 398 /*
399 * Used to enable core support for DMA handling, if can_dma()
400 * exists and returns true then the transfer will be mapped
401 * prior to transfer_one() being called. The driver should
402 * not modify or store xfer and dma_tx and dma_rx must be set
403 * while the device is prepared.
404 */
405 bool (*can_dma)(struct spi_master *master,
406 struct spi_device *spi,
407 struct spi_transfer *xfer);
408
409 /*
390 * These hooks are for drivers that want to use the generic 410 * These hooks are for drivers that want to use the generic
391 * master transfer queueing mechanism. If these are used, the 411 * master transfer queueing mechanism. If these are used, the
392 * transfer() function above must NOT be specified by the driver. 412 * transfer() function above must NOT be specified by the driver.
@@ -404,7 +424,9 @@ struct spi_master {
404 bool rt; 424 bool rt;
405 bool auto_runtime_pm; 425 bool auto_runtime_pm;
406 bool cur_msg_prepared; 426 bool cur_msg_prepared;
427 bool cur_msg_mapped;
407 struct completion xfer_completion; 428 struct completion xfer_completion;
429 size_t max_dma_len;
408 430
409 int (*prepare_transfer_hardware)(struct spi_master *master); 431 int (*prepare_transfer_hardware)(struct spi_master *master);
410 int (*transfer_one_message)(struct spi_master *master, 432 int (*transfer_one_message)(struct spi_master *master,
@@ -425,6 +447,14 @@ struct spi_master {
425 447
426 /* gpio chip select */ 448 /* gpio chip select */
427 int *cs_gpios; 449 int *cs_gpios;
450
451 /* DMA channels for use with core dmaengine helpers */
452 struct dma_chan *dma_tx;
453 struct dma_chan *dma_rx;
454
455 /* dummy data for full duplex devices */
456 void *dummy_rx;
457 void *dummy_tx;
428}; 458};
429 459
430static inline void *spi_master_get_devdata(struct spi_master *master) 460static inline void *spi_master_get_devdata(struct spi_master *master)
@@ -509,6 +539,8 @@ extern struct spi_master *spi_busnum_to_master(u16 busnum);
509 * (optionally) changing the chipselect status, then starting 539 * (optionally) changing the chipselect status, then starting
510 * the next transfer or completing this @spi_message. 540 * the next transfer or completing this @spi_message.
511 * @transfer_list: transfers are sequenced through @spi_message.transfers 541 * @transfer_list: transfers are sequenced through @spi_message.transfers
542 * @tx_sg: Scatterlist for transmit, currently not for client use
543 * @rx_sg: Scatterlist for receive, currently not for client use
512 * 544 *
513 * SPI transfers always write the same number of bytes as they read. 545 * SPI transfers always write the same number of bytes as they read.
514 * Protocol drivers should always provide @rx_buf and/or @tx_buf. 546 * Protocol drivers should always provide @rx_buf and/or @tx_buf.
@@ -576,6 +608,8 @@ struct spi_transfer {
576 608
577 dma_addr_t tx_dma; 609 dma_addr_t tx_dma;
578 dma_addr_t rx_dma; 610 dma_addr_t rx_dma;
611 struct sg_table tx_sg;
612 struct sg_table rx_sg;
579 613
580 unsigned cs_change:1; 614 unsigned cs_change:1;
581 unsigned tx_nbits:3; 615 unsigned tx_nbits:3;