Blame view
sound/firewire/amdtp-stream.h
8.34 KB
b24413180 License cleanup: ... |
1 |
/* SPDX-License-Identifier: GPL-2.0 */ |
31ef9134e ALSA: add LaCie F... |
2 3 |
#ifndef SOUND_FIREWIRE_AMDTP_H_INCLUDED #define SOUND_FIREWIRE_AMDTP_H_INCLUDED |
20b65dd04 ALSA: firewire: i... |
4 |
#include <linux/err.h> |
76fb87894 ALSA: firewire-li... |
5 |
#include <linux/interrupt.h> |
31ef9134e ALSA: add LaCie F... |
6 |
#include <linux/mutex.h> |
5955815e7 ALSA: firewire-li... |
7 |
#include <linux/sched.h> |
777fb574a ALSA: firewire-li... |
8 |
#include <sound/asound.h> |
31ef9134e ALSA: add LaCie F... |
9 10 11 |
#include "packets-buffer.h" /** |
be4a28940 ALSA: firewire-li... |
12 |
* enum cip_flags - describes details of the streaming protocol |
31ef9134e ALSA: add LaCie F... |
13 14 15 16 |
* @CIP_NONBLOCKING: In non-blocking mode, each packet contains * sample_rate/8000 samples, with rounding up or down to adjust * for clock skew and left-over fractional samples. This should * be used if supported by the device. |
e84d15f61 ALSA: dice, firew... |
17 18 19 |
* @CIP_BLOCKING: In blocking mode, each packet contains either zero or * SYT_INTERVAL samples, with these two types alternating so that * the overall sample rate comes out right. |
7ab566453 ALSA: fireworks/f... |
20 |
* @CIP_EMPTY_WITH_TAG0: Only for in-stream. Empty in-packets have TAG0. |
9dae017bf ALSA: firewire-li... |
21 22 |
* @CIP_DBC_IS_END_EVENT: The value of dbc in an packet corresponds to the end * of event in the packet. Out of IEC 61883. |
697022391 ALSA: fireworks/f... |
23 24 |
* @CIP_WRONG_DBS: Only for in-stream. The value of dbs is wrong in in-packets. * The value of data_block_quadlets is used instead of reported value. |
5f217f905 ALSA: firewire-li... |
25 |
* @CIP_SKIP_DBC_ZERO_CHECK: Only for in-stream. Packets with zero in dbc is |
b84b1a27b ALSA: fireworks/f... |
26 |
* skipped for detecting discontinuity. |
9d59124ca ALSA: bebob/firew... |
27 28 |
* @CIP_EMPTY_HAS_WRONG_DBC: Only for in-stream. The value of dbc in empty * packet is wrong but the others are correct. |
a2064710b ALSA: firewire-li... |
29 30 31 |
* @CIP_JUMBO_PAYLOAD: Only for in-stream. The number of data blocks in an * packet is larger than IEC 61883-6 defines. Current implementation * allows 5 times as large as IEC 61883-6 defines. |
2128f78f7 ALSA: firewire-li... |
32 33 |
* @CIP_HEADER_WITHOUT_EOH: Only for in-stream. CIP Header doesn't include * valid EOH. |
3b196c394 ALSA: firewire-li... |
34 |
* @CIP_NO_HEADERS: a lack of headers in packets |
588f2e2ca ALSA: firewire-li... |
35 36 |
* @CIP_UNALIGHED_DBC: Only for in-stream. The value of dbc is not alighed to * the value of current SYT_INTERVAL; e.g. initial value is not zero. |
31ef9134e ALSA: add LaCie F... |
37 |
*/ |
be4a28940 ALSA: firewire-li... |
38 |
enum cip_flags { |
7b3b0d858 ALSA: firewire-li... |
39 40 |
CIP_NONBLOCKING = 0x00, CIP_BLOCKING = 0x01, |
dec63cc8b ALSA: firewire-li... |
41 42 43 44 |
CIP_EMPTY_WITH_TAG0 = 0x02, CIP_DBC_IS_END_EVENT = 0x04, CIP_WRONG_DBS = 0x08, CIP_SKIP_DBC_ZERO_CHECK = 0x10, |
62f00e40b ALSA: firewire-li... |
45 46 |
CIP_EMPTY_HAS_WRONG_DBC = 0x20, CIP_JUMBO_PAYLOAD = 0x40, |
2128f78f7 ALSA: firewire-li... |
47 |
CIP_HEADER_WITHOUT_EOH = 0x80, |
3b196c394 ALSA: firewire-li... |
48 |
CIP_NO_HEADER = 0x100, |
588f2e2ca ALSA: firewire-li... |
49 |
CIP_UNALIGHED_DBC = 0x200, |
31ef9134e ALSA: add LaCie F... |
50 51 52 |
}; /** |
5f217f905 ALSA: firewire-li... |
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
* enum cip_sfc - supported Sampling Frequency Codes (SFCs) * @CIP_SFC_32000: 32,000 data blocks * @CIP_SFC_44100: 44,100 data blocks * @CIP_SFC_48000: 48,000 data blocks * @CIP_SFC_88200: 88,200 data blocks * @CIP_SFC_96000: 96,000 data blocks * @CIP_SFC_176400: 176,400 data blocks * @CIP_SFC_192000: 192,000 data blocks * @CIP_SFC_COUNT: the number of supported SFCs * * These values are used to show nominal Sampling Frequency Code in * Format Dependent Field (FDF) of AMDTP packet header. In IEC 61883-6:2002, * this code means the number of events per second. Actually the code * represents the number of data blocks transferred per second in an AMDTP * stream. * * In IEC 61883-6:2005, some extensions were added to support more types of * data such as 'One Bit LInear Audio', therefore the meaning of SFC became * different depending on the types. * * Currently our implementation is compatible with IEC 61883-6:2002. |
31ef9134e ALSA: add LaCie F... |
74 75 76 77 78 79 80 81 82 |
*/ enum cip_sfc { CIP_SFC_32000 = 0, CIP_SFC_44100 = 1, CIP_SFC_48000 = 2, CIP_SFC_88200 = 3, CIP_SFC_96000 = 4, CIP_SFC_176400 = 5, CIP_SFC_192000 = 6, |
a7304e3bf ALSA: dice: suppo... |
83 |
CIP_SFC_COUNT |
31ef9134e ALSA: add LaCie F... |
84 |
}; |
31ef9134e ALSA: add LaCie F... |
85 86 87 |
struct fw_unit; struct fw_iso_context; struct snd_pcm_substream; |
7b2d99fa6 ALSA: firewire-li... |
88 |
struct snd_pcm_runtime; |
31ef9134e ALSA: add LaCie F... |
89 |
|
3ff7e8f0d ALSA: firewire-li... |
90 91 92 93 |
enum amdtp_stream_direction { AMDTP_OUT_STREAM = 0, AMDTP_IN_STREAM }; |
04130cf8e ALSA: firewire-li... |
94 95 96 97 98 99 100 |
struct pkt_desc { u32 cycle; u32 syt; unsigned int data_blocks; unsigned int data_block_counter; __be32 *ctx_payload; }; |
df075feef ALSA: firewire-li... |
101 |
struct amdtp_stream; |
9a738ad1b ALSA: firewire-li... |
102 |
typedef unsigned int (*amdtp_stream_process_ctx_payloads_t)( |
df075feef ALSA: firewire-li... |
103 |
struct amdtp_stream *s, |
d2c104a34 ALSA: firewire-li... |
104 |
const struct pkt_desc *desc, |
9a738ad1b ALSA: firewire-li... |
105 |
unsigned int packets, |
d2c104a34 ALSA: firewire-li... |
106 |
struct snd_pcm_substream *pcm); |
be4a28940 ALSA: firewire-li... |
107 |
struct amdtp_stream { |
31ef9134e ALSA: add LaCie F... |
108 |
struct fw_unit *unit; |
be4a28940 ALSA: firewire-li... |
109 |
enum cip_flags flags; |
3ff7e8f0d ALSA: firewire-li... |
110 |
enum amdtp_stream_direction direction; |
31ef9134e ALSA: add LaCie F... |
111 |
struct mutex mutex; |
10b2b6dc1 ALSA: firewire-li... |
112 113 |
/* For packet processing. */ struct fw_iso_context *context; |
31ef9134e ALSA: add LaCie F... |
114 |
struct iso_packets_buffer buffer; |
ec00f5e44 ALSA: firewire-li... |
115 |
int packet_index; |
04130cf8e ALSA: firewire-li... |
116 |
struct pkt_desc *pkt_descs; |
3b196c394 ALSA: firewire-li... |
117 |
int tag; |
d3d10a4a1 ALSA: firewire-li... |
118 119 120 121 122 |
union { struct { unsigned int ctx_header_size; // limit for payload of iso packet. |
f11453c7c ALSA: firewire-li... |
123 |
unsigned int max_ctx_payload_length; |
d3d10a4a1 ALSA: firewire-li... |
124 125 126 127 128 |
// For quirks of CIP headers. // Fixed interval of dbc between previos/current // packets. unsigned int dbc_interval; |
d3d10a4a1 ALSA: firewire-li... |
129 130 131 132 133 134 135 136 137 138 |
} tx; struct { // To calculate CIP data blocks and tstamp. unsigned int transfer_delay; unsigned int data_block_state; unsigned int last_syt_offset; unsigned int syt_offset_state; // To generate CIP header. unsigned int fdf; |
3baf30532 ALSA: firewire-li... |
139 |
int syt_override; |
d3d10a4a1 ALSA: firewire-li... |
140 141 |
} rx; } ctx_data; |
10b2b6dc1 ALSA: firewire-li... |
142 143 144 145 |
/* For CIP headers. */ unsigned int source_node_id_field; unsigned int data_block_quadlets; |
31ef9134e ALSA: add LaCie F... |
146 |
unsigned int data_block_counter; |
9863874f0 ALSA: firewire-li... |
147 |
unsigned int sph; |
414ba022a ALSA: firewire-li... |
148 |
unsigned int fmt; |
31ef9134e ALSA: add LaCie F... |
149 |
|
10b2b6dc1 ALSA: firewire-li... |
150 151 152 |
/* Internal flags. */ enum cip_sfc sfc; unsigned int syt_interval; |
31ef9134e ALSA: add LaCie F... |
153 |
|
10b2b6dc1 ALSA: firewire-li... |
154 155 156 |
/* For a PCM substream processing. */ struct snd_pcm_substream *pcm; struct tasklet_struct period_tasklet; |
4a9bfafc6 ALSA: firewire-li... |
157 |
snd_pcm_uframes_t pcm_buffer_pointer; |
31ef9134e ALSA: add LaCie F... |
158 |
unsigned int pcm_period_pointer; |
83d8d72df ALSA: firewire-li... |
159 |
|
10b2b6dc1 ALSA: firewire-li... |
160 161 162 |
/* To wait for first packet. */ bool callbacked; wait_queue_head_t callback_wait; |
a04513f8b ALSA: firewire-li... |
163 |
u32 start_cycle; |
10b2b6dc1 ALSA: firewire-li... |
164 |
|
df075feef ALSA: firewire-li... |
165 166 |
/* For backends to process data blocks. */ void *protocol; |
9a738ad1b ALSA: firewire-li... |
167 |
amdtp_stream_process_ctx_payloads_t process_ctx_payloads; |
6261f90bd ALSA: firewire-li... |
168 169 |
// For domain. |
157a53eef ALSA: firewire-li... |
170 171 |
int channel; int speed; |
6261f90bd ALSA: firewire-li... |
172 |
struct list_head list; |
31ef9134e ALSA: add LaCie F... |
173 |
}; |
be4a28940 ALSA: firewire-li... |
174 |
int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit, |
df075feef ALSA: firewire-li... |
175 176 |
enum amdtp_stream_direction dir, enum cip_flags flags, unsigned int fmt, |
9a738ad1b ALSA: firewire-li... |
177 |
amdtp_stream_process_ctx_payloads_t process_ctx_payloads, |
df075feef ALSA: firewire-li... |
178 |
unsigned int protocol_size); |
be4a28940 ALSA: firewire-li... |
179 |
void amdtp_stream_destroy(struct amdtp_stream *s); |
31ef9134e ALSA: add LaCie F... |
180 |
|
df075feef ALSA: firewire-li... |
181 182 |
int amdtp_stream_set_parameters(struct amdtp_stream *s, unsigned int rate, unsigned int data_block_quadlets); |
be4a28940 ALSA: firewire-li... |
183 |
unsigned int amdtp_stream_get_max_payload(struct amdtp_stream *s); |
31ef9134e ALSA: add LaCie F... |
184 |
|
be4a28940 ALSA: firewire-li... |
185 |
void amdtp_stream_update(struct amdtp_stream *s); |
31ef9134e ALSA: add LaCie F... |
186 |
|
7b2d99fa6 ALSA: firewire-li... |
187 188 |
int amdtp_stream_add_pcm_hw_constraints(struct amdtp_stream *s, struct snd_pcm_runtime *runtime); |
df075feef ALSA: firewire-li... |
189 |
|
be4a28940 ALSA: firewire-li... |
190 191 |
void amdtp_stream_pcm_prepare(struct amdtp_stream *s); unsigned long amdtp_stream_pcm_pointer(struct amdtp_stream *s); |
875becf84 ALSA: firewire: p... |
192 |
int amdtp_stream_pcm_ack(struct amdtp_stream *s); |
be4a28940 ALSA: firewire-li... |
193 |
void amdtp_stream_pcm_abort(struct amdtp_stream *s); |
31ef9134e ALSA: add LaCie F... |
194 |
|
c5280e996 ALSA: dice: make ... |
195 |
extern const unsigned int amdtp_syt_intervals[CIP_SFC_COUNT]; |
1017abed1 ALSA: firewire-li... |
196 |
extern const unsigned int amdtp_rate_table[CIP_SFC_COUNT]; |
a7304e3bf ALSA: dice: suppo... |
197 |
|
be4a28940 ALSA: firewire-li... |
198 199 200 201 202 203 204 |
/** * amdtp_stream_running - check stream is running or not * @s: the AMDTP stream * * If this function returns true, the stream is running. */ static inline bool amdtp_stream_running(struct amdtp_stream *s) |
20b65dd04 ALSA: firewire: i... |
205 206 207 |
{ return !IS_ERR(s->context); } |
31ef9134e ALSA: add LaCie F... |
208 |
/** |
be4a28940 ALSA: firewire-li... |
209 210 |
* amdtp_streaming_error - check for streaming error * @s: the AMDTP stream |
ec00f5e44 ALSA: firewire-li... |
211 212 213 214 |
* * If this function returns true, the stream's packet queue has stopped due to * an asynchronous error. */ |
be4a28940 ALSA: firewire-li... |
215 |
static inline bool amdtp_streaming_error(struct amdtp_stream *s) |
ec00f5e44 ALSA: firewire-li... |
216 217 218 219 220 |
{ return s->packet_index < 0; } /** |
83d8d72df ALSA: firewire-li... |
221 222 223 224 225 226 227 228 229 230 231 |
* amdtp_stream_pcm_running - check PCM substream is running or not * @s: the AMDTP stream * * If this function returns true, PCM substream in the AMDTP stream is running. */ static inline bool amdtp_stream_pcm_running(struct amdtp_stream *s) { return !!s->pcm; } /** |
be4a28940 ALSA: firewire-li... |
232 233 |
* amdtp_stream_pcm_trigger - start/stop playback from a PCM device * @s: the AMDTP stream |
31ef9134e ALSA: add LaCie F... |
234 235 236 237 238 239 |
* @pcm: the PCM device to be started, or %NULL to stop the current device * * Call this function on a running isochronous stream to enable the actual * transmission of PCM data. This function should be called from the PCM * device's .trigger callback. */ |
be4a28940 ALSA: firewire-li... |
240 241 |
static inline void amdtp_stream_pcm_trigger(struct amdtp_stream *s, struct snd_pcm_substream *pcm) |
31ef9134e ALSA: add LaCie F... |
242 |
{ |
6aa7de059 locking/atomics: ... |
243 |
WRITE_ONCE(s->pcm, pcm); |
31ef9134e ALSA: add LaCie F... |
244 |
} |
31ef9134e ALSA: add LaCie F... |
245 246 247 248 |
static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc) { return sfc & 1; } |
7b3b0d858 ALSA: firewire-li... |
249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
/** * amdtp_stream_wait_callback - sleep till callbacked or timeout * @s: the AMDTP stream * @timeout: msec till timeout * * If this function return false, the AMDTP stream should be stopped. */ static inline bool amdtp_stream_wait_callback(struct amdtp_stream *s, unsigned int timeout) { return wait_event_timeout(s->callback_wait, s->callbacked == true, msecs_to_jiffies(timeout)) > 0; } |
3ec3d7a3f ALSA: firewire-li... |
263 264 265 266 267 268 |
struct amdtp_domain { struct list_head streams; }; int amdtp_domain_init(struct amdtp_domain *d); void amdtp_domain_destroy(struct amdtp_domain *d); |
157a53eef ALSA: firewire-li... |
269 270 |
int amdtp_domain_add_stream(struct amdtp_domain *d, struct amdtp_stream *s, int channel, int speed); |
9b4702b06 ALSA: firewire-li... |
271 |
int amdtp_domain_start(struct amdtp_domain *d); |
6261f90bd ALSA: firewire-li... |
272 |
void amdtp_domain_stop(struct amdtp_domain *d); |
31ef9134e ALSA: add LaCie F... |
273 |
#endif |