1#ifndef SOUND_FIREWIRE_AMDTP_H_INCLUDED
2#define SOUND_FIREWIRE_AMDTP_H_INCLUDED
3
4#include <linux/err.h>
5#include <linux/interrupt.h>
6#include <linux/mutex.h>
7#include <linux/sched.h>
8#include <sound/asound.h>
9#include "packets-buffer.h"
10
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
36enum cip_flags {
37 CIP_NONBLOCKING = 0x00,
38 CIP_BLOCKING = 0x01,
39 CIP_EMPTY_WITH_TAG0 = 0x02,
40 CIP_DBC_IS_END_EVENT = 0x04,
41 CIP_WRONG_DBS = 0x08,
42 CIP_SKIP_DBC_ZERO_CHECK = 0x10,
43 CIP_EMPTY_HAS_WRONG_DBC = 0x20,
44 CIP_JUMBO_PAYLOAD = 0x40,
45 CIP_HEADER_WITHOUT_EOH = 0x80,
46 CIP_NO_HEADER = 0x100,
47};
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72enum cip_sfc {
73 CIP_SFC_32000 = 0,
74 CIP_SFC_44100 = 1,
75 CIP_SFC_48000 = 2,
76 CIP_SFC_88200 = 3,
77 CIP_SFC_96000 = 4,
78 CIP_SFC_176400 = 5,
79 CIP_SFC_192000 = 6,
80 CIP_SFC_COUNT
81};
82
83struct fw_unit;
84struct fw_iso_context;
85struct snd_pcm_substream;
86struct snd_pcm_runtime;
87
88enum amdtp_stream_direction {
89 AMDTP_OUT_STREAM = 0,
90 AMDTP_IN_STREAM
91};
92
93struct amdtp_stream;
94typedef unsigned int (*amdtp_stream_process_data_blocks_t)(
95 struct amdtp_stream *s,
96 __be32 *buffer,
97 unsigned int data_blocks,
98 unsigned int *syt);
99struct amdtp_stream {
100 struct fw_unit *unit;
101 enum cip_flags flags;
102 enum amdtp_stream_direction direction;
103 struct mutex mutex;
104
105
106 struct fw_iso_context *context;
107 struct iso_packets_buffer buffer;
108 int packet_index;
109 int tag;
110 int (*handle_packet)(struct amdtp_stream *s,
111 unsigned int payload_quadlets, unsigned int cycle,
112 unsigned int index);
113 unsigned int max_payload_length;
114
115
116 unsigned int source_node_id_field;
117 unsigned int data_block_quadlets;
118 unsigned int data_block_counter;
119 unsigned int sph;
120 unsigned int fmt;
121 unsigned int fdf;
122
123 unsigned int tx_dbc_interval;
124
125 unsigned int tx_first_dbc;
126
127
128 enum cip_sfc sfc;
129 unsigned int syt_interval;
130 unsigned int transfer_delay;
131 unsigned int data_block_state;
132 unsigned int last_syt_offset;
133 unsigned int syt_offset_state;
134
135
136 struct snd_pcm_substream *pcm;
137 struct tasklet_struct period_tasklet;
138 snd_pcm_uframes_t pcm_buffer_pointer;
139 unsigned int pcm_period_pointer;
140
141
142 bool callbacked;
143 wait_queue_head_t callback_wait;
144 u32 start_cycle;
145
146
147 void *protocol;
148 amdtp_stream_process_data_blocks_t process_data_blocks;
149};
150
151int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit,
152 enum amdtp_stream_direction dir, enum cip_flags flags,
153 unsigned int fmt,
154 amdtp_stream_process_data_blocks_t process_data_blocks,
155 unsigned int protocol_size);
156void amdtp_stream_destroy(struct amdtp_stream *s);
157
158int amdtp_stream_set_parameters(struct amdtp_stream *s, unsigned int rate,
159 unsigned int data_block_quadlets);
160unsigned int amdtp_stream_get_max_payload(struct amdtp_stream *s);
161
162int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed);
163void amdtp_stream_update(struct amdtp_stream *s);
164void amdtp_stream_stop(struct amdtp_stream *s);
165
166int amdtp_stream_add_pcm_hw_constraints(struct amdtp_stream *s,
167 struct snd_pcm_runtime *runtime);
168
169void amdtp_stream_pcm_prepare(struct amdtp_stream *s);
170unsigned long amdtp_stream_pcm_pointer(struct amdtp_stream *s);
171int amdtp_stream_pcm_ack(struct amdtp_stream *s);
172void amdtp_stream_pcm_abort(struct amdtp_stream *s);
173
174extern const unsigned int amdtp_syt_intervals[CIP_SFC_COUNT];
175extern const unsigned int amdtp_rate_table[CIP_SFC_COUNT];
176
177
178
179
180
181
182
183static inline bool amdtp_stream_running(struct amdtp_stream *s)
184{
185 return !IS_ERR(s->context);
186}
187
188
189
190
191
192
193
194
195static inline bool amdtp_streaming_error(struct amdtp_stream *s)
196{
197 return s->packet_index < 0;
198}
199
200
201
202
203
204
205
206static inline bool amdtp_stream_pcm_running(struct amdtp_stream *s)
207{
208 return !!s->pcm;
209}
210
211
212
213
214
215
216
217
218
219
220static inline void amdtp_stream_pcm_trigger(struct amdtp_stream *s,
221 struct snd_pcm_substream *pcm)
222{
223 ACCESS_ONCE(s->pcm) = pcm;
224}
225
226static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
227{
228 return sfc & 1;
229}
230
231
232
233
234
235
236
237
238static inline bool amdtp_stream_wait_callback(struct amdtp_stream *s,
239 unsigned int timeout)
240{
241 return wait_event_timeout(s->callback_wait,
242 s->callbacked == true,
243 msecs_to_jiffies(timeout)) > 0;
244}
245
246#endif
247