1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2024 Analog Devices Inc.
4  * Copyright (C) 2024 BayLibre, SAS
5  */
6 
7 #ifndef __LINUX_SPI_OFFLOAD_TYPES_H
8 #define __LINUX_SPI_OFFLOAD_TYPES_H
9 
10 #include <linux/bits.h>
11 #include <linux/types.h>
12 
13 struct device;
14 
15 /* This is write xfer but TX uses external data stream rather than tx_buf. */
16 #define SPI_OFFLOAD_XFER_TX_STREAM	BIT(0)
17 /* This is read xfer but RX uses external data stream rather than rx_buf. */
18 #define SPI_OFFLOAD_XFER_RX_STREAM	BIT(1)
19 
20 /* Offload can be triggered by external hardware event. */
21 #define SPI_OFFLOAD_CAP_TRIGGER			BIT(0)
22 /* Offload can record and then play back TX data when triggered. */
23 #define SPI_OFFLOAD_CAP_TX_STATIC_DATA		BIT(1)
24 /* Offload can get TX data from an external stream source. */
25 #define SPI_OFFLOAD_CAP_TX_STREAM_DMA		BIT(2)
26 /* Offload can send RX data to an external stream sink. */
27 #define SPI_OFFLOAD_CAP_RX_STREAM_DMA		BIT(3)
28 
29 /**
30  * struct spi_offload_config - offload configuration
31  *
32  * This is used to request an offload with specific configuration.
33  */
34 struct spi_offload_config {
35 	/** @capability_flags: required capabilities. See %SPI_OFFLOAD_CAP_* */
36 	u32 capability_flags;
37 };
38 
39 /**
40  * struct spi_offload - offload instance
41  */
42 struct spi_offload {
43 	/** @provider_dev: for get/put reference counting */
44 	struct device *provider_dev;
45 	/** @priv: provider driver private data */
46 	void *priv;
47 	/** @ops: callbacks for offload support */
48 	const struct spi_offload_ops *ops;
49 	/** @xfer_flags: %SPI_OFFLOAD_XFER_* flags supported by provider */
50 	u32 xfer_flags;
51 };
52 
53 enum spi_offload_trigger_type {
54 	/* Indication from SPI peripheral that data is read to read. */
55 	SPI_OFFLOAD_TRIGGER_DATA_READY,
56 	/* Trigger comes from a periodic source such as a clock. */
57 	SPI_OFFLOAD_TRIGGER_PERIODIC,
58 };
59 
60 struct spi_offload_trigger_periodic {
61 	u64 frequency_hz;
62 };
63 
64 struct spi_offload_trigger_config {
65 	/** @type: type discriminator for union */
66 	enum spi_offload_trigger_type type;
67 	union {
68 		struct spi_offload_trigger_periodic periodic;
69 	};
70 };
71 
72 /**
73  * struct spi_offload_ops - callbacks implemented by offload providers
74  */
75 struct spi_offload_ops {
76 	/**
77 	 * @trigger_enable: Optional callback to enable the trigger for the
78 	 * given offload instance.
79 	 */
80 	int (*trigger_enable)(struct spi_offload *offload);
81 	/**
82 	 * @trigger_disable: Optional callback to disable the trigger for the
83 	 * given offload instance.
84 	 */
85 	void (*trigger_disable)(struct spi_offload *offload);
86 	/**
87 	 * @tx_stream_request_dma_chan: Optional callback for controllers that
88 	 * have an offload where the TX data stream is connected directly to a
89 	 * DMA channel.
90 	 */
91 	struct dma_chan *(*tx_stream_request_dma_chan)(struct spi_offload *offload);
92 	/**
93 	 * @rx_stream_request_dma_chan: Optional callback for controllers that
94 	 * have an offload where the RX data stream is connected directly to a
95 	 * DMA channel.
96 	 */
97 	struct dma_chan *(*rx_stream_request_dma_chan)(struct spi_offload *offload);
98 };
99 
100 #endif /* __LINUX_SPI_OFFLOAD_TYPES_H */
101