xref: /openbmc/linux/sound/firewire/amdtp-stream.h (revision f4a345e0)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2d67c46b9STakashi Sakamoto #ifndef SOUND_FIREWIRE_AMDTP_H_INCLUDED
3d67c46b9STakashi Sakamoto #define SOUND_FIREWIRE_AMDTP_H_INCLUDED
4d67c46b9STakashi Sakamoto 
5d67c46b9STakashi Sakamoto #include <linux/err.h>
6d67c46b9STakashi Sakamoto #include <linux/interrupt.h>
7d67c46b9STakashi Sakamoto #include <linux/mutex.h>
85955815eSTakashi Sakamoto #include <linux/sched.h>
9d67c46b9STakashi Sakamoto #include <sound/asound.h>
10d67c46b9STakashi Sakamoto #include "packets-buffer.h"
11d67c46b9STakashi Sakamoto 
12d67c46b9STakashi Sakamoto /**
13d67c46b9STakashi Sakamoto  * enum cip_flags - describes details of the streaming protocol
14d67c46b9STakashi Sakamoto  * @CIP_NONBLOCKING: In non-blocking mode, each packet contains
15d67c46b9STakashi Sakamoto  *	sample_rate/8000 samples, with rounding up or down to adjust
16d67c46b9STakashi Sakamoto  *	for clock skew and left-over fractional samples.  This should
17d67c46b9STakashi Sakamoto  *	be used if supported by the device.
18d67c46b9STakashi Sakamoto  * @CIP_BLOCKING: In blocking mode, each packet contains either zero or
19d67c46b9STakashi Sakamoto  *	SYT_INTERVAL samples, with these two types alternating so that
20d67c46b9STakashi Sakamoto  *	the overall sample rate comes out right.
21d67c46b9STakashi Sakamoto  * @CIP_EMPTY_WITH_TAG0: Only for in-stream. Empty in-packets have TAG0.
229dae017bSTakashi Sakamoto  * @CIP_DBC_IS_END_EVENT: The value of dbc in an packet corresponds to the end
239dae017bSTakashi Sakamoto  * of event in the packet. Out of IEC 61883.
24d67c46b9STakashi Sakamoto  * @CIP_WRONG_DBS: Only for in-stream. The value of dbs is wrong in in-packets.
25d67c46b9STakashi Sakamoto  *	The value of data_block_quadlets is used instead of reported value.
26d67c46b9STakashi Sakamoto  * @CIP_SKIP_DBC_ZERO_CHECK: Only for in-stream.  Packets with zero in dbc is
27d67c46b9STakashi Sakamoto  *	skipped for detecting discontinuity.
28d67c46b9STakashi Sakamoto  * @CIP_EMPTY_HAS_WRONG_DBC: Only for in-stream. The value of dbc in empty
29d67c46b9STakashi Sakamoto  *	packet is wrong but the others are correct.
30d67c46b9STakashi Sakamoto  * @CIP_JUMBO_PAYLOAD: Only for in-stream. The number of data blocks in an
31d67c46b9STakashi Sakamoto  *	packet is larger than IEC 61883-6 defines. Current implementation
32d67c46b9STakashi Sakamoto  *	allows 5 times as large as IEC 61883-6 defines.
332128f78fSTakashi Sakamoto  * @CIP_HEADER_WITHOUT_EOH: Only for in-stream. CIP Header doesn't include
342128f78fSTakashi Sakamoto  *	valid EOH.
353b196c39STakashi Sakamoto  * @CIP_NO_HEADERS: a lack of headers in packets
36588f2e2cSTakashi Sakamoto  * @CIP_UNALIGHED_DBC: Only for in-stream. The value of dbc is not alighed to
37588f2e2cSTakashi Sakamoto  *	the value of current SYT_INTERVAL; e.g. initial value is not zero.
388070d265STakashi Sakamoto  * @CIP_UNAWARE_SYT: For outgoing packet, the value in SYT field of CIP is 0xffff.
398070d265STakashi Sakamoto  *	For incoming packet, the value in SYT field of CIP is not handled.
40f4a345e0STakashi Sakamoto  * @CIP_DBC_IS_PAYLOAD_QUADLETS: Available for incoming packet, and only effective with
41f4a345e0STakashi Sakamoto  *	CIP_DBC_IS_END_EVENT flag. The value of dbc field is the number of accumulated quadlets
42f4a345e0STakashi Sakamoto  *	in CIP payload, instead of the number of accumulated data blocks.
43d67c46b9STakashi Sakamoto  */
44d67c46b9STakashi Sakamoto enum cip_flags {
45d67c46b9STakashi Sakamoto 	CIP_NONBLOCKING		= 0x00,
46d67c46b9STakashi Sakamoto 	CIP_BLOCKING		= 0x01,
47dec63cc8STakashi Sakamoto 	CIP_EMPTY_WITH_TAG0	= 0x02,
48dec63cc8STakashi Sakamoto 	CIP_DBC_IS_END_EVENT	= 0x04,
49dec63cc8STakashi Sakamoto 	CIP_WRONG_DBS		= 0x08,
50dec63cc8STakashi Sakamoto 	CIP_SKIP_DBC_ZERO_CHECK	= 0x10,
5162f00e40STakashi Sakamoto 	CIP_EMPTY_HAS_WRONG_DBC	= 0x20,
5262f00e40STakashi Sakamoto 	CIP_JUMBO_PAYLOAD	= 0x40,
532128f78fSTakashi Sakamoto 	CIP_HEADER_WITHOUT_EOH	= 0x80,
543b196c39STakashi Sakamoto 	CIP_NO_HEADER		= 0x100,
55588f2e2cSTakashi Sakamoto 	CIP_UNALIGHED_DBC	= 0x200,
568070d265STakashi Sakamoto 	CIP_UNAWARE_SYT		= 0x400,
57f4a345e0STakashi Sakamoto 	CIP_DBC_IS_PAYLOAD_QUADLETS = 0x800,
58d67c46b9STakashi Sakamoto };
59d67c46b9STakashi Sakamoto 
60d67c46b9STakashi Sakamoto /**
61d67c46b9STakashi Sakamoto  * enum cip_sfc - supported Sampling Frequency Codes (SFCs)
62d67c46b9STakashi Sakamoto  * @CIP_SFC_32000:   32,000 data blocks
63d67c46b9STakashi Sakamoto  * @CIP_SFC_44100:   44,100 data blocks
64d67c46b9STakashi Sakamoto  * @CIP_SFC_48000:   48,000 data blocks
65d67c46b9STakashi Sakamoto  * @CIP_SFC_88200:   88,200 data blocks
66d67c46b9STakashi Sakamoto  * @CIP_SFC_96000:   96,000 data blocks
67d67c46b9STakashi Sakamoto  * @CIP_SFC_176400: 176,400 data blocks
68d67c46b9STakashi Sakamoto  * @CIP_SFC_192000: 192,000 data blocks
69d67c46b9STakashi Sakamoto  * @CIP_SFC_COUNT: the number of supported SFCs
70d67c46b9STakashi Sakamoto  *
71d67c46b9STakashi Sakamoto  * These values are used to show nominal Sampling Frequency Code in
72d67c46b9STakashi Sakamoto  * Format Dependent Field (FDF) of AMDTP packet header. In IEC 61883-6:2002,
73d67c46b9STakashi Sakamoto  * this code means the number of events per second. Actually the code
74d67c46b9STakashi Sakamoto  * represents the number of data blocks transferred per second in an AMDTP
75d67c46b9STakashi Sakamoto  * stream.
76d67c46b9STakashi Sakamoto  *
77d67c46b9STakashi Sakamoto  * In IEC 61883-6:2005, some extensions were added to support more types of
78d67c46b9STakashi Sakamoto  * data such as 'One Bit LInear Audio', therefore the meaning of SFC became
79d67c46b9STakashi Sakamoto  * different depending on the types.
80d67c46b9STakashi Sakamoto  *
81d67c46b9STakashi Sakamoto  * Currently our implementation is compatible with IEC 61883-6:2002.
82d67c46b9STakashi Sakamoto  */
83d67c46b9STakashi Sakamoto enum cip_sfc {
84d67c46b9STakashi Sakamoto 	CIP_SFC_32000  = 0,
85d67c46b9STakashi Sakamoto 	CIP_SFC_44100  = 1,
86d67c46b9STakashi Sakamoto 	CIP_SFC_48000  = 2,
87d67c46b9STakashi Sakamoto 	CIP_SFC_88200  = 3,
88d67c46b9STakashi Sakamoto 	CIP_SFC_96000  = 4,
89d67c46b9STakashi Sakamoto 	CIP_SFC_176400 = 5,
90d67c46b9STakashi Sakamoto 	CIP_SFC_192000 = 6,
91d67c46b9STakashi Sakamoto 	CIP_SFC_COUNT
92d67c46b9STakashi Sakamoto };
93d67c46b9STakashi Sakamoto 
94d67c46b9STakashi Sakamoto struct fw_unit;
95d67c46b9STakashi Sakamoto struct fw_iso_context;
96d67c46b9STakashi Sakamoto struct snd_pcm_substream;
97d67c46b9STakashi Sakamoto struct snd_pcm_runtime;
98d67c46b9STakashi Sakamoto 
99d67c46b9STakashi Sakamoto enum amdtp_stream_direction {
100d67c46b9STakashi Sakamoto 	AMDTP_OUT_STREAM = 0,
101d67c46b9STakashi Sakamoto 	AMDTP_IN_STREAM
102d67c46b9STakashi Sakamoto };
103d67c46b9STakashi Sakamoto 
10404130cf8STakashi Sakamoto struct pkt_desc {
10504130cf8STakashi Sakamoto 	u32 cycle;
10604130cf8STakashi Sakamoto 	u32 syt;
10704130cf8STakashi Sakamoto 	unsigned int data_blocks;
10804130cf8STakashi Sakamoto 	unsigned int data_block_counter;
10904130cf8STakashi Sakamoto 	__be32 *ctx_payload;
110cec371ffSTakashi Sakamoto 	struct list_head link;
11104130cf8STakashi Sakamoto };
11204130cf8STakashi Sakamoto 
113df075feeSTakashi Sakamoto struct amdtp_stream;
1147fc693e4STakashi Sakamoto typedef void (*amdtp_stream_process_ctx_payloads_t)(struct amdtp_stream *s,
115d2c104a3STakashi Sakamoto 						    const struct pkt_desc *desc,
1160cac60c7STakashi Sakamoto 						    unsigned int count,
117d2c104a3STakashi Sakamoto 						    struct snd_pcm_substream *pcm);
1182472cfb3STakashi Sakamoto 
1192472cfb3STakashi Sakamoto struct amdtp_domain;
120d67c46b9STakashi Sakamoto struct amdtp_stream {
121d67c46b9STakashi Sakamoto 	struct fw_unit *unit;
122ffe66bbeSTakashi Sakamoto 	// The combination of cip_flags enumeration-constants.
123ffe66bbeSTakashi Sakamoto 	unsigned int flags;
124d67c46b9STakashi Sakamoto 	enum amdtp_stream_direction direction;
125d67c46b9STakashi Sakamoto 	struct mutex mutex;
126d67c46b9STakashi Sakamoto 
127d67c46b9STakashi Sakamoto 	/* For packet processing. */
128d67c46b9STakashi Sakamoto 	struct fw_iso_context *context;
129d67c46b9STakashi Sakamoto 	struct iso_packets_buffer buffer;
130a0e02331STakashi Sakamoto 	unsigned int queue_size;
131d67c46b9STakashi Sakamoto 	int packet_index;
132f0117128STakashi Sakamoto 	struct pkt_desc *packet_descs;
133cec371ffSTakashi Sakamoto 	struct list_head packet_descs_list;
134f0117128STakashi Sakamoto 	struct pkt_desc *packet_descs_cursor;
1353b196c39STakashi Sakamoto 	int tag;
136d3d10a4aSTakashi Sakamoto 	union {
137d3d10a4aSTakashi Sakamoto 		struct {
138d3d10a4aSTakashi Sakamoto 			unsigned int ctx_header_size;
139d3d10a4aSTakashi Sakamoto 
140d3d10a4aSTakashi Sakamoto 			// limit for payload of iso packet.
141f11453c7STakashi Sakamoto 			unsigned int max_ctx_payload_length;
142d67c46b9STakashi Sakamoto 
143d3d10a4aSTakashi Sakamoto 			// For quirks of CIP headers.
144d3d10a4aSTakashi Sakamoto 			// Fixed interval of dbc between previos/current
145d3d10a4aSTakashi Sakamoto 			// packets.
146d3d10a4aSTakashi Sakamoto 			unsigned int dbc_interval;
147fb25dcc8STakashi Sakamoto 
148fb25dcc8STakashi Sakamoto 			// The device starts multiplexing events to the packet.
149fb25dcc8STakashi Sakamoto 			bool event_starts;
150f9e5ecdfSTakashi Sakamoto 
151f9e5ecdfSTakashi Sakamoto 			struct {
152f9e5ecdfSTakashi Sakamoto 				struct seq_desc *descs;
153f9e5ecdfSTakashi Sakamoto 				unsigned int size;
154cccddec4STakashi Sakamoto 				unsigned int pos;
155f9e5ecdfSTakashi Sakamoto 			} cache;
156d3d10a4aSTakashi Sakamoto 		} tx;
157d3d10a4aSTakashi Sakamoto 		struct {
158d3d10a4aSTakashi Sakamoto 			// To generate CIP header.
159d3d10a4aSTakashi Sakamoto 			unsigned int fdf;
16060dd4929STakashi Sakamoto 
16160dd4929STakashi Sakamoto 			// To generate constant hardware IRQ.
162e229853dSTakashi Sakamoto 			unsigned int event_count;
1636f24bb8aSTakashi Sakamoto 
16413d11f14STakashi Sakamoto 			// To calculate CIP data blocks and tstamp.
1656f24bb8aSTakashi Sakamoto 			struct {
1666f24bb8aSTakashi Sakamoto 				struct seq_desc *descs;
1676f24bb8aSTakashi Sakamoto 				unsigned int size;
168119c446aSTakashi Sakamoto 				unsigned int pos;
1696f24bb8aSTakashi Sakamoto 			} seq;
1706f24bb8aSTakashi Sakamoto 
1716f24bb8aSTakashi Sakamoto 			unsigned int data_block_state;
1726f24bb8aSTakashi Sakamoto 			unsigned int syt_offset_state;
1736f24bb8aSTakashi Sakamoto 			unsigned int last_syt_offset;
17439c2649cSTakashi Sakamoto 
17539c2649cSTakashi Sakamoto 			struct amdtp_stream *replay_target;
176c38d8cffSTakashi Sakamoto 			unsigned int cache_pos;
17760dd4929STakashi Sakamoto 		} rx;
17860dd4929STakashi Sakamoto 	} ctx_data;
179d3d10a4aSTakashi Sakamoto 
180d67c46b9STakashi Sakamoto 	/* For CIP headers. */
181d67c46b9STakashi Sakamoto 	unsigned int source_node_id_field;
182d67c46b9STakashi Sakamoto 	unsigned int data_block_quadlets;
183d67c46b9STakashi Sakamoto 	unsigned int data_block_counter;
1849863874fSTakashi Sakamoto 	unsigned int sph;
185d67c46b9STakashi Sakamoto 	unsigned int fmt;
186d67c46b9STakashi Sakamoto 
18713d11f14STakashi Sakamoto 	// Internal flags.
18813d11f14STakashi Sakamoto 	unsigned int transfer_delay;
189d67c46b9STakashi Sakamoto 	enum cip_sfc sfc;
190d67c46b9STakashi Sakamoto 	unsigned int syt_interval;
191d67c46b9STakashi Sakamoto 
192d67c46b9STakashi Sakamoto 	/* For a PCM substream processing. */
193d67c46b9STakashi Sakamoto 	struct snd_pcm_substream *pcm;
1944a9bfafcSTakashi Sakamoto 	snd_pcm_uframes_t pcm_buffer_pointer;
195d67c46b9STakashi Sakamoto 	unsigned int pcm_period_pointer;
196a36183f6STakashi Sakamoto 	unsigned int pcm_frame_multiplier;
197d67c46b9STakashi Sakamoto 
198bdaedca7STakashi Sakamoto 	// To start processing content of packets at the same cycle in several contexts for
199bdaedca7STakashi Sakamoto 	// each direction.
200b7c7699bSTakashi Sakamoto 	bool ready_processing;
201bdaedca7STakashi Sakamoto 	wait_queue_head_t ready_wait;
202705794c5STakashi Sakamoto 	unsigned int next_cycle;
203d67c46b9STakashi Sakamoto 
204df075feeSTakashi Sakamoto 	/* For backends to process data blocks. */
205df075feeSTakashi Sakamoto 	void *protocol;
2069a738ad1STakashi Sakamoto 	amdtp_stream_process_ctx_payloads_t process_ctx_payloads;
2076261f90bSTakashi Sakamoto 
2086261f90bSTakashi Sakamoto 	// For domain.
209157a53eeSTakashi Sakamoto 	int channel;
210157a53eeSTakashi Sakamoto 	int speed;
2116261f90bSTakashi Sakamoto 	struct list_head list;
2122472cfb3STakashi Sakamoto 	struct amdtp_domain *domain;
213d67c46b9STakashi Sakamoto };
214d67c46b9STakashi Sakamoto 
215d67c46b9STakashi Sakamoto int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit,
216ffe66bbeSTakashi Sakamoto 		      enum amdtp_stream_direction dir, unsigned int flags,
217df075feeSTakashi Sakamoto 		      unsigned int fmt,
2189a738ad1STakashi Sakamoto 		      amdtp_stream_process_ctx_payloads_t process_ctx_payloads,
219df075feeSTakashi Sakamoto 		      unsigned int protocol_size);
220d67c46b9STakashi Sakamoto void amdtp_stream_destroy(struct amdtp_stream *s);
221d67c46b9STakashi Sakamoto 
222df075feeSTakashi Sakamoto int amdtp_stream_set_parameters(struct amdtp_stream *s, unsigned int rate,
223a36183f6STakashi Sakamoto 				unsigned int data_block_quadlets, unsigned int pcm_frame_multiplier);
224d67c46b9STakashi Sakamoto unsigned int amdtp_stream_get_max_payload(struct amdtp_stream *s);
225d67c46b9STakashi Sakamoto 
226d67c46b9STakashi Sakamoto void amdtp_stream_update(struct amdtp_stream *s);
227d67c46b9STakashi Sakamoto 
228d67c46b9STakashi Sakamoto int amdtp_stream_add_pcm_hw_constraints(struct amdtp_stream *s,
229d67c46b9STakashi Sakamoto 					struct snd_pcm_runtime *runtime);
230df075feeSTakashi Sakamoto 
231d67c46b9STakashi Sakamoto void amdtp_stream_pcm_prepare(struct amdtp_stream *s);
232d67c46b9STakashi Sakamoto void amdtp_stream_pcm_abort(struct amdtp_stream *s);
233d67c46b9STakashi Sakamoto 
234d67c46b9STakashi Sakamoto extern const unsigned int amdtp_syt_intervals[CIP_SFC_COUNT];
235d67c46b9STakashi Sakamoto extern const unsigned int amdtp_rate_table[CIP_SFC_COUNT];
236d67c46b9STakashi Sakamoto 
237d67c46b9STakashi Sakamoto /**
238d67c46b9STakashi Sakamoto  * amdtp_stream_running - check stream is running or not
239d67c46b9STakashi Sakamoto  * @s: the AMDTP stream
240d67c46b9STakashi Sakamoto  *
241d67c46b9STakashi Sakamoto  * If this function returns true, the stream is running.
242d67c46b9STakashi Sakamoto  */
amdtp_stream_running(struct amdtp_stream * s)243d67c46b9STakashi Sakamoto static inline bool amdtp_stream_running(struct amdtp_stream *s)
244d67c46b9STakashi Sakamoto {
245d67c46b9STakashi Sakamoto 	return !IS_ERR(s->context);
246d67c46b9STakashi Sakamoto }
247d67c46b9STakashi Sakamoto 
248d67c46b9STakashi Sakamoto /**
249d67c46b9STakashi Sakamoto  * amdtp_streaming_error - check for streaming error
250d67c46b9STakashi Sakamoto  * @s: the AMDTP stream
251d67c46b9STakashi Sakamoto  *
252d67c46b9STakashi Sakamoto  * If this function returns true, the stream's packet queue has stopped due to
253d67c46b9STakashi Sakamoto  * an asynchronous error.
254d67c46b9STakashi Sakamoto  */
amdtp_streaming_error(struct amdtp_stream * s)255d67c46b9STakashi Sakamoto static inline bool amdtp_streaming_error(struct amdtp_stream *s)
256d67c46b9STakashi Sakamoto {
257d67c46b9STakashi Sakamoto 	return s->packet_index < 0;
258d67c46b9STakashi Sakamoto }
259d67c46b9STakashi Sakamoto 
260d67c46b9STakashi Sakamoto /**
261d67c46b9STakashi Sakamoto  * amdtp_stream_pcm_running - check PCM substream is running or not
262d67c46b9STakashi Sakamoto  * @s: the AMDTP stream
263d67c46b9STakashi Sakamoto  *
264d67c46b9STakashi Sakamoto  * If this function returns true, PCM substream in the AMDTP stream is running.
265d67c46b9STakashi Sakamoto  */
amdtp_stream_pcm_running(struct amdtp_stream * s)266d67c46b9STakashi Sakamoto static inline bool amdtp_stream_pcm_running(struct amdtp_stream *s)
267d67c46b9STakashi Sakamoto {
268d67c46b9STakashi Sakamoto 	return !!s->pcm;
269d67c46b9STakashi Sakamoto }
270d67c46b9STakashi Sakamoto 
271d67c46b9STakashi Sakamoto /**
272d67c46b9STakashi Sakamoto  * amdtp_stream_pcm_trigger - start/stop playback from a PCM device
273d67c46b9STakashi Sakamoto  * @s: the AMDTP stream
274d67c46b9STakashi Sakamoto  * @pcm: the PCM device to be started, or %NULL to stop the current device
275d67c46b9STakashi Sakamoto  *
276d67c46b9STakashi Sakamoto  * Call this function on a running isochronous stream to enable the actual
277d67c46b9STakashi Sakamoto  * transmission of PCM data.  This function should be called from the PCM
278d67c46b9STakashi Sakamoto  * device's .trigger callback.
279d67c46b9STakashi Sakamoto  */
amdtp_stream_pcm_trigger(struct amdtp_stream * s,struct snd_pcm_substream * pcm)280d67c46b9STakashi Sakamoto static inline void amdtp_stream_pcm_trigger(struct amdtp_stream *s,
281d67c46b9STakashi Sakamoto 					    struct snd_pcm_substream *pcm)
282d67c46b9STakashi Sakamoto {
2836aa7de05SMark Rutland 	WRITE_ONCE(s->pcm, pcm);
284d67c46b9STakashi Sakamoto }
285d67c46b9STakashi Sakamoto 
286cec371ffSTakashi Sakamoto /**
287cec371ffSTakashi Sakamoto  * amdtp_stream_next_packet_desc - retrieve next descriptor for amdtp packet.
288cec371ffSTakashi Sakamoto  * @s: the AMDTP stream
289cec371ffSTakashi Sakamoto  * @desc: the descriptor of packet
290cec371ffSTakashi Sakamoto  *
291cec371ffSTakashi Sakamoto  * This macro computes next descriptor so that the list of descriptors behaves circular queue.
292cec371ffSTakashi Sakamoto  */
293cec371ffSTakashi Sakamoto #define amdtp_stream_next_packet_desc(s, desc) \
294cec371ffSTakashi Sakamoto 	list_next_entry_circular(desc, &s->packet_descs_list, link)
295cec371ffSTakashi Sakamoto 
cip_sfc_is_base_44100(enum cip_sfc sfc)296d67c46b9STakashi Sakamoto static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
297d67c46b9STakashi Sakamoto {
298d67c46b9STakashi Sakamoto 	return sfc & 1;
299d67c46b9STakashi Sakamoto }
300d67c46b9STakashi Sakamoto 
30125babf29STakashi Sakamoto struct seq_desc {
30225babf29STakashi Sakamoto 	unsigned int syt_offset;
30325babf29STakashi Sakamoto 	unsigned int data_blocks;
30425babf29STakashi Sakamoto };
30525babf29STakashi Sakamoto 
3063ec3d7a3STakashi Sakamoto struct amdtp_domain {
3073ec3d7a3STakashi Sakamoto 	struct list_head streams;
308d68c3123STakashi Sakamoto 
309d68c3123STakashi Sakamoto 	unsigned int events_per_period;
310a0e02331STakashi Sakamoto 	unsigned int events_per_buffer;
31103b4816dSTakashi Sakamoto 
31203b4816dSTakashi Sakamoto 	struct amdtp_stream *irq_target;
31325babf29STakashi Sakamoto 
314d32872f3STakashi Sakamoto 	struct {
31526541cb1STakashi Sakamoto 		unsigned int tx_init_skip;
316da3623abSTakashi Sakamoto 		unsigned int tx_start;
3179b1fcd9bSTakashi Sakamoto 		unsigned int rx_start;
318da3623abSTakashi Sakamoto 	} processing_cycle;
319f9e5ecdfSTakashi Sakamoto 
320f9e5ecdfSTakashi Sakamoto 	struct {
3212f21a177STakashi Sakamoto 		bool enable:1;
3222f21a177STakashi Sakamoto 		bool on_the_fly:1;
323f9e5ecdfSTakashi Sakamoto 	} replay;
3243ec3d7a3STakashi Sakamoto };
3253ec3d7a3STakashi Sakamoto 
3263ec3d7a3STakashi Sakamoto int amdtp_domain_init(struct amdtp_domain *d);
3273ec3d7a3STakashi Sakamoto void amdtp_domain_destroy(struct amdtp_domain *d);
3283ec3d7a3STakashi Sakamoto 
329157a53eeSTakashi Sakamoto int amdtp_domain_add_stream(struct amdtp_domain *d, struct amdtp_stream *s,
330157a53eeSTakashi Sakamoto 			    int channel, int speed);
331157a53eeSTakashi Sakamoto 
3322f21a177STakashi Sakamoto int amdtp_domain_start(struct amdtp_domain *d, unsigned int tx_init_skip_cycles, bool replay_seq,
3332f21a177STakashi Sakamoto 		       bool replay_on_the_fly);
3346261f90bSTakashi Sakamoto void amdtp_domain_stop(struct amdtp_domain *d);
3356261f90bSTakashi Sakamoto 
amdtp_domain_set_events_per_period(struct amdtp_domain * d,unsigned int events_per_period,unsigned int events_per_buffer)336d68c3123STakashi Sakamoto static inline int amdtp_domain_set_events_per_period(struct amdtp_domain *d,
337a0e02331STakashi Sakamoto 						unsigned int events_per_period,
338a0e02331STakashi Sakamoto 						unsigned int events_per_buffer)
339d68c3123STakashi Sakamoto {
340d68c3123STakashi Sakamoto 	d->events_per_period = events_per_period;
341a0e02331STakashi Sakamoto 	d->events_per_buffer = events_per_buffer;
342d68c3123STakashi Sakamoto 
343d68c3123STakashi Sakamoto 	return 0;
344d68c3123STakashi Sakamoto }
345d68c3123STakashi Sakamoto 
346f890f9a0STakashi Sakamoto unsigned long amdtp_domain_stream_pcm_pointer(struct amdtp_domain *d,
347f890f9a0STakashi Sakamoto 					      struct amdtp_stream *s);
348e6dcc92fSTakashi Sakamoto int amdtp_domain_stream_pcm_ack(struct amdtp_domain *d, struct amdtp_stream *s);
349e6dcc92fSTakashi Sakamoto 
350bdaedca7STakashi Sakamoto /**
351bdaedca7STakashi Sakamoto  * amdtp_domain_wait_ready - sleep till being ready to process packets or timeout
352bdaedca7STakashi Sakamoto  * @d: the AMDTP domain
353bdaedca7STakashi Sakamoto  * @timeout_ms: msec till timeout
354bdaedca7STakashi Sakamoto  *
355bdaedca7STakashi Sakamoto  * If this function return false, the AMDTP domain should be stopped.
356bdaedca7STakashi Sakamoto  */
amdtp_domain_wait_ready(struct amdtp_domain * d,unsigned int timeout_ms)357bdaedca7STakashi Sakamoto static inline bool amdtp_domain_wait_ready(struct amdtp_domain *d, unsigned int timeout_ms)
358bdaedca7STakashi Sakamoto {
359bdaedca7STakashi Sakamoto 	struct amdtp_stream *s;
360bdaedca7STakashi Sakamoto 
361bdaedca7STakashi Sakamoto 	list_for_each_entry(s, &d->streams, list) {
362bdaedca7STakashi Sakamoto 		unsigned int j = msecs_to_jiffies(timeout_ms);
363bdaedca7STakashi Sakamoto 
364bdaedca7STakashi Sakamoto 		if (wait_event_interruptible_timeout(s->ready_wait, s->ready_processing, j) <= 0)
365bdaedca7STakashi Sakamoto 			return false;
366bdaedca7STakashi Sakamoto 	}
367bdaedca7STakashi Sakamoto 
368bdaedca7STakashi Sakamoto 	return true;
369bdaedca7STakashi Sakamoto }
370bdaedca7STakashi Sakamoto 
371d67c46b9STakashi Sakamoto #endif
372