0001
0002 #ifndef SOUND_FIREWIRE_AMDTP_H_INCLUDED
0003 #define SOUND_FIREWIRE_AMDTP_H_INCLUDED
0004
0005 #include <linux/err.h>
0006 #include <linux/interrupt.h>
0007 #include <linux/mutex.h>
0008 #include <linux/sched.h>
0009 #include <sound/asound.h>
0010 #include "packets-buffer.h"
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 enum cip_flags {
0042 CIP_NONBLOCKING = 0x00,
0043 CIP_BLOCKING = 0x01,
0044 CIP_EMPTY_WITH_TAG0 = 0x02,
0045 CIP_DBC_IS_END_EVENT = 0x04,
0046 CIP_WRONG_DBS = 0x08,
0047 CIP_SKIP_DBC_ZERO_CHECK = 0x10,
0048 CIP_EMPTY_HAS_WRONG_DBC = 0x20,
0049 CIP_JUMBO_PAYLOAD = 0x40,
0050 CIP_HEADER_WITHOUT_EOH = 0x80,
0051 CIP_NO_HEADER = 0x100,
0052 CIP_UNALIGHED_DBC = 0x200,
0053 CIP_UNAWARE_SYT = 0x400,
0054 };
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079 enum cip_sfc {
0080 CIP_SFC_32000 = 0,
0081 CIP_SFC_44100 = 1,
0082 CIP_SFC_48000 = 2,
0083 CIP_SFC_88200 = 3,
0084 CIP_SFC_96000 = 4,
0085 CIP_SFC_176400 = 5,
0086 CIP_SFC_192000 = 6,
0087 CIP_SFC_COUNT
0088 };
0089
0090 struct fw_unit;
0091 struct fw_iso_context;
0092 struct snd_pcm_substream;
0093 struct snd_pcm_runtime;
0094
0095 enum amdtp_stream_direction {
0096 AMDTP_OUT_STREAM = 0,
0097 AMDTP_IN_STREAM
0098 };
0099
0100 struct pkt_desc {
0101 u32 cycle;
0102 u32 syt;
0103 unsigned int data_blocks;
0104 unsigned int data_block_counter;
0105 __be32 *ctx_payload;
0106 };
0107
0108 struct amdtp_stream;
0109 typedef unsigned int (*amdtp_stream_process_ctx_payloads_t)(
0110 struct amdtp_stream *s,
0111 const struct pkt_desc *desc,
0112 unsigned int packets,
0113 struct snd_pcm_substream *pcm);
0114
0115 struct amdtp_domain;
0116 struct amdtp_stream {
0117 struct fw_unit *unit;
0118
0119 unsigned int flags;
0120 enum amdtp_stream_direction direction;
0121 struct mutex mutex;
0122
0123
0124 struct fw_iso_context *context;
0125 struct iso_packets_buffer buffer;
0126 unsigned int queue_size;
0127 int packet_index;
0128 struct pkt_desc *pkt_descs;
0129 int tag;
0130 union {
0131 struct {
0132 unsigned int ctx_header_size;
0133
0134
0135 unsigned int max_ctx_payload_length;
0136
0137
0138
0139
0140 unsigned int dbc_interval;
0141
0142
0143 bool event_starts;
0144
0145 struct {
0146 struct seq_desc *descs;
0147 unsigned int size;
0148 unsigned int tail;
0149 } cache;
0150 } tx;
0151 struct {
0152
0153 unsigned int fdf;
0154
0155
0156 unsigned int event_count;
0157
0158
0159 struct {
0160 struct seq_desc *descs;
0161 unsigned int size;
0162 unsigned int tail;
0163 unsigned int head;
0164 } seq;
0165
0166 unsigned int data_block_state;
0167 unsigned int syt_offset_state;
0168 unsigned int last_syt_offset;
0169
0170 struct amdtp_stream *replay_target;
0171 unsigned int cache_head;
0172 } rx;
0173 } ctx_data;
0174
0175
0176 unsigned int source_node_id_field;
0177 unsigned int data_block_quadlets;
0178 unsigned int data_block_counter;
0179 unsigned int sph;
0180 unsigned int fmt;
0181
0182
0183 unsigned int transfer_delay;
0184 enum cip_sfc sfc;
0185 unsigned int syt_interval;
0186
0187
0188 struct snd_pcm_substream *pcm;
0189 snd_pcm_uframes_t pcm_buffer_pointer;
0190 unsigned int pcm_period_pointer;
0191
0192
0193
0194 bool ready_processing;
0195 wait_queue_head_t ready_wait;
0196 unsigned int next_cycle;
0197
0198
0199 void *protocol;
0200 amdtp_stream_process_ctx_payloads_t process_ctx_payloads;
0201
0202
0203 int channel;
0204 int speed;
0205 struct list_head list;
0206 struct amdtp_domain *domain;
0207 };
0208
0209 int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit,
0210 enum amdtp_stream_direction dir, unsigned int flags,
0211 unsigned int fmt,
0212 amdtp_stream_process_ctx_payloads_t process_ctx_payloads,
0213 unsigned int protocol_size);
0214 void amdtp_stream_destroy(struct amdtp_stream *s);
0215
0216 int amdtp_stream_set_parameters(struct amdtp_stream *s, unsigned int rate,
0217 unsigned int data_block_quadlets);
0218 unsigned int amdtp_stream_get_max_payload(struct amdtp_stream *s);
0219
0220 void amdtp_stream_update(struct amdtp_stream *s);
0221
0222 int amdtp_stream_add_pcm_hw_constraints(struct amdtp_stream *s,
0223 struct snd_pcm_runtime *runtime);
0224
0225 void amdtp_stream_pcm_prepare(struct amdtp_stream *s);
0226 void amdtp_stream_pcm_abort(struct amdtp_stream *s);
0227
0228 extern const unsigned int amdtp_syt_intervals[CIP_SFC_COUNT];
0229 extern const unsigned int amdtp_rate_table[CIP_SFC_COUNT];
0230
0231
0232
0233
0234
0235
0236
0237 static inline bool amdtp_stream_running(struct amdtp_stream *s)
0238 {
0239 return !IS_ERR(s->context);
0240 }
0241
0242
0243
0244
0245
0246
0247
0248
0249 static inline bool amdtp_streaming_error(struct amdtp_stream *s)
0250 {
0251 return s->packet_index < 0;
0252 }
0253
0254
0255
0256
0257
0258
0259
0260 static inline bool amdtp_stream_pcm_running(struct amdtp_stream *s)
0261 {
0262 return !!s->pcm;
0263 }
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274 static inline void amdtp_stream_pcm_trigger(struct amdtp_stream *s,
0275 struct snd_pcm_substream *pcm)
0276 {
0277 WRITE_ONCE(s->pcm, pcm);
0278 }
0279
0280 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
0281 {
0282 return sfc & 1;
0283 }
0284
0285 struct seq_desc {
0286 unsigned int syt_offset;
0287 unsigned int data_blocks;
0288 };
0289
0290 struct amdtp_domain {
0291 struct list_head streams;
0292
0293 unsigned int events_per_period;
0294 unsigned int events_per_buffer;
0295
0296 struct amdtp_stream *irq_target;
0297
0298 struct {
0299 unsigned int tx_init_skip;
0300 unsigned int tx_start;
0301 unsigned int rx_start;
0302 } processing_cycle;
0303
0304 struct {
0305 bool enable:1;
0306 bool on_the_fly:1;
0307 } replay;
0308 };
0309
0310 int amdtp_domain_init(struct amdtp_domain *d);
0311 void amdtp_domain_destroy(struct amdtp_domain *d);
0312
0313 int amdtp_domain_add_stream(struct amdtp_domain *d, struct amdtp_stream *s,
0314 int channel, int speed);
0315
0316 int amdtp_domain_start(struct amdtp_domain *d, unsigned int tx_init_skip_cycles, bool replay_seq,
0317 bool replay_on_the_fly);
0318 void amdtp_domain_stop(struct amdtp_domain *d);
0319
0320 static inline int amdtp_domain_set_events_per_period(struct amdtp_domain *d,
0321 unsigned int events_per_period,
0322 unsigned int events_per_buffer)
0323 {
0324 d->events_per_period = events_per_period;
0325 d->events_per_buffer = events_per_buffer;
0326
0327 return 0;
0328 }
0329
0330 unsigned long amdtp_domain_stream_pcm_pointer(struct amdtp_domain *d,
0331 struct amdtp_stream *s);
0332 int amdtp_domain_stream_pcm_ack(struct amdtp_domain *d, struct amdtp_stream *s);
0333
0334
0335
0336
0337
0338
0339
0340
0341 static inline bool amdtp_domain_wait_ready(struct amdtp_domain *d, unsigned int timeout_ms)
0342 {
0343 struct amdtp_stream *s;
0344
0345 list_for_each_entry(s, &d->streams, list) {
0346 unsigned int j = msecs_to_jiffies(timeout_ms);
0347
0348 if (wait_event_interruptible_timeout(s->ready_wait, s->ready_processing, j) <= 0)
0349 return false;
0350 }
0351
0352 return true;
0353 }
0354
0355 #endif