This source file includes following definitions.
- amdtp_stream_running
- amdtp_streaming_error
- amdtp_stream_pcm_running
- amdtp_stream_pcm_trigger
- cip_sfc_is_base_44100
- amdtp_stream_wait_callback
1
2 #ifndef SOUND_FIREWIRE_AMDTP_H_INCLUDED
3 #define SOUND_FIREWIRE_AMDTP_H_INCLUDED
4
5 #include <linux/err.h>
6 #include <linux/interrupt.h>
7 #include <linux/mutex.h>
8 #include <linux/sched.h>
9 #include <sound/asound.h>
10 #include "packets-buffer.h"
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 enum cip_flags {
40 CIP_NONBLOCKING = 0x00,
41 CIP_BLOCKING = 0x01,
42 CIP_EMPTY_WITH_TAG0 = 0x02,
43 CIP_DBC_IS_END_EVENT = 0x04,
44 CIP_WRONG_DBS = 0x08,
45 CIP_SKIP_DBC_ZERO_CHECK = 0x10,
46 CIP_EMPTY_HAS_WRONG_DBC = 0x20,
47 CIP_JUMBO_PAYLOAD = 0x40,
48 CIP_HEADER_WITHOUT_EOH = 0x80,
49 CIP_NO_HEADER = 0x100,
50 CIP_UNALIGHED_DBC = 0x200,
51 };
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76 enum cip_sfc {
77 CIP_SFC_32000 = 0,
78 CIP_SFC_44100 = 1,
79 CIP_SFC_48000 = 2,
80 CIP_SFC_88200 = 3,
81 CIP_SFC_96000 = 4,
82 CIP_SFC_176400 = 5,
83 CIP_SFC_192000 = 6,
84 CIP_SFC_COUNT
85 };
86
87 struct fw_unit;
88 struct fw_iso_context;
89 struct snd_pcm_substream;
90 struct snd_pcm_runtime;
91
92 enum amdtp_stream_direction {
93 AMDTP_OUT_STREAM = 0,
94 AMDTP_IN_STREAM
95 };
96
97 struct pkt_desc {
98 u32 cycle;
99 u32 syt;
100 unsigned int data_blocks;
101 unsigned int data_block_counter;
102 __be32 *ctx_payload;
103 };
104
105 struct amdtp_stream;
106 typedef unsigned int (*amdtp_stream_process_ctx_payloads_t)(
107 struct amdtp_stream *s,
108 const struct pkt_desc *desc,
109 unsigned int packets,
110 struct snd_pcm_substream *pcm);
111 struct amdtp_stream {
112 struct fw_unit *unit;
113 enum cip_flags flags;
114 enum amdtp_stream_direction direction;
115 struct mutex mutex;
116
117
118 struct fw_iso_context *context;
119 struct iso_packets_buffer buffer;
120 int packet_index;
121 struct pkt_desc *pkt_descs;
122 int tag;
123 union {
124 struct {
125 unsigned int ctx_header_size;
126
127
128 unsigned int max_ctx_payload_length;
129
130
131
132
133 unsigned int dbc_interval;
134 } tx;
135 struct {
136
137 unsigned int transfer_delay;
138 unsigned int data_block_state;
139 unsigned int last_syt_offset;
140 unsigned int syt_offset_state;
141
142
143 unsigned int fdf;
144 int syt_override;
145 } rx;
146 } ctx_data;
147
148
149 unsigned int source_node_id_field;
150 unsigned int data_block_quadlets;
151 unsigned int data_block_counter;
152 unsigned int sph;
153 unsigned int fmt;
154
155
156 enum cip_sfc sfc;
157 unsigned int syt_interval;
158
159
160 struct snd_pcm_substream *pcm;
161 struct tasklet_struct period_tasklet;
162 snd_pcm_uframes_t pcm_buffer_pointer;
163 unsigned int pcm_period_pointer;
164
165
166 bool callbacked;
167 wait_queue_head_t callback_wait;
168 u32 start_cycle;
169
170
171 void *protocol;
172 amdtp_stream_process_ctx_payloads_t process_ctx_payloads;
173
174
175 int channel;
176 int speed;
177 struct list_head list;
178 };
179
180 int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit,
181 enum amdtp_stream_direction dir, enum cip_flags flags,
182 unsigned int fmt,
183 amdtp_stream_process_ctx_payloads_t process_ctx_payloads,
184 unsigned int protocol_size);
185 void amdtp_stream_destroy(struct amdtp_stream *s);
186
187 int amdtp_stream_set_parameters(struct amdtp_stream *s, unsigned int rate,
188 unsigned int data_block_quadlets);
189 unsigned int amdtp_stream_get_max_payload(struct amdtp_stream *s);
190
191 void amdtp_stream_update(struct amdtp_stream *s);
192
193 int amdtp_stream_add_pcm_hw_constraints(struct amdtp_stream *s,
194 struct snd_pcm_runtime *runtime);
195
196 void amdtp_stream_pcm_prepare(struct amdtp_stream *s);
197 unsigned long amdtp_stream_pcm_pointer(struct amdtp_stream *s);
198 int amdtp_stream_pcm_ack(struct amdtp_stream *s);
199 void amdtp_stream_pcm_abort(struct amdtp_stream *s);
200
201 extern const unsigned int amdtp_syt_intervals[CIP_SFC_COUNT];
202 extern const unsigned int amdtp_rate_table[CIP_SFC_COUNT];
203
204
205
206
207
208
209
210 static inline bool amdtp_stream_running(struct amdtp_stream *s)
211 {
212 return !IS_ERR(s->context);
213 }
214
215
216
217
218
219
220
221
222 static inline bool amdtp_streaming_error(struct amdtp_stream *s)
223 {
224 return s->packet_index < 0;
225 }
226
227
228
229
230
231
232
233 static inline bool amdtp_stream_pcm_running(struct amdtp_stream *s)
234 {
235 return !!s->pcm;
236 }
237
238
239
240
241
242
243
244
245
246
247 static inline void amdtp_stream_pcm_trigger(struct amdtp_stream *s,
248 struct snd_pcm_substream *pcm)
249 {
250 WRITE_ONCE(s->pcm, pcm);
251 }
252
253 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
254 {
255 return sfc & 1;
256 }
257
258
259
260
261
262
263
264
265 static inline bool amdtp_stream_wait_callback(struct amdtp_stream *s,
266 unsigned int timeout)
267 {
268 return wait_event_timeout(s->callback_wait,
269 s->callbacked == true,
270 msecs_to_jiffies(timeout)) > 0;
271 }
272
273 struct amdtp_domain {
274 struct list_head streams;
275 };
276
277 int amdtp_domain_init(struct amdtp_domain *d);
278 void amdtp_domain_destroy(struct amdtp_domain *d);
279
280 int amdtp_domain_add_stream(struct amdtp_domain *d, struct amdtp_stream *s,
281 int channel, int speed);
282
283 int amdtp_domain_start(struct amdtp_domain *d);
284 void amdtp_domain_stop(struct amdtp_domain *d);
285
286 #endif