Lines Matching defs:motu
3 * motu-stream.c - a part of driver for MOTU FireWire series
8 #include "motu.h"
28 static int keep_resources(struct snd_motu *motu, unsigned int rate,
36 if (stream == &motu->rx_stream) {
37 resources = &motu->rx_resources;
38 packet_format = &motu->rx_packet_formats;
40 if ((motu->spec->flags & SND_MOTU_SPEC_RX_MIDI_2ND_Q) ||
41 (motu->spec->flags & SND_MOTU_SPEC_RX_MIDI_3RD_Q))
44 resources = &motu->tx_resources;
45 packet_format = &motu->tx_packet_formats;
47 if ((motu->spec->flags & SND_MOTU_SPEC_TX_MIDI_2ND_Q) ||
48 (motu->spec->flags & SND_MOTU_SPEC_TX_MIDI_3RD_Q))
59 fw_parent_device(motu->unit)->max_speed);
62 static int begin_session(struct snd_motu *motu)
69 err = snd_motu_transaction_read(motu, ISOC_COMM_CONTROL_OFFSET, ®,
76 (motu->rx_resources.channel << RX_ISOC_COMM_CHANNEL_SHIFT) |
78 (motu->tx_resources.channel << TX_ISOC_COMM_CHANNEL_SHIFT);
81 return snd_motu_transaction_write(motu, ISOC_COMM_CONTROL_OFFSET, ®,
85 static void finish_session(struct snd_motu *motu)
91 err = snd_motu_protocol_switch_fetching_mode(motu, false);
95 err = snd_motu_transaction_read(motu, ISOC_COMM_CONTROL_OFFSET, ®,
105 snd_motu_transaction_write(motu, ISOC_COMM_CONTROL_OFFSET, ®,
109 int snd_motu_stream_cache_packet_formats(struct snd_motu *motu)
113 err = snd_motu_protocol_cache_packet_formats(motu);
117 if (motu->spec->flags & SND_MOTU_SPEC_TX_MIDI_2ND_Q) {
118 motu->tx_packet_formats.midi_flag_offset = 4;
119 motu->tx_packet_formats.midi_byte_offset = 6;
120 } else if (motu->spec->flags & SND_MOTU_SPEC_TX_MIDI_3RD_Q) {
121 motu->tx_packet_formats.midi_flag_offset = 8;
122 motu->tx_packet_formats.midi_byte_offset = 7;
125 if (motu->spec->flags & SND_MOTU_SPEC_RX_MIDI_2ND_Q) {
126 motu->rx_packet_formats.midi_flag_offset = 4;
127 motu->rx_packet_formats.midi_byte_offset = 6;
128 } else if (motu->spec->flags & SND_MOTU_SPEC_RX_MIDI_3RD_Q) {
129 motu->rx_packet_formats.midi_flag_offset = 8;
130 motu->rx_packet_formats.midi_byte_offset = 7;
136 int snd_motu_stream_reserve_duplex(struct snd_motu *motu, unsigned int rate,
143 err = snd_motu_protocol_get_clock_rate(motu, &curr_rate);
149 if (motu->substreams_counter == 0 || curr_rate != rate) {
150 amdtp_domain_stop(&motu->domain);
151 finish_session(motu);
153 fw_iso_resources_free(&motu->tx_resources);
154 fw_iso_resources_free(&motu->rx_resources);
156 kfree(motu->cache.event_offsets);
157 motu->cache.event_offsets = NULL;
159 err = snd_motu_protocol_set_clock_rate(motu, rate);
161 dev_err(&motu->unit->device,
166 err = snd_motu_stream_cache_packet_formats(motu);
170 err = keep_resources(motu, rate, &motu->tx_stream);
174 err = keep_resources(motu, rate, &motu->rx_stream);
176 fw_iso_resources_free(&motu->tx_resources);
180 err = amdtp_domain_set_events_per_period(&motu->domain,
183 fw_iso_resources_free(&motu->tx_resources);
184 fw_iso_resources_free(&motu->rx_resources);
188 motu->cache.size = motu->tx_stream.syt_interval * frames_per_buffer;
189 motu->cache.event_offsets = kcalloc(motu->cache.size, sizeof(*motu->cache.event_offsets),
191 if (!motu->cache.event_offsets) {
192 fw_iso_resources_free(&motu->tx_resources);
193 fw_iso_resources_free(&motu->rx_resources);
201 static int ensure_packet_formats(struct snd_motu *motu)
207 err = snd_motu_transaction_read(motu, PACKET_FORMAT_OFFSET, ®,
216 if (motu->spec->tx_fixed_pcm_chunks[0] == motu->tx_packet_formats.pcm_chunks[0])
218 if (motu->spec->rx_fixed_pcm_chunks[0] == motu->rx_packet_formats.pcm_chunks[0])
220 data |= fw_parent_device(motu->unit)->max_speed;
223 return snd_motu_transaction_write(motu, PACKET_FORMAT_OFFSET, ®,
227 int snd_motu_stream_start_duplex(struct snd_motu *motu)
229 unsigned int generation = motu->rx_resources.generation;
232 if (motu->substreams_counter == 0)
235 if (amdtp_streaming_error(&motu->rx_stream) ||
236 amdtp_streaming_error(&motu->tx_stream)) {
237 amdtp_domain_stop(&motu->domain);
238 finish_session(motu);
241 if (generation != fw_parent_device(motu->unit)->card->generation) {
242 err = fw_iso_resources_update(&motu->rx_resources);
246 err = fw_iso_resources_update(&motu->tx_resources);
251 if (!amdtp_stream_running(&motu->rx_stream)) {
252 int spd = fw_parent_device(motu->unit)->max_speed;
254 err = ensure_packet_formats(motu);
258 if (motu->spec->flags & SND_MOTU_SPEC_REGISTER_DSP) {
259 err = snd_motu_register_dsp_message_parser_init(motu);
262 } else if (motu->spec->flags & SND_MOTU_SPEC_COMMAND_DSP) {
263 err = snd_motu_command_dsp_message_parser_init(motu, motu->tx_stream.sfc);
268 err = begin_session(motu);
270 dev_err(&motu->unit->device,
275 err = amdtp_domain_add_stream(&motu->domain, &motu->tx_stream,
276 motu->tx_resources.channel, spd);
280 err = amdtp_domain_add_stream(&motu->domain, &motu->rx_stream,
281 motu->rx_resources.channel, spd);
285 motu->cache.tail = 0;
286 motu->cache.tx_cycle_count = UINT_MAX;
287 motu->cache.head = 0;
288 motu->cache.rx_cycle_count = UINT_MAX;
293 err = amdtp_domain_start(&motu->domain, 0, true, false);
297 if (!amdtp_domain_wait_ready(&motu->domain, READY_TIMEOUT_MS)) {
302 err = snd_motu_protocol_switch_fetching_mode(motu, true);
304 dev_err(&motu->unit->device,
313 amdtp_domain_stop(&motu->domain);
314 finish_session(motu);
318 void snd_motu_stream_stop_duplex(struct snd_motu *motu)
320 if (motu->substreams_counter == 0) {
321 amdtp_domain_stop(&motu->domain);
322 finish_session(motu);
324 fw_iso_resources_free(&motu->tx_resources);
325 fw_iso_resources_free(&motu->rx_resources);
327 kfree(motu->cache.event_offsets);
328 motu->cache.event_offsets = NULL;
332 static int init_stream(struct snd_motu *motu, struct amdtp_stream *s)
338 if (s == &motu->tx_stream) {
339 resources = &motu->tx_resources;
342 resources = &motu->rx_resources;
346 err = fw_iso_resources_init(resources, motu->unit);
350 err = amdtp_motu_init(s, motu->unit, dir, motu->spec, &motu->cache);
357 static void destroy_stream(struct snd_motu *motu, struct amdtp_stream *s)
361 if (s == &motu->tx_stream)
362 fw_iso_resources_destroy(&motu->tx_resources);
364 fw_iso_resources_destroy(&motu->rx_resources);
367 int snd_motu_stream_init_duplex(struct snd_motu *motu)
371 err = init_stream(motu, &motu->tx_stream);
375 err = init_stream(motu, &motu->rx_stream);
377 destroy_stream(motu, &motu->tx_stream);
381 err = amdtp_domain_init(&motu->domain);
383 destroy_stream(motu, &motu->tx_stream);
384 destroy_stream(motu, &motu->rx_stream);
392 void snd_motu_stream_destroy_duplex(struct snd_motu *motu)
394 amdtp_domain_destroy(&motu->domain);
396 destroy_stream(motu, &motu->rx_stream);
397 destroy_stream(motu, &motu->tx_stream);
399 motu->substreams_counter = 0;
402 static void motu_lock_changed(struct snd_motu *motu)
404 motu->dev_lock_changed = true;
405 wake_up(&motu->hwdep_wait);
408 int snd_motu_stream_lock_try(struct snd_motu *motu)
412 spin_lock_irq(&motu->lock);
414 if (motu->dev_lock_count < 0) {
419 if (motu->dev_lock_count++ == 0)
420 motu_lock_changed(motu);
423 spin_unlock_irq(&motu->lock);
427 void snd_motu_stream_lock_release(struct snd_motu *motu)
429 spin_lock_irq(&motu->lock);
431 if (WARN_ON(motu->dev_lock_count <= 0))
434 if (--motu->dev_lock_count == 0)
435 motu_lock_changed(motu);
437 spin_unlock_irq(&motu->lock);