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, ®, 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, ®, 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, ®, in finish_session()
105 snd_motu_transaction_write(motu, ISOC_COMM_CONTROL_OFFSET, ®, 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, ®, 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, ®, 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 err = begin_session(motu); in snd_motu_stream_start_duplex()
260 dev_err(&motu->unit->device, in snd_motu_stream_start_duplex()
265 err = amdtp_domain_add_stream(&motu->domain, &motu->tx_stream, in snd_motu_stream_start_duplex()
266 motu->tx_resources.channel, spd); in snd_motu_stream_start_duplex()
270 err = amdtp_domain_add_stream(&motu->domain, &motu->rx_stream, in snd_motu_stream_start_duplex()
271 motu->rx_resources.channel, spd); in snd_motu_stream_start_duplex()
275 motu->cache.tail = 0; in snd_motu_stream_start_duplex()
276 motu->cache.tx_cycle_count = UINT_MAX; in snd_motu_stream_start_duplex()
277 motu->cache.head = 0; in snd_motu_stream_start_duplex()
278 motu->cache.rx_cycle_count = UINT_MAX; in snd_motu_stream_start_duplex()
283 err = amdtp_domain_start(&motu->domain, 0, true, false); in snd_motu_stream_start_duplex()
287 if (!amdtp_domain_wait_ready(&motu->domain, READY_TIMEOUT_MS)) { in snd_motu_stream_start_duplex()
292 err = snd_motu_protocol_switch_fetching_mode(motu, true); in snd_motu_stream_start_duplex()
294 dev_err(&motu->unit->device, in snd_motu_stream_start_duplex()
303 amdtp_domain_stop(&motu->domain); in snd_motu_stream_start_duplex()
304 finish_session(motu); in snd_motu_stream_start_duplex()
308 void snd_motu_stream_stop_duplex(struct snd_motu *motu) in snd_motu_stream_stop_duplex() argument
310 if (motu->substreams_counter == 0) { in snd_motu_stream_stop_duplex()
311 amdtp_domain_stop(&motu->domain); in snd_motu_stream_stop_duplex()
312 finish_session(motu); in snd_motu_stream_stop_duplex()
314 fw_iso_resources_free(&motu->tx_resources); in snd_motu_stream_stop_duplex()
315 fw_iso_resources_free(&motu->rx_resources); in snd_motu_stream_stop_duplex()
317 kfree(motu->cache.event_offsets); in snd_motu_stream_stop_duplex()
318 motu->cache.event_offsets = NULL; in snd_motu_stream_stop_duplex()
322 static int init_stream(struct snd_motu *motu, struct amdtp_stream *s) in init_stream() argument
328 if (s == &motu->tx_stream) { in init_stream()
329 resources = &motu->tx_resources; in init_stream()
332 resources = &motu->rx_resources; in init_stream()
336 err = fw_iso_resources_init(resources, motu->unit); in init_stream()
340 err = amdtp_motu_init(s, motu->unit, dir, motu->spec, &motu->cache); in init_stream()
347 static void destroy_stream(struct snd_motu *motu, struct amdtp_stream *s) in destroy_stream() argument
351 if (s == &motu->tx_stream) in destroy_stream()
352 fw_iso_resources_destroy(&motu->tx_resources); in destroy_stream()
354 fw_iso_resources_destroy(&motu->rx_resources); in destroy_stream()
357 int snd_motu_stream_init_duplex(struct snd_motu *motu) in snd_motu_stream_init_duplex() argument
361 err = init_stream(motu, &motu->tx_stream); in snd_motu_stream_init_duplex()
365 err = init_stream(motu, &motu->rx_stream); in snd_motu_stream_init_duplex()
367 destroy_stream(motu, &motu->tx_stream); in snd_motu_stream_init_duplex()
371 err = amdtp_domain_init(&motu->domain); in snd_motu_stream_init_duplex()
373 destroy_stream(motu, &motu->tx_stream); in snd_motu_stream_init_duplex()
374 destroy_stream(motu, &motu->rx_stream); in snd_motu_stream_init_duplex()
382 void snd_motu_stream_destroy_duplex(struct snd_motu *motu) in snd_motu_stream_destroy_duplex() argument
384 amdtp_domain_destroy(&motu->domain); in snd_motu_stream_destroy_duplex()
386 destroy_stream(motu, &motu->rx_stream); in snd_motu_stream_destroy_duplex()
387 destroy_stream(motu, &motu->tx_stream); in snd_motu_stream_destroy_duplex()
389 motu->substreams_counter = 0; in snd_motu_stream_destroy_duplex()
392 static void motu_lock_changed(struct snd_motu *motu) in motu_lock_changed() argument
394 motu->dev_lock_changed = true; in motu_lock_changed()
395 wake_up(&motu->hwdep_wait); in motu_lock_changed()
398 int snd_motu_stream_lock_try(struct snd_motu *motu) in snd_motu_stream_lock_try() argument
402 spin_lock_irq(&motu->lock); in snd_motu_stream_lock_try()
404 if (motu->dev_lock_count < 0) { in snd_motu_stream_lock_try()
409 if (motu->dev_lock_count++ == 0) in snd_motu_stream_lock_try()
410 motu_lock_changed(motu); in snd_motu_stream_lock_try()
413 spin_unlock_irq(&motu->lock); in snd_motu_stream_lock_try()
417 void snd_motu_stream_lock_release(struct snd_motu *motu) in snd_motu_stream_lock_release() argument
419 spin_lock_irq(&motu->lock); in snd_motu_stream_lock_release()
421 if (WARN_ON(motu->dev_lock_count <= 0)) in snd_motu_stream_lock_release()
424 if (--motu->dev_lock_count == 0) in snd_motu_stream_lock_release()
425 motu_lock_changed(motu); in snd_motu_stream_lock_release()
427 spin_unlock_irq(&motu->lock); in snd_motu_stream_lock_release()