Lines Matching refs:motu

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